diff --git a/minecraftcodex/studio/static/coffee/studio.coffee b/minecraftcodex/studio/static/coffee/studio.coffee index 3d6aafe..998a8f2 100644 --- a/minecraftcodex/studio/static/coffee/studio.coffee +++ b/minecraftcodex/studio/static/coffee/studio.coffee @@ -21,7 +21,7 @@ Studio = checkWebGLsupport: -> return !!window.WebGLRenderingContext; - # ChangeCamera + # Callbacks onCameraChange: (cameraType) -> if "#{cameraType}Camera" of StudioObjects @camera = StudioObjects["#{cameraType}Camera"].init @width, @height @@ -36,6 +36,7 @@ Studio = requestAnimationFrame => @animate() + # Scene helpers setSize: (width, height) -> @width = parseInt width @height = parseInt height @@ -44,6 +45,18 @@ Studio = @domElement.style.width = "#{@width}px" @domElement.style.height = "#{@height}px" + # Tests + changeTexture: (path) -> + @scene.remove @object + + texture = new THREE.ImageUtils.loadTexture path + texture.minFilter = THREE.NearestFilter + texture.magFilter = THREE.NearestFilter + material = new THREE.MeshLambertMaterial map: texture + @object = new THREE.Mesh new THREE.CubeGeometry(16, 16, 16), material + @object.rotation.set Math.PI/6, (Math.PI/4)*-1, 0 + @scene.add @object + init: (dom, width, height) -> if not @checkWebGLsupport() return false @@ -58,6 +71,11 @@ Studio = @scene = new THREE.Scene() # test + @light = new THREE.DirectionalLight 0xffffff + @light.position.set(1, 20, 60).normalize() + @light.intensity = 1.6 + @scene.add @light + @object = new THREE.Mesh new THREE.CubeGeometry(16, 16, 16), new THREE.MeshNormalMaterial() @scene.add @object diff --git a/minecraftcodex/studio/templates/studio/main.html b/minecraftcodex/studio/templates/studio/main.html index d1a056c..bbc87f0 100644 --- a/minecraftcodex/studio/templates/studio/main.html +++ b/minecraftcodex/studio/templates/studio/main.html @@ -63,6 +63,11 @@ window.onload = function() { mcstudio.onCameraChange($(this).val()) }) $("select.camera-type").change() + + $('[data-studio="change-texture"]').click(function() { + var texture = $(this).attr('data-texture') + mcstudio.changeTexture(texture) + }) } {% endblock %} @@ -126,7 +131,9 @@ window.onload = function() {
{% for item in textures %} -
+