but0n / Ashes

WebGL2.0 3D Engine - Global Illumination - RayTracing
https://codepen.io/but0n/pen/jddYoX
MIT License
331 stars 15 forks source link

Please support glTF-Embedded format #20

Closed cx20 closed 5 years ago

cx20 commented 5 years ago

I tried to display several glTF models using Ashes. However, it seems that you can not display models in glTF Embedded format. The following is a sample that could not be displayed because of a format problem.

Ashes + glTF Additonal Test Case No.3 http://jsdo.it/cx20/kSsC

Ashes + glTF Additonal Test Case No.5 http://jsdo.it/cx20/YY6E

Ashes + glTF Additonal Test Case No.10 http://jsdo.it/cx20/c2TU

The glTF Embedded format is a format used when incorporating resources into JSON using Data URI. I hope that you can support if possible.

cx20 commented 5 years ago

Perhaps, if you check in the following places if the uri format is a Data URI and set uri or root + uri, I think that it will be displayed. https://github.com/but0n/Ashes/blob/master/src/asset.ts#L137-L146

cx20 commented 5 years ago

The following is a suggestion of a fix code.

static adjustDataUri(root, uri) {
    return uri.substr(0, 5) == "data:" ? uri : root + uri;
}

//gltf.buffers = await Promise.all(gltf.buffers.map(({ uri }) => this.loadBuffer(root + uri)));
gltf.buffers = await Promise.all(gltf.buffers.map(({ uri }) => this.loadBuffer(adjustDataUri(root, uri))));

//gltf.images = await Promise.all(gltf.images.map(({ uri }) => this.loadImage(root + uri)));
gltf.images = await Promise.all(gltf.images.map(({ uri }) => this.loadImage(adjustDataUri(root, uri))));
but0n commented 5 years ago

Thanks for your suggestion! I'm already add the fix code you provide, it will support data url in the next version.

cx20 commented 5 years ago

I tried v0.0.48. However, it seems that there is another error.

ashes.main.js:5711 
Uncaught TypeError: meshChunk.entities(...) is not a function or its return value is not iterable
    at gltfScene.createEntity (ashes.main.js:5711)
    at setTimeout (ashes.main.js:5623)

image

but0n commented 5 years ago

Oh, that was a typo. 😅 It already been fixed in the newest version.

cx20 commented 5 years ago

@but0n I updated the status of gltf-test by confirming that glTF Embedded format can be displayed with Ashes v0.0.49. image

Also updated the sample in jsdo.it. Since there are some samples that can not be displayed yet, I will report it as a separate Issue.