简体   繁体   English

如何将立方体网格转换为菱形

[英]How to transform a cube mesh into a diamond shape

Is there a way in three.js to turn a cube mesh shape into a diamond shape doing something like rotating the axis of the scale and then scaling it? 在three.js中,有没有一种方法可以将立方体网格形状转换为菱形形状,例如旋转刻度轴然后对其进行缩放? I'm trying to create a flat-ish diamond shape, something like x50,y50,x10. 我正在尝试创建扁平的菱形形状,例如x50,y50,x10。 If not, then what's the best way to create a diamond mesh, or a triangle mesh shape? 如果没有,那么创建菱形网格或三角形网格形状的最佳方法是什么?

If you just turn the cube on its end and scale x you'll still have a (now imbalanced) rectangle shape, but if you turn it on it's end, reorient the axis of scale somehow so it's stretching across the middle from point to point, now you could just squeeze the cube with scale x, and you'd have a nice diamond shape with a thin waist. 如果仅将立方体的一端旋转并缩放x,您仍然会拥有一个(现在是不平衡的)矩形形状,但是如果将其打开,请以某种方式重新调整缩放轴的方向,以便它从点到点在中间延伸,现在您可以用比例尺x挤压多维数据集,并且您会拥有漂亮的菱形形状和细腰线。

For clarification, here's a pic of the mesh shape I am trying to make, ideally the diamond shape on the left, but the triangle shape will do also. 为了澄清起见,下面是我要制作的网格形状的图片,理想情况下是左侧的菱形,但是三角形也可以。

这是我要制作的形状的照片

So, is there some way to rotate the axis of the scale? 那么,有什么方法可以旋转刻度轴吗? Is that what new THREE.Matrix4().makeTranslation is for? 那是new THREE.Matrix4().makeTranslation目的吗? How do I use that in this context? 在这种情况下如何使用?

See plunker of my attempt here . 在这里看到我的尝试大手笔 Clearly my cube.scale.x = 0.5; 显然我的cube.scale.x = 0.5; code is not working and needs the axis of transform to be shifted. 代码工作,需要变换所要移动的轴。

Here's the js: 这是js:

cube = new THREE.Mesh( geometry, material );
                cube.rotation.z = Math.PI / 4 ;
                cube.position.y = 35;
                cube.scale.x = 0.5;
                scene.add( cube );

If you want to convert your cube or box into a diamond shape, then the easiest method is to transform your geometry using a pattern like this one: 如果要将立方体或盒子转换为菱形,那么最简单的方法是使用如下所示的模式来转换几何:

var geometry = new THREE.BoxGeometry( 100, 100, 20 );

geometry.applyMatrix( new THREE.Matrix4().makeRotationZ( Math.PI / 4 ) );
geometry.applyMatrix( new THREE.Matrix4().makeScale( 1, 2, 1 ) ); // optional

Once you create your mesh, you still have the option of further scaling the mesh, itself. 创建网格后,您仍然可以选择进一步缩放网格本身。

mesh = new THREE.Mesh( geometry, material );
mesh.scale.set( sz, sy, sz );
scene.add( mesh );

three.js r.71 three.js r.71

What you need to do is to create a hierarchy of objects, the inner object will rotate around the z-axis and the outer object will scale on the x-axis. 您需要做的是创建对象层次结构,内部对象将绕z轴旋转,外部对象将在x轴上缩放。

mesh = new THREE.Mesh(geometry, material);
mesh.rotation.z = Math.PI / 4; // rotate by 45 degrees

var group = new THREE.Group();
group.add( mesh );
group.scale.x = 0.5; // scale by 0.5

scene.add( group );

Here is a fiddle: http://jsfiddle.net/3gxqboer/ 这是一个小提琴: http : //jsfiddle.net/3gxqboer/

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

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