Icosahedron of tetrahedrons-like

Hi community!

There was a question on SO about how to build a geometry, like that:
изображение

So, here is a solution, that changes IcosahedronGeometry by splitting each face into three triangles.

Picture:

Example: https://codepen.io/prisoner849/full/yLXJgaK

Code:

THREE.BufferGeometry.prototype.tripleFace = tripleFace;
...
let g = new THREE.IcosahedronGeometry(5, 5).tripleFace();
...
function tripleFace(){
  let geometry = this;
  let pos = geometry.attributes.position;
  if (geometry.index != null) {
    console.log("Works for non-indexed geometries!");
    return;
  }
  
  let facesCount = pos.count / 3;
  
  let pts = [];
  let triangle = new THREE.Triangle();
  let a = new THREE.Vector3(), b = new THREE.Vector3, c = new THREE.Vector3();
  for(let i = 0; i < facesCount; i++){
    a.fromBufferAttribute(pos, i * 3 + 0);
    b.fromBufferAttribute(pos, i * 3 + 1);
    c.fromBufferAttribute(pos, i * 3 + 2);
    triangle.set(a, b, c);
    let o = new THREE.Vector3();
    triangle.getMidpoint(o);
    
    // make it tetrahedron-like
    let l = a.distanceTo(b);
    let h = Math.sqrt(3) / 2 * l;// scale it at your will
    let d = o.clone().normalize().setLength(h); 
    o.add(d);
    
    pts.push(
      o.clone(), a.clone(), b.clone(),
      o.clone(), b.clone(), c.clone(),
      o.clone(), c.clone(), a.clone()
    );
  }
  
  let g = new THREE.BufferGeometry().setFromPoints(pts);
  g.computeVertexNormals()
  return g;
}
4 Likes

Cool construction. :+1:

It reminds me of an example you can create with my Addon. Produces almost infinite many time-varying geometries with functions. For example as a sphere with four triangles per rectangle (waffled).

sandbox THREEf geometries

https://github.com/hofk/THREEf.js

2 Likes

Neat! You can make Epcot Center’s Spaceship Earth or a cool Disco ball with it!

1 Like

That was the first thought when I made it :smiley: :beers: