xeokit / xeokit-convert

Convert various AEC model formats for efficient viewing in the browser with xeokit.
https://xeokit.github.io/xeokit-convert/docs/
Other
49 stars 52 forks source link

writeXKTModelToArrayBuffer errors when zip option is set explicitly to false #168

Open bartgrundeken opened 1 month ago

bartgrundeken commented 1 month ago

We have been trying to convert an IFC file into an XKT model and then converting that model into an array buffer using writeXKTModelToArrayBuffer, then turning it into an object url. We use version 1.1.19 of xeokit-convert and 0.0.56 of web-ifc. This is the (typescript) code we use:

export async function convert(data: ArrayBuffer) {
    return new Promise<ArrayBuffer>((resolve, reject) => {
        const xktModel = new XKTModel()

        parseIFCIntoXKTModel({
            WebIFC,
            data,
            xktModel,
            wasmPath: 'https://cdn.jsdelivr.net/npm/web-ifc@0.0.56/', // ./ in node
            autoNormals: true,
            log: (msg: unknown) => {
                console.log(msg)
            }
        }).then(
            () => {
                xktModel.finalize()

                resolve(
                    writeXKTModelToArrayBuffer(
                        xktModel,
                        null,
                        {},
                        { zip: false }
                    ) as ArrayBuffer
                )
            },
            (e: unknown) => {
                reject(e instanceof Error ? e : Error(e as string))
            }
        )
    })
}

If we set the zip option to true it works. If we omit the zip option it works as well (and strangely enough generates a smaller file). However, setting zip explicitly to false gives the following error:

RangeError: offset is out of bounds
    at Uint8Array.set (<anonymous>)
    at toArrayBuffer (VM1198 @xeokit_xeokit-convert_dist_xeokit-convert__es.js:13046:13)
    at createArrayBuffer (VM1198 @xeokit_xeokit-convert_dist_xeokit-convert__es.js:13002:10)
    at writeXKTModelToArrayBuffer (VM1198 @xeokit_xeokit-convert_dist_xeokit-convert__es.js:12660:23)
    at convert.ts:34:21

(Running a inside a vite/svelte app on Arc Browser, line numbers might not be reliable)

We tried the same code inside a Node script, and it also gives the same error.

xeolabs commented 1 month ago

Hi, that's not actually working yet and really shouldn't be in any releases yet.

It's been tricky to get the non-zip option working correctly for some reason. This is where the option is applied:

https://github.com/xeokit/xeokit-convert/blob/main/src/XKTModel/writeXKTModelToArrayBuffer.js#L352

We'd love to be able to disable ZIPping, because it would actually load a lot of models faster and be easier on low-spec devices as well. If you happen to see where that can be fixed, feel free to make a fix though. Thanks