فهرست منبع

babylon.js v1.0.11

deltakosh 12 سال پیش
والد
کامیت
57aa407e31

+ 11 - 9
Babylon/Cameras/babylon.arcRotateCamera.js

@@ -1,6 +1,8 @@
 var BABYLON = BABYLON || {};
 
 (function () {
+    var eventPrefix = BABYLON.Tools.GetPointerPrefix();
+
     BABYLON.ArcRotateCamera = function (name, alpha, beta, radius, target, scene) {
         this.name = name;
         this.id = name;
@@ -119,11 +121,11 @@
         this._onLostFocus = function () {
             that._keys = [];
         };
-
-        canvas.addEventListener("pointerdown", this._onPointerDown);
-        canvas.addEventListener("pointerup", this._onPointerUp);
-        canvas.addEventListener("pointerout", this._onPointerUp);
-        canvas.addEventListener("pointermove", this._onPointerMove);
+        
+        canvas.addEventListener(eventPrefix + "down", this._onPointerDown);
+        canvas.addEventListener(eventPrefix + "up", this._onPointerUp);
+        canvas.addEventListener(eventPrefix + "out", this._onPointerUp);
+        canvas.addEventListener(eventPrefix + "move", this._onPointerMove);
         window.addEventListener("keydown", this._onKeyDown, true);
         window.addEventListener("keyup", this._onKeyUp, true);
         window.addEventListener('mousewheel', this._wheel);
@@ -131,10 +133,10 @@
     };
     
     BABYLON.ArcRotateCamera.prototype.detachControl = function (canvas) {
-        canvas.removeEventListener("pointerdown", this._onPointerDown);
-        canvas.removeEventListener("pointerup", this._onPointerUp);
-        canvas.removeEventListener("pointerout", this._onPointerUp);
-        canvas.removeEventListener("pointermove", this._onPointerMove);
+        canvas.removeEventListener(eventPrefix + "down", this._onPointerDown);
+        canvas.removeEventListener(eventPrefix + "up", this._onPointerUp);
+        canvas.removeEventListener(eventPrefix + "out", this._onPointerUp);
+        canvas.removeEventListener(eventPrefix + "move", this._onPointerMove);
         window.removeEventListener("keydown", this._onKeyDown);
         window.removeEventListener("keyup", this._onKeyUp);
         window.removeEventListener('mousewheel', this._wheel);

+ 45 - 36
Babylon/Materials/babylon.effect.js

@@ -9,8 +9,9 @@
         this._uniformsNames = uniformsNames.concat(samplers);
         this._samplers = samplers;
         this._isReady = false;
+        this._compilationError = "";
 
-        var that = this;       
+        var that = this;
 
         // Is in local store ?
         if (BABYLON.Effect.ShadersStore[baseName + "VertexShader"]) {
@@ -19,75 +20,83 @@
             var shaderUrl = BABYLON.Engine.ShadersRepository + baseName;
             // Vertex shader
             BABYLON.Tools.LoadFile(shaderUrl + ".vertex.fx",
-                function(vertexSourceCode) {
+                function (vertexSourceCode) {
                     // Fragment shader
                     BABYLON.Tools.LoadFile(shaderUrl + ".fragment.fx",
-                        function(fragmentSourceCode) {
+                        function (fragmentSourceCode) {
                             that._prepareEffect(vertexSourceCode, fragmentSourceCode, attributesNames, defines);
                         });
                 }
             );
         }
-        
+
         // Cache
         this._valueCache = [];
     };
-    
+
     // Properties
     BABYLON.Effect.prototype.isReady = function () {
         return this._isReady;
     };
-    
-    BABYLON.Effect.prototype.getProgram = function() {
+
+    BABYLON.Effect.prototype.getProgram = function () {
         return this._program;
     };
-    
+
     BABYLON.Effect.prototype.getAttribute = function (index) {
         return this._attributes[index];
     };
-    
+
     BABYLON.Effect.prototype.getAttributesCount = function () {
         return this._attributes.length;
     };
-    
+
     BABYLON.Effect.prototype.getUniformIndex = function (uniformName) {
         return this._uniformsNames.indexOf(uniformName);
     };
-    
+
     BABYLON.Effect.prototype.getUniform = function (uniformName) {
         return this._uniforms[this._uniformsNames.indexOf(uniformName)];
     };
-    
+
     BABYLON.Effect.prototype.getSamplers = function () {
         return this._samplers;
     };
     
+    BABYLON.Effect.prototype.getCompilationError = function () {
+        return this._compilationError;
+    };
+
     // Methods
     BABYLON.Effect.prototype._prepareEffect = function (vertexSourceCode, fragmentSourceCode, attributesNames, defines) {
-        var engine = this._engine;
-        this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
+        try {
+            var engine = this._engine;
+            this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
 
-        this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
-        this._attributes = engine.getAttributes(this._program, attributesNames);
+            this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
+            this._attributes = engine.getAttributes(this._program, attributesNames);
 
-        for (var index = 0; index < this._samplers.length; index++) {
-            var sampler = this.getUniform(this._samplers[index]);
+            for (var index = 0; index < this._samplers.length; index++) {
+                var sampler = this.getUniform(this._samplers[index]);
 
-            if (sampler == null) {
-                this._samplers.splice(index, 1);
-                index--;
+                if (sampler == null) {
+                    this._samplers.splice(index, 1);
+                    index--;
+                }
             }
-        }
 
-        engine.bindSamplers(this);
+            engine.bindSamplers(this);
 
-        this._isReady = true;
+            this._isReady = true;
+        } catch (e) {
+            this._compilationError = e.message;
+        }
     };
 
     BABYLON.Effect.prototype.setTexture = function (channel, texture) {
         this._engine.setTexture(this._samplers.indexOf(channel), texture);
     };
-        
+
     BABYLON.Effect.prototype.setMatrix = function (uniformName, matrix) {
         if (this._valueCache[uniformName] && this._valueCache[uniformName].equals(matrix))
             return;
@@ -95,7 +104,7 @@
         this._valueCache[uniformName] = matrix;
         this._engine.setMatrix(this.getUniform(uniformName), matrix);
     };
-    
+
     BABYLON.Effect.prototype.setBool = function (uniformName, bool) {
         if (this._valueCache[uniformName] && this._valueCache[uniformName] === bool)
             return;
@@ -104,7 +113,7 @@
 
         this._engine.setBool(this.getUniform(uniformName), bool);
     };
-    
+
     BABYLON.Effect.prototype.setVector2 = function (uniformName, x, y) {
         if (this._valueCache[uniformName] && this._valueCache[uniformName][0] == x && this._valueCache[uniformName][1] == y)
             return;
@@ -113,16 +122,16 @@
 
         this._engine.setVector2(this.getUniform(uniformName), x, y);
     };
-    
+
     BABYLON.Effect.prototype.setVector3 = function (uniformName, vector3) {
         if (this._valueCache[uniformName] && this._valueCache[uniformName][0] == vector3.x && this._valueCache[uniformName][1] == vector3.y && this._valueCache[uniformName][2] == vector3.z)
             return;
 
         this._valueCache[uniformName] = [vector3.x, vector3.y, vector3.z];
-        
+
         this._engine.setVector3(this.getUniform(uniformName), vector3);
     };
-    
+
     BABYLON.Effect.prototype.setFloat2 = function (uniformName, x, y) {
         if (this._valueCache[uniformName] && this._valueCache[uniformName][0] == x && this._valueCache[uniformName][1] == y)
             return;
@@ -130,7 +139,7 @@
         this._valueCache[uniformName] = [x, y];
         this._engine.setFloat2(this.getUniform(uniformName), x, y);
     };
-    
+
     BABYLON.Effect.prototype.setFloat3 = function (uniformName, x, y, z) {
         if (this._valueCache[uniformName] && this._valueCache[uniformName][0] == x && this._valueCache[uniformName][1] == y && this._valueCache[uniformName][2] == z)
             return;
@@ -138,7 +147,7 @@
         this._valueCache[uniformName] = [x, y, z];
         this._engine.setFloat3(this.getUniform(uniformName), x, y, z);
     };
-    
+
     BABYLON.Effect.prototype.setFloat4 = function (uniformName, x, y, z, w) {
         if (this._valueCache[uniformName] && this._valueCache[uniformName][0] == x && this._valueCache[uniformName][1] == y && this._valueCache[uniformName][2] == z && this._valueCache[uniformName][3] == w)
             return;
@@ -146,15 +155,15 @@
         this._valueCache[uniformName] = [x, y, z, w];
         this._engine.setFloat4(this.getUniform(uniformName), x, y, z, w);
     };
-    
+
     BABYLON.Effect.prototype.setColor3 = function (uniformName, color3) {
-        if (this._valueCache[uniformName]  && this._valueCache[uniformName][0] == color3.r && this._valueCache[uniformName][1] == color3.g && this._valueCache[uniformName][2] == color3.b)
+        if (this._valueCache[uniformName] && this._valueCache[uniformName][0] == color3.r && this._valueCache[uniformName][1] == color3.g && this._valueCache[uniformName][2] == color3.b)
             return;
 
         this._valueCache[uniformName] = [color3.r, color3.g, color3.b];
         this._engine.setColor3(this.getUniform(uniformName), color3);
     };
-    
+
     BABYLON.Effect.prototype.setColor4 = function (uniformName, color3, alpha) {
         if (this._valueCache[uniformName] && this._valueCache[uniformName][0] == color3.r && this._valueCache[uniformName][1] == color3.g && this._valueCache[uniformName][2] == color3.b && this._valueCache[uniformName][3] == alpha)
             return;
@@ -162,7 +171,7 @@
         this._valueCache[uniformName] = [color3.r, color3.g, color3.b, alpha];
         this._engine.setColor4(this.getUniform(uniformName), color3, alpha);
     };
-    
+
     // Statics
     BABYLON.Effect.ShadersStore = {};
 

+ 2 - 2
Babylon/Materials/babylon.standardMaterial.js

@@ -100,7 +100,7 @@
             defines.push("#define SPECULAR");
         }
         
-        if (this.bumpTexture && this._scene.getEngine().getCaps().standardDerivatives && !isIE()) {
+        if (this.bumpTexture && this._scene.getEngine().getCaps().standardDerivatives) {
             defines.push("#define BUMP");
         }
 
@@ -254,7 +254,7 @@
             this._effect.setMatrix("specularMatrix", this.specularTexture._computeTextureMatrix());
         }
         
-        if (this.bumpTexture && this._scene.getEngine().getCaps().standardDerivatives && !isIE()) {
+        if (this.bumpTexture && this._scene.getEngine().getCaps().standardDerivatives) {
             this._effect.setTexture("bumpSampler", this.bumpTexture);
 
             this._effect.setVector2("vBumpInfos", this.bumpTexture.coordinatesIndex, this.bumpTexture.level);

+ 3 - 3
Babylon/Materials/textures/babylon.videoTexture.js

@@ -7,8 +7,8 @@
 
         this.name = name;
 
-        this.wrapU = BABYLON.Texture.REPEAT_CLAMPMODE;
-        this.wrapV = BABYLON.Texture.REPEAT_CLAMPMODE;
+        this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
+        this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
 
         this._texture = scene.getEngine().createDynamicTexture(size, generateMipMaps);
         var textureSize = this.getSize();
@@ -18,7 +18,7 @@
         this.video.height = textureSize.height;
         this.video.autoplay = true;
         this.video.loop = true;
-
+        
         var that = this;
         this.video.addEventListener("canplaythrough", function () {
             that._texture.isReady = true;

+ 1 - 5
Babylon/Particles/babylon.particleSystem.js

@@ -43,7 +43,6 @@
         this.color1 = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
         this.color2 = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
         this.colorDead = new BABYLON.Color4(0, 0, 0, 1.0);
-        this.deadAlpha = 0;
         this.textureMask = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
 
         // Particles
@@ -176,12 +175,9 @@
             var step = randomNumber(0, 1.0);
 
             var startColor = BABYLON.Color4.Lerp(this.color1, this.color2, step);
-            var deadColor = this.colorDead;
-            startColor.a = 1.0;
-            deadColor.a = this.deadAlpha;
 
             particle.color = startColor;
-            var diff = deadColor.subtract(startColor);
+            var diff = this.colorDead.subtract(startColor);
             particle.colorStep = diff.scale(1.0 / particle.lifeTime);
         }
     };

+ 5 - 1
Babylon/Shaders/default.vertex.fx

@@ -1,4 +1,8 @@
-#define MAP_EXPLICIT	0.
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+#define MAP_EXPLICIT	0.
 #define MAP_SPHERICAL	1.
 #define MAP_PLANAR		2.
 #define MAP_CUBIC		3.

+ 5 - 1
Babylon/Shaders/iedefault.vertex.fx

@@ -1,4 +1,8 @@
-#define MAP_EXPLICIT	0.
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+#define MAP_EXPLICIT	0.
 #define MAP_SPHERICAL	1.
 #define MAP_PLANAR		2.
 #define MAP_CUBIC		3.

+ 5 - 1
Babylon/Shaders/layer.vertex.fx

@@ -1,4 +1,8 @@
-// Attributes
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+// Attributes
 attribute vec2 position;
 
 // Uniforms

+ 5 - 1
Babylon/Shaders/particles.vertex.fx

@@ -1,4 +1,8 @@
-// Attributes
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+// Attributes
 attribute vec3 position;
 attribute vec4 color;
 attribute vec4 options;

+ 5 - 1
Babylon/Shaders/sprites.vertex.fx

@@ -1,4 +1,8 @@
-// Attributes
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+// Attributes
 attribute vec3 position;
 attribute vec4 options;
 attribute vec4 cellInfo;

+ 0 - 1
Babylon/Tools/babylon.sceneLoader.js

@@ -161,7 +161,6 @@
         particleSystem.color1 = BABYLON.Color4.FromArray(parsedParticleSystem.color1);
         particleSystem.color2 = BABYLON.Color4.FromArray(parsedParticleSystem.color2);
         particleSystem.colorDead = BABYLON.Color4.FromArray(parsedParticleSystem.colorDead);
-        particleSystem.deadAlpha = parsedParticleSystem.deadAlpha;
         particleSystem.updateSpeed = parsedParticleSystem.updateSpeed;
         particleSystem.targetStopDuration = parsedParticleSystem.targetStopFrame;
         particleSystem.textureMask = BABYLON.Color4.FromArray(parsedParticleSystem.textureMask);

+ 12 - 0
Babylon/Tools/babylon.tools.js

@@ -2,6 +2,18 @@
 
 (function () {
     BABYLON.Tools = {};
+
+    BABYLON.Tools.GetPointerPrefix = function() {
+        var eventPrefix = "pointer";
+
+        // Check if hand.js is referenced or if the browser natively supports pointer events
+        if (!navigator.pointerEnabled) {
+            eventPrefix = "mouse";
+        }
+
+        return eventPrefix;
+    };
+
     BABYLON.Tools.QueueNewFrame = function (func) {
         if (window.requestAnimationFrame)
             window.requestAnimationFrame(func);

+ 28 - 11
Babylon/babylon.engine.js

@@ -39,7 +39,7 @@
 
         // Extensions
         var derivatives = this._gl.getExtension('OES_standard_derivatives');
-        this._caps.standardDerivatives = (derivatives !== undefined);
+        this._caps.standardDerivatives = (derivatives !== null);
 
         // Cache
         this._loadedTexturesCache = [];
@@ -99,7 +99,7 @@
         this._hardwareScalingLevel = level;
         this.resize();
     };
-    
+
     BABYLON.Engine.prototype.getHardwareScalingLevel = function () {
         return this._hardwareScalingLevel;
     };
@@ -383,14 +383,14 @@
 
         this._gl.uniform3f(uniform, vector3.x, vector3.y, vector3.z);
     };
-    
+
     BABYLON.Engine.prototype.setFloat2 = function (uniform, x, y) {
         if (!uniform)
             return;
 
         this._gl.uniform2f(uniform, x, y);
     };
-    
+
     BABYLON.Engine.prototype.setFloat3 = function (uniform, x, y, z) {
         if (!uniform)
             return;
@@ -559,16 +559,16 @@
         return texture;
     };
 
-    BABYLON.Engine.prototype.createDynamicTexture = function (size, noMipmap) {
+    BABYLON.Engine.prototype.createDynamicTexture = function (size, generateMipMaps) {
         var texture = this._gl.createTexture();
 
         var width = getExponantOfTwo(size, this._caps.maxTextureSize);
-        var height = getExponantOfTwo(size, this._caps.maxTextureSize);
+        var height = width;
 
         this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
         this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, this._gl.LINEAR);
 
-        if (noMipmap) {
+        if (!generateMipMaps) {
             this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.LINEAR);
         } else {
             this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.LINEAR_MIPMAP_LINEAR);
@@ -581,7 +581,7 @@
         texture._width = width;
         texture._height = height;
         texture.isReady = false;
-        texture.noMipmap = noMipmap;
+        texture.generateMipMaps = generateMipMaps;
         texture.references = 1;
 
         this._loadedTexturesCache.push(texture);
@@ -593,7 +593,7 @@
         this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
         this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, true);
         this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, canvas);
-        if (!texture.noMipmap) {
+        if (texture.generateMipMaps) {
             this._gl.generateMipmap(this._gl.TEXTURE_2D);
         }
         this._gl.bindTexture(this._gl.TEXTURE_2D, null);
@@ -604,10 +604,27 @@
     BABYLON.Engine.prototype.updateVideoTexture = function (texture, video) {
         this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
         this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, false);
-        this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, video);
-        if (!texture.noMipmap) {
+
+        // Scale the video if it is a NPOT
+        if (video.videoWidth !== texture._width || video.videoHeight !== texture._height) {
+            if (!texture._workingCanvas) {
+                texture._workingCanvas = document.createElement("canvas");
+                texture._workingContext = texture._workingCanvas.getContext("2d");
+                texture._workingCanvas.width = texture._width;
+                texture._workingCanvas.height = texture._height;
+            }
+
+            texture._workingContext.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, texture._width, texture._height);
+
+            this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, texture._workingCanvas);
+        } else {
+            this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, video);
+        }
+        
+        if (texture.generateMipMaps) {
             this._gl.generateMipmap(this._gl.TEXTURE_2D);
         }
+        
         this._gl.bindTexture(this._gl.TEXTURE_2D, null);
         this._activeTexturesCache = [];
         texture.isReady = true;

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 11
babylon.1.0.10.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 11 - 0
babylon.1.0.11.js


+ 3 - 0
what's new.txt

@@ -1,3 +1,6 @@
+1.0.11:
+ - Fixing a bug with NOPT video texture
+ - Hand.js is no longer required for ArcRotateCamera
 1.0.10:
  - Using typed arrays for Matrix
  - Improving IE11 support