My goal is to assign a unique texture to each face of a THREE.js sphere. To achieve this, I utilized a SphereGeometry to calculate the vertices and then converted each face into a PlaneGeometry by utilizing the vertices of the faces.
THREE.SpherePlaneGeometry = function ( v1, v2, v3, v4 ) {
THREE.Geometry.call( this );
var normal = new THREE.Vector3( 0, 1, 0 );
this.vertices.push( v1.clone() );
this.vertices.push( v2.clone() );
this.vertices.push( v3.clone() );
this.vertices.push( v4.clone() );
var face = new THREE.Face4( 0, 1, 2, 3 );
face.normal.copy( normal );
face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone(), normal.clone() );
this.faces.push( face );
var uvs = [
new THREE.UV( 1.0, 0.0 ),
new THREE.UV( 0.0, 0.0 ),
new THREE.UV( 0.0, 1.0 ),
new THREE.UV( 1.0, 1.0 ),
];
this.faceVertexUvs[ 0 ].push( uvs );
};
To ensure proper execution with the resulting geometry later on:
geometry.computeCentroids();
geometry.computeFaceNormals();
geometry.verticesNeedUpdate = true;
geometry.uvsNeedUpdate = true;
geometry.normalsNeedUpdate = true;
geometry.tangentsNeedUpdate = true;
geometry.elementsNeedUpdate = true;
geometry.dynamic = true;
Upon applying this texture:
The outcome obtained is:
How can we address the distortion between the red and green points? At the poles, one vertex is used twice which may not be ideal. Any suggestions on improving this?