1

I am trying to animate a sphere, with increasing radii. here are the relevant snippets of my code ..

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;

}

and here is animate function , which I am calling ..

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

But I am unable to increase the radius of the sphere, although it is moving perfectly in y-direction,(implying code is working, and error free). Any suggestions what I might be wrong at ..

4

2 回答 2

3

为了沿所有三个轴统一缩放对象:

var sphereScale = 1.0;
...
sphereScale += 0.1;
sphere.scale.set(sphereScale,sphereScale,sphereScale); // x,y,z
于 2013-06-23T07:48:57.437 回答
2

radius 参数用于在创建几何图形时计算顶点的位置,之后更改其值将不起作用。要更改大小,您可以使用比例参数。如果要更改所有三个维度(x、y 和 z)的大小,则在您的动画函数中,替换

sphere.geometry.radius +=0.1;

sphere.scale.x += 0.1;
sphere.scale.y += 0.1;
sphere.scale.z += 0.1;

每次调用 animate 函数时,球体的大小都会增加原始大小的 10%。

希望这可以帮助!

于 2013-06-04T16:15:26.827 回答