admin管理员组文章数量:1430056
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 ..
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 ..
Share Improve this question asked Jun 4, 2013 at 11:34 Tarun GabaTarun Gaba 1,1131 gold badge9 silver badges16 bronze badges 1- Seemingly related: stackoverflow./questions/16335467/…. – veritasetratio Commented Jun 4, 2013 at 11:41
2 Answers
Reset to default 3For uniform scaling of an object along all three axes:
var sphereScale = 1.0;
...
sphereScale += 0.1;
sphere.scale.set(sphereScale,sphereScale,sphereScale); // x,y,z
The radius parameter is used to calculate the position of the vertices when the geometry is created, and changing its value afterwards will have no effect. To change the size, you can use the scale parameters. If you want to change the size in all three dimensions (x, y, and z), then in your animate function, replace
sphere.geometry.radius +=0.1;
with
sphere.scale.x += 0.1;
sphere.scale.y += 0.1;
sphere.scale.z += 0.1;
which will increase the size of your sphere by 10% of the original size every time the animate function is called.
Hope this helps!
本文标签: javascriptWebGL Updating attributes of an object in threejsStack Overflow
版权声明:本文标题:javascript - WebGL: Updating attributes of an object in three.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745486557a2660409.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论