Explorar o código

Extend SubMesh class to deal with an optional shadow depth effect

Popov72 %!s(int64=5) %!d(string=hai) anos
pai
achega
af85c8c1d8
Modificáronse 2 ficheiros con 50 adicións e 0 borrados
  1. 1 0
      src/Meshes/index.ts
  2. 49 0
      src/Meshes/subMesh.shadowDepth.ts

+ 1 - 0
src/Meshes/index.ts

@@ -14,6 +14,7 @@ export * from "./meshSimplification";
 export * from "./meshSimplificationSceneComponent";
 export * from "./polygonMesh";
 export * from "./subMesh";
+export * from "./subMesh.shadowDepth";
 export * from "./meshLODLevel";
 export * from "./transformNode";
 export * from "./Builders/index";

+ 49 - 0
src/Meshes/subMesh.shadowDepth.ts

@@ -0,0 +1,49 @@
+import { Nullable } from "../types";
+import { Effect } from "../Materials/effect";
+import { SubMesh } from './subMesh';
+
+declare type MaterialDefines = import("../Materials/materialDefines").MaterialDefines;
+
+declare module "../Meshes/subMesh" {
+    export interface SubMesh {
+        switchToRegularEffect: () => void;
+
+        switchToShadowDepthEffect: () => void;
+
+        /** @hidden */
+        _materialDefinesShadowDepth: Nullable<MaterialDefines>;
+        /** @hidden */
+        _materialEffectShadowDepth: Nullable<Effect>;
+
+        /** @hidden */
+        _regularDefines: Nullable<MaterialDefines>;
+        /** @hidden */
+        _regularEffect: Nullable<Effect>;
+
+        /** @hidden */
+        _currentEffect: number; /* 0=regular, 1=shadow depth */
+
+    }
+}
+
+SubMesh.prototype._currentEffect = 0;
+
+SubMesh.prototype.switchToRegularEffect = function() {
+    if (this._currentEffect !== 0)  {
+        this._currentEffect = 0;
+        this._materialDefinesShadowDepth = this._materialDefines;
+        this._materialEffectShadowDepth = this._materialEffect;
+        this._materialDefines = this._regularDefines;
+        this._materialEffect = this._regularEffect;
+    }
+};
+
+SubMesh.prototype.switchToShadowDepthEffect = function() {
+    if (this._currentEffect !== 1)  {
+        this._currentEffect = 1;
+        this._regularDefines = this._materialDefines;
+        this._regularEffect = this._materialEffect;
+        this._materialDefines = this._materialDefinesShadowDepth;
+        this._materialEffect = this._materialEffectShadowDepth;
+    }
+};