Browse Source

Fixing race conditions with reflection probes

David catuhe 9 năm trước cách đây
mục cha
commit
1f28481c89

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 15 - 15
dist/preview release/babylon.core.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 714 - 712
dist/preview release/babylon.d.ts


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 22 - 22
dist/preview release/babylon.js


+ 56 - 12
dist/preview release/babylon.max.js

@@ -6412,6 +6412,11 @@ var BABYLON;
             var framebuffer = gl.createFramebuffer();
             gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
             gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
+            // mipmaps
+            if (texture.generateMipMaps) {
+                gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
+                gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
+            }
             // Unbind
             gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
             gl.bindRenderbuffer(gl.RENDERBUFFER, null);
@@ -6497,12 +6502,7 @@ var BABYLON;
             }
             gl.deleteTexture(texture);
             // Unbind channels
-            for (var channel = 0; channel < this._caps.maxTexturesImageUnits; channel++) {
-                this._gl.activeTexture(this._gl["TEXTURE" + channel]);
-                this._gl.bindTexture(this._gl.TEXTURE_2D, null);
-                this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null);
-                this._activeTexturesCache[channel] = null;
-            }
+            this.unbindAllTextures();
             var index = this._loadedTexturesCache.indexOf(texture);
             if (index !== -1) {
                 this._loadedTexturesCache.splice(index, 1);
@@ -6525,6 +6525,14 @@ var BABYLON;
         Engine.prototype.setTextureFromPostProcess = function (channel, postProcess) {
             this._bindTexture(channel, postProcess._textures.data[postProcess._currentRenderTextureInd]);
         };
+        Engine.prototype.unbindAllTextures = function () {
+            for (var channel = 0; channel < this._caps.maxTexturesImageUnits; channel++) {
+                this._gl.activeTexture(this._gl["TEXTURE" + channel]);
+                this._gl.bindTexture(this._gl.TEXTURE_2D, null);
+                this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null);
+                this._activeTexturesCache[channel] = null;
+            }
+        };
         Engine.prototype.setTexture = function (channel, texture) {
             if (channel < 0) {
                 return;
@@ -28377,12 +28385,9 @@ var BABYLON;
             return value < BABYLON.PhysicsEngine.Epsilon ? BABYLON.PhysicsEngine.Epsilon : value;
         };
         CannonJSPlugin.prototype.runOneStep = function (delta) {
+            var _this = this;
             this._world.step(delta);
-            for (var index = 0; index < this._registeredMeshes.length; index++) {
-                var registeredMesh = this._registeredMeshes[index];
-                if (registeredMesh.isChild) {
-                    continue;
-                }
+            this._registeredMeshes.forEach(function (registeredMesh) {
                 // Body position
                 var bodyX = registeredMesh.body.position.x, bodyY = registeredMesh.body.position.y, bodyZ = registeredMesh.body.position.z;
                 registeredMesh.mesh.position.x = bodyX + registeredMesh.delta.x;
@@ -28392,7 +28397,27 @@ var BABYLON;
                 if (registeredMesh.deltaRotation) {
                     registeredMesh.mesh.rotationQuaternion.multiplyInPlace(registeredMesh.deltaRotation);
                 }
-            }
+                //is the physics collision callback is set?
+                if (registeredMesh.mesh.onPhysicsCollide) {
+                    if (!registeredMesh.collisionFunction) {
+                        registeredMesh.collisionFunction = function (e) {
+                            //find the mesh that collided with the registered mesh
+                            for (var idx = 0; idx < _this._registeredMeshes.length; idx++) {
+                                if (_this._registeredMeshes[idx].body == e.body) {
+                                    registeredMesh.mesh.onPhysicsCollide(_this._registeredMeshes[idx].mesh);
+                                }
+                            }
+                        };
+                        registeredMesh.body.addEventListener("collide", registeredMesh.collisionFunction);
+                    }
+                }
+                else {
+                    //unregister, in case the function was removed for some reason
+                    if (registeredMesh.collisionFunction) {
+                        registeredMesh.body.removeEventListener("collide", registeredMesh.collisionFunction);
+                    }
+                }
+            });
         };
         CannonJSPlugin.prototype.setGravity = function (gravity) {
             this._world.gravity.set(gravity.x, gravity.y, gravity.z);
@@ -28736,6 +28761,7 @@ var BABYLON;
             mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
             mesh.computeWorldMatrix(true);
             var bodyConfig = {
+                name: mesh.uniqueId,
                 pos: [bbox.center.x, bbox.center.y, bbox.center.z],
                 rot: [rot.x / OIMO.TO_RAD, rot.y / OIMO.TO_RAD, rot.z / OIMO.TO_RAD],
                 move: options.mass != 0,
@@ -28795,6 +28821,7 @@ var BABYLON;
                 rotations.push.apply(rotations, bodyParameters.rot);
             }
             var body = new OIMO.Body({
+                name: initialMesh.uniqueId,
                 type: types,
                 size: sizes,
                 pos: positions,
@@ -28821,6 +28848,7 @@ var BABYLON;
             mesh.computeWorldMatrix(true);
             var rot = new OIMO.Euler().setFromQuaternion({ x: mesh.rotationQuaternion.x, y: mesh.rotationQuaternion.y, z: mesh.rotationQuaternion.z, s: mesh.rotationQuaternion.w });
             var bodyParameters = {
+                name: mesh.uniqueId,
                 pos: [mesh.position.x, mesh.position.y, mesh.position.z],
                 //A bug in Oimo (Body class) prevents us from using rot directly.
                 rot: [0, 0, 0],
@@ -28976,6 +29004,22 @@ var BABYLON;
                     mesh.rotationQuaternion.copyFrom(body.getQuaternion());
                     mesh.computeWorldMatrix();
                 }
+                //check if the collide callback is set. 
+                if (mesh.onPhysicsCollide) {
+                    var meshUniqueName = mesh.uniqueId;
+                    var contact = this._world.contacts;
+                    while (contact !== null) {
+                        //is this body colliding with any other?
+                        if ((contact.body1.name == mesh.uniqueId || contact.body2.name == mesh.uniqueId) && contact.touching && !contact.body1.sleeping && !contact.body2.sleeping) {
+                            var otherUniqueId = contact.body1.name == mesh.uniqueId ? contact.body2.name : contact.body1.name;
+                            //get the mesh and execute the callback
+                            var otherMesh = mesh.getScene().getMeshByUniqueID(otherUniqueId);
+                            if (otherMesh)
+                                mesh.onPhysicsCollide(otherMesh);
+                        }
+                        contact = contact.next;
+                    }
+                }
             }
         };
         return OimoJSPlugin;

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 22 - 22
dist/preview release/babylon.noworker.js


+ 1 - 1
src/Mesh/babylon.abstractMesh.ts

@@ -74,7 +74,7 @@
         public _physicsMass: number;
         public _physicsFriction: number;
         public _physicRestitution: number;
-        public onPhysicsCollide: (collidedMesh: AbstractMesh) => void;
+        public onPhysicsCollide: (collidedMesh: AbstractMesh) => void; 
 
         // Collisions
         private _checkCollisions = false;

+ 12 - 11
src/Physics/Plugins/babylon.cannonJSPlugin.ts

@@ -1,21 +1,21 @@
 module BABYLON {
     declare var CANNON;
-    
+
     interface IRegisteredMesh {
         mesh: AbstractMesh;
         body: any; //Cannon body
-        material : any;
+        material: any;
         delta: Vector3;
         deltaRotation: Quaternion;
         heightmap: boolean;
         collisionFunction?: (event: any) => void;
-        
+
     }
 
     export class CannonJSPlugin implements IPhysicsEnginePlugin {
 
         private _world: any;
-        private _registeredMeshes : Array<IRegisteredMesh> = [];
+        private _registeredMeshes: Array<IRegisteredMesh> = [];
         private _physicsMaterials = [];
 
         public initialize(iterations: number = 10): void {
@@ -46,14 +46,14 @@
                 if (registeredMesh.deltaRotation) {
                     registeredMesh.mesh.rotationQuaternion.multiplyInPlace(registeredMesh.deltaRotation);
                 }
-                
+
                 //is the physics collision callback is set?
-                if(registeredMesh.mesh.onPhysicsCollide) {
-                    if(!registeredMesh.collisionFunction) {
+                if (registeredMesh.mesh.onPhysicsCollide) {
+                    if (!registeredMesh.collisionFunction) {
                         registeredMesh.collisionFunction = (e) => {
                             //find the mesh that collided with the registered mesh
                             for (var idx = 0; idx < this._registeredMeshes.length; idx++) {
-                                if(this._registeredMeshes[idx].body == e.body) {
+                                if (this._registeredMeshes[idx].body == e.body) {
                                     registeredMesh.mesh.onPhysicsCollide(this._registeredMeshes[idx].mesh);
                                 }
                             }
@@ -62,11 +62,11 @@
                     }
                 } else {
                     //unregister, in case the function was removed for some reason
-                    if(registeredMesh.collisionFunction) {
-                        registeredMesh.body.removeEventListener("collide", registeredMesh.collisionFunction)
+                    if (registeredMesh.collisionFunction) {
+                        registeredMesh.body.removeEventListener("collide", registeredMesh.collisionFunction);
                     }
                 }
-            })
+            });
         }
 
         public setGravity(gravity: Vector3): void {
@@ -485,3 +485,4 @@
 
 
 
+

+ 2 - 1
src/Physics/Plugins/babylon.oimoJSPlugin.js

@@ -120,6 +120,7 @@ var BABYLON;
                 rotations.push.apply(rotations, bodyParameters.rot);
             }
             var body = new OIMO.Body({
+                name: initialMesh.uniqueId,
                 type: types,
                 size: sizes,
                 pos: positions,
@@ -308,7 +309,7 @@ var BABYLON;
                     var contact = this._world.contacts;
                     while (contact !== null) {
                         //is this body colliding with any other?
-                        if ((contact.body1.name == mesh.uniqueId || contact.body2.name == mesh.uniqueId) && contact.touching && !contact.sleeping) {
+                        if ((contact.body1.name == mesh.uniqueId || contact.body2.name == mesh.uniqueId) && contact.touching && !contact.body1.sleeping && !contact.body2.sleeping) {
                             var otherUniqueId = contact.body1.name == mesh.uniqueId ? contact.body2.name : contact.body1.name;
                             //get the mesh and execute the callback
                             var otherMesh = mesh.getScene().getMeshByUniqueID(otherUniqueId);

+ 5 - 4
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -384,16 +384,16 @@ module BABYLON {
                 }
                 
                 //check if the collide callback is set. 
-                if(mesh.onPhysicsCollide) {
+                if (mesh.onPhysicsCollide) {
                     var meshUniqueName = mesh.uniqueId;
                     var contact = this._world.contacts;
-                    while(contact!==null){
+                    while (contact !== null) {
                         //is this body colliding with any other?
-                        if((contact.body1.name == mesh.uniqueId || contact.body2.name == mesh.uniqueId) && contact.touching && /* !contact.sleeping*/ !contact.body1.sleeping && !contact.body2.sleeping) {
+                        if ((contact.body1.name == mesh.uniqueId || contact.body2.name == mesh.uniqueId) && contact.touching && /* !contact.sleeping*/ !contact.body1.sleeping && !contact.body2.sleeping) {
                             var otherUniqueId = contact.body1.name == mesh.uniqueId ? contact.body2.name : contact.body1.name;
                             //get the mesh and execute the callback
                             var otherMesh = mesh.getScene().getMeshByUniqueID(otherUniqueId);
-                            if(otherMesh)
+                            if (otherMesh)
                                 mesh.onPhysicsCollide(otherMesh);
                         }
                         contact = contact.next;
@@ -405,3 +405,4 @@ module BABYLON {
 }
 
 
+

+ 14 - 6
src/babylon.engine.js

@@ -1695,6 +1695,11 @@ var BABYLON;
             var framebuffer = gl.createFramebuffer();
             gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
             gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
+            // mipmaps
+            if (texture.generateMipMaps) {
+                gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
+                gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
+            }
             // Unbind
             gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
             gl.bindRenderbuffer(gl.RENDERBUFFER, null);
@@ -1780,12 +1785,7 @@ var BABYLON;
             }
             gl.deleteTexture(texture);
             // Unbind channels
-            for (var channel = 0; channel < this._caps.maxTexturesImageUnits; channel++) {
-                this._gl.activeTexture(this._gl["TEXTURE" + channel]);
-                this._gl.bindTexture(this._gl.TEXTURE_2D, null);
-                this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null);
-                this._activeTexturesCache[channel] = null;
-            }
+            this.unbindAllTextures();
             var index = this._loadedTexturesCache.indexOf(texture);
             if (index !== -1) {
                 this._loadedTexturesCache.splice(index, 1);
@@ -1808,6 +1808,14 @@ var BABYLON;
         Engine.prototype.setTextureFromPostProcess = function (channel, postProcess) {
             this._bindTexture(channel, postProcess._textures.data[postProcess._currentRenderTextureInd]);
         };
+        Engine.prototype.unbindAllTextures = function () {
+            for (var channel = 0; channel < this._caps.maxTexturesImageUnits; channel++) {
+                this._gl.activeTexture(this._gl["TEXTURE" + channel]);
+                this._gl.bindTexture(this._gl.TEXTURE_2D, null);
+                this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null);
+                this._activeTexturesCache[channel] = null;
+            }
+        };
         Engine.prototype.setTexture = function (channel, texture) {
             if (channel < 0) {
                 return;

+ 16 - 6
src/babylon.engine.ts

@@ -2011,6 +2011,12 @@
             gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
             gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
 
+            // mipmaps
+            if (texture.generateMipMaps) {
+                gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
+                gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
+            }
+
             // Unbind
             gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
             gl.bindRenderbuffer(gl.RENDERBUFFER, null);
@@ -2125,12 +2131,7 @@
             gl.deleteTexture(texture);
 
             // Unbind channels
-            for (var channel = 0; channel < this._caps.maxTexturesImageUnits; channel++) {
-                this._gl.activeTexture(this._gl["TEXTURE" + channel]);
-                this._gl.bindTexture(this._gl.TEXTURE_2D, null);
-                this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null);
-                this._activeTexturesCache[channel] = null;
-            }
+            this.unbindAllTextures();
 
             var index = this._loadedTexturesCache.indexOf(texture);
             if (index !== -1) {
@@ -2160,6 +2161,15 @@
             this._bindTexture(channel, postProcess._textures.data[postProcess._currentRenderTextureInd]);
         }
 
+        public unbindAllTextures(): void {
+            for (var channel = 0; channel < this._caps.maxTexturesImageUnits; channel++) {
+                this._gl.activeTexture(this._gl["TEXTURE" + channel]);
+                this._gl.bindTexture(this._gl.TEXTURE_2D, null);
+                this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null);
+                this._activeTexturesCache[channel] = null;
+            }
+        }
+
         public setTexture(channel: number, texture: BaseTexture): void {
             if (channel < 0) {
                 return;