diff --git a/.gitignore b/.gitignore index 8699765f..4c699070 100644 --- a/.gitignore +++ b/.gitignore @@ -1,44 +1,44 @@ -.idea - -/build -/node_modules - -/resource/obj/1* -/resource/obj/2* -/resource/obj/capsule -/resource/obj/cerberus -/resource/obj/datamogensen -/resource/obj/emmy3d -/resource/obj/PTV1 -/resource/obj/rolleiflex -/resource/obj/totoro -/resource/obj/vive-controller -/resource/obj/walt -/resource/obj/zomax -/resource/pcd - -/screenshots - -/test/meshspray/main.html -/test/meshspray/main.min.html -/test/meshspray/webgl_*.html -/test/objloader2/main.html -/test/objloader2/main.min.html -/test/objloader2/webgl_*.html -/test/wwobjloader2/main.html -/test/wwobjloader2/main.min.html -/test/wwobjloader2/webgl_*.html -/test/wwobjloader2stage/main.html -/test/wwobjloader2stage/main.min.html -/test/wwobjloader2stage/webgl_*.html -/test/wwparallels/main.html -/test/wwparallels/main.min.html -/test/wwparallels/webgl_*.html - -/*.log -/*.tgz -/docs/styles -/docs/fonts -/docs/img -/docs/scripts -/docs/* +.idea + +/build +/node_modules + +/resource/obj/1* +/resource/obj/2* +/resource/obj/capsule +/resource/obj/cerberus +/resource/obj/datamogensen +/resource/obj/emmy3d +/resource/obj/PTV1 +/resource/obj/rolleiflex +/resource/obj/totoro +/resource/obj/vive-controller +/resource/obj/walt +/resource/obj/zomax +/resource/pcd + +/screenshots + +/test/meshspray/main.html +/test/meshspray/main.min.html +/test/meshspray/webgl_*.html +/test/objloader2/main.html +/test/objloader2/main.min.html +/test/objloader2/webgl_*.html +/test/wwobjloader2/main.html +/test/wwobjloader2/main.min.html +/test/wwobjloader2/webgl_*.html +/test/wwobjloader2stage/main.html +/test/wwobjloader2stage/main.min.html +/test/wwobjloader2stage/webgl_*.html +/test/wwparallels/main.html +/test/wwparallels/main.min.html +/test/wwparallels/webgl_*.html + +/*.log +/*.tgz +/docs/styles +/docs/fonts +/docs/img +/docs/scripts +/docs/* diff --git a/LICENSE b/LICENSE index f2c577a8..8fa7efb0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,8 +1,8 @@ -The MIT License (MIT) -Copyright (c) 2016-2017 Kai Salmen - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - +The MIT License (MIT) +Copyright (c) 2016-2017 Kai Salmen + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 4c25b57e..83e7bdef 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,93 @@ -OBJLoader2 (sync&async) for three.js -=== - -[![Latest NPM release](https://img.shields.io/npm/v/wwobjloader2.svg)](https://www.npmjs.com/package/wwobjloader2) -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/kaisalmen/WWOBJLoader/blob/master/LICENSE) - -OBJLoader2 is a new loader for the OBJ file format that is additionally executable within a web worker. - -Interested in recent changes? Check the [CHANGELOG](CHANGELOG.md). - -## Repository structure / NPM content -The directory structure is organized as follows: -- **build**: Contains build libraries and documentation (NPM only) -- **src**: Contains the sources for the loaders -- **test**: Contains Tests/HTML examples -- **resource**: Contains OBJs, MTLs and textures (GitHub only) - -## Building -**This only applies to GitHub:** Before you can start to play around some post-checkout initialization steps have to be performed.
-**[npm](https://nodejs.org)** and **[gulp](http://gulpjs.com/)** must be installed on your local platform. They are required for retrieving dependencies and for building combined source bundles and the documentation. -After checkout run:
-```bash -npm update -``` - -You require gulp to be able to build the bundles. If you have not yet installed the cli, execute this:
-```bash -npm install --global gulp-cli -``` - -From the project's root run `gulp` to create The documentation in directory **build/docs** and the bundles in directory **build**: - - **OBJLoader2[.min].js**: Contains all code required for the loader to work - - **LoaderSupport[.min].js**: Consists of common support functions, worker control and worker director code - -### Models and resources -Use gulp to download missing resources (OBJ, MTL files and textures): -```bash -gulp get-resources -``` - - -## Implementation Overview -Version 2.0.0 introduced substantial enhancements and chances especially but not only to the way the web worker execution of the parser is performed: -- `OBJLoader2` and `WWOBJLoader2` have been fused. Worker based asynchronous execution of the loader is now handled by `parseAsync`, `load` with `useAsync` flag or `run` which is used for batch processing (see example **OBJLoader2 usage options** below). Common functionality independent of OBJ parsing has been moved to package `THREE.LoaderSupport` located in `LoaderSupport.js`. The Parser can either be executed directly or it is run inside a web worker (`THREE.LoaderSupport.WorkerSupport` handles the building and execution). Raw results are passed to a common mesh builder function. These support classes can be used to transform other Loaders to support asynchronous parsing. - -### Features -`OBJLoader2` contains all features of the existing `OBJLoader` and it has to . These are some interesting POIs: -- `OBJLoader2.parse` method accepts arraybuffer or string as input. Text processing is approx. 15-20 pecent slower -- `OBJLoader2.parseAsync` only accepts arraybuffer as input as buffer is passed to worker. -- Face N-Gons are supported -- Indexed rendering is now available, but `OBJLoader2` must it must be switched on via `setUseIndices` (see `useLoadSync` in example **OBJLoader2 usage options** below). -- `OBJLoader2` must now be re-instantiated every time it is used, but caching of worker code via `WorkerSupport` and `LoaderDirector` is available -- `ConsoleLogger` now encapsulates all console logging. Logging can be fully deactivated or switched to debug mode (issue #15) -- Progress callbacks provide numerical values to indicate overall progress of download or parsing (issue #16) -- New mesh detection solely relies on 'v' and 'f' occurrences. 'o' and 'g' are meta information, that no longer drive the decision (issue #21) -- Multi-Materials are created when needed -- Flat smoothing defined by "s 0" or "s off" is supported and Multi-Material is created when one object/group defines both smoothing groups equal and not equal to zero. -- Multiple mesh definitions within one group are supported (issue #27) -- Negative face indices are now supported (issue #28) -- Support for points (added) and lines (fixed) (issue #33) - -### Directing the symphony -`LoaderDirector` is able to create a configurable amount of `OBJLoader2` via reflection just by providing parameters. It is now able to direct all loaders that over automation via `run` and use `WorkerSupport` to allow running the `Parser` in a web worker. An instruction queue is fed and all workers created will work to deplete it once they have been started. - - -### Web Worker Support -`LoaderSupport` offers utility functions used to serialize existing code into strings that are used to build the web worker code. Any loader that uses it must provide a function that builds the parser code (for example see `buildCode` inside `OBJLoader2.parseAsync`). `WorkerSupport` provides wrapper code to create the web worker and to organize communication with it. Configuration of the Parser inside the worker is handled by a configuration object that configures the parser identical to synchronous usage. - -## Examples: -[OBJLoader2 basic usage](https://kaisalmen.de/wwobjloader2/objloader2/main.min.html)
-[OBJLoader2 usage options](https://kaisalmen.de/wwobjloader2/wwobjloader2/main.min.html)
-[OBJLoader2 Stage](https://kaisalmen.de/wwobjloader2/wwobjloader2stage/main.min.html)
-[LoaderDirector Mesh Spray](https://kaisalmen.de/wwobjloader2/meshspray/main.min.html)
-[LoaderDirector Parallels Demo](https://kaisalmen.de/wwobjloader2/wwparallels/main.min.html)
- -## Http server for development -If you have `docker` and `docker-compose` installed on your development platform, you are now able to launch `nginx` which is serving the complete content of this repository. Any changes to files are directly available in the HTTP server. This is solely meant for development. - -From the command-line, use the following command to launch the HTTP server: -```bash -docker-compose up -d -``` -Content is available here: [http://localhost:8085](http://localhost:8085)
-Nginx configuration is stored here: `resource/nginx/nginx.conf`. Adjust according your needs. - -From the command-line, use the following to stop the HTTP server: -```bash -docker-compose down -``` - -Have fun! - -Kai +OBJLoader2 (sync&async) for three.js +=== + +[![Latest NPM release](https://img.shields.io/npm/v/wwobjloader2.svg)](https://www.npmjs.com/package/wwobjloader2) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/kaisalmen/WWOBJLoader/blob/master/LICENSE) + +OBJLoader2 is a new loader for the OBJ file format that is additionally executable within a web worker. + +Interested in recent changes? Check the [CHANGELOG](CHANGELOG.md). + +## Repository structure / NPM content +The directory structure is organized as follows: +- **build**: Contains build libraries and documentation (NPM only) +- **src**: Contains the sources for the loaders +- **test**: Contains Tests/HTML examples +- **resource**: Contains OBJs, MTLs and textures (GitHub only) + +## Building +**This only applies to GitHub:** Before you can start to play around some post-checkout initialization steps have to be performed.
+**[npm](https://nodejs.org)** and **[gulp](http://gulpjs.com/)** must be installed on your local platform. They are required for retrieving dependencies and for building combined source bundles and the documentation. +After checkout run:
+```bash +npm update +``` + +You require gulp to be able to build the bundles. If you have not yet installed the cli, execute this:
+```bash +npm install --global gulp-cli +``` + +From the project's root run `gulp` to create The documentation in directory **build/docs** and the bundles in directory **build**: + - **OBJLoader2[.min].js**: Contains all code required for the loader to work + - **LoaderSupport[.min].js**: Consists of common support functions, worker control and worker director code + +### Models and resources +Use gulp to download missing resources (OBJ, MTL files and textures): +```bash +gulp get-resources +``` + + +## Implementation Overview +Version 2.0.0 introduced substantial enhancements and chances especially but not only to the way the web worker execution of the parser is performed: +- `OBJLoader2` and `WWOBJLoader2` have been fused. Worker based asynchronous execution of the loader is now handled by `parseAsync`, `load` with `useAsync` flag or `run` which is used for batch processing (see example **OBJLoader2 usage options** below). Common functionality independent of OBJ parsing has been moved to package `THREE.LoaderSupport` located in `LoaderSupport.js`. The Parser can either be executed directly or it is run inside a web worker (`THREE.LoaderSupport.WorkerSupport` handles the building and execution). Raw results are passed to a common mesh builder function. These support classes can be used to transform other Loaders to support asynchronous parsing. + +### Features +`OBJLoader2` contains all features of the existing `OBJLoader` and it has to . These are some interesting POIs: +- `OBJLoader2.parse` method accepts arraybuffer or string as input. Text processing is approx. 15-20 pecent slower +- `OBJLoader2.parseAsync` only accepts arraybuffer as input as buffer is passed to worker. +- Face N-Gons are supported +- Indexed rendering is now available, but `OBJLoader2` must it must be switched on via `setUseIndices` (see `useLoadSync` in example **OBJLoader2 usage options** below). +- `OBJLoader2` must now be re-instantiated every time it is used, but caching of worker code via `WorkerSupport` and `LoaderDirector` is available +- `ConsoleLogger` now encapsulates all console logging. Logging can be fully deactivated or switched to debug mode (issue #15) +- Progress callbacks provide numerical values to indicate overall progress of download or parsing (issue #16) +- New mesh detection solely relies on 'v' and 'f' occurrences. 'o' and 'g' are meta information, that no longer drive the decision (issue #21) +- Multi-Materials are created when needed +- Flat smoothing defined by "s 0" or "s off" is supported and Multi-Material is created when one object/group defines both smoothing groups equal and not equal to zero. +- Multiple mesh definitions within one group are supported (issue #27) +- Negative face indices are now supported (issue #28) +- Support for points (added) and lines (fixed) (issue #33) + +### Directing the symphony +`LoaderDirector` is able to create a configurable amount of `OBJLoader2` via reflection just by providing parameters. It is now able to direct all loaders that over automation via `run` and use `WorkerSupport` to allow running the `Parser` in a web worker. An instruction queue is fed and all workers created will work to deplete it once they have been started. + + +### Web Worker Support +`LoaderSupport` offers utility functions used to serialize existing code into strings that are used to build the web worker code. Any loader that uses it must provide a function that builds the parser code (for example see `buildCode` inside `OBJLoader2.parseAsync`). `WorkerSupport` provides wrapper code to create the web worker and to organize communication with it. Configuration of the Parser inside the worker is handled by a configuration object that configures the parser identical to synchronous usage. + +## Examples: +[OBJLoader2 basic usage](https://kaisalmen.de/wwobjloader2/objloader2/main.min.html)
+[OBJLoader2 usage options](https://kaisalmen.de/wwobjloader2/wwobjloader2/main.min.html)
+[OBJLoader2 Stage](https://kaisalmen.de/wwobjloader2/wwobjloader2stage/main.min.html)
+[LoaderDirector Mesh Spray](https://kaisalmen.de/wwobjloader2/meshspray/main.min.html)
+[LoaderDirector Parallels Demo](https://kaisalmen.de/wwobjloader2/wwparallels/main.min.html)
+ +## Http server for development +If you have `docker` and `docker-compose` installed on your development platform, you are now able to launch `nginx` which is serving the complete content of this repository. Any changes to files are directly available in the HTTP server. This is solely meant for development. + +From the command-line, use the following command to launch the HTTP server: +```bash +docker-compose up -d +``` +Content is available here: [http://localhost:8085](http://localhost:8085)
+Nginx configuration is stored here: `resource/nginx/nginx.conf`. Adjust according your needs. + +From the command-line, use the following to stop the HTTP server: +```bash +docker-compose down +``` + +Have fun! + +Kai diff --git a/docker-compose.yml b/docker-compose.yml index 8d7eb471..4373deb1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,11 @@ -version: '3.3' - -services: - obj2nginx: - image: nginx - ports: - - 8085:80 - volumes: - - .:/usr/share/nginx/html:ro - - ./resource/nginx/nginx.conf:/etc/nginx/nginx.conf:ro - container_name: obj2nginx +version: '3.3' + +services: + obj2nginx: + image: nginx + ports: + - 8085:80 + volumes: + - .:/usr/share/nginx/html:ro + - ./resource/nginx/nginx.conf:/etc/nginx/nginx.conf:ro + container_name: obj2nginx diff --git a/docs/threejs/LoaderSupport.html b/docs/threejs/LoaderSupport.html index 981aa831..1e48806a 100644 --- a/docs/threejs/LoaderSupport.html +++ b/docs/threejs/LoaderSupport.html @@ -405,12 +405,35 @@

LoaderBase( [page:LoadingManager manager], [page:LoaderSupport.ConsoleLogger [page:LoaderSupport.ConsoleLogger logger] - logger to be used
- Base class to be used by loaders. + Base class to be used by Loaders that provide load, parse, parseAsync and run

Methods

- + +

[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError], [page:Function onMeshAlter], [page:boolean useAsync] )

+
+ [page:String url] - A string containing the path/URL of the file to be loaded.
+ [page:Function onLoad] - A function to be called after loading is successfully completed. The function receives loaded [page:Object3D] as an argument.
+ [page:Function onProgress] - (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains [page:Integer total] and [page:Integer loaded] bytes.
+ [page:Function onError] - (optional) A function to be called if an error occurs during loading. The function receives the error as an argument.
+ [page:Function onMeshAlter] - (optional) A function to be called after a new mesh raw data becomes available for alteration.
+ [page:boolean useAsync] - (optional) If true, uses async loading with worker, if false loads data synchronously. +
+
+ Use this convenient method to load a file at the given URL. By default the fileLoader uses an ArrayBuffer. +
+ +

[method:ConsoleLogger checkResourceDescriptorFiles] ( [page:THREE.LoaderSupport.ResourceDescriptor resources], [page:Object fileDesc] )

+
+ [page:THREE.LoaderSupport.ResourceDescriptor resources] - Array of {@link THREE.LoaderSupport.ResourceDescriptor} + [page:Object fileDesc] - Object describing which resources are of interest (ext, type (string or UInt8Array) and ignore (boolean)) +
+
+ Identify files or content of interest from an Array of {@link THREE.LoaderSupport.ResourceDescriptor}. Returns Object with each "ext" and the corresponding {@link THREE.LoaderSupport.ResourceDescriptor} +
+ +

[method:ConsoleLogger getLogger] ()

Returns [page:LoaderSupport.ConsoleLogger]. diff --git a/docs/threejs/OBJLoader2.html b/docs/threejs/OBJLoader2.html index 58275258..41932c73 100644 --- a/docs/threejs/OBJLoader2.html +++ b/docs/threejs/OBJLoader2.html @@ -1,186 +1,178 @@ - - - - - - - - - - - -

[name]

- -
A loader for loading a .obj resource.
- The OBJ file format is a simple data-format - that represents 3D geometry in a human redeable format as, the position of each vertex, the UV position of - each texture coordinate vertex, vertex normals, and the faces that make each polygon defined as a list of - vertices, and texture vertices. -
- -

Examples

- - - // instantiate the loader - var loader = new THREE.OBJLoader2(); - - // function called on successful load - var callbackOnLoad = function ( event ) { - scene.add( event.detail.loaderRootNode ); - }; - - // load a resource from provided URL synchronously - loader.load( 'obj/female02/female02.obj', callbackOnLoad, null, null, null, false ); - - - [example:webgl_loader_obj2] - Simple example
- [example:webgl_loader_obj2_options] - Example for multiple use-cases (parse, load and run with instructions (sync and async)
- [example:webgl_loader_obj2_run_director] - Advanced example using [page:LoaderSupport.LoaderWorkerDirector] for orchestration of multiple workers. - - -

Constructor

- -

[name]( [page:LoadingManager manager], [page:LoaderSupport.ConsoleLogger logger] )

-
- [page:LoadingManager manager] - The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager]. - [page:LoaderSupport.ConsoleLogger logger] - logger to be used -
-
- Use [name] to load OBJ data from files or to parse OBJ data from arraybuffer or text. -
- - -

Methods

- -

[method:Object3D parse]( {[page:arraybuffer content]|[page:String content]] )

-
- [[page:arraybuffer content]|[page:String content]] OBJ data as Uint8Array or String -
-
- Parses OBJ data synchronously from arraybuffer or string and returns the [page:Object3D loaderRoorNode]. -
- - -

[method:Object3D parseAsync]( [page:arraybuffer content], [page:Function onLoad] )

-
- [page:arraybuffer content] - OBJ data as Uint8Array
- [page:Function onLoad] - Called after worker successfully completed loading
-
-
- Parses OBJ content asynchronously from arraybuffer. -
- - -

[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError], [page:Function onMeshAlter], [page:boolean useAsync] )

-
- [page:String url] - A string containing the path/URL of the .obj file.
- [page:Function onLoad] - A function to be called after loading is successfully completed. The function receives loaded [page:Object3D] as an argument.
- [page:Function onProgress] - (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains [page:Integer total] and [page:Integer loaded] bytes.
- [page:Function onError] - (optional) A function to be called if an error occurs during loading. The function receives the error as an argument.
- [page:Function onMeshAlter] - (optional) A function to be called after a new mesh raw data becomes available for alteration.
- [page:boolean useAsync] - (optional) If true, uses async loading with worker, if false loads data synchronously. -
-
- Use this convenient method to load an OBJ file at the given URL. By default the fileLoader uses an arraybuffer. -
- - -

[method:null run]( [page:LoaderSupport.PrepData params], [page:LoaderSupport.WorkerSupport workerSupportExternal] )

-
- [page:LoaderSupport.PrepData params] - prepData All parameters and resources required for execution
- [page:LoaderSupport.WorkerSupport workerSupportExternal] - Use pre-existing WorkerSupport -
-
- Run the loader according the provided instructions. -
- - -

[method:null setMaterialPerSmoothingGroup] ( [page:boolean materialPerSmoothingGroup] )

-
- [page:boolean materialPerSmoothingGroup] -
-
- Tells whether a material shall be created per smoothing group. -
- - -

The following methods are inherited from [page:LoaderSupport.Commons]

- -

[method:ConsoleLogger getLogger] ()

-
- Returns [page:LoaderSupport.ConsoleLogger]. -
- - -

[method:null setModelName] ( [page:String modelName] )

-
- [page:String modelName] -
-
- Set the name of the model. -
- - -

[method:null setPath] ( [page:String path] )

-
- [page:String path] - URL -
-
- The URL of the base path. -
- - -

[method:null setStreamMeshesTo] ( [page:Object3D streamMeshesTo] )

-
- [page:Object3D streamMeshesTo] - Object already attached to scenegraph where new meshes will be attached to -
-
- Set the node where the loaded objects will be attached directly. -
- - -

[method:null setMaterials] ( Array of [page:Material materials] )

-
- Array of [page:Material materials] - Array of [page:Material Materials] -
-
- Set materials loaded by MTLLoader or any other supplier of an Array of [page:Material Materials]. -
- - -

[method:null setUseIndices]( [page:Boolean useIndices] )

-
- [page:Boolean useIndices] -
-
- Instructs loaders to create indexed [page:BufferGeometry]. -
- - -

[method:null setDisregardNormals]( [page:Boolean disregardNormals] )

-
- [page:Boolean disregardNormals] -
-
- Tells whether normals should be completely disregarded and regenerated. -
- - -

[method:null loadMtl]( [page:String url], [page:Object content], [page:Function callbackOnLoad], [page:String crossOrigin], [page:Object materialOptions])

-
- [page:String url] - URL to the file - [page:Object content] - The file content as arraybuffer or text - [page:Function callbackOnLoad] - Callback to be called after successful load - [page:String crossOrigin] - (optional) CORS value - [page:Function materialOptions] - (optional) Set material loading options for MTLLoader -
-
- Utility method for loading an mtl file according resource description. Provide url or content.. -
- - -

Source

- - [link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/OBJLoader2.js examples/js/loaders/OBJLoader2.js] - - + + + + + + + + + + + +

[name]

+ +
A loader for loading a .obj resource.
+ The OBJ file format is a simple data-format + that represents 3D geometry in a human redeable format as, the position of each vertex, the UV position of + each texture coordinate vertex, vertex normals, and the faces that make each polygon defined as a list of + vertices, and texture vertices. +
+ +

Examples

+ + + // instantiate the loader + var loader = new THREE.OBJLoader2(); + + // function called on successful load + var callbackOnLoad = function ( event ) { + scene.add( event.detail.loaderRootNode ); + }; + + // load a resource from provided URL synchronously + loader.load( 'obj/female02/female02.obj', callbackOnLoad, null, null, null, false ); + + + [example:webgl_loader_obj2] - Simple example
+ [example:webgl_loader_obj2_options] - Example for multiple use-cases (parse, load and run with instructions (sync and async)
+ [example:webgl_loader_obj2_run_director] - Advanced example using [page:LoaderSupport.LoaderWorkerDirector] for orchestration of multiple workers. + + +

Constructor

+ +

[name]( [page:LoadingManager manager], [page:LoaderSupport.ConsoleLogger logger] )

+
+ [page:LoadingManager manager] - The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
+ [page:LoaderSupport.ConsoleLogger logger] - logger to be used +
+
+ Use [name] to load OBJ data from files or to parse OBJ data from arraybuffer or text. +
+ + +

Methods

+ +

[method:Object3D parse]( {[page:arraybuffer content]|[page:String content]] )

+
+ [[page:arraybuffer content]|[page:String content]] OBJ data as Uint8Array or String +
+
+ Parses OBJ data synchronously from arraybuffer or string and returns the [page:Object3D loaderRoorNode]. +
+ + +

[method:Object3D parseAsync]( [page:arraybuffer content], [page:Function onLoad] )

+
+ [page:arraybuffer content] - OBJ data as Uint8Array
+ [page:Function onLoad] - Called after worker successfully completed loading
+
+
+ Parses OBJ content asynchronously from arraybuffer. +
+ + +

[method:null load] => [page:LoaderSupport.LoaderBase.load]

+ + +

[method:null run]( [page:LoaderSupport.PrepData params], [page:LoaderSupport.WorkerSupport workerSupportExternal] )

+
+ [page:LoaderSupport.PrepData params] - prepData All parameters and resources required for execution
+ [page:LoaderSupport.WorkerSupport workerSupportExternal] - Use pre-existing WorkerSupport +
+
+ Run the loader according the provided instructions. +
+ + +

[method:Object checkResourceDescriptorFiles] => [page:LoaderSupport.LoaderBase.checkResourceDescriptorFiles]

+ + +

[method:null setMaterialPerSmoothingGroup] ( [page:boolean materialPerSmoothingGroup] )

+
+ [page:boolean materialPerSmoothingGroup] +
+
+ Tells whether a material shall be created per smoothing group. +
+ + +

The following methods are inherited from [page:LoaderSupport.Commons]

+ +

[method:ConsoleLogger getLogger] ()

+
+ Returns [page:LoaderSupport.ConsoleLogger]. +
+ + +

[method:null setModelName] ( [page:String modelName] )

+
+ [page:String modelName] +
+
+ Set the name of the model. +
+ + +

[method:null setPath] ( [page:String path] )

+
+ [page:String path] - URL +
+
+ The URL of the base path. +
+ + +

[method:null setStreamMeshesTo] ( [page:Object3D streamMeshesTo] )

+
+ [page:Object3D streamMeshesTo] - Object already attached to scenegraph where new meshes will be attached to +
+
+ Set the node where the loaded objects will be attached directly. +
+ + +

[method:null setMaterials] ( Array of [page:Material materials] )

+
+ Array of [page:Material materials] - Array of [page:Material Materials] +
+
+ Set materials loaded by MTLLoader or any other supplier of an Array of [page:Material Materials]. +
+ + +

[method:null setUseIndices]( [page:Boolean useIndices] )

+
+ [page:Boolean useIndices] +
+
+ Instructs loaders to create indexed [page:BufferGeometry]. +
+ + +

[method:null setDisregardNormals]( [page:Boolean disregardNormals] )

+
+ [page:Boolean disregardNormals] +
+
+ Tells whether normals should be completely disregarded and regenerated. +
+ + +

[method:null loadMtl]( [page:String url], [page:Object content], [page:Function callbackOnLoad], [page:String crossOrigin], [page:Object materialOptions])

+
+ [page:String url] - URL to the file + [page:Object content] - The file content as arraybuffer or text + [page:Function callbackOnLoad] - Callback to be called after successful load + [page:String crossOrigin] - (optional) CORS value + [page:Function materialOptions] - (optional) Set material loading options for MTLLoader +
+
+ Utility method for loading an mtl file according resource description. Provide url or content.. +
+ + +

Source

+ + [link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/OBJLoader2.js examples/js/loaders/OBJLoader2.js] + + diff --git a/gulpfile.js b/gulpfile.js index a1cc2dec..fe52751f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,666 +1,666 @@ -'use strict'; - -var fs = require( 'fs' ); - -var gulp = require( 'gulp' ); -var del = require( 'del' ); -var rename = require( 'gulp-rename' ); -var concat = require( 'gulp-concat' ); -var uglify = require( 'gulp-uglify' ); -var header = require( 'gulp-header' ); -var replace = require( 'gulp-replace-task' ); -var remoteSrc = require( 'gulp-remote-src' ); -var gutil = require( 'gulp-util' ); -var decompress = require('gulp-decompress'); - -var jsdoc = require( 'gulp-jsdoc3' ); -var config = require('./jsdoc.json'); - -var packageContent = require('./package.json'); - -var DIR = { - BUILD: 'build/', - DOCS: 'docs/', - EXAMPLES: 'build/examples', - TEST: 'test/' -}; - -function buildHeader() { - return "/**\n" + - " * @author Kai Salmen / https://kaisalmen.de\n" + - " * Development repository: https://github.com/kaisalmen/WWOBJLoader\n" + - " */" + - "\n\n'use strict';\n\n"; -}; - -gulp.task( 'clean-build', function () { - return del.sync( DIR.BUILD ); -}); - -gulp.task( 'set-versions', function () { - gulp.src( - [ 'src/loaders/OBJLoader2.js' ] - ) - .pipe( replace( { - patterns: [ { - match: /var OBJLOADER2_VERSION.*/g, - replacement: "var OBJLOADER2_VERSION = '"+ packageContent.versions.loader_obj2 + "';" - } ] - } ) ) - .pipe( gulp.dest( "src/loaders" ) ); - - gulp.src( - [ 'src/loaders/support/LoaderWorkerSupport.js' ] - ) - .pipe( replace( { - patterns: [ { - match: /var WORKER_SUPPORT_VERSION.*/g, - replacement: "var WORKER_SUPPORT_VERSION = '"+ packageContent.versions.loader_worker_support + "';" - } ] - } ) ) - .pipe( gulp.dest( "src/loaders/support" ) ); - - gulp.src( - [ 'src/loaders/support/LoaderWorkerDirector.js' ] - ) - .pipe( replace( { - patterns: [ { - match: /var LOADER_WORKER_DIRECTOR_VERSION.*/g, - replacement: "var LOADER_WORKER_DIRECTOR_VERSION = '"+ packageContent.versions.loader_worker_director + "';" - } ] - } ) ) - .pipe( gulp.dest( "src/loaders/support" ) ); - - gulp.src( - [ 'src/loaders/support/LoaderBuilder.js' ] - ) - .pipe( replace( { - patterns: [ { - match: /var LOADER_BUILDER_VERSION.*/g, - replacement: "var LOADER_BUILDER_VERSION = '"+ packageContent.versions.loader_builder + "';" - } ] - } ) ) - .pipe( gulp.dest( "src/loaders/support" ) ); -} ); - -gulp.task( 'bundle-loader-support', function () { - var builtHeader = buildHeader(); - gulp.src( - [ - 'src/loaders/support/LoaderCommons.js', - 'src/loaders/support/LoaderBuilder.js', - 'src/loaders/support/LoaderBase.js', - 'src/loaders/support/LoaderWorkerSupport.js', - 'src/loaders/support/LoaderWorkerDirector.js' - ] - ) - .pipe( concat( 'LoaderSupport.js' ) ) - .pipe( header( builtHeader ) ) - .pipe( gulp.dest( DIR.BUILD ) ) - - .pipe( uglify( { mangle: { toplevel: true } } ) ) - .pipe( rename( { basename: 'LoaderSupport.min' } ) ) - .pipe( gulp.dest( DIR.BUILD ) ); -} ); - -gulp.task( 'bundle-objloader2', function () { - var builtHeader = buildHeader(); - gulp.src( - [ - 'src/loaders/OBJLoader2.js' - ] - ) - .pipe( concat( 'OBJLoader2.js' ) ) - .pipe( header( builtHeader ) ) - .pipe( gulp.dest( DIR.BUILD ) ) - - .pipe( uglify( { mangle: { toplevel: true } } ) ) - .pipe( rename( { basename: 'OBJLoader2.min' } ) ) - .pipe( gulp.dest( DIR.BUILD ) ); -} ); - - -gulp.task( 'create-docs', function ( cb ) { - del.sync( DIR.DOCS + 'fonts' ); - del.sync( DIR.DOCS + 'img' ); - del.sync( DIR.DOCS + 'scripts' ); - del.sync( DIR.DOCS + 'styles' ); - del.sync( DIR.DOCS + '*.html' ); - del.sync( DIR.DOCS + '*.md' ); - gulp.src( - [ - 'README.md', - 'src/loaders/support/LoaderCommons.js', - 'src/loaders/support/LoaderBuilder.js', - 'src/loaders/support/LoaderBase.js', - 'src/loaders/support/LoaderWorkerSupport.js', - 'src/loaders/support/LoaderWorkerDirector.js', - 'src/loaders/OBJLoader2.js' - ], - { - read: false - } - ) - .pipe( jsdoc( config, cb ) ); - - gulp.src( [ 'CHANGELOG.md' ] ) - .pipe( gulp.dest( DIR.DOCS ) ); -}); - - -var exampleDef = { - css: { - common: "", - main: "", - link_all_ref: "\n\", - link_all: "", - link_tabs: "", - style_all: "", - style_tabs: "" - }, - js: { - inline_code: "", - inline_tabs: "", - ext_code: "", - ext_three: "