[英]three.js Cube Geometry - how to update parameters?
Possibly dumb question but here goes. 可能是愚蠢的问题,但这是可行的。 Three.js geometries have 'parameter' feilds associated with them, see the box geometry here...
Three.js几何具有与之关联的“参数”领域,请参见此处的框几何...
I am trying to update these parameters like this... 我正在尝试像这样更新这些参数...
var nodeSize = 10;
var geometry = new THREE.CubeGeometry(nodeSize, nodeSize, nodeSize);
mesh = new THREE.Mesh(geometry, new THREE.MeshNormalMaterial({side:THREE.DoubleSide}));
scene.add(mesh);
mesh.geometry.parameters.depth=20;
But of course, the geometry remains unchanged. 但是,当然,几何形状保持不变。 Is there a way of updating the geometry by editing these parameters?
是否可以通过编辑这些参数来更新几何?
fiddle here https://jsfiddle.net/kn3owveg/2/ 在这里摆弄https://jsfiddle.net/kn3owveg/2/
Any help appreciated! 任何帮助表示赞赏!
parameters.depth
is only used at geometry construction time. parameters.depth
仅在几何构造时使用。 it has no effect when modifying it. 修改时无效。 you can think of it as
read only
. 您可以将其视为
read only
。
Use the example at BoxGeometry and the gui on the right to see how to achieve what you want. 使用BoxGeometry上的示例和右侧的gui来查看如何实现所需的功能。
Gaitat is totally right, you can't change geometry with changing of parameters
. Gaitat是完全正确的,您无法通过更改
parameters
来更改几何。
And there can be another solution. 还有其他解决方案。 With scaling of your cube.
随着您的多维数据集缩放。
function setSize( myMesh, xSize, ySize, zSize){
scaleFactorX = xSize / myMesh.geometry.parameters.width;
scaleFactorY = ySize / myMesh.geometry.parameters.height;
scaleFactorZ = zSize / myMesh.geometry.parameters.depth;
myMesh.scale.set( scaleFactorX, scaleFactorY, scaleFactorZ );
}
...
setSize(mesh, 10, 10, 20);
更改参数后,需要再次render
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.