我正在尝试为一个球体制作动画,增加半径。这是我的代码的相关片段..
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/