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

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

Open
bartgrundeken opened this issue Jul 27, 2024 · 1 comment

Comments

@bartgrundeken
Copy link

bartgrundeken commented Jul 27, 2024

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/[email protected]/', // ./ 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
Copy link
Member

xeolabs commented Jul 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants