Преглед на файлове

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

Temechon преди 8 години
родител
ревизия
0eab3835de

+ 4 - 0
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/ExportationOptions.cs

@@ -13,6 +13,8 @@ namespace Unity3D2Babylon
         public bool AttachUnityEditor { get; set; }
         public bool ShowDebugControls { get; set; }
         public float ReflectionDefaultLevel { get; set; }
+        public SerializableVector3 LightRotationOffset { get; set; }
+        public float LightIntensityFactor { get; set; }
         public int DefaultQualityLevel { get; set; }
         public bool EmbeddedShaders { get; set; }
         public bool ExportLightmaps { get; set; }
@@ -53,6 +55,8 @@ namespace Unity3D2Babylon
             CompileTypeScript = true;
             AttachUnityEditor = true;
             ShowDebugControls = true;
+            LightRotationOffset = new Vector3(0,0,0);
+            LightIntensityFactor = 1f;
             ReflectionDefaultLevel = 0.25f;
             DefaultQualityLevel = 90;
             EmbeddedShaders = true;

+ 7 - 0
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/ExporterWindow.cs

@@ -460,6 +460,13 @@ namespace Unity3D2Babylon
             exportationOptions.DefaultPhysicsEngine = (int)(BabylonPhysicsEngine)EditorGUILayout.EnumPopup("Default Physics Engine", (BabylonPhysicsEngine)exportationOptions.DefaultPhysicsEngine, GUILayout.ExpandWidth(true));
             EditorGUILayout.EndHorizontal();
             EditorGUILayout.Space();
+            EditorGUILayout.BeginHorizontal();
+            GUILayout.Label(" Light Rotation Offset");
+            exportationOptions.LightRotationOffset = EditorGUILayout.Vector3Field("", exportationOptions.LightRotationOffset, GUILayout.ExpandWidth(false));
+            EditorGUILayout.EndHorizontal();
+            EditorGUILayout.Space();
+            exportationOptions.LightIntensityFactor = EditorGUILayout.Slider(" Light Intensity Factor", exportationOptions.LightIntensityFactor, 0, 10.0f);
+            EditorGUILayout.Space();
             exportationOptions.ReflectionDefaultLevel = EditorGUILayout.Slider(" Default Reflection Level", exportationOptions.ReflectionDefaultLevel, 0, 1.0f);
             EditorGUILayout.Space();
             exportationOptions.DefaultImageFormat = (int)(BabylonImageFormat)EditorGUILayout.EnumPopup(" Prefered Texture Format", (BabylonImageFormat)exportationOptions.DefaultImageFormat, GUILayout.ExpandWidth(true));

+ 5 - 2
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.Lights.cs

@@ -98,11 +98,14 @@ namespace Unity3D2Babylon
 
             var direction = new Vector3(0, 0, 1);
             var transformedDirection = light.transform.TransformDirection(direction);
+            transformedDirection[0] += exportationOptions.LightRotationOffset.X;
+            transformedDirection[1] += exportationOptions.LightRotationOffset.Y;
+            transformedDirection[2] += exportationOptions.LightRotationOffset.Z;
             babylonLight.direction = transformedDirection.ToFloat();
-
+            
             babylonLight.diffuse = light.color.ToFloat();
 
-            babylonLight.intensity = light.intensity;
+            babylonLight.intensity = light.intensity * exportationOptions.LightIntensityFactor;
 
             babylonLight.angle = light.spotAngle * (float)Math.PI / 180;
             babylonLight.exponent = 1.0f;

+ 15 - 5
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.Materials.cs

@@ -173,8 +173,8 @@ namespace Unity3D2Babylon
                         {
                             ExporterWindow.ReportProgress(1, "Exporting texture cube item: " + textureName);
                             var tempTexture = new Texture2D(textureFace.width, textureFace.height, TextureFormat.ARGB32, false);
-                            Color[] pixels = textureFace.GetPixels();
-                            tempTexture.SetPixels(pixels);
+                            Color32[] pixels = textureFace.GetPixels32();
+                            tempTexture.SetPixels32(pixels);
                             tempTexture.Apply();
                             if (png)
                             {
@@ -207,8 +207,15 @@ namespace Unity3D2Babylon
             {
                 string srcTexturePath = AssetDatabase.GetAssetPath(texture2D);
                 var importTool = new BabylonTextureImporter(srcTexturePath);
-                bool isReadable = importTool.IsReadable();
-                if (!isReadable) importTool.SetReadable();
+                var previousConvertToNormalmap = importTool.textureImporter.convertToNormalmap;
+                var previousAlphaSource = importTool.textureImporter.alphaSource;
+                var previousTextureType = importTool.textureImporter.textureType;
+                importTool.SetReadable();
+                importTool.textureImporter.textureType = (isLightmap) ? TextureImporterType.Lightmap : TextureImporterType.Default;
+                importTool.textureImporter.alphaSource = TextureImporterAlphaSource.FromInput;
+                importTool.textureImporter.convertToNormalmap = false;
+                AssetDatabase.ImportAsset(texturePath);
+
                 try
                 {
                     var usePNG = texture2D.alphaIsTransparency;
@@ -248,7 +255,10 @@ namespace Unity3D2Babylon
                 }
                 finally
                 {
-                    if (!isReadable) importTool.ForceUpdate();
+                    importTool.textureImporter.textureType = previousTextureType;
+                    importTool.textureImporter.alphaSource = previousAlphaSource;
+                    importTool.textureImporter.convertToNormalmap = previousConvertToNormalmap;
+                    importTool.ForceUpdate();
                 }
             }
             else if (texture2D.alphaIsTransparency || texturePath.EndsWith(".png"))

BIN
Exporters/Unity 5/EditorToolkit/Redist/Asset Store-5.x/BabylonJS/BabylonJS Editor Toolkit.unitypackage


+ 8 - 1
Exporters/Unity 5/EditorToolkit/Redist/readme.me

@@ -17,5 +17,12 @@ Place the 'BabylonJS' folder containing the .unitypackage in your Unity Asset St
 BabylonJS - Creating New Projects
 ==========================================
 
-When creating a new unity project, select 'Add Asset Package' and enable 'BabylonJS Toolkit' support.
+When creating a new unity project, select 'Add Asset Package' and enable 'BabylonJS Editor Toolkit' support.
+
+
+==========================================
+BabylonJS - Importing Existing Projects
+==========================================
+
+When using an existing unity project, select 'Assets->Import Package...' and choose your 'BabylonJS Editor Toolkit' unity package.
 

+ 11 - 3
src/Materials/Textures/babylon.mirrorTexture.ts

@@ -6,8 +6,8 @@
         private _mirrorMatrix = Matrix.Zero();
         private _savedViewMatrix: Matrix;
 
-        constructor(name: string, size: number, scene: Scene, generateMipMaps?: boolean) {
-            super(name, size, scene, generateMipMaps, true);
+        constructor(name: string, size: any, scene: Scene, generateMipMaps?: boolean, type: number = Engine.TEXTURETYPE_UNSIGNED_INT, samplingMode = Texture.BILINEAR_SAMPLINGMODE, generateDepthBuffer = true) {
+            super(name, size, scene, generateMipMaps, true, type, false, samplingMode, generateDepthBuffer);
 
             this.onBeforeRenderObservable.add(() => {
                 Matrix.ReflectionToRef(this.mirrorPlane, this._mirrorMatrix);
@@ -35,7 +35,15 @@
 
         public clone(): MirrorTexture {
             var textureSize = this.getSize();
-            var newTexture = new MirrorTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
+            var newTexture = new MirrorTexture(
+                this.name,
+                textureSize.width,
+                this.getScene(),
+                this._renderTargetOptions.generateMipMaps,
+                this._renderTargetOptions.type,
+                this._renderTargetOptions.samplingMode,
+                this._renderTargetOptions.generateDepthBuffer
+            );
 
             // Base texture
             newTexture.hasAlpha = this.hasAlpha;

+ 35 - 21
src/Materials/Textures/babylon.renderTargetTexture.ts

@@ -99,9 +99,15 @@
         private _currentRefreshId = -1;
         private _refreshRate = 1;
         private _textureMatrix: Matrix;
-
-        constructor(name: string, size: any, scene: Scene, generateMipMaps?: boolean, doNotChangeAspectRatio: boolean = true, type: number = Engine.TEXTURETYPE_UNSIGNED_INT, public isCube = false, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, 
-            generateDepthBuffer = true, generateStencilBuffer = false) {
+        protected _renderTargetOptions: {
+            generateMipMaps: boolean,
+            type: number,
+            samplingMode: number,
+            generateDepthBuffer: boolean,
+            generateStencilBuffer: boolean
+        };
+
+        constructor(name: string, size: any, scene: Scene, generateMipMaps?: boolean, doNotChangeAspectRatio: boolean = true, type: number = Engine.TEXTURETYPE_UNSIGNED_INT, public isCube = false, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, generateDepthBuffer = true, generateStencilBuffer = false) {
             super(null, scene, !generateMipMaps);
 
             this.name = name;
@@ -110,28 +116,25 @@
             this._generateMipMaps = generateMipMaps;
             this._doNotChangeAspectRatio = doNotChangeAspectRatio;
 
+            this._renderTargetOptions = {
+                generateMipMaps: generateMipMaps,
+                type: type,
+                samplingMode: samplingMode,
+                generateDepthBuffer: generateDepthBuffer,
+                generateStencilBuffer: generateStencilBuffer
+            };
+
             if (samplingMode === Texture.NEAREST_SAMPLINGMODE) {
                 this.wrapU = Texture.CLAMP_ADDRESSMODE;
                 this.wrapV = Texture.CLAMP_ADDRESSMODE;
             }
 
             if (isCube) {
-                this._texture = scene.getEngine().createRenderTargetCubeTexture(size, { 
-                    generateMipMaps: generateMipMaps, 
-                    samplingMode: samplingMode,
-                    generateDepthBuffer: generateDepthBuffer,
-                    generateStencilBuffer: generateStencilBuffer 
-                });
+                this._texture = scene.getEngine().createRenderTargetCubeTexture(size, this._renderTargetOptions);
                 this.coordinatesMode = Texture.INVCUBIC_MODE;
                 this._textureMatrix = Matrix.Identity();
             } else {
-                this._texture = scene.getEngine().createRenderTargetTexture(size, { 
-                    generateMipMaps: generateMipMaps, 
-                    type: type, 
-                    samplingMode: samplingMode,
-                    generateDepthBuffer: generateDepthBuffer,
-                    generateStencilBuffer: generateStencilBuffer 
-                });
+                this._texture = scene.getEngine().createRenderTargetTexture(size, this._renderTargetOptions);
             }
 
             // Rendering groups
@@ -185,7 +188,7 @@
         public scale(ratio: number): void {
             var newSize = this._size * ratio;
 
-            this.resize(newSize, this._generateMipMaps);
+            this.resize(newSize);
         }
 
         public getReflectionTextureMatrix(): Matrix {
@@ -196,12 +199,12 @@
             return super.getReflectionTextureMatrix();
         }
 
-        public resize(size: any, generateMipMaps?: boolean) {
+        public resize(size: any) {
             this.releaseInternalTexture();
             if (this.isCube) {
-                this._texture = this.getScene().getEngine().createRenderTargetCubeTexture(size);
+                this._texture = this.getScene().getEngine().createRenderTargetCubeTexture(size, this._renderTargetOptions);
             } else {
-                this._texture = this.getScene().getEngine().createRenderTargetTexture(size, generateMipMaps);
+                this._texture = this.getScene().getEngine().createRenderTargetTexture(size, this._renderTargetOptions);
             }
         }
 
@@ -394,7 +397,18 @@
 
         public clone(): RenderTargetTexture {
             var textureSize = this.getSize();
-            var newTexture = new RenderTargetTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
+            var newTexture = new RenderTargetTexture(
+                this.name,
+                textureSize.width,
+                this.getScene(),
+                this._renderTargetOptions.generateMipMaps,
+                this._doNotChangeAspectRatio,
+                this._renderTargetOptions.type,
+                this.isCube,
+                this._renderTargetOptions.samplingMode,
+                this._renderTargetOptions.generateDepthBuffer,
+                this._renderTargetOptions.generateStencilBuffer
+            );
 
             // Base texture
             newTexture.hasAlpha = this.hasAlpha;

+ 1 - 1
src/Mesh/babylon.meshBuilder.ts

@@ -548,7 +548,7 @@
          * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.  
          */
         public static CreateLathe(name: string, options: { shape: Vector3[], radius?: number, tessellation?: number, arc?: number, closed?: boolean, updatable?: boolean, sideOrientation?: number, cap?: number, invertUV?: boolean }, scene: Scene): Mesh {
-            var arc: number = (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
+            var arc: number = options.arc ? ((options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc) : 1.0;
             var closed: boolean = (options.closed === undefined) ? true : options.closed;
             var shape = options.shape;
             var radius = options.radius || 1;