playcanvas / playcanvas-gltf

glTF 2.0 support for the PlayCanvas Engine
MIT License
102 stars 31 forks source link

Failed to load Duck.gltf model #1

Closed cx20 closed 6 years ago

cx20 commented 6 years ago

I tried loading Duck.gltf using PlayCanvas + glTF Loader. http://jsdo.it/cx20/yh4S

However, glTF-Embedded format can be load, but otherwise it got an error.

[OK] https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Duck/glTF-Embedded/Duck.gltf [NG] https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Duck/glTF/Duck.gltf

gltf-loader.js:5 
Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at dataURItoArrayBuffer (https://cdn.rawgit.com/playcanvas/playcanvas-gltf/5489ff62/src/gltf-loader.js:5:26)
    at https://cdn.rawgit.com/playcanvas/playcanvas-gltf/5489ff62/src/gltf-loader.js:516:35
    at Array.forEach (<anonymous>)
    at loadBuffers (https://cdn.rawgit.com/playcanvas/playcanvas-gltf/5489ff62/src/gltf-loader.js:515:26)
    at loadGltf (https://cdn.rawgit.com/playcanvas/playcanvas-gltf/5489ff62/src/gltf-loader.js:602:54)
    at XMLHttpRequest.req.onload (http://jsrun.it/cx20/yh4S:132:16)

https://github.com/playcanvas/playcanvas-gltf/blob/master/src/gltf-loader.js#L5

If the normal glTF format is supported, I will add playcanvas-gltf to gltf-test.

willeastcott commented 6 years ago

This is because the glTF loader currently only supports:

I just committed the first part of support non-embedded glTF files here: https://github.com/playcanvas/playcanvas-gltf/commit/6ff7720d12a1a54b2b758f710e626a5a7bdf80db

This gives the loader code access to the external .bin and image files referenced by the glTF file. Now I just need to update the loader to load the days from these files.

cx20 commented 6 years ago

I have understood the status of current glTF Loader. I added the following tests to gltf-test. Other tests are added when normal glTF format is supported.

https://github.com/cx20/gltf-test#format-tests image

https://cx20.github.io/gltf-test/ image

cx20 commented 6 years ago

I tried loading non-embedded glTF files with the latest glTF viewer. Since the geometry of Duck is displayed, it seems that the bin file can be load correctly. However, image file seems not to be load. image

willeastcott commented 6 years ago

Fixed in https://github.com/playcanvas/playcanvas-gltf/commit/be2b66f9b001ad50e6e9a94fc501a8eb5db43abd

cx20 commented 6 years ago

I confirmed that non-embedded glTF files can be load with the latest glTF viewer. image

willeastcott commented 6 years ago

Excellent. 👍

cx20 commented 6 years ago

However, in my gltf-test, I can not display it yet. https://cx20.github.io/gltf-test/examples/playcanvas/index.html?model=Duck&scale=1&type=glTF

I think it is necessary to pass more than one file name, but I did not understand how to do it.

willeastcott commented 6 years ago

Currently, you have to pass an array of File objects, which is not so easy to generate. At the moment, this is generated in the viewer index.html. I think I'm going to change this such that you can pass in a callback to the loadGltf function, and when the loader requests a file, you can load it from whatever source you like.

cx20 commented 6 years ago

Thank you for the advice. I think it is difficult to create an array of File objects, so I'd like to test waiting for loader fixes.

willeastcott commented 6 years ago

OK. I'll figure out an easier mechanism for loading multi-file glTF.

willeastcott commented 6 years ago

I have made it much easier to loaded multi-file glTF for you. See this change. Now you can do:

        app.assets.loadFromUrl('assets/car.gltf', 'json', function (err, asset) {
            var json = asset.resource;
            var gltf = JSON.parse(json);
            loadGltf(gltf, app.graphicsDevice, function (roots) {
                // add the loaded scene to the hierarchy
                roots.forEach(function (root) {
                    app.root.addChild(root);
                });
            }, {
                basePath: 'assets/'
            });
        });

I have updated the API function descriptions in the top-level readme. 😄

cx20 commented 6 years ago

I confirmed that playcanvas-gltf supported normal glTF format and added test to gltf-test. The following is the current test result.

https://github.com/cx20/gltf-test#format-tests image

https://github.com/cx20/gltf-test#simple-models-for-testing-individual-features image

https://github.com/cx20/gltf-test#more-complex-models image

https://github.com/cx20/gltf-test#pbr-models image

https://github.com/cx20/gltf-test#further-pbr-models image

https://github.com/cx20/gltf-test#agi-sample-models image

willeastcott commented 6 years ago

OK, well, I guess that's progress. 😄

TODO:

willeastcott commented 6 years ago

I've fixed the problem preventing the SciFi Helment loading here:

image

cx20 commented 6 years ago

I confirmed that the Sci Fi Helmet is displayed and I updated the status of gltf-test. https://github.com/cx20/gltf-test#further-pbr-models

willeastcott commented 6 years ago

I've done a first pass at supporting morph target animation from glTF. This means the following models (from the glTF sample models repo) should now work correctly:

cx20 commented 6 years ago

I confirmed that morph target animation works and updated the status of gltf-test. https://github.com/cx20/gltf-test#simple-models-for-testing-individual-features

willeastcott commented 6 years ago

I've just added support for vertex colors. This required an update to the PlayCanvas Engine itself. See here. This allows tests 'VertexColorTest' and 'BoxVertexColors' to work correctly. Because the engine PR to support vertex colors has not yet been merged, I've checked in a 'dev' build of the engine into this repo. Hopefully we can merge and deploy that on Monday.

cx20 commented 6 years ago

I understand. I will test again when PR is merged into the PlayCanvas Engine.

cx20 commented 6 years ago

I confirmed that VertexColorTest and BoxVertexColors can be displayed with the latest PlayCanvas engine.

willeastcott commented 6 years ago

Excellent. 👍 I'll look at transform-based keyframes next, I think.

willeastcott commented 6 years ago

My latest commit fixes:

We're getting closer... 😸

cx20 commented 6 years ago

I confirmed that the above five models will be displayed. https://github.com/cx20/gltf-test

willeastcott commented 6 years ago

I've added initial support for Draco mesh compression here. Try the duck to verify this for yourself.

cx20 commented 6 years ago

Thank you for working quickly to support Draco. I confirmed that Box and Duck glTF Draco format can be displayed. https://cx20.github.io/gltf-test/index.html I am waiting for other models to be displayed as well.

willeastcott commented 6 years ago

Ah yes, most other Draco models weren't loading. Corset and Boombox now work too because of this commit. Still some problems with GearboxAssy. I'll look into it...

cx20 commented 6 years ago

I noticed a mystery problem. However it is interesting :-)

2CylinderEngine.gltf Draco format result: image

Lantern.gltf Draco format result: image

willeastcott commented 6 years ago

OK, this is now fixed. All Draco models should now work in PlayCanvas (obviously, I still need to finish skinning support though).

2CylinderEngine.gltf Draco format result: image

Lantern.gltf Draco format result: image

cx20 commented 6 years ago

I confirmed that the glTF Draco model is displayed except skinning animation. I updated the following status. https://github.com/cx20/gltf-test#format-tests image

willeastcott commented 6 years ago

I have now implemented skinning. This means all Draco models now work correctly. Plus the following scenes:

Unfortunately, there are some issues with:

image

willeastcott commented 6 years ago

I think I see why RiggedSimple has problems. There are vertices where the skin weights do not sum to 1. Calling @guycalledfrank - what do you think about this? I could try normalizing the weights on load, but I notice Three.js can load this model fine without renormalizing. Three's skinning GLSL is slightly different to PlayCanvas. I wonder if PlayCanvas is bugged somehow...

cx20 commented 6 years ago

I updated the status of gltf-test because I confirmed that RiggedSimple and BrainStem are displayed correctly. https://github.com/cx20/gltf-test

willeastcott commented 6 years ago

OK, the following now work due to this PR in the engine:

So you can now also remove the comment 'skinning animation support yet' for the Draco format.

cx20 commented 6 years ago

Wonderful work! I confirmed that all skinning animation models are displayed. https://github.com/cx20/gltf-test

willeastcott commented 6 years ago

Since this issue was originally about fixing unpacked glTF scenes, I'm going to close it.

The remaining issues that I'm aware of that are preventing the PlayCanvas glTF loader from passing every one of your test have now been added as new issues. These cover:

Thank you so much for all your help so far! 😄