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;
}