老师我的正方体不显示是为什么
来源:9-3 场景添加灯光

weixin_慕设计8093086
2024-12-24
import * as THREE from “three”;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.set(0,0,20)
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const geometry = new THREE.BoxGeometry( 2, 2,2 );
const material = new THREE.MeshLambertMaterial( { color: 0x00ff00 ,wireframe:true} );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );
const sphereGeometry = new THREE.SphereGeometry( 1, 10, 10 );
const sphereMaterial = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
const sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
sphere.position.x= 3
sphere.position.y= 1
scene.add( sphere );
const spotLight = new THREE.SpotLight( 0xffffff );
spotLight.position.set( -10, 10, 10 );
scene.add( spotLight );
function animate() {
requestAnimationFrame( animate );
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render( scene, camera );
}
animate();
1回答
-
yancy
2024-12-30
看代码没啥问题,看到你用了 lambert 材质,可以看下是不是光源没有覆盖到立方体上
00
相似问题