From 81829b1a83531edf08a085dd7393559d825bf3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Mart=C3=ADn?= Date: Thu, 30 May 2013 17:38:12 +0200 Subject: [PATCH] Added the possibility to reset the composition maintaining the canvas size --- minecraftcodex/studio/static/coffee/studio.coffee | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/minecraftcodex/studio/static/coffee/studio.coffee b/minecraftcodex/studio/static/coffee/studio.coffee index 998a8f2..8a721bd 100644 --- a/minecraftcodex/studio/static/coffee/studio.coffee +++ b/minecraftcodex/studio/static/coffee/studio.coffee @@ -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