Skip to content
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

Update Draco decoder and fix IE compatibility #7990

Merged
merged 2 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 48 additions & 30 deletions dist/preview release/draco_decoder_gltf.js

Large diffs are not rendered by default.

Binary file modified dist/preview release/draco_decoder_gltf.wasm
Binary file not shown.
234 changes: 119 additions & 115 deletions dist/preview release/draco_wasm_wrapper_gltf.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/preview release/what's new.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

- Allow logging of shader code when a compilation error occurs ([Popov72](https://github.com/Popov72))
- Add back support for selecting textures based on engine capabilities ([bghgary](https://github.com/bghgary))
- Fix Draco decoder when running on IE11 ([bghgary](https://github.com/bghgary))

### NME

Expand Down
13 changes: 13 additions & 0 deletions src/Meshes/Compression/building-draco.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Instructions for building the JavaScript version of Draco with IE compatibility

Draco prebuilt libraries are not compatible with IE. Thus we must build the JavaScript fallback version of the Draco decoder ourselves.

Follow the instructions for building Draco from https://github.com/google/draco/blob/master/BUILDING.md#javascript-encoderdecoder except enable the BUILD_FOR_GLTF and IE_COMPATIBLE flags when running `cmake`.

```
$ cmake ../ -DCMAKE_TOOLCHAIN_FILE=/path/to/Emscripten.cmake -DBUILD_FOR_GLTF=ON -DIE_COMPATIBLE=ON`
```

Then copy the output `draco_decoder.js` to Babylon.js dist folder.

_Note that the WebAssembly versions are copied directly from the Draco repo._
8 changes: 4 additions & 4 deletions src/Meshes/Compression/dracoCompression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function decodeMesh(decoderModule: any, dataView: ArrayBufferView, attributes: {
* The worker function that gets converted to a blob url to pass into a worker.
*/
function worker(): void {
let decoderPromise: Promise<any> | undefined;
let decoderPromise: PromiseLike<any> | undefined;

onmessage = (event) => {
const data = event.data;
Expand All @@ -142,7 +142,7 @@ function worker(): void {
const decoder = data.decoder;
if (decoder.url) {
importScripts(decoder.url);
decoderPromise = createDecoderAsync(decoder.wasmBinary);
decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });
}
postMessage("done");
break;
Expand All @@ -152,7 +152,7 @@ function worker(): void {
throw new Error("Draco decoder module is not available");
}
decoderPromise.then((decoder) => {
decodeMesh(decoder.module, data.dataView, data.attributes, (indices) => {
decodeMesh(decoder, data.dataView, data.attributes, (indices) => {
postMessage({ id: "indices", value: indices }, [indices.buffer]);
}, (kind, data) => {
postMessage({ id: kind, value: data }, [data.buffer]);
Expand Down Expand Up @@ -304,7 +304,7 @@ export class DracoCompression implements IDisposable {

if (numWorkers && typeof Worker === "function") {
this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {
const workerContent = `${createDecoderAsync}${decodeMesh}(${worker})()`;
const workerContent = `${decodeMesh}(${worker})()`;
const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
const workerPromises = new Array<Promise<Worker>>(numWorkers);
for (let i = 0; i < workerPromises.length; i++) {
Expand Down