0

I am trying to figure out how I can have a mesh that repeats and duplicate it or clone it so it that it snaps to the corresponding. I believe there may be two parts of code.

  1. One to set the pivot of the object
  2. Snap to the last objects pivot maybe its a child object at that point?

Any help would be greatly appreciated.

nufftalon
  • 25
  • 6

1 Answers1

0

Your question is rather unclear to me but consider the following:

var overall = new THREE.Object3D();
for (var i=0; i<10; i+=1) {
  var tet = new THREE.Mesh(new THREE.TetrahedronGeometry(),
       new THREE.MeshLambertMaterial({color:0x909090}));
  tet.position.set(i-5,0,0);
  overall.add(tet);
}

now the overall object is composed of ten independent tetrahedrons.

Alternatively, you might want just one mesh, so:

var tetGeo = new THREE.TetrahedronGeometry();
var compGeo = new THREE.Geometry();
var mv = new THREE.Matrix4();
for (var i=0; i<10; i+=1) {
  var nt = tetGeo.clone();
  mv.makeTranslation(i-5,0,0);
  nt.appplyMatrix(mv);
  compGeo.merge(nt);
}
var overallMesh = new THREE.Mesh(compGeo,
       new THREE.MeshLambertMaterial({color:0x909090}));
bjorke
  • 3,295
  • 1
  • 16
  • 20
  • Thanks for the response and I apologize if I was unclear what I meant essentially was this: create an object set pivot point on that object (example change pivot to lower right corner), clone existing object offset to left or right snap to the last created objects pivot point. So basically we can snap duplicate objects side by side via the last respected objects pivot point. – nufftalon Aug 04 '15 at 13:37
  • I will experiment with the code you have provided, I believe the code you provided does the following: if index is less than 10 add 1, in the for loop it creates a cloned TetrahedronGeometry, make the Matrix translation less then 5 in the x axis, and merges the geometry. So this overall mesh would serve as parent to the 9 children? Is it something like that? – nufftalon Aug 04 '15 at 13:43
  • Yes. There isn't a notion of "pivot point" here like there is, say, in Maya or Blender. But the first example, to use language of programs like that, creates a group with ten smaller meshes, while the second example makes one large object merged from ten smaller ones. – bjorke Aug 04 '15 at 18:52