How to strech(scale) mesh on the world axis

与世无争的帅哥 提交于 2019-12-13 04:43:18

问题


There is an online 3d editor where you can edit individual meshes (move, scale, rotate). Ability to edit meshes implemented using custom transform controls which based on threejs's TransformControls code. This is fragment from mousemove event:

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:

P.S. I think that custom mesh matrix must be created, but I have very little experience with matrices

Thanks!


回答1:


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/

three.js r.67



来源:https://stackoverflow.com/questions/22954255/how-to-strechscale-mesh-on-the-world-axis

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