-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OBJLoader2 and WWOBJLoader2 #10631
OBJLoader2 and WWOBJLoader2 #10631
Conversation
https://rawgit.com/kaisalmen/three.js/WWOBJLoader2/examples/#webgl_loader_obj2 Textures not loading due to CORS issues, but otherwise it looks good! I guess we should handle CORS failures at some point, right now the console is full of warnings. |
6f2e7af
to
8da8b72
Compare
The CORS I do not understand. I have tried to reproduce the issue locally and on my website's server, but it works fine in both cases. A manual test with Chrome revealed that the following request: Edit 2017-01-24: If I understand correctly nothing needs to be set regarding CORS as the expectation is to retrieve everything from the same URL, just the server answers unexpectedly with a redirect. Btw, |
8da8b72
to
8e20478
Compare
@mrdoob did you have time to think about the issue? Where can I help here? |
examples/js/loaders/OBJLoader2.js
Outdated
this.fileLoader = new THREE.FileLoader( this.manager ); | ||
|
||
this.meshCreator = new THREE.OBJLoader2.MeshCreator(); | ||
this.parser = new THREE.OBJLoader2.Parser( this.meshCreator ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason MeshCreator
and Parser
need to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about doing...
THREE.OBJLoader2 = (function () {
function MeshCreator( manager ) {
...
}
function Parser() {
...
}
function OBJLoader2( manager ) {
this.manager = ( manager == null ) ? THREE.DefaultLoadingManager : manager;
this.path = '';
this.fileLoader = new THREE.FileLoader( this.manager );
this.meshCreator = new MeshCreator();
this.parser = new Parser( this.meshCreator );
this.validated = false;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parser
is also used by WWOBJLoader2
to construct the web worker. WWOBJLoader2.prototype._buildWebWorkerCode builds a string, that is afterwards put into a blob to create the worker. It basically requires these classes (link to code), whereas the top block is common code for OBJLoader2
and WWOBJLoader2
and the bottom block is defined privately in WWOBJLoader2
. I didn't want to copy the code into both packages and therefore Parser
is public:
// parser re-construction
this.workerCode += 'if ( THREE.OBJLoader2 === undefined ) { THREE.OBJLoader2 = {} }\n\n';
this.workerCode += buildObject( 'THREE.OBJLoader2.consts', THREE.OBJLoader2.consts );
this.workerCode += buildSingelton( 'THREE.OBJLoader2.Parser', 'Parser', THREE.OBJLoader2.Parser );
this.workerCode += buildSingelton( 'THREE.OBJLoader2._RawObject', '_RawObject', THREE.OBJLoader2._RawObject );
this.workerCode += buildSingelton( 'THREE.OBJLoader2.RawObjectDescription', 'RawObjectDescription', THREE.OBJLoader2.RawObjectDescription );
// web worker construction
this.workerCode += buildSingelton( 'THREE.OBJLoader2.WW.OBJLoader', 'OBJLoader', wwDef );
this.workerCode += buildSingelton( 'THREE.OBJLoader2.WW.MeshCreator', 'MeshCreator', wwMeshCreatorDef );
this.workerCode += 'THREE.OBJLoader2.WW.OBJLoaderRef = new THREE.OBJLoader2.WW.OBJLoader();\n\n';
this.workerCode += buildSingelton( 'THREE.OBJLoader2.WW.OBJLoaderRunner', 'OBJLoaderRunner', wwLoaderRunnerDef );
this.workerCode += 'new THREE.OBJLoader2.WW.OBJLoaderRunner();\n\n';
MeshCreator
on the other hand could be private as the worker has its own MeshCreator that basically supplies transferables back to WWOBJLoader2
which then creates the Meshes integrated into the scene graph. Initially, exposing MeshCreator
seemed required, but this is no longer the case.
I could update the code in the dev repo and push updated bundles to this branch.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could update the code in the dev repo and push updated bundles to this branch.
What do you think?
Yep, lets start by making MeshCreator
private. By making that code private it'll make the code easier to read for someone that wants to improve it (so there are less cases to consider).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed an update. MeshCreator
is now contained within OBJLoader2
.
I might have an idea how to make the Parser
private, too. OBJLoader2
would expose a builder function and OBJLoader2
needs then to be used internally by WWOBJLoader
. Don't know if that is a good idea. Will do some prototyping...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OBJLoader2
would expose a builder function andOBJLoader2
needs then to be used internally byWWOBJLoader
. Don't know if that is a good idea. Will do some prototyping...
I like the idea 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Builder function works! I pushed another update.
The minified versions of the bundles produce non-working worker code, but this is only a concern for the dev repo. I hope to find the error tomorrow.
Please, have a look at what I did, but don't merge it, yet as minified fix may introduce slight changes to builder functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I have pushed V1.0.3.
Uglified/Minified version is built with mangle=false otherwise it becomes almost impossible to predict the names of internally renamed objects when building the code string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrdoob Any further remarks or are we good to go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed the CORS issue. WWOBJLoader2
and WWOBJLoader2Director
can now pass crossOrigin to MTLLoader
.
I read #10465 and also set "anonymous" in the examples and now it works fine with rawgit!
Now, I think all issues you brought up are addressed! 👍
examples/files.js
Outdated
@@ -117,6 +118,8 @@ var files = { | |||
"webgl_loader_utf8", | |||
"webgl_loader_vrml", | |||
"webgl_loader_vtk", | |||
"webgl_loader_wwobj2", | |||
"webgl_loader_wwobj2_parallels", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity... do you mind renaming these to webgl_loader_obj2_ww
and webgl_loader_obj2_ww_parallels
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, done.
|
||
'use strict'; | ||
|
||
if ( THREE.examples === undefined ) THREE.examples = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a good practice... We shouldn't add stuff to the THREE
namespace like this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it in the namespace from all examples as it is really not required.
I do the following in OBJLoader2
:
if ( THREE.OBJLoader2 === undefined ) { THREE.OBJLoader2 = {} }
THREE.OBJLoader2.version = '1.0.4';
Do you generally object to this practice or just for examples. What do you suggest instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of the loader itself is fine. It was just THREE.examples
as I didn't think it was necessary.
What's |
My personal preference is to separate the what (demo or app) from how it is run. The "how" can even be generalized when the app follows conventions (if you are interested see AppRunner and ThreeJsApp which is used by every demo on my website). This approach helps me to store what I learned in a structured way and to ease restart with code after a longer break. As I understand it three.js examples should whenever possible follow the single page approach to ease understanding for other users. In the dev repo I use some template + gulp code to create the single page examples meaning the external content is baked into the files. I guess, the names I chose weren't the best. What about Is there anything else that should be discussed or modified? |
Hey, I added a forgotten feature: WWOBJLoader2 can now be configured to stream or not stream in the mesh data (new: show only once all meshes are loaded from file). @mrdoob I am done with extending the examples. I will stop changing things now and wait for your feedback. Looking forward to have this merge request completed. 😊 |
@mrdoob do you plan to include this in r85? |
I have adjusted |
@mrdoob, @jonnenauha I have combined all commits into one with larger comment listing all changes and put it on top of dev commit 6776a15 |
Again I'm hoping the new loader will be included in the repo at some point. I just don't have the power to do that. I'm sure @mrdoob will eventually get here to give some feedback on the situation, has a lot on his plate. From my perspective the code looks good, demos are great and the perf should be there. |
examples/js/loaders/OBJLoader2.js
Outdated
this.rawObjectDescriptions[ index ] = this.rawObjectDescriptionInUse; | ||
} | ||
|
||
RawObject.prototype._buildIndex = function ( materialName, smoothingGroup) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thing... why are you underscoring these methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RawObject
and MeshCreator
were initially public and all non-public methods were underscored. This is no longer necessary and it is likely misleading. I was just lazy. Should be fairly easy to adjust... Give me half an hour.
Thanks for changing the title, btw. 😉
I forced/combined another commit:
I carefully checked for regressions. It looks good as far as I can see! 😄 Good night! 😴 Edit 2017-03-23: All changes were just related to names (functions and classes). I did not perform any functional code changes. I think it is more logical now. Thank you for pointing at it! |
Improvements since initial external V1.0.0 release: OBJLoader2: - Removed need for making Parser public. OBJLoader2 has a build function for web worker code. - MeshCreator is now private to OBJLoader2 WWOBJLoader2: - Added checks for Blob and URL.createObjectURL - Worker code build: Removed need to adjust constructor and some new Object calls - Allow to properly set CORS to MTLLoader via WWOBJLoader2 and WWOBJLoader2Director - Now allows to enable/disable mesh streaming Example webgl_loader_obj - Added GridHelper - resources to load are now defined outside example classes Example webgl_loader_obj2_ww - Allow to clear all meshes in - Allows to load user OBJ/MTL files - Added GridHelper - resources to load are now defined outside example classes All Examples: - Created one page examples and tuned naming - All examples now use dat.gui - Removed namespace "THREE.examples" - Fixed comment typos - Fixed some code formatting issues - Fixed tabs in examples General: - Headers now carry references to development repository
OBJLoader2: - Removed underscores from functions of private classes WWOBJLoader2: - Adjusted naming of web worker classes
Adjusted to removal of MultiMaterial
Sweet! |
Many thanks! |
Thank you! 😄 |
#9756 Added OBJLoader2.js and WWOBJLoader2.js V1.0.1 and three examples: obj2, wwobj2 and wwobj2_parallels.
Header now carry references to development repository.
Added checks for Blob and URL.createObjectURL