Skip to content

Instantly share code, notes, and snippets.

@kishalmi
Created October 23, 2013 07:53
Show Gist options
  • Save kishalmi/7114307 to your computer and use it in GitHub Desktop.
Save kishalmi/7114307 to your computer and use it in GitHub Desktop.
create a geometry suitable for a THREE.Line of type THREE.LineStrip from a sphere (not displaying triangle-edges of a sphere wireframe)
/**
* create a geometry suitable for a THREE.Line of type THREE.LineStrip from a sphere
* thereby not displaying triangle-edges of a sphere wireframe.
* @param {THREE.SphereGeometry} geoSphere
* @returns {THREE.Geometry}
*/
function lineStripGeometryFromSphereGeometry(geoSphere) {
var geoLine = new THREE.Geometry(),
w = geoSphere.widthSegments, h = geoSphere.heightSegments,
x, y;
// add rings (lineStrip adds zero meridian, which is why this only works for phi,theta 0-2PI)
for (y = 0; y <= h; y++)
for (x = 0; x <= w; x++)
geoLine.vertices.push(geoSphere.vertices[y * (w + 1) + x].clone());
// add meridians
for (x = 1; x <= w; x++) {
var yFrom = (x % 2) ? h : 0;
var yTo = h - yFrom;
var yStep = (x % 2) ? -1 : +1;
for (y = yFrom; y != yTo; y += yStep)
geoLine.vertices.push(geoSphere.vertices[y * (w + 1) + x].clone());
}
return geoLine;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment