Three.js 从MeshBasicMaterial切换到MeshStandardMaterial只会显示黑屏
这里有三个问题。当我在第10行调用MeshStandardMaterial时,不知道为什么我的代码不起作用。当我将其切换到MeshBasicMaterial时,它可以工作,但我需要MeshStandardMaterial的功能才能将.bumpMap添加到渲染中。有人能帮忙吗Three.js 从MeshBasicMaterial切换到MeshStandardMaterial只会显示黑屏,three.js,Three.js,这里有三个问题。当我在第10行调用MeshStandardMaterial时,不知道为什么我的代码不起作用。当我将其切换到MeshBasicMaterial时,它可以工作,但我需要MeshStandardMaterial的功能才能将.bumpMap添加到渲染中。有人能帮忙吗 const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.inne
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const geometry = new THREE.SphereGeometry(5,32,32);
// const texture = new THREE.TextureLoader().load( 'textures/8081_earthmap10k.jpg' );
const material = new THREE.MeshBasicMaterial( { color: 0xffffff } );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 15;
const animate = function () {
requestAnimationFrame( animate );
// cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render( scene, camera );
};
animate();
上面的代码工作正常,在黑色背景上显示旋转的白色(0xffffff)球体,但下面的代码不工作,它只显示黑色背景
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const geometry = new THREE.SphereGeometry(5,32,32);
// const texture = new THREE.TextureLoader().load( 'textures/8081_earthmap10k.jpg' );
const material = new THREE.MeshStandardMaterial( { color: 0xffffff } );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 15;
const animate = function () {
requestAnimationFrame( animate );
// cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render( scene, camera );
};
animate();
再一次,我在这两个方面唯一的改变是在第10行调用MeshStandardMaterial。。。我在这里遗漏了什么吗?
MeshBasicMaterial
是一种未发光的材质MeshStandardMaterial
是一种发光材质
因此,只要不向场景添加灯光或向材质添加环境贴图,使用
MeshStandardMaterial
的对象将是黑色的。NVM,我知道了。我刚才补充说
const color = 0xFFFFFF;
const intensity = 1;
const light = new THREE.AmbientLight(color, intensity);
scene.add(light);
添加我的球体后,它工作了!
干杯
感谢用户Mugen87澄清了这一点 哦,谢谢!那么,是否要向MeshStandardMaterial添加.lightMap属性或.lightMapIntensity以使其工作?