Last active
March 21, 2016 09:13
-
-
Save sdcb/9d3a2f167b1384753176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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