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

Editor scene #438

merged 31 commits into from
May 25, 2023

Conversation

elalish
Copy link
Owner
@elalish elalish commented May 22, 2023

Fixes #431

This adds GLTFNode and GLTFMaterial to ManifoldCAD.org, which gives us some pretty huge new capabilities. We can now easily create entire scene hierarchies and export them to GLB, all while avoiding duplication of the underlying mesh data if you reference a manifold several times. You can change material properties on any node - they act like CSS where it applies to everything underneath, but is overridden by anything specified lower down. Since specifying parents is only possible during node construction/cloning I believe it's impossible to construct a scene that's not a tree.

It started to get complex enough that I took @donmccurdy's advice and switched our editor (and examples) over to Vite. It's a pretty nice build system and we don't have to worry about import maps anymore. It also makes mixing JS and TS very easy, so I took the liberty of switching our worker over to TS, which was very helpful in development. I'll probably transition the rest of the editor to TS soon.

There's not a very clean way to use raw.githack with Vite, and I'm not a huge fan of checking in builds anyway, so I'm going to abandon this for now.

@elalish elalish self-assigned this May 22, 2023
@codecov
Copy link

codecov bot commented May 22, 2023

Codecov Report

Patch coverage: 90.62% and project coverage change: -0.04 ⚠️

Comparison is base (812ca5c) 89.74% compared to head (8e5c3fc) 89.70%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #438      +/-   ##
==========================================
- Coverage   89.74%   89.70%   -0.04%     
==========================================
  Files          35       35              
  Lines        4201     4237      +36     
==========================================
+ Hits         3770     3801      +31     
- Misses        431      436       +5     
Impacted Files Coverage Δ
src/manifold/include/manifold.h 100.00% <ø> (ø)
src/manifold/src/manifold.cpp 92.14% <90.62%> (-0.20%) ⬇️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

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.

@@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {examples} from './examples.js';
const exampleFunctions = examples.functionBodies;
import ManifoldWorker from './worker?worker';
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is an interesting new Vite syntax.

@@ -144,6 +155,28 @@ export function writeMesh(doc, manifoldMesh, attributes, materials) {
const buffer = doc.getRoot().listBuffers()[0];
const manifoldExtension = doc.createExtension(EXTManifold);

const attributeUnion = [];
for (const matAttributes of attributes) {
matAttributes.forEach((attribute, i) => {
Copy link
Owner Author

Choose a reason for hiding this comment

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

The input attributes is now a string[][] instead of string[], since different materials can have different attributes.

@@ -0,0 +1,30 @@
{
"name": "vite-starter",
Copy link
Owner Author

Choose a reason for hiding this comment

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

Should change this.

// Use GLTFNode for disjoint manifolds rather than compose(), as this will
// keep them better organized in the GLB. This will also allow you to
// specify material properties, and even vertex colors via
// setProperties(). See Tetrahedron Puzzle example.
Copy link
Owner Author

Choose a reason for hiding this comment

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

Here's the interesting part!

// unlit = false,
// name = ''
// }
const node = new GLTFNode();
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is a good example of what's possible with this new API, plus it's pretty.

[(k + i - j) * size, (k - i) * size, (-j) * size];
node.material = {
baseColorFactor:
[(k + i - j + 1) / m, (k - i + 1) / m, (j + 1) / m]
Copy link
Owner Author

Choose a reason for hiding this comment

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

This shows how you can reuse the same manifold many times, even with different materials, but just a single one gets packed in the GLB and referenced appropriately.

}
const attributes = [];
const materials = [];
const manifoldMesh = readMesh(mesh, attributes, materials);
Copy link
Owner Author

Choose a reason for hiding this comment

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

Our JS testing is now giving us dramatically more coverage - we're using the worker directly instead of duplicating its functionality, which means we're also round-tripping every test through write-GLB and read-GLB now.

@@ -207,7 +207,7 @@ class Manifold {
Manifold Mirror(glm::vec3) const;
Manifold Warp(std::function<void(glm::vec3&)>) const;
Manifold SetProperties(
int, std::function<void(glm::vec3, const float*, float*)>) const;
int, std::function<void(float*, glm::vec3, const float*)>) const;
Copy link
Owner Author

Choose a reason for hiding this comment

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

I switched the order here because I forgot to follow my own style of putting output arguments before input arguments.

@elalish elalish requested review from pca006132 and geoffder May 24, 2023 06:17
@geoffder
Copy link
Collaborator

Ah nice, no more of that exporting mess in test.js, took me a moment to figure out why the constructors/functions I was adding weren't showing up for use in examples.js to be honest. I suppose I'll try to rebase what I have so far onto this branch the next time I work on the bindings and see where I'm at. Still gradually figuring out the JS stuff as I work on the new bindings, but I think I'll be at the point of adding examples for testing and working out the kinks soon.

@geoffder
Copy link
Collaborator
geoffder commented May 25, 2023

@elalish I've rebased the WIP bindings onto this branch, but now I'm not sure what the invocation is for running the tests (should I be using the worker one, I noticed that test/test.js actually still exists, but running npm test from that directory or npm test/test doesn't work). It's probably obvious, but I've got about zero familiarity with js.

edit: installing vitest and running npm vitest from the examples directory seems to have been the trick. Also, I see now that the test directory doesn't belong anymore and is a remnant of my rebasing

@elalish
Copy link
Owner Author
elalish commented May 25, 2023

Yeah, sorry I need to update the README. Basically everything is run from the examples directory now, since that package.json has all the deps and such. Just npm install, npm run build, npm test.

@elalish elalish merged commit 7293521 into master May 25, 2023
@elalish elalish deleted the editorScene branch May 25, 2023 16:40
@elalish elalish mentioned this pull request Nov 3, 2023
cartesian-theatrics pushed a commit to cartesian-theatrics/manifold that referenced this pull request Mar 11, 2024
* SetProperties working

* cleanup

* added Node

* switched to Vite

* scene export working

* vertex color output works

* added unlit

* fixed rename bug

* switch worker to TS

* don't fail on empty manifolds

* reusing meshes

* cleanup, updated gyroid example

* change signature of setPropFunc

* updated examples

* add dist for githack testing

* Revert "add dist for githack testing"

This reverts commit 8769d7a.

* remove duplicate files

* updated docs

* fixed some bugs

* multi-material working

* switched to vitest

* tests pass

* fixed examples

* fix CI

* update deployment

* tweak logging

* cleanup

* fix copy

* updated READMEs

* extend timeout
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.

Scene hierarchy in manifoldCAD
2 participants
0