Added the possibility to reset the composition maintaining the canvas size
This commit is contained in:
parent
1289d7cf52
commit
81829b1a83
|
@ -1,5 +1,6 @@
|
|||
Studio =
|
||||
domElement: null
|
||||
_dom: null
|
||||
|
||||
renderer: null
|
||||
width: 600
|
||||
|
@ -8,6 +9,7 @@ Studio =
|
|||
scene: null
|
||||
|
||||
camera: null
|
||||
_cameraType: null
|
||||
|
||||
animating: false
|
||||
|
||||
|
@ -24,6 +26,7 @@ Studio =
|
|||
# Callbacks
|
||||
onCameraChange: (cameraType) ->
|
||||
if "#{cameraType}Camera" of StudioObjects
|
||||
@_cameraType = cameraType
|
||||
@camera = StudioObjects["#{cameraType}Camera"].init @width, @height
|
||||
if not @animating
|
||||
@animate()
|
||||
|
@ -31,9 +34,11 @@ Studio =
|
|||
# Animation
|
||||
animate: ->
|
||||
if @scene and @camera
|
||||
if not @animating
|
||||
@animating = true
|
||||
@renderer.render @scene, @camera
|
||||
|
||||
requestAnimationFrame =>
|
||||
@_animationFrame = requestAnimationFrame =>
|
||||
@animate()
|
||||
|
||||
# Scene helpers
|
||||
|
@ -45,6 +50,8 @@ Studio =
|
|||
@domElement.style.width = "#{@width}px"
|
||||
@domElement.style.height = "#{@height}px"
|
||||
|
||||
@onCameraChange @_cameraType
|
||||
|
||||
# Tests
|
||||
changeTexture: (path) ->
|
||||
@scene.remove @object
|
||||
|
@ -57,11 +64,17 @@ Studio =
|
|||
@object.rotation.set Math.PI/6, (Math.PI/4)*-1, 0
|
||||
@scene.add @object
|
||||
|
||||
reset: ->
|
||||
cancelAnimationFrame @_animationFrame
|
||||
@renderer.domElement.remove()
|
||||
@init @_dom, @width, @height
|
||||
|
||||
init: (dom, width, height) ->
|
||||
if not @checkWebGLsupport()
|
||||
return false
|
||||
|
||||
@domElement = document.querySelector dom
|
||||
@_dom = dom
|
||||
|
||||
@renderer = new THREE.WebGLRenderer()
|
||||
@setSize width, height
|
||||
|
|
Loading…
Reference in New Issue