How do I create resizable objects in THREE.JS

亡梦爱人 提交于 2019-12-22 12:37:37

问题


Lets say I have a simple cube and some variables specifying its width, height and depth.

How do I update my THREE mesh when the w/h/d changes? (I have everything else like changelisteners etc). Do I update vertices directly? Or is it easier to just redraw everything?


回答1:


I think easiest would be to create your cube with 1 unit dimensions (1x1x1). Then set the dimensions by scaling it:

mesh.scale.x = width;
mesh.scale.y = height;
mesh.scale.z = depth;

Not actually sure if mesh supports scale, if not, you can wrap it in Object3D

var obj = new THREE.Object3D();
    obj.add(mesh);
obj.scale.x = width;
obj.scale.y = height;
obj.scale.z = depth;

Nothing stops you from modifying the vertices directly. I think you need to specify geometry.dynamic=true; and then geometry.verticesNeedUpdate=true; in that case.



来源:https://stackoverflow.com/questions/14524348/how-do-i-create-resizable-objects-in-three-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!