Javascript 是否可以随时间更改widthSegments参数(从球体测量法)?

Javascript 是否可以随时间更改widthSegments参数(从球体测量法)?,javascript,three.js,Javascript,Three.js,使用Three.JS,我有以下球体几何体: var radius = 1 ; var widthSegments = 12; var heightSegments = 12; var geometry = new THREE.SphereGeometry(radius, widthSegments, heightSegments); const material = new THREE.PointsMaterial

使用Three.JS,我有以下球体几何体:

        var radius = 1 ;
        var widthSegments = 12;
        var heightSegments = 12;

        var geometry = new THREE.SphereGeometry(radius, widthSegments, heightSegments);
        const material = new THREE.PointsMaterial({
            color: 'white',
            size: 0.01, 
        });
我希望它的属性,
widthSegments
,随着时间的变化而变化。因此,我尝试创建以下函数:

  var ChangeWidth = function (){
        var time = Date.now() * 0.0005;
        widthSegments =  Math.sin(time * 0.7) * 30;
    }
然后将其添加到我的
update
函数中

   function update() 
        {
            requestAnimationFrame( update );
            renderer.render( scene, camera );
            animate();    
            ChangeWidth();
        }
但事实上,一切都没有改变。是否可以更改
宽度段
,从而更改变量
几何图形

编辑

使用新的
widthSegments
值删除并重新创建几何图形的新功能

function update() {
            scene.add(points);
            requestAnimationFrame( update );
            renderer.render( scene, camera );
            }
        update();

        while (widthSegments < 60){

        // I begin the loop by destroying the older geometry
        var DestroyGeometry = function() {
            scene.remove(points);
            points.geometry.dispose();
        }

        DestroyGeometry();    

        // Then, I create a new geometry
        const newGeometry = new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments );
        points = new THREE.Points( newGeometry, material );

        // Making sure the widthSegments is going to be increase
        widthSegments += 0.5; 

        // I end creating a new function to render the NewGeometry
        var Recreate = function() {
            scene.add(points);
            requestAnimationFrame( update );
            renderer.render( scene, camera );
        }

        Recreate();
        }
函数更新(){
场景。添加(点);
requestAnimationFrame(更新);
渲染器。渲染(场景、摄影机);
}
更新();
而(宽度小于60){
//我通过破坏旧的几何体开始循环
var DestroyGeometry=函数(){
场景。移除(点);
points.geometry.dispose();
}
破坏几何();
//然后,我创建一个新的几何体
const newGeometry=新的三个球体缓冲几何体(半径、宽度段、高度段);
点=新的三个点(新几何体、材质);
//确保宽度段将增加
宽度+=0.5;
//我结束创建一个新函数来渲染新几何体
var=function(){
场景。添加(点);
requestAnimationFrame(更新);
渲染器。渲染(场景、摄影机);
}
重新创建();
}
但这显然是行不通的。
DestroyGeometry()
Recreate()
函数都没有任何效果。我想知道它们是否可以放在
while
循环中

是否可以更改宽度段,从而更改可变几何体

否,仅在构造几何体时才计算所有几何体生成器的参数。如果要随时间更改参数,必须删除旧几何图形并创建新几何图形。比如:

场景。移除(点);
points.geometry.dispose();//自由内部缓冲区
const newGeometry=新的三个球体缓冲几何体(半径、宽度段、高度段);
点=新的三个点。点(新几何体、材质);//使用新几何图形和现有材质创建新点云
场景。添加(点);

BTW:
widthSegments
表示传递给
球墨测量的ctor的值(无参考!)。随着时间的推移更改
widthSegments
的值在任何情况下都不会产生任何效果。因此,理论上,我应该能够创建一个while循环,用所述新参数销毁并重新创建几何体,对吗?我想我成功了,但是循环太快了,我需要以某种方式放慢速度。我尝试了一些asyc并等待,但失败了。我用我的新功能编辑了原始帖子。你的方法不适合这种动画。我建议您研究变形目标动画的工作原理。