So i use this code
_cube2sphere = function (cube) {
cube.divideScalar(this.radius);
var x2 = cube.x*cube.x;
var y2 = cube.y*cube.y;
var z2 = cube.z*cube.z;
var sphere = new THREE.Vector3(
cube.x*Math.sqrt(1.0 - y2*0.5 - z2*0.5 + y2*z2*0.3333333),
cube.y*Math.sqrt(1.0 - x2*0.5 - z2*0.5 + x2*z2*0.3333333),
cube.z*Math.sqrt(1.0 - x2*0.5 - y2*0.5 + x2*y2*0.3333333)
);
return sphere.multiplyScalar(this.radius);
};
_spherifyVerts = function (geometry) {
var verts = geometry.attributes.position.array;
for (var i = 0; i < verts.length; i += 3) {
var pos = new THREE.Vector3(verts[i], verts[i + 1], verts[i + 2]);
pos = _cube2sphere(pos);
verts[i] = pos.x;
verts[i + 1] = pos.y;
verts[i + 2] = pos.z;
}
to Spherify a cube. It works well when cube is in 0,0,0 coords, otherwise everything goes bananas. What would be the strategy to Spherify a cube that is not in the center?