javascript - WebGL : Updating attributes of an object in three. js

标签 javascript 3d three.js

我正在尝试为一个球体制作动画,增加半径。这是我的代码的相关片段..

function create_sphere(){

var sphereMaterial = new THREE.MeshLambertMaterial(
{
    color: 0xCC0000
});


var radius=2,segments=50,rings=50;  
sphere_geometry = new THREE.SphereGeometry(radius, segments, rings)
sphere = new THREE.Mesh(sphere_geometry,sphereMaterial);
sphere.position.y = -10;
sphere.position.needsUpdate = true;
sphere.geometry.dynamic = true;

}

这里是 animate 函数,我称之为 ..

function animate(){
sphere.position.y+=0.1;
sphere.geometry.radius +=0.1;
scene.add(sphere);
renderer.render(scene, camera);
requestAnimationFrame(animate);    
}

但我无法增加球体的半径,尽管它在 y 方向上完美地移动(暗示代码正在运行,并且没有错误)。 任何建议我可能是错的..

最佳答案

为了沿所有三个轴均匀缩放对象:

var sphereScale = 1.0;
...
sphereScale += 0.1;
sphere.scale.set(sphereScale,sphereScale,sphereScale); // x,y,z

关于javascript - WebGL : Updating attributes of an object in three. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16916761/

相关文章:

javascript - 简单的 jQuery 验证失败

javascript - Angular中多层指令之间的通信

javascript - 在 Threejs 平面上渲染 TMX map

three.js - 内部映射着色器自阴影

javascript - 将位置设置为其他对象的位置在 THREE.js 中不起作用

javascript - 使用 Javascript 获取设备的唯一 ID

javascript - 内联 youtube 视频在 iOS 上的 cordova 应用程序中不起作用

qt - 如何在 Qt3D 中绘制物体的轮廓?

arrays - OpenGL点数组

browser - Blender 与 Unity