javascript - Explode or move meshes away from center -


i trying move meshes ,of loaded obj file made of, away each other user can see meshes.

i trying mimic following example

demo

go link click on explode icon in ui tray , move slider.

what have done far have access meshes of model can apply function on them. far have looped through them , gave them random position vector.

it works fine , whole model explodes every mesh separately visible.

the problem

by giving random position vector move random place. want move them shared link. appreciated. new awesome threejs , love learn more. in advance

edit example code

    function getrandomarbitrary(min, max) {   return math.random() * (max - min) + min; } for(var = 0; < mainstand.children.length; i++) {     pos1 = getrandomarbitrary(1 , 2);     pos2 = getrandomarbitrary(1 , 2);     pos3 = getrandomarbitrary(1 , 2);     mainstand.children[i].position.set(pos1 , pos2 , pos3); } 

where mainstand loaded obj model

what want move every mesh away center position. done calculating vector between mesh position , center, , move mesh along direction:

var center = new three.vector3(0, 0, 0); var distancetomove = 0.1;  (var = 0; < mainstand.children.length; i++) {     var meshposition = mainstand.children[i].position;      var direction = meshposition.clone().sub(center).normalize();      var movethisfar = direction.clone().multiplyscalar(distancetomove);      mainstand.children[i].position.add(movethisfar); } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -