Basicially I like to connect the right side of mesh 1 to the left side of mesh 2.
Currently, If I scale mesh1 I have to reposition mesh2 in order to have the same distance as before.
So let's scale mesh 1 to 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
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?
...
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.
Consider a third imaginary mesh, mesh3
, such that it is a combination of mesh1
and mesh2
.
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:
Approach 1:
mesh1
and mesh3
each by k
. mesh3
and mesh1
, meshDiff
. mesh2
= meshDiff
. Approach 2:
mesh3
by k
. mesh3
, mesh31
and mesh32
, such that they are oriented along mesh1
and mesh2
respectively. mesh1
= mesh31
and mesh2
= mesh32
. The approaches are very similar. Keep three.js's API in mind to choose the best approach.
Note: You needn't ever render 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. Nonetheless, I hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.