-
-
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
GLTFLoader v2 #9786
GLTFLoader v2 #9786
Conversation
The objective here is to deprecate https://github.com/mrdoob/three.js/tree/dev/examples/js/loaders/gltf in favor of a single glTF loader in the THREE.js project. We should eventually move /examples/js/loaders/gltf to /examples/js/loaders/deprecated/gltf, update the docs to point to the new class and update the glTF example to use the new class. I feel this could be a separate pull request once this new GLTFLoader.js is merged and battle ready. |
72ec94d
to
120e198
Compare
5cb7f79
to
2a25f2c
Compare
2a25f2c
to
fa9bb26
Compare
547e51a
to
9db5bbe
Compare
@mrdoob do you prefer everything squashed in to one commit or is the current commit history acceptable? |
Also, I'm wondering whether instead of adding |
@richtr this looks like a lovely refactor; but I haven't actually tried it - is there a fork I can grab to test everything out against it? |
You can clone and switch to the branch that this is on: git clone [email protected]:richtr/three.js.git three.js-richtr
cd three.js-richtr
git checkout feature/GLTFLoader Then run a local web server using a one-liner within that root directory. I've also mirrored this branch to here: https://richtr.github.io/three.js/examples/webgl_loader_gltf.html if you want to see how it works quickly online too. I've used this PR successfully with all the models in https://github.com/KhronosGroup/glTF/tree/master/sampleModels but it would be good to get more testing in too. |
@richtr I've been wanting migrate the json file I'm currently generating to glTF. I've tested a few .dae files converted with https://cesiumjs.org/convertmodel.html with your feature/GLTFLoader branch and they seem to work fine. This pull made me look into gltf and for a file that was 27,9mb with the Three.js format, it becomes 13,2mb in GLTF and 4,7mb zipped. Geometry loaded fine, but textures as .png did not load for my files. I'm not sure if it is something in particular with my model. I don't get any errors that the .png are not found, but the meshes don't get a texture applied. Maybe a sample file generated from my process would help? |
@richtr This is a simple box. It has a material with a diffuse channel as a jpg. The box itself loads, but I get errors such as: So I can see the box, but no material. I've compared with the other glts files and while there are some differences, I am not sure which ones are causing the material to not be understood. The program and shaders seems to be defined in the same manner, and the glsl files have the same relationship in the directory to the .gltf file. The process to make this: Create box in Rhino 3d, export as .dae, run through collada2gltf with no special options, define the model in your |
Great work, @richtr! I'm looking forward to see this land 👍 I also tested the loader with:
I'll see if I can find some more test models :) |
Improves spec compliance: primitive.mode is optional
No need to squash 😊
I would just fix |
|
||
this.crossOrigin = value; | ||
|
||
}, | ||
|
||
parse: function ( json ) { | ||
setBaseUrl: function( value ) { |
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've been renaming this method to setPath
in other loaders:
https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/OBJLoader.js#L56-L60
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.
It's good to have consistency here. Fixed in e0e7dbf.
OK. I have moved In addition, I have updated the documentation to reflect the API and point to this new GLTFLoader in commit 5b0bfba. In db17203 I have moved the old |
@richtr It didn't seem to work with transparent KHR materials, but maybe I misread the spec when I did our exporter, but I think |
… in the 'values' section but every use of these params I've seen in the wild has been outside this section
… we can remove double flip from GLTFLoader
@fraguada wrote:
It seems fine to work with no errors for me with the 'View-Perspective' camera you have set up in your glTF file: I see no errors on the console when I load this (both |
1db4fc2
to
8d254a4
Compare
@richtr GLTFLoader v2 does not support Safari? I tested old and new glTF loaders. @mrdoob's GLTFLoader (basic loader) can display a duck in Safari. |
It does but it looks like there is an issue specifically with We currently run everything (including data URIs) through I'd prefer that this issue would be fixed in Update: The simplest test case I could come up that shows the issue is the following:
|
@richtr v2 is supports Safari. However, |
I've created a new pull request to fix the issue documented above in Using #9823 and this PR (#9786) together fixes the issue of loading and rendering |
2b8275d
to
0ac2aa0
Compare
… global library.* tracking. Other general refactoring
Thaaanks! 😊 |
* Initial GLTFLoader updates so it will also obtain async resources over the network * First take at adding shader support to new GLTFLoader * First working custom shaders version of GLTFLoader.js * Fully working custom GLTF shaders + general library fix-ups * Add skins, animations, lights, extensions and continue to refactor the library * Refactor new GLTFLoader (seperate glTF parsing and internal library building) * Fix GLSL shader update binding to point at the correct nodes + more general refactoring * Make _each thenable and refactor dependencies graph + other minor fixes * Improves spec compliance: primitive.mode is optional * Update GLTFLoader v2 with feedback on PR: mrdoob#9786 - Replace .set(...) with .fromArray(...) where possible for THREE.js Math objects (thanks @mrdoob) - Include fix for mrdoob#8381 (thanks @cx20) - Move THREE.GLTFShaders to THREE.GLTFLoader.Shaders - Move THREE.GLTFAnimator to THREE.GLTFLoader.Animations - Rename .setBaseUrl(...) to .setPath(...) - Update demo page 'examples/webgl_loader_gltf_new.html' with renamed APIs * Replace 'examples/webgl_loader_gltf.html' with new version of GLTFLoader * Update documentation at /docs/?q=gltf#Reference/Loaders/GLTFLoader to reference new GLTFLoader * Move /examples/js/loaders/gltf/* to /examples/js/loaders/deprecated/gltf/* * Actually add a fix for mrdoob#8381 * Re-fix mrdoob#8381 in a more logical way * Update material parameter checking and validation. * Fix issue whereby the spec says doubleSided and transparent should be in the 'values' section but every use of these params I've seen in the wild has been outside this section * Ambient is not a valid properties for THREE.js materials * THREE textures have flipY set to true by default. By setting to false we can remove double flip from GLTFLoader * Fix issue where Firefox Promise then callback can not correctly keep track of its key * Remove debugging from examples/loaders/deprecated/gltf/glTFLoader.js * Refactor waitForDependencies in to _withDependencies. Remove need for global library.* tracking. Other general refactoring
* Initial GLTFLoader updates so it will also obtain async resources over the network * First take at adding shader support to new GLTFLoader * First working custom shaders version of GLTFLoader.js * Fully working custom GLTF shaders + general library fix-ups * Add skins, animations, lights, extensions and continue to refactor the library * Refactor new GLTFLoader (seperate glTF parsing and internal library building) * Fix GLSL shader update binding to point at the correct nodes + more general refactoring * Make _each thenable and refactor dependencies graph + other minor fixes * Improves spec compliance: primitive.mode is optional * Update GLTFLoader v2 with feedback on PR: mrdoob#9786 - Replace .set(...) with .fromArray(...) where possible for THREE.js Math objects (thanks @mrdoob) - Include fix for mrdoob#8381 (thanks @cx20) - Move THREE.GLTFShaders to THREE.GLTFLoader.Shaders - Move THREE.GLTFAnimator to THREE.GLTFLoader.Animations - Rename .setBaseUrl(...) to .setPath(...) - Update demo page 'examples/webgl_loader_gltf_new.html' with renamed APIs * Replace 'examples/webgl_loader_gltf.html' with new version of GLTFLoader * Update documentation at /docs/?q=gltf#Reference/Loaders/GLTFLoader to reference new GLTFLoader * Move /examples/js/loaders/gltf/* to /examples/js/loaders/deprecated/gltf/* * Actually add a fix for mrdoob#8381 * Re-fix mrdoob#8381 in a more logical way * Update material parameter checking and validation. * Fix issue whereby the spec says doubleSided and transparent should be in the 'values' section but every use of these params I've seen in the wild has been outside this section * Ambient is not a valid properties for THREE.js materials * THREE textures have flipY set to true by default. By setting to false we can remove double flip from GLTFLoader * Fix issue where Firefox Promise then callback can not correctly keep track of its key * Remove debugging from examples/loaders/deprecated/gltf/glTFLoader.js * Refactor waitForDependencies in to _withDependencies. Remove need for global library.* tracking. Other general refactoring
This is a complete refactor/rewrite of the existing glTF code in https://github.com/mrdoob/three.js/tree/dev/examples/js/loaders/gltf.
The new
GLTFLoader.js
includes all of the features of the legacy glTF code.The benefits of this rewrite are as follows: