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

Add support for emscripten laz compression #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

but0n
Copy link

@but0n but0n commented Oct 15, 2024

This PR adds a LazWriter class for managing LAZ file writing in the browser.

JavaScript Example:

...
const writer = new Module.LazWriter()
    .setPointFormat(pointFormat)
    .setTransform(
        header_info.offset.x,
        header_info.offset.y,
        header_info.offset.z,
        header_info.scale.x,
        header_info.scale.y,
        header_info.scale.z,
    );
writer.open(
    output.ptr,
    output.size,
);
for (var i = 0; i < pointCount; ++i) {
    laszip.getPoint(pointbuf.ptr);
    writer.writePoint(pointbuf.ptr);
}
const actual_size = writer.close();
const filebuf = output.resize(Number(actual_size)).to_owned_buffer();
const blob = new Blob([filebuf.buffer], { type: 'application/octet-stream' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = 'output.laz';
link.click();
URL.revokeObjectURL(url);

Additionally, the PR updates the CMakeLists.txt to include:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s WASM_BIGINT -s EXPORTED_FUNCTIONS=['_malloc, _free']")

This ensures that symbols like _malloc and _free, which were previously exported from native code for internal use, are explicitly exported to the Module object. These changes were made necessary due to an Emscripten update from about a year ago (ChangeLog).

Let me know if you need any adjustments!

clean

Fix js bundle issue, enable ESM by default

Fix type definitions
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

Successfully merging this pull request may close these issues.

1 participant