Created
November 28, 2013 02:31
-
-
Save bhollis/7686441 to your computer and use it in GitHub Desktop.
Three.js snippet for creating a checkerboard plane. Good for use as a floor in demos.
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
# Build a checkerboard colored square plane with "segments" number of tiles per side. | |
# Using three.js v62 | |
checkerboard = (segments=8) -> | |
geometry = new THREE.PlaneGeometry(100, 100, segments, segments) | |
materialEven = new THREE.MeshBasicMaterial(color: 0xccccfc) | |
materialOdd = new THREE.MeshBasicMaterial(color: 0x444464) | |
materials = [materialEven, materialOdd] | |
for x in [0...segments] | |
for y in [0...segments] | |
i = x * segments + y | |
j = 2 * i | |
geometry.faces[ j ].materialIndex = geometry.faces[ j + 1 ].materialIndex = (x + y) % 2 | |
new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment