我制作了一个场景,我想在哪里想要制作立方体动画,但它一直给我一个错误: TypeError:无法读取undefined
的属性'rotation' function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
var time = Date.now() * 0.005;
camera.position.x += ( mouseX - camera.position.x ) * 0.05;
camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
camera.lookAt( scene.position );
for ( i = 0; i < scene.children.length; i ++ ) {
var object = scene.children[ i ];
if ( object instanceof THREE.PointCloud ) {
object.rotation.y += 0.01 ;
}
}
cube.rotation.y = time* 0.01;
renderer.render( scene, camera );
}
PoinCloud工作得很好,但是为了治愈它会给我一个错误。
有人可以帮我解决问题吗?
答案 0 :(得分:0)
您是否创建了这样的立方体?
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );
答案 1 :(得分:0)
无论如何,即使得到相同的代码,这是有效的(真的,我逐行检查它们),我将行改为:
for ( i = 0; i < scene.children.length; i ++ ) {
var object = scene.children[ i ];
if ( object instanceof THREE.Mesh ) {
object.rotation.y += 0.1 ;
}
}