Skip to content

Instantly share code, notes, and snippets.

@sgrif
Created March 2, 2014 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgrif/9315186 to your computer and use it in GitHub Desktop.
Save sgrif/9315186 to your computer and use it in GitHub Desktop.
class THREE.BoneHelper extends THREE.Object3D
constructor: (@bone, @size) ->
super()
@size ?= 1
cubeGeometry = new THREE.CubeGeometry(@size, @size, @size)
cubeMaterial = new THREE.MeshBasicMaterial()
@cube = new THREE.Mesh(cubeGeometry, cubeMaterial)
@cube.matrixAutoUpdate = false
@add(@cube)
@update()
update: =>
@cube.matrix.copy(@bone.skinMatrix)
@remove(@line) if @line?
if @bone.parent instanceof THREE.Bone
lineMaterial = new THREE.LineBasicMaterial()
lineGeometry = new THREE.Geometry()
lineGeometry.vertices.push(new THREE.Vector3().getPositionFromMatrix(@bone.skinMatrix))
lineGeometry.vertices.push(new THREE.Vector3().getPositionFromMatrix(@bone.parent.skinMatrix))
@line = new THREE.Line(lineGeometry, lineMaterial)
@add(@line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment