Просмотр исходного кода

New ```Light.includedOnlyMeshes``` array to define explicitely which mesh is affected by a light

David Catuhe 11 лет назад
Родитель
Сommit
1cd7c6f69f

+ 18 - 0
Babylon/Lights/babylon.light.js

@@ -14,8 +14,10 @@ var BABYLON;
             this.specular = new BABYLON.Color3(1.0, 1.0, 1.0);
             this.intensity = 1.0;
             this.range = Number.MAX_VALUE;
+            this.includedOnlyMeshes = new Array();
             this.excludedMeshes = new Array();
             this._excludedMeshesIds = new Array();
+            this._includedOnlyMeshesIds = new Array();
 
             scene.lights.push(this);
         }
@@ -30,6 +32,22 @@ var BABYLON;
             return BABYLON.Matrix.Identity();
         };
 
+        Light.prototype.canAffectMesh = function (mesh) {
+            if (!mesh) {
+                return true;
+            }
+
+            if (this.includedOnlyMeshes.length > 0 && this.includedOnlyMeshes.indexOf(mesh) === -1) {
+                return false;
+            }
+
+            if (this.includedOnlyMeshes.length > 0 && this.excludedMeshes.indexOf(mesh) !== -1) {
+                return false;
+            }
+
+            return true;
+        };
+
         Light.prototype.getWorldMatrix = function () {
             this._currentRenderId = this.getScene().getRenderId();
 

+ 18 - 0
Babylon/Lights/babylon.light.ts

@@ -4,11 +4,13 @@
         public specular = new Color3(1.0, 1.0, 1.0);
         public intensity = 1.0;
         public range = Number.MAX_VALUE;
+        public includedOnlyMeshes = new Array<AbstractMesh>();
         public excludedMeshes = new Array<AbstractMesh>();
 
         public _shadowGenerator: ShadowGenerator;
         private _parentedWorldMatrix: Matrix;
         public _excludedMeshesIds = new Array<string>();
+        public _includedOnlyMeshesIds = new Array<string>();
 
         constructor(name: string, scene: Scene) {
             super(name, scene);
@@ -27,6 +29,22 @@
             return Matrix.Identity();
         }
 
+        public canAffectMesh(mesh: AbstractMesh): boolean {
+            if (!mesh) {
+                return true;
+            }
+
+            if (this.includedOnlyMeshes.length > 0 && this.includedOnlyMeshes.indexOf(mesh) === -1) {
+                return false;
+            }
+
+            if (this.includedOnlyMeshes.length > 0 && this.excludedMeshes.indexOf(mesh) !== -1) {
+                return false;
+            }
+
+            return true;
+        }
+
         public getWorldMatrix(): Matrix {
             this._currentRenderId = this.getScene().getRenderId();
 

+ 4 - 0
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -307,6 +307,10 @@
                 light._excludedMeshesIds = parsedLight.excludedMeshesIds;
             }
 
+            if (parsedLight.includedOnlyMeshesIds) {
+                light._includedOnlyMeshesIds = parsedLight.includedOnlyMeshesIds;
+            }
+
             // Animations
             if (parsedLight.animations) {
                 for (var animationIndex = 0; animationIndex < parsedLight.animations.length; animationIndex++) {

+ 4 - 0
Babylon/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -306,6 +306,10 @@
             light._excludedMeshesIds = parsedLight.excludedMeshesIds;
         }
 
+        if (parsedLight.includedOnlyMeshesIds) {
+            light._includedOnlyMeshesIds = parsedLight.includedOnlyMeshesIds;
+        }
+
         // Animations
         if (parsedLight.animations) {
             for (var animationIndex = 0; animationIndex < parsedLight.animations.length; animationIndex++) {

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

@@ -167,6 +167,7 @@ var BABYLON;
                         continue;
                     }
 
+                    // Excluded check
                     if (light._excludedMeshesIds.length > 0) {
                         for (var excludedIndex = 0; excludedIndex < light._excludedMeshesIds.length; excludedIndex++) {
                             var excludedMesh = scene.getMeshByID(light._excludedMeshesIds[excludedIndex]);
@@ -179,7 +180,20 @@ var BABYLON;
                         light._excludedMeshesIds = [];
                     }
 
-                    if (mesh && light.excludedMeshes.indexOf(mesh) !== -1) {
+                    // Included check
+                    if (light._includedOnlyMeshesIds.length > 0) {
+                        for (var includedOnlyIndex = 0; includedOnlyIndex < light._includedOnlyMeshesIds.length; includedOnlyIndex++) {
+                            var includedOnlyMesh = scene.getMeshByID(light._includedOnlyMeshesIds[includedOnlyIndex]);
+
+                            if (includedOnlyMesh) {
+                                light.includedOnlyMeshes.push(includedOnlyMesh);
+                            }
+                        }
+
+                        light._includedOnlyMeshesIds = [];
+                    }
+
+                    if (!light.canAffectMesh(mesh)) {
                         continue;
                     }
 
@@ -403,7 +417,7 @@ var BABYLON;
                         continue;
                     }
 
-                    if (mesh && light.excludedMeshes.indexOf(mesh) !== -1) {
+                    if (!light.canAffectMesh(mesh)) {
                         continue;
                     }
 

+ 16 - 2
Babylon/Materials/babylon.standardMaterial.ts

@@ -170,6 +170,7 @@
                         continue;
                     }
 
+                    // Excluded check
                     if (light._excludedMeshesIds.length > 0) {
                         for (var excludedIndex = 0; excludedIndex < light._excludedMeshesIds.length; excludedIndex++) {
                             var excludedMesh = scene.getMeshByID(light._excludedMeshesIds[excludedIndex]);
@@ -182,7 +183,20 @@
                         light._excludedMeshesIds = [];
                     }
 
-                    if (mesh && light.excludedMeshes.indexOf(mesh) !== -1) {
+                    // Included check
+                    if (light._includedOnlyMeshesIds.length > 0) {
+                        for (var includedOnlyIndex = 0; includedOnlyIndex < light._includedOnlyMeshesIds.length; includedOnlyIndex++) {
+                            var includedOnlyMesh = scene.getMeshByID(light._includedOnlyMeshesIds[includedOnlyIndex]);
+
+                            if (includedOnlyMesh) {
+                                light.includedOnlyMeshes.push(includedOnlyMesh);
+                            }
+                        }
+
+                        light._includedOnlyMeshesIds = [];
+                    }
+
+                    if (!light.canAffectMesh(mesh)) {
                         continue;
                     }
 
@@ -409,7 +423,7 @@
                         continue;
                     }
 
-                    if (mesh && light.excludedMeshes.indexOf(mesh) !== -1) {
+                    if (!light.canAffectMesh(mesh)) {
                         continue;
                     }
 

+ 2 - 2
Babylon/babylon.scene.js

@@ -1182,8 +1182,8 @@
             // Moving coordinates to local viewport world
             x = x / this._engine.getHardwareScalingLevel() - viewport.x;
             y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
-
-            return BABYLON.Ray.CreateNew(x / window.devicePixelRatio, y / window.devicePixelRatio, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
+            return BABYLON.Ray.CreateNew(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
+            //       return BABYLON.Ray.CreateNew(x / window.devicePixelRatio, y / window.devicePixelRatio, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
         };
 
         Scene.prototype._internalPick = function (rayFunction, predicate, fastCheck) {

+ 2 - 2
Babylon/babylon.scene.ts

@@ -1268,8 +1268,8 @@
             // Moving coordinates to local viewport world
             x = x / this._engine.getHardwareScalingLevel() - viewport.x;
             y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
-
-            return BABYLON.Ray.CreateNew(x / window.devicePixelRatio, y / window.devicePixelRatio, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
+            return BABYLON.Ray.CreateNew(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
+     //       return BABYLON.Ray.CreateNew(x / window.devicePixelRatio, y / window.devicePixelRatio, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
         }
 
         private _internalPick(rayFunction: (world: Matrix) => Ray, predicate: (mesh: AbstractMesh) => boolean, fastCheck?: boolean): PickingInfo {

Разница между файлами не показана из-за своего большого размера
+ 28 - 0
babylon.1.14-beta-debug.js


Разница между файлами не показана из-за своего большого размера
+ 15 - 0
babylon.1.14-beta.js