简体   繁体   English

缩放mesh1,mesh2的位置会自动更改吗?

[英]Scale mesh1, mesh2 automatically change it's position?

Basicially I like to connect the right side of mesh 1 to the left side of mesh 2. 基本上,我喜欢将网格1的右侧连接到网格2的左侧。

Currently, If I scale mesh1 I have to reposition mesh2 in order to have the same distance as before. 目前,如果我缩放mesh1,则必须重新定位mesh2,以使其具有与以前相同的距离。

So let's scale mesh 1 to z: 2 因此,将网格1缩放到z:2

var tween = new TWEEN.Tween(mesh1.scale).to({ z: 2 }, 1000).start();
tween.easing(TWEEN.Easing.Elastic.InOut);

In order to have the same distance to mesh 1 as before I have to reposition mesh 2 to z:1.5 为了与网格1保持相同的距离,我必须将网格2重新定位为z:1.5

var tween = new TWEEN.Tween(mesh2.position).to({ z: 1.5 }, 1000).start();
tween.easing(TWEEN.Easing.Elastic.InOut);

Are there any options in connecting the colored mesh faces. 连接彩色网格面时是否有任何选择? So If I scale mesh 1, mesh 2 automatically change it's position? 那么,如果我缩放网格1,则网格2会自动更改其位置?

在此处输入图片说明

... ...

var geometry = new THREE.BoxGeometry( 1, 1, 1 );


var mesh1 = new THREE.Mesh( geometry, 
new THREE.MeshPhongMaterial({color: 0x222222}));
mesh1 .position.set( 0, 0, 0 );
mesh1 .scale.set( 1, 1, 1 );
scene.add( mesh1 );

var mesh2 = new THREE.Mesh( geometry, 
new THREE.MeshPhongMaterial({color: 0x222222}));
mesh2 .position.set( 0, 0, 1 );
mesh2 .scale.set( 1, 1, 1 );
scene.add( mesh2 );

This is a geometric problem. 这是一个几何问题。

I haven't worked with three.js before, but I believe I have a geometric solution. 我以前没有使用three.js,但我相信我有一个几何解决方案。

Consider a third imaginary mesh, mesh3 , such that it is a combination of mesh1 and mesh2 . 考虑一个第三假想目, mesh3 ,使得它的组合mesh1mesh2

That is: 那是:

mesh1: position(0, 0, 0), scale(1, 1, 1);
mesh2: position(0, 0, 1), scale(1, 1, 1);
mesh3: position(0, 0, 0), scale(1, 1, 2); // Loosely, mesh3 = mesh1 + mesh2

Now to scale the structure by a scalar k , I propose two approaches: 现在,用标量k缩放结构,我提出了两种方法:

Approach 1: 方法1:

  1. Scale mesh1 and mesh3 each by k . 规模mesh1mesh3各自通过k
  2. Compute the difference between mesh3 and mesh1 , meshDiff . 计算之间的区别mesh3mesh1meshDiff
  3. Set mesh2 = meshDiff . 设置mesh2 = meshDiff

Approach 2: 方法二:

  1. Scale mesh3 by k . k缩放mesh3
  2. Compute two halves of mesh3 , mesh31 and mesh32 , such that they are oriented along mesh1 and mesh2 respectively. 计算mesh3mesh31mesh32两半, mesh3使它们分别沿着mesh2 mesh1mesh2定向。
  3. Set mesh1 = mesh31 and mesh2 = mesh32 . 设置mesh1 = mesh31mesh2 = mesh32

The approaches are very similar. 这些方法非常相似。 Keep three.js's API in mind to choose the best approach. 请记住three.js的API,以选择最佳方法。

Note: You needn't ever render mesh3 . 注意:不需要渲染mesh3 It only exists as a computational aid. 它仅作为计算辅助而存在。

Generality: 概论:

The idea presented above can be used in other situations as well, wherein geometries sharing a common feature need to be scaled. 上面提出的想法也可以用在其他情况下,其中共享一个公共特征的几何形状需要缩放。

Hope this helps. 希望这可以帮助。

PS: I realize that this answer is a little abstract. PS:我知道这个答案有点抽象。 Nonetheless, I hope it helps. 尽管如此,我希望它会有所帮助。

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

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