Browse Source

Merge pull request #1051 from sebavan/OBJLoaderFix

Obj loader fix
David Catuhe 9 years ago
parent
commit
7317ed822e

File diff suppressed because it is too large
+ 25 - 19
dist/preview release/babylon.core.js


+ 61 - 61
dist/preview release/babylon.d.ts

@@ -6136,27 +6136,6 @@ declare module BABYLON {
 }
 
 declare module BABYLON {
-    class ReflectionProbe {
-        name: string;
-        private _scene;
-        private _renderTargetTexture;
-        private _projectionMatrix;
-        private _viewMatrix;
-        private _target;
-        private _add;
-        private _attachedMesh;
-        position: Vector3;
-        constructor(name: string, size: number, scene: Scene, generateMipMaps?: boolean);
-        refreshRate: number;
-        getScene(): Scene;
-        cubeTexture: RenderTargetTexture;
-        renderList: AbstractMesh[];
-        attachToMesh(mesh: AbstractMesh): void;
-        dispose(): void;
-    }
-}
-
-declare module BABYLON {
     class AnaglyphPostProcess extends PostProcess {
         constructor(name: string, ratio: number, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean);
     }
@@ -6726,6 +6705,27 @@ declare module BABYLON {
 }
 
 declare module BABYLON {
+    class ReflectionProbe {
+        name: string;
+        private _scene;
+        private _renderTargetTexture;
+        private _projectionMatrix;
+        private _viewMatrix;
+        private _target;
+        private _add;
+        private _attachedMesh;
+        position: Vector3;
+        constructor(name: string, size: number, scene: Scene, generateMipMaps?: boolean);
+        refreshRate: number;
+        getScene(): Scene;
+        cubeTexture: RenderTargetTexture;
+        renderList: AbstractMesh[];
+        attachToMesh(mesh: AbstractMesh): void;
+        dispose(): void;
+    }
+}
+
+declare module BABYLON {
     class BoundingBoxRenderer {
         frontColor: Color3;
         backColor: Color3;
@@ -6899,6 +6899,46 @@ declare module BABYLON {
 }
 
 declare module BABYLON.Internals {
+    class _AlphaState {
+        private _isAlphaBlendDirty;
+        private _isBlendFunctionParametersDirty;
+        private _alphaBlend;
+        private _blendFunctionParameters;
+        isDirty: boolean;
+        alphaBlend: boolean;
+        setAlphaBlendFunctionParameters(value0: number, value1: number, value2: number, value3: number): void;
+        reset(): void;
+        apply(gl: WebGLRenderingContext): void;
+    }
+}
+
+declare module BABYLON.Internals {
+    class _DepthCullingState {
+        private _isDepthTestDirty;
+        private _isDepthMaskDirty;
+        private _isDepthFuncDirty;
+        private _isCullFaceDirty;
+        private _isCullDirty;
+        private _isZOffsetDirty;
+        private _depthTest;
+        private _depthMask;
+        private _depthFunc;
+        private _cull;
+        private _cullFace;
+        private _zOffset;
+        isDirty: boolean;
+        zOffset: number;
+        cullFace: number;
+        cull: boolean;
+        depthFunc: number;
+        depthMask: boolean;
+        depthTest: boolean;
+        reset(): void;
+        apply(gl: WebGLRenderingContext): void;
+    }
+}
+
+declare module BABYLON.Internals {
     class AndOrNotEvaluator {
         static Eval(query: string, evaluateCallback: (val: any) => boolean): boolean;
         private static _HandleParenthesisContent(parenthesisContent, evaluateCallback);
@@ -7574,46 +7614,6 @@ declare module BABYLON {
     }
 }
 
-declare module BABYLON.Internals {
-    class _AlphaState {
-        private _isAlphaBlendDirty;
-        private _isBlendFunctionParametersDirty;
-        private _alphaBlend;
-        private _blendFunctionParameters;
-        isDirty: boolean;
-        alphaBlend: boolean;
-        setAlphaBlendFunctionParameters(value0: number, value1: number, value2: number, value3: number): void;
-        reset(): void;
-        apply(gl: WebGLRenderingContext): void;
-    }
-}
-
-declare module BABYLON.Internals {
-    class _DepthCullingState {
-        private _isDepthTestDirty;
-        private _isDepthMaskDirty;
-        private _isDepthFuncDirty;
-        private _isCullFaceDirty;
-        private _isCullDirty;
-        private _isZOffsetDirty;
-        private _depthTest;
-        private _depthMask;
-        private _depthFunc;
-        private _cull;
-        private _cullFace;
-        private _zOffset;
-        isDirty: boolean;
-        zOffset: number;
-        cullFace: number;
-        cull: boolean;
-        depthFunc: number;
-        depthMask: boolean;
-        depthTest: boolean;
-        reset(): void;
-        apply(gl: WebGLRenderingContext): void;
-    }
-}
-
 declare module BABYLON {
     class ArcRotateCameraGamepadInput implements ICameraInput<ArcRotateCamera> {
         camera: ArcRotateCamera;

File diff suppressed because it is too large
+ 33 - 26
dist/preview release/babylon.js


File diff suppressed because it is too large
+ 8 - 4
dist/preview release/babylon.max.js


File diff suppressed because it is too large
+ 32 - 25
dist/preview release/babylon.noworker.js


File diff suppressed because it is too large
+ 735 - 720
loaders/OBJ/babylon.objFileLoader.js


+ 52 - 28
loaders/OBJ/babylon.objFileLoader.ts

@@ -1,4 +1,4 @@
-
+/// <reference path="../../dist/preview release/babylon.d.ts"/>
 
 module BABYLON {
 
@@ -95,14 +95,14 @@ module BABYLON {
                 } else if (key === "map_ka") {
                     // ambient texture map with a loaded image
                     //We must first get the folder of the image
-                    material.ambientTexture = new BABYLON.Texture(rootUrl + value, scene);
+                    material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
                 } else if (key === "map_kd") {
                     // Diffuse texture map with a loaded image
-                    material.diffuseTexture = new BABYLON.Texture(rootUrl + value, scene);
+                    material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
                 } else if (key === "map_ks") {
                     // Specular texture map with a loaded image
                     //We must first get the folder of the image
-                    material.specularTexture = new BABYLON.Texture(rootUrl + value, scene);
+                    material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
                 } else if (key === "map_ns") {
                     //Specular
                     //Specular highlight component
@@ -113,10 +113,10 @@ module BABYLON {
                     //    continue;
                 } else if (key === "map_bump") {
                     //The bump texture
-                    material.bumpTexture = new BABYLON.Texture(rootUrl + value, scene);
+                    material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
                 } else if (key === "map_d") {
                     // The dissolve of the material
-                    material.opacityTexture = new BABYLON.Texture(rootUrl + value, scene);
+                    material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
 
 
                     //Options for illumination
@@ -152,6 +152,40 @@ module BABYLON {
             //At the end of the file, add the last material
             this.materials.push(material);
         }
+        
+        /**
+         * Gets the texture for the material.
+         * 
+         * If the material is imported from input file,
+         * We sanitize the url to ensure it takes the textre from aside the material.
+         * 
+         * @param rootUrl The root url to load from
+         * @param value The value stored in the mtl
+         * @return The Texture
+         */
+        private static _getTexture(rootUrl:string, value: string, scene: Scene): Texture {
+            var url = rootUrl;
+            // Load from input file.
+            if (rootUrl === "file:") {
+                var lastDelimiter = value.lastIndexOf("\\");
+                if (lastDelimiter === -1) {
+                    lastDelimiter = value.lastIndexOf("/");
+                }
+                
+                if (lastDelimiter > -1) {
+                    url += value.substr(lastDelimiter + 1); 
+                }
+                else {
+                    url += value;
+                }
+            }
+            // Not from input file.
+            else {
+                url += value;
+            }
+            
+            return new BABYLON.Texture(url, scene);
+        }
     }
 
     export class OBJFileLoader implements ISceneLoaderPlugin {
@@ -170,13 +204,13 @@ module BABYLON {
         // vt float float
         public uvPattern = /vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
         // f vertex vertex vertex ...
-        public facePattern1 = /f\s(([\d]{1,}[\s]?){3,})+/;
+        public facePattern1 = /f\s+(([\d]{1,}[\s]?){3,})+/;
         // f vertex/uvs vertex/uvs vertex/uvs ...
-        public facePattern2 = /f\s((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
+        public facePattern2 = /f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
         // f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal ...
-        public facePattern3 = /f\s((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
+        public facePattern3 = /f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
         // f vertex//normal vertex//normal vertex//normal ...
-        public facePattern4 = /f\s((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
+        public facePattern4 = /f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
 
 
         /**
@@ -191,26 +225,16 @@ module BABYLON {
          * @private
          */
         private _loadMTL(url: string, rootUrl: string, onSuccess: (response: string) => any) {
-            //XMLHTTP object to load the file
-            var request = new XMLHttpRequest();
             //The complete path to the mtl file
             var pathOfFile = BABYLON.Tools.BaseUrl + rootUrl + url;
-            //Get the file synchronously
-            request.open('GET', pathOfFile, false);
-            //Check the server status
-            request.onreadystatechange = function () {
-                if (request.readyState === 4) {
-                    if (request.status === 200 || BABYLON.Tools.ValidateXHRData(request, 1)) {
-                        //Data are loaded
-                        onSuccess(request.responseText);
-                    }
-                    else {
-                        //File not found
-                        console.warn("Error status: " + request.status + " - Unable to load " + pathOfFile);
-                    }
-                }
-            };
-            request.send(null);
+            
+            // Loads through the babylon tools to allow fileInput search.
+            BABYLON.Tools.LoadFile(pathOfFile, 
+                onSuccess, 
+                null, 
+                null, 
+                false, 
+                () => { console.warn("Error - Unable to load " + pathOfFile); })
         }
 
         public importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]): boolean {

+ 1 - 1
materialsLibrary/dist/babylon.pbrMaterial.js

@@ -199,7 +199,7 @@ var BABYLON;
              * Debug Control allowing to overload the reflectivity color.
              * This as to be use with the overloadedReflectivityIntensity parameter.
              */
-            this.overloadedReflectivity = BABYLON.Color3.White();
+            this.overloadedReflectivity = new BABYLON.Color3(0.3, 0.3, 0.3);
             /**
              * Debug Control indicating how much the overloaded reflectivity color is used against the default one.
              */

File diff suppressed because it is too large
+ 1 - 1
materialsLibrary/dist/babylon.pbrMaterial.min.js


+ 1 - 1
materialsLibrary/materials/pbr/babylon.pbrMaterial.ts

@@ -213,7 +213,7 @@ module BABYLON {
          * This as to be use with the overloadedReflectivityIntensity parameter.
          */
         @serializeAsColor3()
-        public overloadedReflectivity: Color3 = BABYLON.Color3.White();
+        public overloadedReflectivity: Color3 = new BABYLON.Color3(0.3, 0.3, 0.3);
         
         /**
          * Debug Control indicating how much the overloaded reflectivity color is used against the default one.

File diff suppressed because it is too large
+ 654 - 388
materialsLibrary/test/refs/babylon.max.js


+ 6 - 2
src/Tools/babylon.filesInput.js

@@ -76,8 +76,12 @@ var BABYLON;
                             FilesInput.FilesToLoad[this._filesToLoad[i].name] = this._filesToLoad[i];
                             break;
                         default:
-                            if ((this._filesToLoad[i].name.indexOf(".babylon") !== -1 || this._filesToLoad[i].name.indexOf(".stl") !== -1 ||
-                                this._filesToLoad[i].name.indexOf(".obj") !== -1 || this._filesToLoad[i].name.indexOf(".mtl") !== -1)
+                            if (this._filesToLoad[i].name.indexOf(".mtl") !== -1) {
+                                FilesInput.FilesToLoad[this._filesToLoad[i].name] = this._filesToLoad[i];
+                            }
+                            else if ((this._filesToLoad[i].name.indexOf(".babylon") !== -1 ||
+                                this._filesToLoad[i].name.indexOf(".stl") !== -1 ||
+                                this._filesToLoad[i].name.indexOf(".obj") !== -1)
                                 && this._filesToLoad[i].name.indexOf(".manifest") === -1
                                 && this._filesToLoad[i].name.indexOf(".incremental") === -1 && this._filesToLoad[i].name.indexOf(".babylonmeshdata") === -1
                                 && this._filesToLoad[i].name.indexOf(".babylongeometrydata") === -1 && this._filesToLoad[i].name.indexOf(".babylonbinarymeshdata") === -1 &&

+ 7 - 3
src/Tools/babylon.filesInput.ts

@@ -100,9 +100,13 @@
                             FilesInput.FilesToLoad[this._filesToLoad[i].name] = this._filesToLoad[i];
                             break;
                         default:
-                            if ((
-                                this._filesToLoad[i].name.indexOf(".babylon") !== -1 || this._filesToLoad[i].name.indexOf(".stl") !== -1 ||
-                                this._filesToLoad[i].name.indexOf(".obj") !== -1 || this._filesToLoad[i].name.indexOf(".mtl") !== -1
+                            if (this._filesToLoad[i].name.indexOf(".mtl") !== -1) {
+                                FilesInput.FilesToLoad[this._filesToLoad[i].name] = this._filesToLoad[i];
+                            }
+                            else if ((
+                                this._filesToLoad[i].name.indexOf(".babylon") !== -1 || 
+                                this._filesToLoad[i].name.indexOf(".stl") !== -1 ||
+                                this._filesToLoad[i].name.indexOf(".obj") !== -1
                                 )   
                                 && this._filesToLoad[i].name.indexOf(".manifest") === -1
                                 && this._filesToLoad[i].name.indexOf(".incremental") === -1 && this._filesToLoad[i].name.indexOf(".babylonmeshdata") === -1

+ 1 - 1
src/Tools/babylon.tools.js

@@ -288,7 +288,7 @@ var BABYLON;
             };
             if (url.indexOf("file:") !== -1) {
                 var fileName = url.substring(5);
-                Tools.ReadFile(BABYLON.FilesInput.FilesToLoad[fileName], callback, progressCallBack, true);
+                Tools.ReadFile(BABYLON.FilesInput.FilesToLoad[fileName], callback, progressCallBack, useArrayBuffer);
             }
             else {
                 // Caching all files

+ 1 - 1
src/Tools/babylon.tools.ts

@@ -357,7 +357,7 @@
 
             if (url.indexOf("file:") !== -1) {
                 var fileName = url.substring(5);
-                Tools.ReadFile(FilesInput.FilesToLoad[fileName], callback, progressCallBack, true);
+                Tools.ReadFile(FilesInput.FilesToLoad[fileName], callback, progressCallBack, useArrayBuffer);
             }
             else {
                 // Caching all files