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