简体   繁体   中英

three.js - only one sphere is visible

I'm trying to build 3 red Spheres with three.js...with no luck :-(

Now this is my code...anybody can tell me what I'm doing wrong?? The only thing I see is one red sphere...

var camera, scene, renderer,
mouseX = 0, mouseY = 0;

init();

function init() {

// Camera params : 
// field of view, aspect ratio for render output, near and far clipping plane. 
    camera = new THREE.Camera( 75, window.innerWidth / window.innerHeight, 1, 1000 );

// move the camera backwards so we can see stuff! 
// default position is 0,0,0.
camera.position.z = 1000;

// the scene contains all the 3D object data
    scene = new THREE.Scene();

// and the CanvasRenderer figures out what the 
// stuff in the scene looks like and draws it!  
    renderer = new THREE.CanvasRenderer();
    renderer.setSize( window.innerWidth, window.innerHeight );

// the renderer's canvas domElement is added to the body
    document.body.appendChild( renderer.domElement );

makeParticles(); 

// add the mouse move listener
document.addEventListener( 'mousemove', onMouseMove, false );

// render 30 times a second (should also look 
// at requestAnimationFrame) 
setInterval(update,1000/30); 

}

function update(){

//updateParticles();

// and render the scene from the perspective of the camera
renderer.render( scene, camera );

}

function makeParticles() { 

var geometry,material,mesh; 

    // create a sphere shape        
    geometry = new THREE.SphereGeometry( 50, 16, 16 );

    // give a shape red color
    material = new THREE.MeshLambertMaterial({color: 0xFF1111});    

    // create an object
    mesh = new THREE.Mesh( geometry, material );

    mesh.position.x = 0;

    // add it to the scene
    scene.addObject( mesh );
}

// called when the mouse moves
function onMouseMove( event ) {
// store the mouseX and mouseY position 
mouseX = event.clientX;
mouseY = event.clientY;
}

有点晚了,但是如果您所有的球都在同一位置(mesh.position.x = 0;),您只会看到一个球。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM