Przeglądaj źródła

Merge pull request #1016 from julien-moreau/master

Materials Libray: sky material can now work with Vector3 to set sun position
David Catuhe 9 lat temu
rodzic
commit
93842f3816

+ 16 - 7
materialsLibrary/dist/babylon.skyMaterial.js

@@ -36,8 +36,9 @@ var BABYLON;
             this.distance = 500;
             this.inclination = 0.49;
             this.azimuth = 0.25;
+            this.sunPosition = new BABYLON.Vector3(0, 100, 0);
+            this.useSunPosition = false;
             // Private members
-            this._sunPosition = BABYLON.Vector3.Zero();
             this._cameraPosition = BABYLON.Vector3.Zero();
             this._defines = new SkyMaterialDefines();
             this._cachedDefines = new SkyMaterialDefines();
@@ -173,12 +174,14 @@ var BABYLON;
             this._effect.setFloat("rayleigh", this.rayleigh);
             this._effect.setFloat("mieCoefficient", this.mieCoefficient);
             this._effect.setFloat("mieDirectionalG", this.mieDirectionalG);
-            var theta = Math.PI * (this.inclination - 0.5);
-            var phi = 2 * Math.PI * (this.azimuth - 0.5);
-            this._sunPosition.x = this.distance * Math.cos(phi);
-            this._sunPosition.y = this.distance * Math.sin(phi) * Math.sin(theta);
-            this._sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
-            this._effect.setVector3("sunPosition", this._sunPosition);
+            if (!this.useSunPosition) {
+                var theta = Math.PI * (this.inclination - 0.5);
+                var phi = 2 * Math.PI * (this.azimuth - 0.5);
+                this.sunPosition.x = this.distance * Math.cos(phi);
+                this.sunPosition.y = this.distance * Math.sin(phi) * Math.sin(theta);
+                this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
+            }
+            this._effect.setVector3("sunPosition", this.sunPosition);
             _super.prototype.bind.call(this, world, mesh);
         };
         SkyMaterial.prototype.getAnimatables = function () {
@@ -224,6 +227,12 @@ var BABYLON;
         __decorate([
             BABYLON.serialize()
         ], SkyMaterial.prototype, "azimuth");
+        __decorate([
+            BABYLON.serializeAsVector3()
+        ], SkyMaterial.prototype, "sunPosition");
+        __decorate([
+            BABYLON.serialize()
+        ], SkyMaterial.prototype, "useSunPosition");
         return SkyMaterial;
     })(BABYLON.Material);
     BABYLON.SkyMaterial = SkyMaterial;

Plik diff jest za duży
+ 1 - 1
materialsLibrary/dist/babylon.skyMaterial.min.js


+ 2 - 1
materialsLibrary/dist/dts/babylon.skyMaterial.d.ts

@@ -9,7 +9,8 @@ declare module BABYLON {
         distance: number;
         inclination: number;
         azimuth: number;
-        private _sunPosition;
+        sunPosition: Vector3;
+        useSunPosition: boolean;
         private _cameraPosition;
         private _renderId;
         private _defines;

+ 15 - 8
materialsLibrary/materials/sky/babylon.skyMaterial.ts

@@ -40,8 +40,13 @@ module BABYLON {
         @serialize()
         public azimuth: number = 0.25;
         
+        @serializeAsVector3()
+        public sunPosition: Vector3 = new Vector3(0, 100, 0);
+        
+        @serialize()
+        public useSunPosition: boolean = false;
+        
         // Private members
-        private _sunPosition: Vector3 = Vector3.Zero();
         private _cameraPosition: Vector3 = Vector3.Zero();
         
         private _renderId: number;
@@ -224,14 +229,16 @@ module BABYLON {
 			this._effect.setFloat("mieCoefficient", this.mieCoefficient);
 			this._effect.setFloat("mieDirectionalG", this.mieDirectionalG);
             
-            var theta = Math.PI * (this.inclination - 0.5);
-			var phi = 2 * Math.PI * (this.azimuth - 0.5);
-            
-            this._sunPosition.x = this.distance * Math.cos( phi );
-			this._sunPosition.y = this.distance * Math.sin( phi ) * Math.sin( theta );
-			this._sunPosition.z = this.distance * Math.sin( phi ) * Math.cos( theta );
+            if (!this.useSunPosition) {
+                var theta = Math.PI * (this.inclination - 0.5);
+                var phi = 2 * Math.PI * (this.azimuth - 0.5);
+                
+                this.sunPosition.x = this.distance * Math.cos(phi);
+                this.sunPosition.y = this.distance * Math.sin(phi) * Math.sin(theta);
+                this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
+            }
             
-			this._effect.setVector3("sunPosition", this._sunPosition);
+			this._effect.setVector3("sunPosition", this.sunPosition);
 
             super.bind(world, mesh);
         }