8000 Editor scene by elalish · Pull Request #438 · elalish/manifold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Editor scene #438

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

Merged
merged 31 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c61486e
SetProperties working
elalish May 15, 2023
573619d
cleanup
elalish May 15, 2023
975884b
added Node
elalish May 16, 2023
16a8711
switched to Vite
elalish May 16, 2023
0b57308
scene export working
elalish May 16, 2023
c5bd224
Merge branch 'master' of github.com:elalish/manifold into editorScene
elalish May 17, 2023
d44d6b8
vertex color output works
elalish May 17, 2023
5891f2f
added unlit
elalish May 17, 2023
4b374fb
fixed rename bug
elalish May 17, 2023
091fabe
switch worker to TS
elalish May 18, 2023
795e946
don't fail on empty manifolds
elalish May 19, 2023
e95a3f1
reusing meshes
elalish May 21, 2023
5f86e90
cleanup, updated gyroid example
elalish May 22, 2023
dd7aad6
8000 change signature of setPropFunc
elalish May 22, 2023
014505e
updated examples
elalish May 22, 2023
8769d7a
add dist for githack testing
elalish May 22, 2023
ab0f7c8
Revert "add dist for githack testing"
elalish May 23, 2023
d0eca7f
remove duplicate files
elalish May 23, 2023
f4cb2d7
updated docs
elalish May 23, 2023
974bee1
fixed some bugs
elalish May 23, 2023
c7ebef7
multi-material working
elalish May 23, 2023
2e8c89a
switched to vitest
elalish May 23, 2023
8be584b
tests pass
elalish May 24, 2023
9dc0672
fixed examples
elalish May 24, 2023
b8e8891
fix CI
elalish May 24, 2023
cbba6a2
update deployment
elalish May 24, 2023
40f5bc4
tweak logging
elalish May 24, 2023
4be5fd8
cleanup
elalish May 24, 2023
fcbbf22
fix copy
elalish May 24, 2023
7d57f66
updated READMEs
elalish May 25, 2023
8e5c3fc
extend timeout
elalish May 25, 2023
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
5 changes: 2 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ jobs:
mkdir public
mv ./samples ./public
mv ./docs ./public
mv ./bindings/wasm/examples/* ./public

- name: Download WASM files
- name: Download built examples
uses: dawidd6/action-download-artifact@v2
with:
workflow: manifold.yml
workflow_conclusion: completed
pr: ${{github.event.pull_request.number}}
name: wasm
path: ./public/built
path: ./public

- name: Deploy to Github Pages
uses: peaceiris/actions-gh-pages@v3
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/manifold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,17 @@ jobs:
run: |
cd build/test
node ./manifold_test.js
cd ../bindings/wasm
npm install
- name: Test examples
run: |
cd bindings/wasm/examples
npm ci
npm run build
npm test
- name: Upload WASM files
uses: actions/upload-artifact@v3
with:
name: wasm
path: |
build/bindings/wasm/manifold.js
build/bindings/wasm/manifold.wasm
build/bindings/wasm/manifold.d.ts
build/bindings/wasm/manifold-global-types.d.ts
build/bindings/wasm/manifold-encapsulated-types.d.ts
path: bindings/wasm/examples/dist/
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's now more to deploy, but it's simpler.

retention-days: 90

build_windows:
Expand Down
11 changes: 8 additions & 3 deletions bindings/wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ target_link_options(manifoldjs PUBLIC --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/bindi
target_compile_features(manifoldjs PUBLIC cxx_std_17)
set_target_properties(manifoldjs PROPERTIES OUTPUT_NAME "manifold")

file(COPY examples;test;. DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS examples;test)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples/built)

add_custom_command(
TARGET manifoldjs POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/manifold.*
${CMAKE_CURRENT_BINARY_DIR}/manifold-*.d.ts
${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts
${CMAKE_CURRENT_SOURCE_DIR}/examples/built/)

add_custom_command(
TARGET manifoldjs POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts
${CMAKE_CURRENT_SOURCE_DIR}/examples/public/)
17 changes: 2 additions & 15 deletions bindings/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,9 @@ The most significant contribution here is a guaranteed-manifold [mesh Boolean](h

Since Manifold is a WASM module, it does not automatically garbage-collect like regular JavaScript. You must manually `delete()` each manifold object constructed by your scripts, see [discussion](https://github.com/elalish/manifold/discussions/256#discussioncomment-3944287).

## Local development
## Examples

First, follow the directions in the root README to get your C++ build environment set up and working for WASM. From this directory (`bindings/wasm/`) you can test the JS bindings by running:

```
npm install
npm test
```

You can also test the manifoldCAD.org editor as well as our other example pages by serving from `bindings/wasm/examples/` with e.g. `npx http-server`.

Note that the `emcmake` command automatically copies your WASM build into `examples/built/` - these are checked into our repo in order to make sharing repro cases much easier. Note that you can test manifoldCAD.org on anyone's branch by simply going to: `https://raw.githack.com/<user>/manifold/<branch>/bindings/wasm/examples/index.html` e.g. https://raw.githack.com/elalish/manifold/glTFextension/bindings/wasm/examples/index.html

Of course these built files may easily end up with conflicts, but there's no need to address them; simply overwrite them with your newer build. These files are also not used for our deployed pages, as the deployment process overwrites them with current builds. Never edit anything in the `built` directory by hand.

When testing [manifoldCAD.org](https://manifoldcad.org/) (either locally or the deployed version) note that it uses a service worker for faster loading. This means you need to open the page twice to see updates (the first time loads the old version and caches the new one, the second time loads the new version from cache). To see changes on each reload, open Chrome dev tools, go to the Application tab and check "update on reload".
Please see our usage [examples](https://github.com/elalish/manifold/tree/master/bindings/wasm/examples) to see how to interface this library with `three.js`, `<model-viewer>`, and `glTF`. Of particular note are the included libraries for lossless roundtrip of manifold meshes through glTF files, via a new extension: [EXT_manifold](https://github.com/KhronosGroup/glTF/pull/2286).

## About the author

Expand Down
7 changes: 7 additions & 0 deletions bindings/wasm/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ Manifold Warp(Manifold& manifold, uintptr_t funcPtr) {
return manifold.Warp(f);
}

Manifold SetProperties(Manifold& manifold, int numProp, uintptr_t funcPtr) {
void (*f)(float*, glm::vec3, const float*) =
reinterpret_cast<void (*)(float*, glm::vec3, const float*)>(funcPtr);
return manifold.SetProperties(numProp, f);
}

Manifold LevelSetJs(uintptr_t funcPtr, Box bounds, float edgeLength,
float level) {
float (*f)(const glm::vec3&) =
Expand Down Expand Up @@ -254,6 +260,7 @@ EMSCRIPTEN_BINDINGS(whatever) {
.function("_GetMeshJS", &GetMeshJS)
.function("refine", &Manifold::Refine)
.function("_Warp", &Warp)
.function("_SetProperties", &SetProperties)
.function("transform", &Transform)
.function("_Translate", &Manifold::Translate)
.function("_Rotate", &Manifold::Rotate)
Expand Down
27 changes: 27 additions & 0 deletions bindings/wasm/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@ Module.setup = function() {
return out;
};

Module.Manifold.prototype.setProperties = function(numProp, func) {
const oldNumProp = this.numProp;
const wasmFuncPtr = addFunction(function(newPtr, vec3Ptr, oldPtr) {
const newProp = [];
for (let i = 0; i < numProp; ++i) {
newProp[i] = getValue(newPtr + 4 * i, 'float');
}
const pos = [];
for (let i = 0; i < 3; ++i) {
pos[i] = getValue(vec3Ptr + 4 * i, 'float');
}
const oldProp = [];
for (let i = 0; i < oldNumProp; ++i) {
oldProp[i] = getValue(oldPtr + 4 * i, 'float');
}

func(newProp, pos, oldProp);

for (let i = 0; i < numProp; ++i) {
setValue(newPtr + 4 * i, newProp[i], 'float');
}
}, 'viii');
const out = this._SetProperties(numProp, wasmFuncPtr);
removeFunction(wasmFuncPtr);
return out;
};

Module.Manifold.prototype.translate = function(...vec) {
return this._Translate(vararg2vec(vec));
};
Expand Down
26 changes: 26 additions & 0 deletions bindings/wasm/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# WASM/JS Examples

This is the home of our editor, [ManifoldCAD.org](https://manifoldcad.org/), as well as our other public examples of integrations with `three.js`, `<model-viewer>`, and `glTF`. Included are `manifold-gltf.js` and `gltf-io.js`, which are intended to be fairly general-purpose libraries for interfacing between manifolds and glTF. We should probably make them into their own npm package at some point.

## Local development

First, follow the directions in the root README to get your C++ build environment set up and working for WASM. From this directory (`bindings/wasm/examples/`) you can test the JS bindings by running:

```
npm install
npm test
```

To develop the manifoldCAD.org editor as well as our other example pages, run
```
npm run dev
```
which will serve the pages, watch for changes, and automatically rebuild and refresh. This build step doesn't do TS type-checking, so to verify everything is correct (beyond VSCode's TS linting), run
```
npm run build
```
See `package.json` for other useful scripts.

Note that the `emcmake` command automatically copies your WASM build into `built/`, (here, not just under the `buildWASM` directory) which is then packaged by Vite into `dist/assets/`.

When testing [ManifoldCAD.org](https://manifoldcad.org/) (either locally or the deployed version) note that it uses a service worker for faster loading. This means you need to open the page twice to see updates (the first time loads the old version and caches the new one, the second time loads the new version from cache). To see changes on each reload, open Chrome dev tools, go to the Application tab and check "update on reload".
Loading
0