如何在 THREE.JS 中创建可调整大小的对象 [英] How do I create resizable objects in THREE.JS
问题描述
假设我有一个简单的立方体和一些指定其宽度、高度和深度的变量.
Lets say I have a simple cube and some variables specifying its width, height and depth.
当 w/h/d 发生变化时,我如何更新我的三个网格?(我有其他一切,如更改监听器等).我是否直接更新顶点?还是重绘一切更容易?
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 个单位尺寸 (1x1x1) 的立方体.然后通过缩放来设置尺寸:
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;
实际上不确定mesh是否支持缩放,如果不支持,您可以将其包裹在Object3D中
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;
没有什么可以阻止您直接修改顶点.我认为你需要指定 geometry.dynamic=true;
然后 geometry.verticesNeedUpdate=true;
在这种情况下.
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.
这篇关于如何在 THREE.JS 中创建可调整大小的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!