浏览代码

Moving parse functions

Skeleton, LensFlareSystem, ShadowGenerator, Material, MultiMaterial,
ParticleSystem
Raanan Weber 9 年之前
父节点
当前提交
8fc24e9dd1

+ 21 - 0
src/Bones/babylon.skeleton.ts

@@ -136,5 +136,26 @@
             // Remove from scene
             this.getScene().removeSkeleton(this);
         }
+        
+        public static ParseSkeleton(parsedSkeleton: any, scene: BABYLON.Scene) : BABYLON.Skeleton {
+            var skeleton = new BABYLON.Skeleton(parsedSkeleton.name, parsedSkeleton.id, scene);
+
+            for (var index = 0; index < parsedSkeleton.bones.length; index++) {
+                var parsedBone = parsedSkeleton.bones[index];
+    
+                var parentBone = null;
+                if (parsedBone.parentBoneIndex > -1) {
+                    parentBone = skeleton.bones[parsedBone.parentBoneIndex];
+                }
+    
+                var bone = new BABYLON.Bone(parsedBone.name, skeleton, parentBone, BABYLON.Matrix.FromArray(parsedBone.matrix));
+    
+                if (parsedBone.animation) {
+                    bone.animations.push(Animation.ParseAnimation(parsedBone.animation));
+                }
+            }
+    
+            return skeleton;
+        }
     }
 }

+ 1 - 1
src/LensFlare/babylon.lensFlare.ts

@@ -13,7 +13,7 @@
             system.lensFlares.push(this);
         }
 
-        public dispose = function (): void {
+        public dispose = function(): void {
             if (this.texture) {
                 this.texture.dispose();
             }

+ 14 - 0
src/LensFlare/babylon.lensFlareSystem.ts

@@ -233,5 +233,19 @@
             var index = this._scene.lensFlareSystems.indexOf(this);
             this._scene.lensFlareSystems.splice(index, 1);
         }
+        
+        public static ParseLensFlareSystem(parsedLensFlareSystem: any, scene: Scene, rootUrl: string): LensFlare {
+            var emitter = scene.getLastEntryByID(parsedLensFlareSystem.emitterId);
+
+            var lensFlareSystem = new LensFlareSystem("lensFlareSystem#" + parsedLensFlareSystem.emitterId, emitter, scene);
+            lensFlareSystem.borderLimit = parsedLensFlareSystem.borderLimit;
+
+            for (var index = 0; index < parsedLensFlareSystem.flares.length; index++) {
+                var parsedFlare = parsedLensFlareSystem.flares[index];
+                var flare = new LensFlare(parsedFlare.size, parsedFlare.position, Color3.FromArray(parsedFlare.color), rootUrl + parsedFlare.textureName, lensFlareSystem);
+            }
+
+            return lensFlareSystem;
+        }
     }
 } 

+ 37 - 4
src/Lights/Shadows/babylon.shadowGenerator.ts

@@ -89,7 +89,7 @@
                 (!this._light.supportsVSM() && (
                     this.filter === ShadowGenerator.FILTER_VARIANCESHADOWMAP ||
                     this.filter === ShadowGenerator.FILTER_BLURVARIANCESHADOWMAP
-                    ));
+                ));
         }
         public set usePoissonSampling(value: boolean) {
             this.filter = (value ? ShadowGenerator.FILTER_POISSONSAMPLING : ShadowGenerator.FILTER_NONE);
@@ -135,11 +135,11 @@
             this._shadowMap = new RenderTargetTexture(light.name + "_shadowMap", mapSize, this._scene, false, true, Engine.TEXTURETYPE_UNSIGNED_INT, light.needCube());
             this._shadowMap.wrapU = Texture.CLAMP_ADDRESSMODE;
             this._shadowMap.wrapV = Texture.CLAMP_ADDRESSMODE;
-            this._shadowMap.anisotropicFilteringLevel = 1;        
+            this._shadowMap.anisotropicFilteringLevel = 1;
             this._shadowMap.updateSamplingMode(Texture.NEAREST_SAMPLINGMODE);
             this._shadowMap.renderParticles = false;
 
-            
+
             this._shadowMap.onBeforeRender = (faceIndex: number) => {
                 this._currentFaceIndex = faceIndex;
             }
@@ -332,7 +332,7 @@
             if (Math.abs(Vector3.Dot(this._lightDirection, Vector3.Up())) === 1.0) {
                 this._lightDirection.z = 0.0000000000001; // Need to avoid perfectly perpendicular light
             }
-                
+
             if (this._light.computeTransformedPosition()) {
                 lightPosition = this._light.transformedPosition;
             }
@@ -391,5 +391,38 @@
                 this._boxBlurPostprocess.dispose();
             }
         }
+
+        public static ParseShadowGenerator(parsedShadowGenerator: any, scene: Scene): ShadowGenerator {
+            var light = scene.getLightByID(parsedShadowGenerator.lightId);
+            var shadowGenerator = new ShadowGenerator(parsedShadowGenerator.mapSize, light);
+
+            for (var meshIndex = 0; meshIndex < parsedShadowGenerator.renderList.length; meshIndex++) {
+                var mesh = scene.getMeshByID(parsedShadowGenerator.renderList[meshIndex]);
+
+                shadowGenerator.getShadowMap().renderList.push(mesh);
+            }
+
+            if (parsedShadowGenerator.usePoissonSampling) {
+                shadowGenerator.usePoissonSampling = true;
+            } else if (parsedShadowGenerator.useVarianceShadowMap) {
+                shadowGenerator.useVarianceShadowMap = true;
+            } else if (parsedShadowGenerator.useBlurVarianceShadowMap) {
+                shadowGenerator.useBlurVarianceShadowMap = true;
+
+                if (parsedShadowGenerator.blurScale) {
+                    shadowGenerator.blurScale = parsedShadowGenerator.blurScale;
+                }
+
+                if (parsedShadowGenerator.blurBoxOffset) {
+                    shadowGenerator.blurBoxOffset = parsedShadowGenerator.blurBoxOffset;
+                }
+            }
+
+            if (parsedShadowGenerator.bias !== undefined) {
+                shadowGenerator.bias = parsedShadowGenerator.bias;
+            }
+
+            return shadowGenerator;
+        }
     }
 } 

+ 17 - 8
src/Materials/babylon.material.ts

@@ -26,11 +26,11 @@
             for (var index = 0; index < this._keys.length; index++) {
                 var prop = this._keys[index];
 
-                if (typeof(this[prop]) === "number") {
+                if (typeof (this[prop]) === "number") {
                     this[prop] = 0;
-                
-                }else { 
-                    this[prop] = false; 
+
+                } else {
+                    this[prop] = false;
                 }
             }
         }
@@ -40,10 +40,10 @@
             for (var index = 0; index < this._keys.length; index++) {
                 var prop = this._keys[index];
 
-                if (typeof(this[prop]) === "number") {
-                    result += "#define "  + prop + " " + this[prop] + "\n";
-                
-                }else if (this[prop]) {
+                if (typeof (this[prop]) === "number") {
+                    result += "#define " + prop + " " + this[prop] + "\n";
+
+                } else if (this[prop]) {
                     result += "#define " + prop + "\n";
                 }
             }
@@ -266,5 +266,14 @@
             other.pointSize = this.pointSize;
             other.pointsCloud = this.pointsCloud;
         }
+
+        public static ParseMaterial(parsedMaterial: any, scene: Scene, rootUrl: string) {
+            if (!parsedMaterial.customType) {
+                return StandardMaterial.Parse(parsedMaterial, scene, rootUrl);
+            }
+
+            //TODO this is where custom materials are inspected and parsed.
+            return null;
+        }
     }
 } 

+ 20 - 0
src/Materials/babylon.multiMaterial.ts

@@ -41,5 +41,25 @@
 
             return newMultiMaterial;
         }
+
+        public static ParseMultiMaterial(parsedMultiMaterial: any, scene: Scene): MultiMaterial {
+            var multiMaterial = new BABYLON.MultiMaterial(parsedMultiMaterial.name, scene);
+
+            multiMaterial.id = parsedMultiMaterial.id;
+
+            Tags.AddTagsTo(multiMaterial, parsedMultiMaterial.tags);
+
+            for (var matIndex = 0; matIndex < parsedMultiMaterial.materials.length; matIndex++) {
+                var subMatId = parsedMultiMaterial.materials[matIndex];
+
+                if (subMatId) {
+                    multiMaterial.subMaterials.push(scene.getMaterialByID(subMatId));
+                } else {
+                    multiMaterial.subMaterials.push(null);
+                }
+            }
+
+            return multiMaterial;
+        }
     }
 } 

+ 33 - 0
src/Particles/babylon.particleSystem.ts

@@ -445,5 +445,38 @@
 
             return result;
         }
+
+        public static ParseParticleSystem(parsedParticleSystem: any, scene: Scene, rootUrl: string): ParticleSystem {
+            var emitter = scene.getLastMeshByID(parsedParticleSystem.emitterId);
+
+            var particleSystem = new ParticleSystem("particles#" + emitter.name, parsedParticleSystem.capacity, scene);
+            if (parsedParticleSystem.textureName) {
+                particleSystem.particleTexture = new Texture(rootUrl + parsedParticleSystem.textureName, scene);
+                particleSystem.particleTexture.name = parsedParticleSystem.textureName;
+            }
+            particleSystem.minAngularSpeed = parsedParticleSystem.minAngularSpeed;
+            particleSystem.maxAngularSpeed = parsedParticleSystem.maxAngularSpeed;
+            particleSystem.minSize = parsedParticleSystem.minSize;
+            particleSystem.maxSize = parsedParticleSystem.maxSize;
+            particleSystem.minLifeTime = parsedParticleSystem.minLifeTime;
+            particleSystem.maxLifeTime = parsedParticleSystem.maxLifeTime;
+            particleSystem.emitter = emitter;
+            particleSystem.emitRate = parsedParticleSystem.emitRate;
+            particleSystem.minEmitBox = Vector3.FromArray(parsedParticleSystem.minEmitBox);
+            particleSystem.maxEmitBox = Vector3.FromArray(parsedParticleSystem.maxEmitBox);
+            particleSystem.gravity = Vector3.FromArray(parsedParticleSystem.gravity);
+            particleSystem.direction1 = Vector3.FromArray(parsedParticleSystem.direction1);
+            particleSystem.direction2 = Vector3.FromArray(parsedParticleSystem.direction2);
+            particleSystem.color1 = Color4.FromArray(parsedParticleSystem.color1);
+            particleSystem.color2 = Color4.FromArray(parsedParticleSystem.color2);
+            particleSystem.colorDead = Color4.FromArray(parsedParticleSystem.colorDead);
+            particleSystem.updateSpeed = parsedParticleSystem.updateSpeed;
+            particleSystem.targetStopDuration = parsedParticleSystem.targetStopFrame;
+            particleSystem.textureMask = Color4.FromArray(parsedParticleSystem.textureMask);
+            particleSystem.blendMode = parsedParticleSystem.blendMode;
+            particleSystem.start();
+
+            return particleSystem;
+        }
     }
 }