Skip to content

Instantly share code, notes, and snippets.

@bhollis
Created November 28, 2013 02:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhollis/7686441 to your computer and use it in GitHub Desktop.
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.
# 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