我正在尝试用飞机创建一个简单的场景。它将具有纹理
以下是代码:https://jsfiddle.net/0w6vfLt4/1/
但是纹理是黑色的。如果将map: texture
更改为color: white
,将会看到一个白色的平面。意味着其他所有东西都在工作,但是纹理
我在做什么错?以及如何解决这个问题?
答案 0 :(得分:1)
尝试将load函数与此处的回调一起使用https://threejs.org/docs/index.html#api/en/loaders/TextureLoader 并将纹理设置为像https://threejs.org/docs/#api/en/textures/Texture.repeat
那样重复
text
//Create a scene, camera and a renderer
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 10;
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
//Load the texture
var loader = new THREE.TextureLoader();
loader.load(
"https://cdn.glitch.com/62a3a7d1-3c19-4fb7-b1ef-a1c65ba38596%2Fboard.svg?v=1577426114562",
function (texture) {
var material = new THREE.MeshBasicMaterial({ map: texture });
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set( 4, 4 );
//Create a 8x8 plane with texture
var geometry = new THREE.PlaneBufferGeometry(8, 8);
//var material = new THREE.MeshBasicMaterial({ map: texture });
var plane = new THREE.Mesh(geometry, material);
scene.add(plane);
//Render the scene
renderer.render(scene, camera);
document.body.appendChild(renderer.domElement);
},
undefined,
function ( err ) {
console.error( 'An error happened.' );
}
);
body {
margin: 0;
font-family: monospace;
}
canvas {
width: 100%;
height: 100%;
}