hrgdavor / jscadui

MIT License
30 stars 9 forks source link

fixed 3mf hierarchy export #37

Closed elalish closed 1 year ago

elalish commented 1 year ago

Since I'm introducing a couple of breaking API changes anyway, I took the liberty of renaming a few things to reduce confusion (hopefully). transforms -> transform (since there's only one), items -> children since there is now a dedicated input called items which correspond to 3MF items. These allow one to define the roots of the component trees (before, the branches were all getting duplicated). I also added an optional precision parameter - it cut the file size by ~30% setting it to 7 instead of the default (since manifold uses float precision). I doubt there are many 3D printers that can really make use of double precision...

I've tested this in ManifoldCAD.org with corresponding changes to export our scene hierarchy and it's working well. My auto-format doesn't match the code that was here before very well - is that okay?

elalish commented 1 year ago

Here's some rough TS types representing the API I'm proposing, if that's helpful:

interface Mesh3MF {
  id: string;
  vertices: Float32Array;
  indices: Uint32Array;
  name?: string;
}

interface Child3MF {
  objectID: string;
  transform?: mat4;
}

interface Component3MF {
  id: string;
  children: Array<Child3MF>;
  name?: string;
}

interface Header {
  unit?: 'micron'|'millimeter'|'centimeter'|'inch'|'foot'|'meter';
  title?: string;
  author?: string;
  description?: string;
  application?: string;
  creationDate?: string;
  license?: string;
  modificationDate?: string;
}

interface To3MF {
  meshes: Array<Mesh3MF>;
  components: Array<Component3MF>;
  items: Array<Child3MF>;
  precision: number;
  header: Header;
}

function to3dmodel(input: To3MF): string;
elalish commented 1 year ago

Oh right, except I totally forgot to update the rest of your code here for these breaking API changes. I'm happy to do that, but I'll wait for review first.

hrgdavor commented 1 year ago

Oh right, except I totally forgot to update the rest of your code here for these breaking API changes. I'm happy to do that, but I'll wait for review first.

The version is primarily made to be first integrated into manifold, so there should not be any/many problems in the resto of the code.