瀏覽代碼

Associated with #2894

David Catuhe 7 年之前
父節點
當前提交
06b9cbceec

+ 6 - 2
Playground/scripts/shadows.js

@@ -42,13 +42,17 @@
 	// Torus
 	var torus = BABYLON.Mesh.CreateTorus("torus", 4, 2, 30, scene, false);
 
+	// Box
+    var box = BABYLON.Mesh.CreateBox("box", 3);
+    box.parent = torus;	
+
 	// Shadows
 	var shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
-	shadowGenerator.getShadowMap().renderList.push(torus);
+	shadowGenerator.addShadowCaster(torus);
 	shadowGenerator.useExponentialShadowMap = true;
 
 	var shadowGenerator2 = new BABYLON.ShadowGenerator(1024, light2);
-	shadowGenerator2.getShadowMap().renderList.push(torus);
+	shadowGenerator2.addShadowCaster(torus);
 	shadowGenerator2.usePoissonSampling = true;
 
 	ground.receiveShadows = true;

File diff suppressed because it is too large
+ 4542 - 4530
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 4542 - 4530
dist/preview release/babylon.module.d.ts


+ 2 - 1
dist/preview release/what's new.md

@@ -18,7 +18,8 @@
 - Added support for Particle animation in ParticleSystem. [Doc here](http://doc.babylonjs.com/tutorials/particles#particle-animation) ([Ibraheem Osama](https://github.com/IbraheemOsama))
 
 ## Updates
-- Several inspector improvments ([temechon](https://github.com/temechon))
+- Added `shadowGenerator.addShadowCaster` and `shadowGenerator.removeShadowCaster` helper functions ([deltakosh](https://github.com/deltakosh))
+- Several inspector improvements ([temechon](https://github.com/temechon))
 - New observables for actions: `onBeforeExecuteObservable` for all actions and `onInterpolationDoneObservable` for `InterpolateValueAction` ([deltakosh](https://github.com/deltakosh))
 - New observables for gamepads: `onButtonDownObservable`, `onButtonUpObservable`, `onPadDownObservable`, `onPadUpObservable` ([deltakosh](https://github.com/deltakosh))
 - New `camera.storeState()` and `camera.restoreState()` functions to store / restore cameras position / rotation / fov. (Doc here)[http://doc.babylonjs.com/tutorials/cameras#state] ([deltakosh](https://github.com/deltakosh))

+ 36 - 0
src/Lights/Shadows/babylon.shadowGenerator.ts

@@ -270,6 +270,42 @@
         }
 
         /**
+         * Helper function to add a mesh and its descendants to the list of shadow casters
+         * @param mesh Mesh to add
+         * @param includeDescendants boolean indicating if the descendants should be added. Default to true
+         */
+        public addShadowCaster(mesh: AbstractMesh, includeDescendants = true): ShadowGenerator {
+            this._shadowMap.renderList.push(mesh);
+
+            if (includeDescendants) {
+                this._shadowMap.renderList.push(...mesh.getChildMeshes());
+            }
+
+            return this;
+        }
+
+        /**
+         * Helper function to remove a mesh and its descendants from the list of shadow casters
+         * @param mesh Mesh to remove
+         * @param includeDescendants boolean indicating if the descendants should be removed. Default to true
+         */
+        public removeShadowCaster(mesh: AbstractMesh, includeDescendants = true): ShadowGenerator {
+            var index = this._shadowMap.renderList.indexOf(mesh);
+
+            if (index !== -1) {
+                this._shadowMap.renderList.splice(index, 1);
+            }
+
+            if (includeDescendants) {
+                for (var child of mesh.getChildren()) {
+                    this.removeShadowCaster(<any>child);
+                }
+            }
+
+            return this;
+        }
+
+        /**
 		 * Controls the extent to which the shadows fade out at the edge of the frustum
          * Used only by directionals and spots
 		 */