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

Merge remote-tracking branch 'BabylonJS/master'

MackeyK24 преди 8 години
родител
ревизия
032f64671d

+ 11 - 3
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.Meshes.cs

@@ -294,13 +294,21 @@ namespace Unity3D2Babylon
                     if (mesh.subMeshCount > 1)
                     {
                         BabylonMultiMaterial bMultiMat;
-                        if (!multiMatDictionary.ContainsKey(renderer.sharedMaterial.name))
+
+                        string multiMatName = "";
+                        for (int i = 0; i < renderer.sharedMaterials.Length; i++)
+                        {
+                            multiMatName += renderer.sharedMaterials[i].name;
+                        }
+                    
+
+                        if (!multiMatDictionary.ContainsKey(multiMatName))
                         {
                             bMultiMat = new BabylonMultiMaterial
                             {
                                 materials = new string[mesh.subMeshCount],
                                 id = Guid.NewGuid().ToString(),
-                                name = renderer.sharedMaterial.name
+                                name = multiMatName
                             };
 
                             for (int i = 0; i < renderer.sharedMaterials.Length; i++)
@@ -319,7 +327,7 @@ namespace Unity3D2Babylon
                         }
                         else
                         {
-                            bMultiMat = multiMatDictionary[renderer.sharedMaterial.name];
+                            bMultiMat = multiMatDictionary[multiMatName];
                         }
 
                         babylonMesh.materialId = bMultiMat.id;

+ 11 - 1
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.cs

@@ -395,7 +395,17 @@ namespace Unity3D2Babylon
                                 collisionMesh = new BabylonMesh();
                                 collisionMesh.tags = "[MESHCOLLIDER]";
                                 // Generate Mesh Collider Geometry
-                                Tools.GenerateBabylonMeshData(meshCollider.sharedMesh, collisionMesh);
+                               
+                                if(!meshCollider.sharedMesh)
+                                {
+                                    UnityEngine.Debug.LogWarning(meshCollider.gameObject+" has a Mesh Collider component without a mesh");
+                                }
+                                else
+                                {
+                                    Tools.GenerateBabylonMeshData(meshCollider.sharedMesh, collisionMesh);
+                                }
+
+                            
                                 collisionMesh.position = Vector3.zero.ToFloat();
                                 collisionMesh.rotation = Vector3.zero.ToFloat();
                                 float factorX = 1f, factorY = 1f, factorZ = 1f;

+ 3 - 1
Playground/zipContent/index.html

@@ -26,7 +26,9 @@
         </style>
     </head>
 <body>
-    <canvas id="renderCanvas"></canvas>
+    <div id="canvasZone">
+        <canvas id="renderCanvas"></canvas>
+    </div>
     <script>
         var canvas = document.getElementById("renderCanvas");
         var engine = new BABYLON.Engine(canvas, true);

+ 12 - 2
canvas2D/src/Engine/babylon.renderablePrim2d.ts

@@ -920,7 +920,10 @@
         }
 
         private static _uV = new Vector2(1, 1);
-
+        private static _s = Vector3.Zero();
+        private static _r = Quaternion.Identity();
+        private static _t = Vector3.Zero();
+        private static _uV3 = new Vector3(1, 1, 1);
         /**
          * Update the instanceDataBase level properties of a part
          * @param part the part to update
@@ -928,7 +931,14 @@
          */
         protected updateInstanceDataPart(part: InstanceDataBase, positionOffset: Vector2 = null) {
             let t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform);    // Compute the transformation into the renderGroup's space
-            let rgScale = (this._areSomeFlagsSet(SmartPropertyPrim.flagDontInheritParentScale) || !this.applyActualScaleOnTransform()) ? RenderablePrim2D._uV : this.renderGroup.actualScale;         // We still need to apply the scale of the renderGroup to our rendering, so get it.
+            let rgScale = this._areSomeFlagsSet(SmartPropertyPrim.flagDontInheritParentScale) ? RenderablePrim2D._uV : this.renderGroup.actualScale;         // We still need to apply the scale of the renderGroup to our rendering, so get it.
+
+            if (!this.applyActualScaleOnTransform()) {
+                t.decompose(RenderablePrim2D._s, RenderablePrim2D._r, RenderablePrim2D._t);
+                t = Matrix.Compose(RenderablePrim2D._uV3, RenderablePrim2D._r, RenderablePrim2D._t);
+            }
+
+            //let rgScale = (this._areSomeFlagsSet(SmartPropertyPrim.flagDontInheritParentScale) || !this.applyActualScaleOnTransform()) ? RenderablePrim2D._uV : this.renderGroup.actualScale;         // We still need to apply the scale of the renderGroup to our rendering, so get it.
             let size = (<Size>this.renderGroup.viewportSize);
             let zBias = this.actualZOffset;
 

Файловите разлики са ограничени, защото са твърде много
+ 25 - 25
dist/preview release/babylon.core.js


Файловите разлики са ограничени, защото са твърде много
+ 6107 - 6105
dist/preview release/babylon.d.ts


Файловите разлики са ограничени, защото са твърде много
+ 36 - 36
dist/preview release/babylon.js


Файловите разлики са ограничени, защото са твърде много
+ 154 - 135
dist/preview release/babylon.max.js


Файловите разлики са ограничени, защото са твърде много
+ 35 - 35
dist/preview release/babylon.noworker.js


+ 89 - 80
src/Math/babylon.math.ts

@@ -2934,15 +2934,21 @@
         }
 
         public static OrthoLHToRef(width: number, height: number, znear: number, zfar: number, result: Matrix): void {
-            var hw = 2.0 / width;
-            var hh = 2.0 / height;
-            var id = 1.0 / (zfar - znear);
-            var nid = znear / (znear - zfar);
-
-            Matrix.FromValuesToRef(hw, 0, 0, 0,
-                0, hh, 0, 0,
-                0, 0, id, 0,
-                0, 0, nid, 1, result);
+            let n = znear;
+            let f = zfar;
+
+            let a = 2.0 / width;
+            let b = 2.0 / height;
+            let c = 2.0 / (f - n);
+            let d = -(f + n)/(f - n);
+
+            BABYLON.Matrix.FromValuesToRef(
+                a, 0, 0, 0,
+                0, b, 0, 0,
+                0, 0, c, 0,
+                0, 0, d, 1,
+                result
+            );
         }
 
         public static OrthoOffCenterLH(left: number, right: number, bottom: number, top: number, znear: number, zfar: number): Matrix {
@@ -2954,16 +2960,23 @@
         }
 
         public static OrthoOffCenterLHToRef(left: number, right, bottom: number, top: number, znear: number, zfar: number, result: Matrix): void {
-            result.m[0] = 2.0 / (right - left);
-            result.m[1] = result.m[2] = result.m[3] = 0;
-            result.m[5] = 2.0 / (top - bottom);
-            result.m[4] = result.m[6] = result.m[7] = 0;
-            result.m[10] = 1.0 / (zfar - znear);
-            result.m[8] = result.m[9] = result.m[11] = 0;
-            result.m[12] = (left + right) / (left - right);
-            result.m[13] = (top + bottom) / (bottom - top);
-            result.m[14] = -znear / (zfar - znear);
-            result.m[15] = 1.0;
+            let n = znear;
+            let f = zfar;
+
+            let a = 2.0 / (right - left);
+            let b = 2.0 / (top - bottom);
+            let c = 2.0 / (f - n);
+            let d = -(f + n)/(f - n);
+            let i0 = (left + right) / (left - right);
+            let i1 = (top + bottom) / (bottom - top);
+
+            BABYLON.Matrix.FromValuesToRef(
+                a, 0, 0, 0,
+                0, b, 0, 0,
+                0, 0, c, 0,
+                i0, i1, d, 1,
+                result
+            );
         }
 
         public static OrthoOffCenterRH(left: number, right: number, bottom: number, top: number, znear: number, zfar: number): Matrix {
@@ -2982,15 +2995,21 @@
         public static PerspectiveLH(width: number, height: number, znear: number, zfar: number): Matrix {
             var matrix = Matrix.Zero();
 
-            matrix.m[0] = (2.0 * znear) / width;
-            matrix.m[1] = matrix.m[2] = matrix.m[3] = 0.0;
-            matrix.m[5] = (2.0 * znear) / height;
-            matrix.m[4] = matrix.m[6] = matrix.m[7] = 0.0;
-            matrix.m[10] = -zfar / (znear - zfar);
-            matrix.m[8] = matrix.m[9] = 0.0;
-            matrix.m[11] = 1.0;
-            matrix.m[12] = matrix.m[13] = matrix.m[15] = 0.0;
-            matrix.m[14] = (znear * zfar) / (znear - zfar);
+            let n = znear;
+            let f = zfar;
+
+            let a = 2.0 * n / width;
+            let b = 2.0 * n / height;
+            let c = (f + n)/(f - n);
+            let d = -2.0 * f * n/(f - n);
+
+            BABYLON.Matrix.FromValuesToRef(
+                a, 0, 0, 0,
+                0, b, 0, 0,
+                0, 0, c, 1,
+                0, 0, d, 0,
+                matrix
+            );
 
             return matrix;
         }
@@ -3004,30 +3023,22 @@
         }
 
         public static PerspectiveFovLHToRef(fov: number, aspect: number, znear: number, zfar: number, result: Matrix, isVerticalFovFixed = true): void {
-            var tan = 1.0 / (Math.tan(fov * 0.5));
-
-            if (isVerticalFovFixed) {
-                result.m[0] = tan / aspect;
-            }
-            else {
-                result.m[0] = tan;
-            }
-
-            result.m[1] = result.m[2] = result.m[3] = 0.0;
-
-            if (isVerticalFovFixed) {
-                result.m[5] = tan;
-            }
-            else {
-                result.m[5] = tan * aspect;
-            }
-
-            result.m[4] = result.m[6] = result.m[7] = 0.0;
-            result.m[8] = result.m[9] = 0.0;
-            result.m[10] = zfar / (zfar - znear);
-            result.m[11] = 1.0;
-            result.m[12] = result.m[13] = result.m[15] = 0.0;
-            result.m[14] = -(znear * zfar) / (zfar - znear);
+            let n = znear;
+            let f = zfar;
+
+            let t = 1.0 / (Math.tan(fov * 0.5));
+            let a = isVerticalFovFixed ? (t / aspect) : t;
+            let b = isVerticalFovFixed ? t : (t * aspect);
+            let c = (f + n)/(f - n);
+            let d = -2.0 * f * n/(f - n);
+
+            BABYLON.Matrix.FromValuesToRef(
+                a, 0, 0, 0,
+                0, b, 0, 0,
+                0, 0, c, 1,
+                0, 0, d, 0,
+                result
+            );
         }
 
         public static PerspectiveFovRH(fov: number, aspect: number, znear: number, zfar: number): Matrix {
@@ -3039,33 +3050,31 @@
         }
 
         public static PerspectiveFovRHToRef(fov: number, aspect: number, znear: number, zfar: number, result: Matrix, isVerticalFovFixed = true): void {
-            var tan = 1.0 / (Math.tan(fov * 0.5));
-
-            if (isVerticalFovFixed) {
-                result.m[0] = tan / aspect;
-            }
-            else {
-                result.m[0] = tan;
-            }
-
-            result.m[1] = result.m[2] = result.m[3] = 0.0;
-
-            if (isVerticalFovFixed) {
-                result.m[5] = tan;
-            }
-            else {
-                result.m[5] = tan * aspect;
-            }
-
-            result.m[4] = result.m[6] = result.m[7] = 0.0;
-            result.m[8] = result.m[9] = 0.0;
-            result.m[10] = zfar / (znear - zfar);
-            result.m[11] = -1.0;
-            result.m[12] = result.m[13] = result.m[15] = 0.0;
-            result.m[14] = (znear * zfar) / (znear - zfar);
+            //alternatively this could be expressed as:
+            //    m = PerspectiveFovLHToRef
+            //    m[10] *= -1.0;
+            //    m[11] *= -1.0;
+
+            let n = znear;
+            let f = zfar;
+
+            let t = 1.0 / (Math.tan(fov * 0.5));
+            let a = isVerticalFovFixed ? (t / aspect) : t;
+            let b = isVerticalFovFixed ? t : (t * aspect);
+            let c = -(f + n)/(f - n);
+            let d = -2*f*n/(f - n);
+
+            BABYLON.Matrix.FromValuesToRef(
+                a, 0, 0, 0,
+                0, b, 0, 0,
+                0, 0, c,-1,
+                0, 0, d, 0,
+                result
+            );
         }
 
         public static PerspectiveFovWebVRToRef(fov, znear: number, zfar: number, result: Matrix, isVerticalFovFixed = true): void {
+            //left handed
             var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);
             var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);
             var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);
@@ -3078,12 +3087,12 @@
             result.m[6] = result.m[7] =  0.0;
             result.m[8] = ((leftTan - rightTan) * xScale * 0.5);
             result.m[9] = -((upTan - downTan) * yScale * 0.5);
-            //result.m[10] = -(znear + zfar) / (zfar - znear);
-            result.m[10] = -zfar / (znear - zfar);
+            result.m[10] = -(znear + zfar) / (zfar - znear);
+            // result.m[10] = -zfar / (znear - zfar);
             result.m[11] = 1.0;
             result.m[12] = result.m[13] = result.m[15] = 0.0;
-            //result.m[14] = -(2.0 * zfar * znear) / (zfar - znear);
-            result.m[14] = (znear * zfar) / (znear - zfar);
+            result.m[14] = -(2.0 * zfar * znear) / (zfar - znear);
+            // result.m[14] = (znear * zfar) / (znear - zfar);
         }
 
         public static GetFinalMatrix(viewport: Viewport, world: Matrix, view: Matrix, projection: Matrix, zmin: number, zmax: number): Matrix {

+ 28 - 30
src/Rendering/babylon.renderingManager.ts

@@ -77,45 +77,43 @@
             for (let index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {
                 this._depthStencilBufferAlreadyCleaned = index === RenderingManager.MIN_RENDERINGGROUPS;
                 var renderingGroup = this._renderingGroups[index];
+                if(!renderingGroup && !observable)
+                    continue;
 
                 this._currentIndex = index;
 
-                if (renderingGroup) {
-                    let renderingGroupMask = 0;
-
-                    // Fire PRECLEAR stage
-                    if (observable) {
-                        renderingGroupMask = Math.pow(2, index);
-                        info.renderStage = RenderingGroupInfo.STAGE_PRECLEAR;
-                        info.renderingGroupId = index;
-                        observable.notifyObservers(info, renderingGroupMask);
-                    }
-
-                    // Clear depth/stencil if needed
-                    let autoClear = this._autoClearDepthStencil[index];
-                    if (autoClear && autoClear.autoClear) {
-                        this._clearDepthStencilBuffer(autoClear.depth, autoClear.stencil);
-                    }
+                let renderingGroupMask = 0;
 
-                    // Fire PREOPAQUE stage
-                    if (observable) {
-                        info.renderStage = RenderingGroupInfo.STAGE_PREOPAQUE;
-                        observable.notifyObservers(info, renderingGroupMask);
-                    }
+                // Fire PRECLEAR stage
+                if (observable) {
+                    renderingGroupMask = Math.pow(2, index);
+                    info.renderStage = RenderingGroupInfo.STAGE_PRECLEAR;
+                    info.renderingGroupId = index;
+                    observable.notifyObservers(info, renderingGroupMask);
+                }
 
+                // Clear depth/stencil if needed
+                let autoClear = this._autoClearDepthStencil[index];
+                if (autoClear && autoClear.autoClear) {
+                    this._clearDepthStencilBuffer(autoClear.depth, autoClear.stencil);
+                }
+
+                if (observable) {
+                    // Fire PREOPAQUE stage
+                    info.renderStage = RenderingGroupInfo.STAGE_PREOPAQUE;
+                    observable.notifyObservers(info, renderingGroupMask);
                     // Fire PRETRANSPARENT stage
-                    if (observable) {
-                        info.renderStage = RenderingGroupInfo.STAGE_PRETRANSPARENT;
-                        observable.notifyObservers(info, renderingGroupMask);
-                    }
+                    info.renderStage = RenderingGroupInfo.STAGE_PRETRANSPARENT;
+                    observable.notifyObservers(info, renderingGroupMask);
+                }
 
+                if (renderingGroup)
                     renderingGroup.render(customRenderFunction, renderSprites, renderParticles, activeMeshes);
 
-                    // Fire POSTTRANSPARENT stage
-                    if (observable) {
-                        info.renderStage = RenderingGroupInfo.STAGE_POSTTRANSPARENT;
-                        observable.notifyObservers(info, renderingGroupMask);
-                    }
+                // Fire POSTTRANSPARENT stage
+                if (observable) {
+                    info.renderStage = RenderingGroupInfo.STAGE_POSTTRANSPARENT;
+                    observable.notifyObservers(info, renderingGroupMask);
                 }
             }
         }

+ 14 - 0
src/babylon.engine.ts

@@ -214,6 +214,7 @@
         private static _ALPHA_MULTIPLY = 4;
         private static _ALPHA_MAXIMIZED = 5;
         private static _ALPHA_ONEONE = 6;
+        private static _ALPHA_PREMULTIPLIED = 7;
 
         private static _DELAYLOADSTATE_NONE = 0;
         private static _DELAYLOADSTATE_LOADED = 1;
@@ -337,6 +338,10 @@
             return Engine._ALPHA_MAXIMIZED;
         }
 
+        public static get ALPHA_PREMULTIPLIED(): number {
+            return Engine._ALPHA_PREMULTIPLIED;
+        }
+
         public static get DELAYLOADSTATE_NONE(): number {
             return Engine._DELAYLOADSTATE_NONE;
         }
@@ -1859,6 +1864,10 @@
                 case Engine.ALPHA_DISABLE:
                     this._alphaState.alphaBlend = false;
                     break;
+                case Engine.ALPHA_PREMULTIPLIED:
+                    this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);
+                    this._alphaState.alphaBlend = true;
+                    break;
                 case Engine.ALPHA_COMBINE:
                     this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE);
                     this._alphaState.alphaBlend = true;
@@ -2152,6 +2161,11 @@
 
             this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, filters.mag);
             this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, filters.min);
+
+            if (generateMipMaps) {
+                this._gl.generateMipmap(this._gl.TEXTURE_2D);
+            }
+
             this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
 
             texture.samplingMode = samplingMode;