David Catuhe 11 年 前
コミット
704571c1cd

+ 5 - 0
Babylon/Lights/babylon.directionalLight.js

@@ -17,6 +17,11 @@ var BABYLON;
 
             this.position = direction.scale(-1);
         }
+        DirectionalLight.prototype.setDirectionToTarget = function (target) {
+            this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
+            return this.direction;
+        };
+
         DirectionalLight.prototype._computeTransformedPosition = function () {
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this._transformedPosition) {

+ 5 - 0
Babylon/Lights/babylon.directionalLight.ts

@@ -15,6 +15,11 @@
             this.position = direction.scale(-1);
         }
 
+        public setDirectionToTarget(target: Vector3): Vector3 {
+            this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
+            return this.direction;
+        }
+
         public _computeTransformedPosition(): boolean {
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this._transformedPosition) {

+ 5 - 0
Babylon/Lights/babylon.spotLight.js

@@ -18,6 +18,11 @@ var BABYLON;
             this.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0);
             this.specular = new BABYLON.Color3(1.0, 1.0, 1.0);
         }
+        SpotLight.prototype.setDirectionToTarget = function (target) {
+            this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
+            return this.direction;
+        };
+
         //ANY
         SpotLight.prototype.transferToEffect = function (effect, positionUniformName, directionUniformName) {
             var normalizeDirection;

+ 5 - 0
Babylon/Lights/babylon.spotLight.ts

@@ -12,6 +12,11 @@
             super(name, scene);
         }
 
+        public setDirectionToTarget(target: Vector3): Vector3 {
+            this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
+            return this.direction;
+        }
+
         //ANY
         public transferToEffect(effect, positionUniformName: string, directionUniformName: string): void {
             var normalizeDirection;

+ 5 - 0
Babylon/Mesh/babylon.vertexBuffer.js

@@ -59,6 +59,11 @@
 
         // Methods
         VertexBuffer.prototype.update = function (data) {
+            if (!this._updatable) {
+                console.log("You cannot update a non-updatable vertex buffer");
+                return;
+            }
+
             this._engine.updateDynamicVertexBuffer(this._buffer, data);
             this._data = data;
 

+ 5 - 0
Babylon/Mesh/babylon.vertexBuffer.ts

@@ -67,6 +67,11 @@
 
         // Methods
         public update(data: number[]): void {
+            if (!this._updatable) {
+                console.log("You cannot update a non-updatable vertex buffer");
+                return;
+            }
+
             this._engine.updateDynamicVertexBuffer(this._buffer, data);
             this._data = data;
 

+ 21 - 6
Babylon/babylon.engine.js

@@ -72,9 +72,13 @@ var BABYLON = BABYLON || {};
         };
 
         this._compiledEffects = {};
+        this._lastVertexAttribIndex = 0;
 
-        this._gl.enable(this._gl.DEPTH_TEST);
-        this._gl.depthFunc(this._gl.LEQUAL);
+        // Depth buffer
+        this._depthMask = false;
+        this.setDepthBuffer(true);
+        this.setDepthFunctionToLessOrEqual();
+        this.setDepthWrite(true);
 
         // Fullscreen
         this.isFullscreen = false;
@@ -231,13 +235,15 @@ var BABYLON = BABYLON || {};
 
     BABYLON.Engine.prototype.clear = function (color, backBuffer, depthStencil) {
         this._gl.clearColor(color.r, color.g, color.b, color.a !== undefined ? color.a : 1.0);
-        this._gl.clearDepth(1.0);
+        if (this._depthMask) {
+            this._gl.clearDepth(1.0);
+        }
         var mode = 0;
 
         if (backBuffer)
             mode |= this._gl.COLOR_BUFFER_BIT;
 
-        if (depthStencil)
+        if (depthStencil && this._depthMask)
             mode |= this._gl.DEPTH_BUFFER_BIT;
 
         this._gl.clear(mode);
@@ -498,15 +504,23 @@ var BABYLON = BABYLON || {};
         // Use program
         this._gl.useProgram(effect.getProgram());
 
-        for (var index = 0; index < effect.getAttributesCount() ; index++) {
+        var currentCount = effect.getAttributesCount();
+        var maxIndex = 0;
+        for (var index = 0; index < currentCount; index++) {
             // Attributes
             var order = effect.getAttribute(index);
 
             if (order >= 0) {
                 this._gl.enableVertexAttribArray(effect.getAttribute(index));
+                maxIndex = Math.max(maxIndex, order);
             }
         }
 
+        for (index = maxIndex + 1; index <= this._lastVertexAttribIndex; index++) {
+            this._gl.disableVertexAttribArray(index);
+        }
+
+        this._lastVertexAttribIndex = maxIndex;
         this._currentEffect = effect;
     };
     
@@ -605,6 +619,7 @@ var BABYLON = BABYLON || {};
 
     BABYLON.Engine.prototype.setDepthWrite = function (enable) {
         this._gl.depthMask(enable);
+        this._depthMask = enable;
     };
 
     BABYLON.Engine.prototype.setColorWrite = function (enable) {
@@ -788,7 +803,7 @@ var BABYLON = BABYLON || {};
         this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
         this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY ? false : true); // Video are upside down by default
 
-        // Scale the video if it is a NPOT
+        // Scale the video if it is a NPOT using the current working canvas
         if (video.videoWidth !== texture._width || video.videoHeight !== texture._height) {
             if (!texture._workingCanvas) {
                 texture._workingCanvas = document.createElement("canvas");