Three.js - 只有一个球体可见

发布于 2024-12-18 07:26:32 字数 1826 浏览 0 评论 0原文

我正在尝试用 Three.js 构建 3 个红色球体...但运气不佳:-(

现在这是我的代码...任何人都可以告诉我我做错了什么? 我唯一看到的就是一个红色的球体......

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;
}

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黎夕旧梦 2024-12-25 07:26:32

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

Kind of late, but if all your spheres are in the same position (mesh.position.x = 0;) you will only see one sphere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文