Skip to content

Instantly share code, notes, and snippets.

@sdcb
Last active March 21, 2016 09:46
Show Gist options
  • Save sdcb/8fbaeafff8b5a63b5e8f to your computer and use it in GitHub Desktop.
Save sdcb/8fbaeafff8b5a63b5e8f to your computer and use it in GitHub Desktop.
class FaceColorBoxGeometry extends THREE.BoxGeometry {
constructor(width: number, height: number, depth: number, widthSegments?: number, heightSegments?: number, depthSegments?: number) {
super(width, height, depth, widthSegments, heightSegments, depthSegments);
for (let face of this.faces) {
let color = new THREE.Color();
if (face.normal.x < 0 || face.normal.y < 0 || face.normal.z < 0) {
color.setRGB(1, 1, 1);
if (face.normal.x < 0) color.r = 0;
if (face.normal.y < 0) color.g = 0;
if (face.normal.z < 0) color.b = 0;
} else {
color.setRGB(face.normal.x, face.normal.y, face.normal.z);
}
face.color = color;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment