Bläddra i källkod

1.2.1:
- Support for PointerLock ()
- StandardMaterial now supports per-vertex color
- Blender exporter supports per-vertex color

deltakosh 12 år sedan
förälder
incheckning
0552ff144a
33 ändrade filer med 290 tillägg och 405 borttagningar
  1. 12 3
      Babylon/Cameras/babylon.freeCamera.js
  2. 63 56
      Babylon/Materials/babylon.standardMaterial.js
  3. 2 1
      Babylon/Mesh/babylon.mesh.js
  4. 8 0
      Babylon/Shaders/default.fragment.fx
  5. 21 9
      Babylon/Shaders/default.vertex.fx
  6. 11 7
      Babylon/Tools/babylon.sceneLoader.js
  7. 0 220
      Babylon/Tools/babylon.tools.dds.js
  8. 2 2
      Babylon/Tools/babylon.tools.js
  9. 45 14
      Babylon/babylon.engine.js
  10. 51 25
      Exporters/Blender/io_export_babylon.py
  11. 1 1
      Samples/Scenes/Espilit/espilit.babylon
  12. 1 1
      Samples/Scenes/Flat2009/Flat2009.babylon
  13. 1 1
      Samples/Scenes/Heart/Heart.babylon
  14. 1 1
      Samples/Scenes/SpaceDek/SpaceDek.babylon
  15. 1 1
      Samples/Scenes/Spaceship/Spaceship.babylon
  16. 0 1
      Samples/Scenes/TestAnim/TestAnim.babylon
  17. 1 1
      Samples/Scenes/TheCar/TheCar.babylon
  18. 1 1
      Samples/Scenes/Viper/Viper.babylon
  19. 1 1
      Samples/Scenes/WCafe/WCafe.babylon
  20. 14 15
      Samples/Scenes/WorldMonger/Shaders/Ground/ground.fragment.fx
  21. 16 13
      Samples/Scenes/WorldMonger/Shaders/Ground/ground.vertex.fx
  22. 1 1
      Samples/Scenes/WorldMonger/Shaders/Ground/groundMaterial.js
  23. 1 1
      Samples/Scenes/WorldMonger/Shaders/Water/waterMaterial.js
  24. 10 8
      Samples/Scenes/WorldMonger/babylon.js
  25. 1 0
      Samples/Scenes/WorldMonger/hand.minified-1.1.1.js
  26. 1 1
      Samples/Scenes/WorldMonger/index.css
  27. 1 1
      Samples/Scenes/WorldMonger/index.html
  28. 1 2
      Samples/Scenes/WorldMonger/index.js
  29. 3 3
      Samples/babylon.js
  30. 1 1
      Samples/index.js
  31. 0 13
      babylon.1.2.0.js
  32. 13 0
      babylon.1.2.1.js
  33. 4 0
      what's new.txt

+ 12 - 3
Babylon/Cameras/babylon.freeCamera.js

@@ -86,6 +86,7 @@
     BABYLON.FreeCamera.prototype.attachControl = function (canvas) {
         var previousPosition;
         var that = this;
+        var engine = this._scene.getEngine();
 
         this._onMouseDown = function (evt) {
             previousPosition = {
@@ -108,12 +109,20 @@
         };
 
         this._onMouseMove = function (evt) {
-            if (!previousPosition) {
+            if (!previousPosition && !engine.isPointerLock) {
                 return;
             }
 
-            var offsetX = evt.clientX - previousPosition.x;
-            var offsetY = evt.clientY - previousPosition.y;
+            var offsetX;
+            var offsetY;
+
+            if (!engine.isPointerLock) {
+                offsetX = evt.clientX - previousPosition.x;
+                offsetY = evt.clientY - previousPosition.y;
+            } else {
+                offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
+                offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
+            }            
 
             that.cameraRotation.y += offsetX / 2000.0;
             that.cameraRotation.x += offsetY / 2000.0;

+ 63 - 56
Babylon/Materials/babylon.standardMaterial.js

@@ -2,10 +2,10 @@
 
 (function () {
 
-    var isIE = function() {
+    var isIE = function () {
         return window.ActiveXObject !== undefined;
     };
-    
+
     BABYLON.StandardMaterial = function (name, scene) {
         this.name = name;
         this.id = name;
@@ -30,7 +30,7 @@
         this._cachedDefines = null;
 
         this._renderTargets = new BABYLON.Tools.SmartArray(16);
-        
+
         // Internals
         this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
         this._lightMatrix = BABYLON.Matrix.Zero();
@@ -54,66 +54,67 @@
     // Methods   
     BABYLON.StandardMaterial.prototype.isReady = function (mesh) {
         var engine = this._scene.getEngine();
+        var defines = [];
 
         // Textures
-        if (this.diffuseTexture && !this.diffuseTexture.isReady()) {
-            return false;
-        }
-
-        if (this.ambientTexture && !this.ambientTexture.isReady()) {
-            return false;
-        }
-
-        if (this.opacityTexture && !this.opacityTexture.isReady()) {
-            return false;
-        }
-
-        if (this.reflectionTexture && !this.reflectionTexture.isReady()) {
-            return false;
-        }
-
-        if (this.emissiveTexture && !this.emissiveTexture.isReady()) {
-            return false;
-        }
-
-        if (this.specularTexture && !this.specularTexture.isReady()) {
-            return false;
-        }
-        
-        if (this.bumpTexture && !this.bumpTexture.isReady()) {
-            return false;
-        }
-
-        // Effect
-        var defines = [];
         if (this.diffuseTexture) {
-            defines.push("#define DIFFUSE");
+
+            if (!this.diffuseTexture.isReady()) {
+                return false;
+            } else {
+                defines.push("#define DIFFUSE");
+            }
         }
 
         if (this.ambientTexture) {
-            defines.push("#define AMBIENT");
+            if (!this.ambientTexture.isReady()) {
+                return false;
+            } else {
+                defines.push("#define AMBIENT");
+            }
         }
 
         if (this.opacityTexture) {
-            defines.push("#define OPACITY");
+            if (!this.opacityTexture.isReady()) {
+                return false;
+            } else {
+                defines.push("#define OPACITY");
+            }
         }
 
         if (this.reflectionTexture) {
-            defines.push("#define REFLECTION");
+            if (!this.reflectionTexture.isReady()) {
+                return false;
+            } else {
+                defines.push("#define REFLECTION");
+            }
         }
 
         if (this.emissiveTexture) {
-            defines.push("#define EMISSIVE");
+            if (!this.emissiveTexture.isReady()) {
+                return false;
+            } else {
+                defines.push("#define EMISSIVE");
+            }
         }
 
         if (this.specularTexture) {
-            defines.push("#define SPECULAR");
+            if (!this.specularTexture.isReady()) {
+                return false;
+            } else {
+                defines.push("#define SPECULAR");
+            }
         }
-        
-        if (this.bumpTexture && this._scene.getEngine().getCaps().standardDerivatives) {
-            defines.push("#define BUMP");
+
+        if (this._scene.getEngine().getCaps().standardDerivatives && this.bumpTexture) {
+            if (!this.bumpTexture.isReady()) {
+                return false;
+            } else {                
+                defines.push("#define BUMP");
+            }
         }
 
+        // Effect
         if (BABYLON.clipPlane) {
             defines.push("#define CLIPPLANE");
         }
@@ -121,7 +122,7 @@
         if (engine.getAlphaTesting()) {
             defines.push("#define ALPHATEST");
         }
-        
+
         // Fog
         if (this._scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
             defines.push("#define FOG");
@@ -137,15 +138,15 @@
             }
 
             defines.push("#define LIGHT" + lightIndex);
-            
+
             if (light instanceof BABYLON.SpotLight) {
                 defines.push("#define SPOTLIGHT" + lightIndex);
             } else if (light instanceof BABYLON.HemisphericLight) {
                 defines.push("#define HEMILIGHT" + lightIndex);
             } else {
-                defines.push("#define POINTDIRLIGHT" + lightIndex);               
+                defines.push("#define POINTDIRLIGHT" + lightIndex);
             }
-            
+
             // Shadows
             var shadowGenerator = light.getShadowGenerator();
             if (mesh && mesh.receiveShadows && shadowGenerator && shadowGenerator.isReady()) {
@@ -170,22 +171,28 @@
         if (mesh) {
             switch (mesh._uvCount) {
                 case 1:
-                    attribs = ["position", "normal", "uv"];
+                    attribs.push("uv");
                     defines.push("#define UV1");
                     break;
                 case 2:
-                    attribs = ["position", "normal", "uv", "uv2"];
+                    attribs.push("uv");
+                    attribs.push("uv2");
                     defines.push("#define UV1");
                     defines.push("#define UV2");
                     break;
             }
+            
+            if (mesh._hasVertexColor){
+                attribs.push("color");
+                defines.push("#define VERTEXCOLOR");
+            }
         }
 
         // Get correct effect      
         var join = defines.join("\n");
         if (this._cachedDefines != join) {
             this._cachedDefines = join;
-            
+
             // IE patch
             var shaderName = "default";
             if (isIE()) {
@@ -281,7 +288,7 @@
             this._effect.setFloat2("vSpecularInfos", this.specularTexture.coordinatesIndex, this.specularTexture.level);
             this._effect.setMatrix("specularMatrix", this.specularTexture._computeTextureMatrix());
         }
-        
+
         if (this.bumpTexture && this._scene.getEngine().getCaps().standardDerivatives) {
             this._effect.setTexture("bumpSampler", this.bumpTexture);
 
@@ -307,13 +314,13 @@
             if (!light.isEnabled) {
                 continue;
             }
-                        
+
             if (light instanceof BABYLON.PointLight) {
                 // Point Light
                 this._effect.setFloat4("vLightData" + lightIndex, light.position.x, light.position.y, light.position.z, 0);
             } else if (light instanceof BABYLON.DirectionalLight) {
                 // Directional Light
-                this._effect.setFloat4("vLightData" + lightIndex, light.direction.x, light.direction.y, light.direction.z, 1);               
+                this._effect.setFloat4("vLightData" + lightIndex, light.direction.x, light.direction.y, light.direction.z, 1);
             } else if (light instanceof BABYLON.SpotLight) {
                 // Spot Light
                 this._effect.setFloat4("vLightData" + lightIndex, light.position.x, light.position.y, light.position.z, light.exponent);
@@ -330,7 +337,7 @@
             light.specular.scaleToRef(light.intensity, this._scaledSpecular);
             this._effect.setColor3("vLightDiffuse" + lightIndex, this._scaledDiffuse);
             this._effect.setColor3("vLightSpecular" + lightIndex, this._scaledSpecular);
-            
+
             // Shadows
             var shadowGenerator = light.getShadowGenerator();
             if (mesh.receiveShadows && shadowGenerator && shadowGenerator.isReady()) {
@@ -348,7 +355,7 @@
         if (BABYLON.clipPlane) {
             this._effect.setFloat4("vClipPlane", BABYLON.clipPlane.normal.x, BABYLON.clipPlane.normal.y, BABYLON.clipPlane.normal.z, BABYLON.clipPlane.d);
         }
-        
+
         // View
         if (this._scene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
             this._effect.setMatrix("view", this._scene.getViewMatrix());
@@ -387,7 +394,7 @@
         if (this.specularTexture && this.specularTexture.animations && this.specularTexture.animations.length > 0) {
             results.push(this.specularTexture);
         }
-        
+
         if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
             results.push(this.bumpTexture);
         }
@@ -419,7 +426,7 @@
         if (this.specularTexture) {
             this.specularTexture.dispose();
         }
-        
+
         if (this.bumpTexture) {
             this.bumpTexture.dispose();
         }

+ 2 - 1
Babylon/Mesh/babylon.mesh.js

@@ -265,12 +265,13 @@
         }
     };
 
-    BABYLON.Mesh.prototype.setVertices = function (vertices, uvCount, updatable) {
+    BABYLON.Mesh.prototype.setVertices = function (vertices, uvCount, updatable, hasVertexColor) {
         if (this._vertexBuffer) {
             this._scene.getEngine()._releaseBuffer(this._vertexBuffer);
         }
 
         this._uvCount = uvCount;
+        this._hasVertexColor = hasVertexColor;
 
         if (updatable) {
             this._vertexBuffer = this._scene.getEngine().createDynamicVertexBuffer(vertices.length * 4);

+ 8 - 0
Babylon/Shaders/default.fragment.fx

@@ -15,6 +15,10 @@ uniform vec3 vEmissiveColor;
 varying vec3 vPositionW;
 varying vec3 vNormalW;
 
+#ifdef VERTEXCOLOR
+varying vec3 vColor;
+#endif
+
 // Lights
 #ifdef LIGHT0
 uniform vec4 vLightData0;
@@ -358,6 +362,10 @@ void main(void) {
 	vec4 baseColor = vec4(1., 1., 1., 1.);
 	vec3 diffuseColor = vDiffuseColor.rgb;
 
+#ifdef VERTEXCOLOR
+	diffuseColor *= vColor;
+#endif
+
 #ifdef DIFFUSE
 	baseColor = texture2D(diffuseSampler, vDiffuseUV);
 

+ 21 - 9
Babylon/Shaders/default.vertex.fx

@@ -18,6 +18,9 @@ attribute vec2 uv;
 #ifdef UV2
 attribute vec2 uv2;
 #endif
+#ifdef VERTEXCOLOR
+attribute vec3 color;
+#endif
 
 // Uniforms
 uniform mat4 world;
@@ -71,6 +74,10 @@ uniform mat4 bumpMatrix;
 varying vec3 vPositionW;
 varying vec3 vNormalW;
 
+#ifdef VERTEXCOLOR
+varying vec3 vColor;
+#endif
+
 #ifdef CLIPPLANE
 uniform vec4 vClipPlane;
 varying float fClipDistance;
@@ -101,10 +108,10 @@ varying vec4 vPositionFromLight3;
 
 #ifdef REFLECTION
 vec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)
-{	
+{
 	if (mode == MAP_SPHERICAL)
 	{
-		vec3 coords = vec3(view * vec4(worldNormal, 0.0));	
+		vec3 coords = vec3(view * vec4(worldNormal, 0.0));
 
 		return vec3(reflectionMatrix * vec4(coords, 1.0));
 	}
@@ -136,7 +143,7 @@ vec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)
 #endif
 
 void main(void) {
-	gl_Position = worldViewProjection * vec4(position, 1.0);   
+	gl_Position = worldViewProjection * vec4(position, 1.0);
 
 	vec4 worldPos = world * vec4(position, 1.0);
 	vPositionW = vec3(worldPos);
@@ -222,27 +229,32 @@ void main(void) {
 
 	// Clip plane
 #ifdef CLIPPLANE
-		fClipDistance = dot(worldPos, vClipPlane);
+	fClipDistance = dot(worldPos, vClipPlane);
 #endif
 
 	// Fog
 #ifdef FOG
-		fFogDistance = (view * worldPos).z;
+	fFogDistance = (view * worldPos).z;
 #endif
 
 	// Shadows
 #ifdef SHADOWS
 #ifdef LIGHT0
-		vPositionFromLight0 = lightMatrix0 * vec4(position, 1.0);
+	vPositionFromLight0 = lightMatrix0 * vec4(position, 1.0);
 #endif
 #ifdef LIGHT1
-		vPositionFromLight1 = lightMatrix1 * vec4(position, 1.0);
+	vPositionFromLight1 = lightMatrix1 * vec4(position, 1.0);
 #endif
 #ifdef LIGHT2
-		vPositionFromLight2 = lightMatrix2 * vec4(position, 1.0);
+	vPositionFromLight2 = lightMatrix2 * vec4(position, 1.0);
 #endif
 #ifdef LIGHT3
-		vPositionFromLight3 = lightMatrix3 * vec4(position, 1.0);
+	vPositionFromLight3 = lightMatrix3 * vec4(position, 1.0);
 #endif
 #endif
+
+	// Vertex color
+#ifdef VERTEXCOLOR
+	vColor = color;
+#endif
 }

+ 11 - 7
Babylon/Tools/babylon.sceneLoader.js

@@ -249,20 +249,24 @@
     };
 
     var parseMesh = function (parsedMesh, scene) {
-        var declaration = null;
+        var declaration =  [3, 3];
         
+        // Texture coordinates
         switch (parsedMesh.uvCount) {
-            case 0:
-                declaration = [3, 3];
-                break;
             case 1:
-                declaration = [3, 3, 2];
+                declaration.push(2);
                 break;
             case 2:
-                declaration = [3, 3, 2, 2];
+                declaration.push(2);
+                declaration.push(2);
                 break;
         }
 
+        // Vertex color
+        if (parsedMesh.hasVertexColor) {
+            declaration.push(3);
+        }
+
         var mesh = new BABYLON.Mesh(parsedMesh.name, declaration, scene);
         mesh.id = parsedMesh.id;
 
@@ -284,7 +288,7 @@
         mesh.checkCollisions = parsedMesh.checkCollisions;
 
         if (parsedMesh.vertices && parsedMesh.indices) {
-            mesh.setVertices(parsedMesh.vertices, parsedMesh.uvCount);
+            mesh.setVertices(parsedMesh.vertices, parsedMesh.uvCount, false, parsedMesh.hasVertexColor);
             mesh.setIndices(parsedMesh.indices);
         }
 

+ 0 - 220
Babylon/Tools/babylon.tools.dds.js

@@ -1,220 +0,0 @@
-var BABYLON = BABYLON || {};
-
-(function () {
-    BABYLON.Tools = BABYLON.Tools || {};
-
-    // Based on https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js
-
-    // All values and structures referenced from:
-    // http://msdn.microsoft.com/en-us/library/bb943991.aspx/
-    var DDS_MAGIC = 0x20534444;
-
-    var DDSD_CAPS = 0x1,
-        DDSD_HEIGHT = 0x2,
-        DDSD_WIDTH = 0x4,
-        DDSD_PITCH = 0x8,
-        DDSD_PIXELFORMAT = 0x1000,
-        DDSD_MIPMAPCOUNT = 0x20000,
-        DDSD_LINEARSIZE = 0x80000,
-        DDSD_DEPTH = 0x800000;
-
-    var DDSCAPS_COMPLEX = 0x8,
-        DDSCAPS_MIPMAP = 0x400000,
-        DDSCAPS_TEXTURE = 0x1000;
-
-    var DDSCAPS2_CUBEMAP = 0x200,
-        DDSCAPS2_CUBEMAP_POSITIVEX = 0x400,
-        DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800,
-        DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000,
-        DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000,
-        DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000,
-        DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000,
-        DDSCAPS2_VOLUME = 0x200000;
-
-    var DDPF_ALPHAPIXELS = 0x1,
-        DDPF_ALPHA = 0x2,
-        DDPF_FOURCC = 0x4,
-        DDPF_RGB = 0x40,
-        DDPF_YUV = 0x200,
-        DDPF_LUMINANCE = 0x20000;
-
-    function fourCCToInt32(value) {
-        return value.charCodeAt(0) +
-            (value.charCodeAt(1) << 8) +
-            (value.charCodeAt(2) << 16) +
-            (value.charCodeAt(3) << 24);
-    }
-
-    function int32ToFourCC(value) {
-        return String.fromCharCode(
-            value & 0xff,
-            (value >> 8) & 0xff,
-            (value >> 16) & 0xff,
-            (value >> 24) & 0xff
-        );
-    }
-
-    var FOURCC_DXT1 = fourCCToInt32("DXT1");
-    var FOURCC_DXT3 = fourCCToInt32("DXT3");
-    var FOURCC_DXT5 = fourCCToInt32("DXT5");
-
-    var headerLengthInt = 31; // The header length in 32 bit ints
-
-    // Offsets into the header array
-    var off_magic = 0;
-
-    var off_size = 1;
-    var off_flags = 2;
-    var off_height = 3;
-    var off_width = 4;
-
-    var off_mipmapCount = 7;
-
-    var off_pfFlags = 20;
-    var off_pfFourCC = 21;
-
-    function dxtToRgb565(src, src16Offset, width, height) {
-        var c = new Uint16Array(4);
-        var dst = new Uint16Array(width * height);
-        var nWords = (width * height) / 4;
-        var m = 0;
-        var dstI = 0;
-        var i = 0;
-        var r0 = 0, g0 = 0, b0 = 0, r1 = 0, g1 = 0, b1 = 0;
-
-        var blockWidth = width / 4;
-        var blockHeight = height / 4;
-        for (var blockY = 0; blockY < blockHeight; blockY++) {
-            for (var blockX = 0; blockX < blockWidth; blockX++) {
-                i = src16Offset + 4 * (blockY * blockWidth + blockX);
-                c[0] = src[i];
-                c[1] = src[i + 1];
-                r0 = c[0] & 0x1f;
-                g0 = c[0] & 0x7e0;
-                b0 = c[0] & 0xf800;
-                r1 = c[1] & 0x1f;
-                g1 = c[1] & 0x7e0;
-                b1 = c[1] & 0xf800;
-                // Interpolate between c0 and c1 to get c2 and c3.
-                // Note that we approximate 1/3 as 3/8 and 2/3 as 5/8 for
-                // speed.  This also appears to be what the hardware DXT
-                // decoder in many GPUs does :)
-                c[2] = ((5 * r0 + 3 * r1) >> 3)
-                    | (((5 * g0 + 3 * g1) >> 3) & 0x7e0)
-                    | (((5 * b0 + 3 * b1) >> 3) & 0xf800);
-                c[3] = ((5 * r1 + 3 * r0) >> 3)
-                    | (((5 * g1 + 3 * g0) >> 3) & 0x7e0)
-                    | (((5 * b1 + 3 * b0) >> 3) & 0xf800);
-                m = src[i + 2];
-                dstI = (blockY * 4) * width + blockX * 4;
-                dst[dstI] = c[m & 0x3];
-                dst[dstI + 1] = c[(m >> 2) & 0x3];
-                dst[dstI + 2] = c[(m >> 4) & 0x3];
-                dst[dstI + 3] = c[(m >> 6) & 0x3];
-                dstI += width;
-                dst[dstI] = c[(m >> 8) & 0x3];
-                dst[dstI + 1] = c[(m >> 10) & 0x3];
-                dst[dstI + 2] = c[(m >> 12) & 0x3];
-                dst[dstI + 3] = c[(m >> 14)];
-                m = src[i + 3];
-                dstI += width;
-                dst[dstI] = c[m & 0x3];
-                dst[dstI + 1] = c[(m >> 2) & 0x3];
-                dst[dstI + 2] = c[(m >> 4) & 0x3];
-                dst[dstI + 3] = c[(m >> 6) & 0x3];
-                dstI += width;
-                dst[dstI] = c[(m >> 8) & 0x3];
-                dst[dstI + 1] = c[(m >> 10) & 0x3];
-                dst[dstI + 2] = c[(m >> 12) & 0x3];
-                dst[dstI + 3] = c[(m >> 14)];
-            }
-        }
-        return dst;
-    }
-
-    function uploadDDSLevels(gl, ext, arrayBuffer) {
-        var header = new Int32Array(arrayBuffer, 0, headerLengthInt),
-            fourCC, blockBytes, internalFormat,
-            width, height, dataLength, dataOffset,
-            rgb565Data, byteArray, mipmapCount, i;
-
-
-        if (header[off_magic] != DDS_MAGIC) {
-            console.error("Invalid magic number in DDS header");
-            return 0;
-        }
-
-        if (!header[off_pfFlags] & DDPF_FOURCC) {
-            console.error("Unsupported format, must contain a FourCC code");
-            return 0;
-        }
-
-
-        fourCC = header[off_pfFourCC];
-        switch (fourCC) {
-            case FOURCC_DXT1:
-                blockBytes = 8;
-                internalFormat = ext ? ext.COMPRESSED_RGB_S3TC_DXT1_EXT : null;
-                break;
-
-
-            case FOURCC_DXT3:
-                blockBytes = 16;
-                internalFormat = ext ? ext.COMPRESSED_RGBA_S3TC_DXT3_EXT : null;
-                break;
-
-
-            case FOURCC_DXT5:
-                blockBytes = 16;
-                internalFormat = ext ? ext.COMPRESSED_RGBA_S3TC_DXT5_EXT : null;
-                break;
-
-
-            default:
-                console.error("Unsupported FourCC code:", int32ToFourCC(fourCC));
-                return null;
-        }
-
-
-        mipmapCount = 1;
-        if (header[off_flags] & DDSD_MIPMAPCOUNT && loadMipmaps !== false) {
-            mipmapCount = Math.max(1, header[off_mipmapCount]);
-        }
-
-
-        width = header[off_width];
-        height = header[off_height];
-        dataOffset = header[off_size] + 4;
-
-
-        if (ext) {
-            for (i = 0; i < mipmapCount; ++i) {
-                dataLength = Math.max(4, width) / 4 * Math.max(4, height) / 4 * blockBytes;
-                byteArray = new Uint8Array(arrayBuffer, dataOffset, dataLength);
-                gl.compressedTexImage2D(gl.TEXTURE_2D, i, internalFormat, width, height, 0, byteArray);
-                dataOffset += dataLength;
-                width *= 0.5;
-                height *= 0.5;
-            }
-        } else {
-            if (fourCC == FOURCC_DXT1) {
-                dataLength = Math.max(4, width) / 4 * Math.max(4, height) / 4 * blockBytes;
-                byteArray = new Uint16Array(arrayBuffer);
-                rgb565Data = dxtToRgb565(byteArray, dataOffset / 2, width, height);
-                gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, width, height, 0, gl.RGB, gl.UNSIGNED_SHORT_5_6_5, rgb565Data);
-                if (loadMipmaps) {
-                    gl.generateMipmap(gl.TEXTURE_2D);
-                }
-            } else {
-                console.error("No manual decoder for", int32ToFourCC(fourCC), "and no native support");
-                return 0;
-            }
-        }
-
-        return mipmapCount;
-    }
-
-    BABYLON.Tools.LoadDDSTexture = function(gl, ext, data) {
-        return uploadDDSLevels(gl, ext, data);
-    };
-})();

+ 2 - 2
Babylon/Tools/babylon.tools.js

@@ -79,8 +79,8 @@
             element.msRequestFullscreen();
         else if (element.webkitRequestFullscreen)
             element.webkitRequestFullscreen();
-        else if (element.mozRequestFullscreen)
-            element.mozRequestFullscreen();
+        else if (element.mozRequestFullScreen)
+            element.mozRequestFullScreen();        
     };
 
     BABYLON.Tools.ExitFullscreen = function () {

+ 45 - 14
Babylon/babylon.engine.js

@@ -61,21 +61,51 @@
         // Fullscreen
         this.isFullscreen = false;
         var that = this;
-        document.addEventListener("fullscreenchange", function () {
-            that.isFullscreen = document.fullscreen;
-        }, false);
 
-        document.addEventListener("mozfullscreenchange", function () {
-            that.isFullscreen = document.mozFullScreen;
-        }, false);
+        var onFullscreenChange = function () {
+            if (document.fullscreen !== undefined) {
+                that.isFullscreen = document.fullscreen;
+            } else if (document.mozFullScreen !== undefined) {
+                that.isFullscreen = document.mozFullScreen;
+            } else if (document.webkitIsFullScreen !== undefined) {
+                that.isFullscreen = document.webkitIsFullScreen;
+            } else if (document.msIsFullScreen !== undefined) {
+                that.isFullscreen = document.msIsFullScreen;
+            }
+            
+            // Pointer lock
+            if (that.isFullscreen && that._pointerLockRequested) {
+                canvas.requestPointerLock = canvas.requestPointerLock ||
+                                            canvas.msRequestPointerLock ||
+                                            canvas.mozRequestPointerLock ||
+                                            canvas.webkitRequestPointerLock;
+
+                if (canvas.requestPointerLock) {
+                    canvas.requestPointerLock();
+                }
+            }
+        };
 
-        document.addEventListener("webkitfullscreenchange", function () {
-            that.isFullscreen = document.webkitIsFullScreen;
-        }, false);
+        document.addEventListener("fullscreenchange", onFullscreenChange, false);
+        document.addEventListener("mozfullscreenchange", onFullscreenChange, false);
+        document.addEventListener("webkitfullscreenchange", onFullscreenChange, false);
+        document.addEventListener("msfullscreenchange", onFullscreenChange, false);
+        
+        // Pointer lock
+        this.isPointerLock = false;
+
+        var onPointerLockChange = function () {
+            that.isPointerLock = (document.mozPointerLockElement === canvas ||
+                                  document.webkitPointerLockElement === canvas ||
+                                  document.msPointerLockElement === canvas ||
+                                  document.pointerLockElement === canvas
+            );
+        };
 
-        document.addEventListener("msfullscreenchange", function () {
-            that.isFullscreen = document.msIsFullScreen;
-        }, false);
+        document.addEventListener("pointerlockchange", onPointerLockChange, false);
+        document.addEventListener("mspointerlockchange", onPointerLockChange, false);
+        document.addEventListener("mozpointerlockchange", onPointerLockChange, false);
+        document.addEventListener("webkitpointerlockchange", onPointerLockChange, false);
     };
 
     // Properties
@@ -149,11 +179,12 @@
         });
     };
 
-    BABYLON.Engine.prototype.switchFullscreen = function (element) {
+    BABYLON.Engine.prototype.switchFullscreen = function (requestPointerLock) {
         if (this.isFullscreen) {
             BABYLON.Tools.ExitFullscreen();
         } else {
-            BABYLON.Tools.RequestFullscreen(element ? element : this._renderingCanvas);
+            this._pointerLockRequested = requestPointerLock;
+            BABYLON.Tools.RequestFullscreen(this._renderingCanvas);
         }
     };
 

+ 51 - 25
Exporters/Blender/io_export_babylon.py

@@ -314,6 +314,7 @@ class Export_babylon(bpy.types.Operator, ExportHelper):
 		indices=",\"indices\":["	
 		hasUV = True;
 		hasUV2 = True;
+		hasVertexColor = True
 		
 		if len(mesh.tessface_uv_textures) > 0:
 			UVmap=mesh.tessface_uv_textures[0].data	
@@ -324,10 +325,16 @@ class Export_babylon(bpy.types.Operator, ExportHelper):
 			UV2map=mesh.tessface_uv_textures[1].data
 		else:
 			hasUV2 = False
+
+		if len(mesh.vertex_colors) > 0:
+			Colormap = mesh.tessface_vertex_colors.active.data
+		else:
+			hasVertexColor = False
 			
 		alreadySavedVertices = []
 		vertices_UVs=[]
 		vertices_UV2s=[]
+		vertices_Colors=[]
 		vertices_indices=[]
 		subMeshes = []
 				
@@ -335,9 +342,9 @@ class Export_babylon(bpy.types.Operator, ExportHelper):
 			alreadySavedVertices.append(False)
 			vertices_UVs.append([])
 			vertices_UV2s.append([])
+			vertices_Colors.append([])
 			vertices_indices.append([])
-		
-		
+						
 		materialsCount = max(1, len(object.material_slots))
 		verticesCount = 0
 		indicesCount = 0
@@ -364,33 +371,44 @@ class Export_babylon(bpy.types.Operator, ExportHelper):
 						
 					if hasUV2:
 						vertex_UV2 = UV2map[face.index].uv[v]
+
+					if hasVertexColor:		
+						if v == 0:				
+							vertex_Color = Colormap[face.index].color1
+						if v == 1:				
+							vertex_Color = Colormap[face.index].color2
+						if v == 2:				
+							vertex_Color = Colormap[face.index].color3
 						
 					# Check if the current vertex is already saved					
 					alreadySaved = alreadySavedVertices[vertex_index]
-					index_UV = 0
 					if alreadySaved:
 						alreadySaved=False						
-						
-						if hasUV:
-							for vUV in vertices_UVs[vertex_index]:
-								if (vUV[0]==vertex_UV[0] and vUV[1]==vertex_UV[1]):
-									if hasUV2:
-										vUV2 = vertices_UV2s[vertex_index][index_UV]
-										if (vUV2[0]==vertex_UV2[0] and vUV2[1]==vertex_UV2[1]):
-											if vertices_indices[vertex_index][index_UV] >= subMeshes[materialIndex].verticesStart:
-												alreadySaved=True
-												break
-									else:
-										alreadySaved=True
-										break
-								index_UV+=1
-						else:
-							for savedIndex in vertices_indices[vertex_index]:
-								if savedIndex >= subMeshes[materialIndex].verticesStart:
-									alreadySaved=True
-									break
-								index_UV+=1
-					  
+					
+						# UV
+						index_UV = 0
+						for savedIndex in vertices_indices[vertex_index]:
+							if hasUV:												
+								vUV = vertices_UVs[vertex_index][index_UV]
+								if (vUV[0]!=vertex_UV[0] or vUV[1]!=vertex_UV[1]):
+									continue
+
+							if hasUV2:
+								vUV2 = vertices_UV2s[vertex_index][index_UV]
+								if (vUV2[0]!=vertex_UV2[0] or vUV2[1]!=vertex_UV2[1]):
+									continue
+
+							if hasVertexColor:
+								vColor = vertices_Colors[vertex_index][index_UV]
+								if (vColor.r!=vertex_Color.r or vColor.g!=vertex_Color.g or vColor.b!=vertex_Color.b):
+									continue
+
+							if vertices_indices[vertex_index][index_UV] >= subMeshes[materialIndex].verticesStart:
+								alreadySaved=True
+								break
+
+							index_UV+=1					
+
 					if (alreadySaved):
 						# Reuse vertex
 						index=vertices_indices[vertex_index][index_UV]
@@ -402,15 +420,22 @@ class Export_babylon(bpy.types.Operator, ExportHelper):
 							vertices_UVs[vertex_index].append(vertex_UV)
 						if hasUV2:
 							vertices_UV2s[vertex_index].append(vertex_UV2)
+						if hasVertexColor:	
+							vertices_Colors[vertex_index].append(vertex_Color)
+
 						vertices_indices[vertex_index].append(index)
 						
 						vertices+="%.4f,%.4f,%.4f,"%(position.x,position.z,position.y)				
 						vertices+="%.4f,%.4f,%.4f,"%(normal.x,normal.z,normal.y)
+
 						if hasUV:
 							vertices+="%.4f,%.4f,"%(vertex_UV[0], vertex_UV[1])
 							
 						if hasUV2:
 							vertices+="%.4f,%.4f,"%(vertex_UV2[0], vertex_UV2[1])
+
+						if hasVertexColor:	
+							vertices+="%.4f,%.4f,%.4f,"%(vertex_Color.r,vertex_Color.g,vertex_Color.b)
 						
 						verticesCount += 1
 					indices+="%i,"%(index)
@@ -468,7 +493,8 @@ class Export_babylon(bpy.types.Operator, ExportHelper):
 			Export_babylon.write_int(file_handler, "uvCount", 1)
 		else:
 			Export_babylon.write_int(file_handler, "uvCount", 0)
-			
+		
+		Export_babylon.write_bool(file_handler, "hasVertexColor", hasVertexColor)
 		file_handler.write(vertices)	
 		file_handler.write(indices)	
 		

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
Samples/Scenes/Espilit/espilit.babylon


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
Samples/Scenes/Flat2009/Flat2009.babylon


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
Samples/Scenes/Heart/Heart.babylon


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
Samples/Scenes/SpaceDek/SpaceDek.babylon


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
Samples/Scenes/Spaceship/Spaceship.babylon


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 1
Samples/Scenes/TestAnim/TestAnim.babylon


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
Samples/Scenes/TheCar/TheCar.babylon


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
Samples/Scenes/Viper/Viper.babylon


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
Samples/Scenes/WCafe/WCafe.babylon


+ 14 - 15
Samples/Scenes/WorldMonger/Shaders/Ground/ground.fragment.fx

@@ -4,35 +4,34 @@ precision mediump float;
 
 uniform vec3 vEyePosition;
 uniform vec3 vLimits;
+uniform vec3 vLightPosition;
+
+// UVs
+varying vec4 vGroundSnowUV;
+varying vec4 vGrassBlendUV;
+varying vec4 vRockSandUV;
 
 // Ground
-varying vec2 vGroundUV;
 uniform sampler2D groundSampler;
 
 // Sand
-varying vec2 vSandUV;
 uniform sampler2D sandSampler;
 
 // Rock
-varying vec2 vRockUV;
 uniform sampler2D rockSampler;
 
 // Snow
-varying vec2 vSnowUV;
 uniform sampler2D snowSampler;
 
 // Snow
-varying vec2 vGrassUV;
 uniform sampler2D grassSampler;
 
 // Snow
-varying vec2 vBlendUV;
 uniform sampler2D blendSampler;
 
 // Lights
 varying vec3 vPositionW;
 varying vec3 vNormalW;
-uniform vec3 vLightPosition;
 
 #ifdef CLIPPLANE
 varying float fClipDistance;
@@ -62,20 +61,20 @@ void main(void) {
 		float lowLimit = vLimits.x - 2.;
 		float gradient = clamp((vPositionW.y - lowLimit) / (vLimits.x - lowLimit), 0., 1.);
 
-		float blend = texture2D(blendSampler, vBlendUV).r;
-		vec3 groundColor = texture2D(groundSampler, vGroundUV).rgb * (1.0 - blend) + blend * texture2D(grassSampler, vGrassUV).rgb;
+		float blend = texture2D(blendSampler, vGrassBlendUV.zw).r;
+		vec3 groundColor = texture2D(groundSampler, vGroundSnowUV.xy).rgb * (1.0 - blend) + blend * texture2D(grassSampler, vGrassBlendUV.xy).rgb;
 
-		finalColor = ndl * (texture2D(sandSampler, vSandUV).rgb * (1.0 - gradient) + gradient * groundColor);
+		finalColor = ndl * (texture2D(sandSampler, vRockSandUV.zw).rgb * (1.0 - gradient) + gradient * groundColor);
 	}
 	else if (vPositionW.y > vLimits.x && vPositionW.y <= vLimits.y)
 	{
 		float lowLimit = vLimits.y - 2.;
 		float gradient = clamp((vPositionW.y - lowLimit) / (vLimits.y - lowLimit), 0., 1.);
 
-		float blend = texture2D(blendSampler, vBlendUV).r;
-		vec3 currentColor = texture2D(groundSampler, vGroundUV).rgb * (1.0 - blend) + blend  * texture2D(grassSampler, vGrassUV).rgb;
+		float blend = texture2D(blendSampler, vGrassBlendUV.zw).r;
+		vec3 currentColor = texture2D(groundSampler, vGroundSnowUV.xy).rgb * (1.0 - blend) + blend  * texture2D(grassSampler, vGrassBlendUV.xy).rgb;
 
-		finalColor = ndl * (currentColor * (1.0 - gradient) + gradient * texture2D(rockSampler, vRockUV + uvOffset).rgb);
+		finalColor = ndl * (currentColor * (1.0 - gradient) + gradient * texture2D(rockSampler, vRockSandUV.xy + uvOffset).rgb);
 	}
 	else if (vPositionW.y > vLimits.y && vPositionW.y <= vLimits.z)
 	{
@@ -87,7 +86,7 @@ void main(void) {
 		float specComp = dot(normalize(vNormalW), angleW);
 		specComp = pow(specComp, 256.);
 
-		finalColor = ndl * (texture2D(rockSampler, vRockUV + uvOffset).rgb * (1.0 - gradient)) + gradient *(ndl * texture2D(snowSampler, vSnowUV).rgb + specComp);
+		finalColor = ndl * (texture2D(rockSampler, vRockSandUV.xy + uvOffset).rgb * (1.0 - gradient)) + gradient *(ndl * texture2D(snowSampler, vGroundSnowUV.zw).rgb + specComp);
 	}
 	else
 	{
@@ -96,7 +95,7 @@ void main(void) {
 		float specComp = dot(normalize(vNormalW), angleW);
 		specComp = pow(specComp, 256.) * 0.8;
 
-		finalColor = texture2D(snowSampler, vSnowUV).rgb * ndl + specComp;
+		finalColor = texture2D(snowSampler, vGroundSnowUV.zw).rgb * ndl + specComp;
 	}
 
 	gl_FragColor = vec4(finalColor, 1.);

+ 16 - 13
Samples/Scenes/WorldMonger/Shaders/Ground/ground.vertex.fx

@@ -1,4 +1,8 @@
-// Attributes
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+// Attributes
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec2 uv;
@@ -7,28 +11,27 @@ attribute vec2 uv;
 uniform mat4 world;
 uniform mat4 worldViewProjection;
 
+// UVs
+varying vec4 vGroundSnowUV;
+varying vec4 vGrassBlendUV;
+varying vec4 vRockSandUV;
+
 // Ground
-varying vec2 vGroundUV;
 uniform mat4 groundMatrix;
 
 // Snow
-varying vec2 vSnowUV;
 uniform mat4 snowMatrix;
 
 // Rock
-varying vec2 vRockUV;
 uniform mat4 rockMatrix;
 
 // Sand
-varying vec2 vSandUV;
 uniform mat4 sandMatrix;
 
 // Grass
-varying vec2 vGrassUV;
 uniform mat4 grassMatrix;
 
 // Blend
-varying vec2 vBlendUV;
 uniform mat4 blendMatrix;
 
 // Normal
@@ -47,12 +50,12 @@ void main(void) {
 	vPositionW = vec3(worldPos);
 	vNormalW = normalize(vec3(world * vec4(normal, 0.0)));
 
-	vGroundUV = vec2(groundMatrix * vec4(uv, 1.0, 0.0));
-	vSnowUV = vec2(snowMatrix * vec4(uv, 1.0, 0.0));
-	vRockUV = vec2(rockMatrix * vec4(uv, 1.0, 0.0));
-	vSandUV = vec2(sandMatrix * vec4(uv, 1.0, 0.0));
-	vGrassUV = vec2(grassMatrix * vec4(uv, 1.0, 0.0));
-	vBlendUV = vec2(blendMatrix * vec4(uv, 1.0, 0.0));
+	vGroundSnowUV.xy = vec2(groundMatrix * vec4(uv, 1.0, 0.0));
+	vGroundSnowUV.zw = vec2(snowMatrix * vec4(uv, 1.0, 0.0));
+	vRockSandUV.xy = vec2(rockMatrix * vec4(uv, 1.0, 0.0));
+	vRockSandUV.zw = vec2(sandMatrix * vec4(uv, 1.0, 0.0));
+	vGrassBlendUV.xy = vec2(grassMatrix * vec4(uv, 1.0, 0.0));
+	vGrassBlendUV.zw = vec2(blendMatrix * vec4(uv, 1.0, 0.0));
 
 	// Clip plane
 #ifdef CLIPPLANE

+ 1 - 1
Samples/Scenes/WorldMonger/Shaders/Ground/groundMaterial.js

@@ -76,7 +76,7 @@
         if (this._cachedDefines != join) {
             this._cachedDefines = join;
 
-            this._effect = engine.createEffect("Shaders/Ground/ground",
+            this._effect = engine.createEffect("./Shaders/Ground/ground",
                 ["position", "normal", "uv"],
                 ["worldViewProjection", "groundMatrix", "sandMatrix", "rockMatrix", "snowMatrix", "grassMatrix", "blendMatrix", "world", "vLightPosition", "vEyePosition", "vLimits", "vClipPlane"],
                 ["groundSampler", "sandSampler", "rockSampler", "snowSampler", "grassSampler", "blendSampler"],

+ 1 - 1
Samples/Scenes/WorldMonger/Shaders/Water/waterMaterial.js

@@ -69,7 +69,7 @@
             return false;
         }
 
-        this._effect = engine.createEffect("Shaders/Water/water",
+        this._effect = engine.createEffect("./Shaders/Water/water",
             ["position", "normal", "uv"],
             ["worldViewProjection", "world", "view", "vLightPosition", "vEyePosition", "waterColor", "vLevels", "waveData", "windMatrix"],
             ["reflectionSampler", "refractionSampler", "bumpSampler"],

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 10 - 8
Samples/Scenes/WorldMonger/babylon.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 0
Samples/Scenes/WorldMonger/hand.minified-1.1.1.js


+ 1 - 1
Samples/Scenes/WorldMonger/index.css

@@ -62,7 +62,7 @@ a {
     bottom: 70px;
     color: white;
     padding-right: 10px;
-    width: 340px;
+    width: 360px;
     height: 50px;
     transition: all 0.5s ease;
     -webkit-transition: all 0.5s ease;

+ 1 - 1
Samples/Scenes/WorldMonger/index.html

@@ -6,7 +6,7 @@
     <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
     <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
     <link href="index.css" rel="stylesheet" />
-    <script src="hand.minified-1.1.0.js"></script>
+    <script src="hand.minified-1.1.1.js"></script>
     <script src="babylon.js"></script>
     <script src="Shaders/Ground/groundMaterial.js"></script>
     <script src="Shaders/Water/waterMaterial.js"></script>

+ 1 - 2
Samples/Scenes/WorldMonger/index.js

@@ -9,7 +9,6 @@
     }
 
     // Babylon
-    BABYLON.Engine.ShadersRepository = "";
     var engine = new BABYLON.Engine(canvas, true);
     var scene = new BABYLON.Scene(engine);
     var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
@@ -32,7 +31,7 @@
     var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "Assets/heightMap.png", 100, 100, 100, 0, 12, scene, true);
     var groundMaterial = new WORLDMONGER.GroundMaterial("ground", scene, sun);
     ground.material = groundMaterial;
-    ground.position.y = -2.0;    
+    ground.position.y = -2.0;
 
     var extraGround = BABYLON.Mesh.CreateGround("extraGround", 1000, 1000, 1, scene, false);
     var extraGroundMaterial = new BABYLON.StandardMaterial("extraGround", scene);

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 3 - 3
Samples/babylon.js


+ 1 - 1
Samples/index.js

@@ -422,7 +422,7 @@
 
     fullscreen.addEventListener("click", function () {
         if (engine) {
-            engine.switchFullscreen(document.getElementById("rootDiv"));
+            engine.switchFullscreen(true);
         }
     });
 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 13
babylon.1.2.0.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 13 - 0
babylon.1.2.1.js


+ 4 - 0
what's new.txt

@@ -1,3 +1,7 @@
+1.2.1:
+ - Support for PointerLock ()
+ - StandardMaterial now supports per-vertex color
+ - Blender exporter supports per-vertex color
 1.2.0:
  - Major rework of the API to remove GC pressure.
  - FreeCamera: Support for QWERTY keyboards