简体   繁体   English

如何在世界轴上拉伸(缩放)网格

[英]How to strech(scale) mesh on the world axis

There is an online 3d editor where you can edit individual meshes (move, scale, rotate). 有一个在线3d编辑器,您可以在其中编辑单个网格(移动,缩放,旋转)。 Ability to edit meshes implemented using custom transform controls which based on threejs's TransformControls code. 能够编辑使用基于Threejs的TransformControls代码的自定义转换控件实现的网格。 This is fragment from mousemove event: 这是mousemove事件的片段:

var intersect = intersectObjects(pointer, [xzPlane]); // intersect mouse's pointer with horizontal plane

var point = new THREE.Vector3();
point.copy(intersect.point);
point.sub(offset); // coords from mousedown event (from start stretching)

// some code for 'scale' value calculating base on 'point' variable
// var scale = ...;
//

 mesh.scale.x = scale;

This code works well if the mesh does not rotate. 如果网格不旋转,则此代码效果很好。

Requires scaling always happened to the world coordinate system. 需要缩放总是发生在世界坐标系上。 This is programming question 这是编程问题

For example, from this: 例如,从此:

旋转但未缩放

To this: 对此:

旋转,然后缩放

PS I think that custom mesh matrix must be created, but I have very little experience with matrices PS:我认为必须创建自定义网格矩阵,但是我对矩阵的经验很少

Thanks! 谢谢!

Instead of setting the rotation, like so: 而不是设置旋转,像这样:

mesh.rotation.set( Math.PI/4, 0, 0 );

apply the identical rotation to the geometry, instead: 将相同的旋转应用于几何,而不是:

var euler = new THREE.Euler( Math.PI / 4, 0, 0 );
mesh.geometry.applyMatrix( new THREE.Matrix4().makeRotationFromEuler( euler ) );

Now, you can set the scale and get the result you want. 现在,您可以设置比例并获得所需的结果。

mesh.scale.z = 2;

fiddle: http://jsfiddle.net/Tm7Ab/5/ 小提琴: http//jsfiddle.net/Tm7Ab/5/

three.js r.67 three.js r.67

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM