Skip to content

Instantly share code, notes, and snippets.

@sdcb
Last active March 21, 2016 09:13
Show Gist options
  • Save sdcb/9d3a2f167b1384753176 to your computer and use it in GitHub Desktop.
Save sdcb/9d3a2f167b1384753176 to your computer and use it in GitHub Desktop.
class VertexColorBoxGeometry extends THREE.BoxGeometry {
constructor(width: number, height: number, depth: number, widthSegments?: number, heightSegments?: number, depthSegments?: number) {
super(width, height, depth, widthSegments, heightSegments, depthSegments);
let faceIndices = ['a', 'b', 'c', 'd'];
for (let face of this.faces) {
let numberOfSides = (face instanceof THREE.Face3) ? 3 : 4;
for (let i = 0; i < numberOfSides; i++) {
let vertexIndex = face[faceIndices[i]];
let point = this.vertices[vertexIndex];
let color = new THREE.Color(0xffffff);
color.setRGB(0.5 + point.x / width, 0.5 + point.y / height, 0.5 + point.z / depth);
face.vertexColors[i] = color;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment