Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Add decimate, remesh and generated levels of detail

Nguyen Xuan An7100ec87a1e2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6de0efe4..da053266 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## Unreleased
+- Add `decimate`, `remesh` and generated levels of detail (issue #40). `decimate` (a `ratio` of triangles) is a quadric edge collapse of our own that keeps open boundaries, the borders between tags and the tags themselves; it measured 0.25 to 0.85 of the Hausdorff error of meshoptimizer 1.3.0 on the same meshes and adds no dependency, but takes about 2.5 s on 100k triangles where meshoptimizer takes 0.09 s. `remesh` (`voxelSize` or `resolution`, at most 192 per side and 4,194,304 cells, checked before allocation) builds a closed quad surface from a BVH signed distance with surface nets. Both are edits and stack nodes, in the MCP schemas, and load on demand with the mesh code. `generateMeshLods`, `generateGeometryLods` and `generateAssetLods` (also in `67js/addons/mesh`) return levels with a measured error for runtime selection (issue #37). Four decimate and two remesh cases join the Blender comparison, compared by volume, area and Hausdorff distance because face counts differ.
+
- Load agent scene code on demand: mesh editing, `lathe`/`extrude`/`tube`, material `pattern` and `motion` now sit behind `loadAgentSceneModules(recipe)` (or `loadAllAgentSceneModules()`), and `createAgentScene` throws an error naming that call when a needed module is missing. A recipe of primitives drops from 141,241 to 73,581 bytes gzip in `scene:agent-scene` (every lazy chunk still totals 145,049). `npm run size` now bundles with code splitting and reports the initial load, plus a `+lazy` row for the total. `npm test` preloads every module. The archive no longer carries 29 docs that the site serves (physics, lighting, terrain and the other addon docs); agent docs stay
- Add joint limits, node constraints and drivers to motion (issue #58). Two-bone IK takes `limits` per joint and axis in degrees and `bendToward`; `scene_inspect` `motionIk` now carries `limited` (each pose a limit changed) and `warnings` (`hyperextended`, and `wrong-bend` for a knee or elbow bent the unnatural way, which a wrong pole used to hide behind `reached`). `motion.constraints` adds `copy_location`, `copy_rotation`, `copy_scale`, `limit_location`, `limit_rotation`, `track_to`, `child_of` (with an inverse and an influence blend) and `floor`, and `motion.drivers` sets a node component or material property from a bounded JSON expression over time and other nodes (never run as code). The order is tracks, IK, drivers, constraints, with no state between samples, so a seek equals playing. `copy_rotation`, `limit_rotation`, `track_to`, `child_of` and `floor` match Blender 5.2 world matrices in 8 recorded cases (`tests/fixtures/blender/constraints.json`). Joint limits are also in `67js/addons/skeleton-pose`. The `leg-plant` task joins the agent modeling suite. The expression language is a new small one in `src/motion-expression.js`: the field expressions of the mesh addon were not on `main` yet
diff --git a/bench/size/budgets.json b/bench/size/budgets.json
index dde83593..27dfbd1c 100644
--- a/bench/size/budgets.json
+++ b/bench/size/budgets.json
@@ -15,7 +15,7 @@
"entry:sculpt": 2500,
"entry:surface": 10100,
"entry:mesh-query": 15900,
- "entry:mesh": 49400,
+ "entry:mesh": 56900,
"entry:shrinkwrap": 18300,
"entry:surface-attachment": 11800,
"entry:physics": 18000,
@@ -29,13 +29,13 @@
"entry:clutter": 5300,
"entry:texture-set": 900,
"entry:agent-scene": 49200,
- "entry:agent-scene+lazy": 140600,
+ "entry:agent-scene+lazy": 147900,
"entry:agent-asset": 75600,
- "entry:agent-asset+lazy": 147700,
+ "entry:agent-asset+lazy": 155000,
"entry:hdri": 3300,
"scene:lit-box": 56000,
"scene:gltf-box": 75300,
"scene:agent-scene": 75700,
- "scene:agent-scene+lazy": 167100
+ "scene:agent-scene+lazy": 174400
}
}
diff --git a/docs/mesh.md b/docs/mesh.md
index fc7544ca..c1481ac5 100644
--- a/docs/mesh.md
+++ b/docs/mesh.md
@@ -197,7 +197,7 @@ These three (and `bevel`, below) work as edits and as stack nodes:
### Modifier stack
-A recipe mesh may carry `stack`, a list of `mirror`, `array`, `solidify`, `bevel`, `subdivide`, `uv_unwrap`, `set_position` and `displace` nodes (up to 16) evaluated after the
+A recipe mesh may carry `stack`, a list of `mirror`, `array`, `solidify`, `bevel`, `subdivide`, `uv_unwrap`, `set_position`, `displace`, `decimate` and `remesh` nodes (up to 16) evaluated after the
edits without changing them, as Blender's modifier stack. Every prefix (the edit result, then each node) is cached
by its recipe text in a least-recently-used cache bounded at 64 entries and 64 MiB, so changing a late node reuses
the earlier work. Results list one entry per node with `cached: true` when reused. `meshCacheStats()` reports hits
@@ -351,6 +351,36 @@ Timing, measured on this machine: one level on a 100,489-quad grid takes about 2
with a crease on every edge. That is fast enough that 67.js does not keep a stencil table; a stack node reuses its cached
result until an earlier node changes.
+### Decimate, remesh and levels of detail
+
+`decimate` (`ratio`, above 0 and at most 1) reduces the triangulated mesh by quadric edge collapse. The ratio is of
+triangles, never below four. Open boundaries and the borders between faces with different tags are constraints: their
+vertices only collapse along the constraint and extra planes hold them in place. Tags carry over; corner and edge
+attributes (`uv`, colour, `sharp`) are dropped, so unwrap after it. The result reports `triangles` before and after, and
+`stoppedEarly` when constraints stopped it above the ratio. `decimateMesh(mesh, { ratio })` is the same in code.
+
+`remesh` (`voxelSize`, or `resolution` cells along the longest side up to 192) samples the signed distance to the
+surface on a grid and builds a closed quad surface with surface nets. Only cells near the surface are queried through the
+triangle BVH; the rest take their sign from a flood fill. The grid is checked before it is allocated (192 per side, 4,194,304
+cells). The mesh must be closed, and the result carries no tags or attributes.
+
+`generateMeshLods(mesh, { ratios })` (also `generateGeometryLods` for renderer geometry such as a recipe part, and
+`generateAssetLods` for a static imported asset) returns level 0, the input, and one level for each ratio, from strictly
+decreasing ratios in (0, 1), up to 8. Each level has `triangles`, `error` (the farthest its vertices lie from the input surface, in
+the input's units) and `relativeError` (over the bounds diagonal); the asset form returns a whole asset per level.
+Skinned and morphed parts are refused. `surfaceDeviation(a, b)` gives the vertex Hausdorff distance both ways.
+
+Why our own collapse and not meshoptimizer 1.3.0 (npm, MIT, 2026-09-25): on the same sphere, torus and open bowl at
+ratios 0.5, 0.2 and 0.05 our Hausdorff error was 0.25 to 0.85 of its error (0.0088 against 0.0153 at 0.5 and 0.0647 against 0.0773
+at 0.05 on the sphere, 0.0403 against 0.1603 at 0.05 on the open bowl with its borders locked), and the volume stayed closer
+in all nine runs. It has no tag support, and its simplifier adds about 15 KB gzip of WebAssembly (the build three.js ships), where
+this code, with remesh and the levels, adds about 7 KB gzip to the lazy mesh code and nothing to the initial load (+32 bytes). It is about 28 times faster, so the cost is time: about 2.5 seconds for a 100k-triangle sphere down to a
+tenth, against about 0.09 seconds.
+
+Blender comparison (`tests/fixtures/blender`): 4 decimate and 2 remesh cases on a bumpy sphere, a torus and an open bowl,
+compared with the Decimate (collapse) and Remesh (voxel) modifiers by face count, volume, area and the Hausdorff distance to
+the input, because face counts differ. `differences.json` lists the remesh face counts, which differ by 2% and 7%.
+
### UV unwrap
`uv_unwrap` writes the corner attribute `uv` (and the edge attribute `seam`), as an edit or as a stack node. It
diff --git a/docs/parity.md b/docs/parity.md
index 2f59451f..647d0c04 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -48,7 +48,7 @@ To move to a new Blender release, run `node scripts/parity-manual-snapshot.mjs`.
| Modeling > Meshes > Properties | partial | `smoothAngle` and face tags. There is no sharp edge attribute or crease. | | #39 |
| Modeling > Meshes > UVs | partial | `uv_unwrap` with LSCM, axis charts and shelf packing. Patterns can not use the result yet. | | #50 |
| Modeling > Meshes > Mesh Analysis | partial | `lintMesh` reports topology problems. There is no check for thin walls or intersections. | | #66 |
-| Modeling > Meshes > Remeshing | missing | No remesh. | | #40 |
+| Modeling > Meshes > Remeshing | partial | `remesh` rebuilds a closed mesh as an even quad surface on a voxel grid (surface nets over a BVH signed distance). Quad remesh and Instant Meshes style retopology are not here. | [blender golden](../tests/blender-golden.test.js) | #40 |
| Modeling > Curves | partial | `tube` follows a curve and `extrude` follows a contour. There is no curve object. | | #45 |
| Modeling > Curves (New) | missing | No hair curves. | | #63 |
| Modeling > Surfaces | out of scope | Issue #45 records NURBS surfaces as out of scope unless demand appears. | | |
@@ -72,13 +72,13 @@ To move to a new Blender release, run `node scripts/parity-manual-snapshot.mjs`.
| Modeling > Modifiers > Generate > Boolean Modifier | partial | Manifold boolean as an edit. It is not a stack node. | [mesh-boolean](../tests/mesh-boolean.test.js), [Blender results](../tests/fixtures/blender/golden.json) | |
| Modeling > Modifiers > Generate > Build Modifier | missing | No equivalent. | | |
| Modeling > Modifiers > Generate > Curve to Tube Modifier | partial | `tube` is a geometry type. It is not a stack node. | [modeling](../tests/modeling.test.js) | #45 |
-| Modeling > Modifiers > Generate > Decimate Modifier | missing | No decimation. | | #40 |
+| Modeling > Modifiers > Generate > Decimate Modifier | partial | Collapse mode as `decimate` with a ratio, keeping open boundaries and tag borders; `generateMeshLods`, `generateGeometryLods` and `generateAssetLods` make levels with a measured error. Unsubdivide and planar modes, vertex-group weighting and symmetry are missing. Compared with Blender on 4 shared fixtures by volume, area and Hausdorff distance. | [blender golden](../tests/blender-golden.test.js), [decimate](../tests/mesh-decimate.test.js) | #40 |
| Modeling > Modifiers > Generate > Edge Split Modifier | missing | No equivalent. `smoothAngle` splits normals by angle. | | #42 |
| Modeling > Modifiers > Generate > Mask Modifier | missing | No equivalent. | | |
| Modeling > Modifiers > Generate > Mesh to Volume Modifier | missing | No volume objects. | | |
| Modeling > Modifiers > Generate > Mirror Modifier | done | Stack node with axis and merge. | [mesh-stack](../tests/mesh-stack.test.js), [Blender results](../tests/fixtures/blender/golden.json) | |
| Modeling > Modifiers > Generate > Multiresolution Modifier | missing | No multiresolution. | | |
-| Modeling > Modifiers > Generate > Remesh Modifier | missing | No remesh. | | #40 |
+| Modeling > Modifiers > Generate > Remesh Modifier | partial | Voxel mode as `remesh` (voxel size or resolution), as an edit or a stack node, compared with Blender on 2 shared fixtures. Blocks, smooth and sharp modes are missing. | [blender golden](../tests/blender-golden.test.js), [decimate](../tests/mesh-decimate.test.js) | #40 |
| Modeling > Modifiers > Generate > Scatter on Surface Modifier | partial | `instances` with a `surface` source scatters a node at seeded, area-weighted points with yaw, scale and normal alignment, and `where` filters them. No minimum distance or density map, and `addons/clutter` and `addons/grass` still scatter in code. | [src/mesh-instances.js](../src/mesh-instances.js), [tests/mesh-fields.test.js](../tests/mesh-fields.test.js) | #42 |
| Modeling > Modifiers > Generate > Screw Modifier | partial | `lathe` covers a full turn. There is no stack node or screw offset. | | #42 |
| Modeling > Modifiers > Generate > Skin Modifier | missing | No equivalent. | | #42 |
diff --git a/scripts/blender-golden.py b/scripts/blender-golden.py
index a8aebe5b..e0fccc77 100644
--- a/scripts/blender-golden.py
+++ b/scripts/blender-golden.py
@@ -8,6 +8,7 @@ from pathlib import Path
import bmesh
import bpy
from mathutils import Vector
+from mathutils.bvhtree import BVHTree
FIXTURE_DIRECTORY = Path(__file__).resolve().parent.parent / "tests" / "fixtures" / "blender"
DEFAULT_MAX_ANGLE = 10
@@ -401,7 +402,24 @@ def add_displace(mesh_object, edit, _inputs):
modifier.texture_coords = "LOCAL"
+def add_decimate(mesh_object, edit, _inputs):
+ modifier = mesh_object.modifiers.new("Decimate", "DECIMATE")
+ modifier.decimate_type = "COLLAPSE"
+ modifier.ratio = edit["ratio"]
+ modifier.use_collapse_triangulate = True
+
+
+def add_remesh(mesh_object, edit, _inputs):
+ modifier = mesh_object.modifiers.new("Remesh", "REMESH")
+ modifier.mode = "VOXEL"
+ modifier.voxel_size = edit["voxelSize"]
+ modifier.adaptivity = 0
+ modifier.use_smooth_shade = False
+
+
MODIFIERS = {
+ "decimate": add_decimate,
+ "remesh": add_remesh,
"set_position": add_set_position,
"displace": add_displace,
"mirror": add_mirror,
@@ -485,6 +503,40 @@ def measure(bm):
}
+def surface_tree(bm):
+ triangulated = bm.copy()
+ bmesh.ops.triangulate(triangulated, faces=list(triangulated.faces))
+ triangulated.verts.ensure_lookup_table()
+ tree = BVHTree.FromBMesh(triangulated)
+ return tree, triangulated
+
+
+def farthest_vertex(bm, tree):
+ farthest = 0.0
+ for vertex in bm.verts:
+ location = tree.find_nearest(vertex.co)[0]
+ if location is not None:
+ farthest = max(farthest, (location - vertex.co).length)
+ return farthest
+
+
+# Approximating operations change the face count, so they are compared by what the surface does: its volume and area
+# and its Hausdorff distance to the input, measured at vertices in both directions (the same way the JS test does).
+def measure_surface(bm, reference):
+ measured = measure(bm)
+ output_tree, output_copy = surface_tree(bm)
+ reference_tree, reference_copy = surface_tree(reference)
+ hausdorff = max(farthest_vertex(bm, reference_tree), farthest_vertex(reference, output_tree))
+ output_copy.free()
+ reference_copy.free()
+ return {
+ "faceCount": measured["faceCount"],
+ "volume": measured["volume"],
+ "area": measured["area"],
+ "hausdorff": round(hausdorff, 6),
+ }
+
+
def remove_all_objects():
for mesh_object in list(bpy.data.objects):
bpy.data.objects.remove(mesh_object)
@@ -502,7 +554,12 @@ def main():
if operation == "grid_fill":
runner = run_operator_case
bm = runner(case, fixture["inputs"])
- results[case["id"]] = measure(bm)
+ if case.get("compare") == "surface":
+ reference = new_bmesh(fixture["inputs"][case["input"]])
+ results[case["id"]] = measure_surface(bm, reference)
+ reference.free()
+ else:
+ results[case["id"]] = measure(bm)
bm.free()
output = {"blenderVersion": bpy.app.version_string, "results": results}
(FIXTURE_DIRECTORY / "golden.json").write_text(json.dumps(output, indent=1) + "\n", encoding="utf-8")
diff --git a/scripts/mcp-server.mjs b/scripts/mcp-server.mjs
index 160af612..755ce050 100644
--- a/scripts/mcp-server.mjs
+++ b/scripts/mcp-server.mjs
@@ -280,12 +280,21 @@ const stackNodes = [
crease: z.record(z.string(), z.unknown()).optional().describe('Edge rule for creased edges, the same rules as bevel: {"angle":60} keeps the rims of a cylinder sharp. Boundary edges are always sharp.'),
sharpness: bounded(0, 10).optional().describe('Crease strength, only with crease. A crease stays fully sharp for that many levels and a fraction blends smooth and sharp. Defaults to 10, sharp at every level.'),
}).describe('Catmull-Clark subdivision with semi-sharp creases, like the Subdivision Surface modifier of Blender. Faces keep their tags and corner attributes such as uv blend linearly. Put it before uv_unwrap. Check the budget: 3 levels make 64 times the faces.'),
+ z.strictObject({
+ op: z.literal('decimate'),
+ ratio: z.number().gt(0).max(1).describe('Share of the triangles to keep, counted after triangulation. 0.25 keeps a quarter.'),
+ }).describe('Quadric edge collapse like the Decimate modifier of Blender. Open boundaries and the borders between tags stay in place, tags carry over, and uv and colour are dropped, so unwrap after it. The result reports triangles before and after, and stoppedEarly when constraints prevented the ratio.'),
+ z.strictObject({
+ op: z.literal('remesh'),
+ voxelSize: z.number().positive().optional().describe('Edge of one grid cell. Give this or resolution.'),
+ resolution: z.number().int().min(4).max(192).optional().describe('Cells along the longest side. Give this or voxelSize.'),
+ }).describe('Voxel remesh like the Remesh modifier of Blender: a closed quad surface of even cells. The mesh must be closed (fill_holes first); tags and attributes are dropped. Over 192 cells per side or 4 million cells is refused before it runs.'),
];
const meshStack = z.array(z.discriminatedUnion('op', stackNodes)).max(16);
const meshEdits = z.array(z.discriminatedUnion('op', [...meshEdit.options, ...stackNodes])).max(64);
const geometry = z.discriminatedUnion('type', [
...primitiveGeometries(true),
- z.strictObject({ id: identifier, type: z.literal('mesh'), base: z.discriminatedUnion('type', primitiveGeometries(false)).describe('Starting shape, converted to welded quads with axis face tags.'), edits: meshEdits.optional().describe('Replayable edit log, applied in order.'), stack: meshStack.optional().describe('Non-destructive modifier stack (mirror, array, solidify, bevel, uv_unwrap, subdivide) evaluated after the edits.'), smoothAngle: bounded(0, 180).optional().describe('Edges bending more than this many degrees render hard. Defaults to 30.') }),
+ z.strictObject({ id: identifier, type: z.literal('mesh'), base: z.discriminatedUnion('type', primitiveGeometries(false)).describe('Starting shape, converted to welded quads with axis face tags.'), edits: meshEdits.optional().describe('Replayable edit log, applied in order.'), stack: meshStack.optional().describe('Non-destructive modifier stack (mirror, array, solidify, bevel, uv_unwrap, subdivide, decimate, remesh) evaluated after the edits.'), smoothAngle: bounded(0, 180).optional().describe('Edges bending more than this many degrees render hard. Defaults to 30.') }),
]);
function motionTrack(kind, property, value, tangent) {
return z.strictObject({
@@ -512,7 +521,7 @@ export function createAgentMcpServer(runtime, { version = packageMetadata.versio
register('scene_inspect', 'Read revision, counts and selected nodes. For a recipe with physics, the result lists body final positions, resting times, contacts and sensor enter/leave events. Bounds describe authored geometry rather than shader displacement.', z.strictObject({ ...sessionFields, ids: z.array(identifier).max(4096).optional().describe('Selected node IDs. Omit to inspect scene order.'), kind: z.enum(['meshes', 'hierarchy']).optional().describe('Imported assets only: hierarchy exposes stable source-node IDs and joints.'), offset: z.number().int().min(0).max(4096).optional().describe('Imported assets only: pagination offset.'), limit: z.number().int().min(1).max(4096).optional().describe('Maximum returned node records. Defaults to 64.'), includeBounds: z.boolean().optional().describe('Include world geometry bounds. Defaults to false.') }), readOnly, async argumentsValue => jsonResult(await runtime.inspect(argumentsValue)));
register('mesh_inspect', 'Check recipe geometries as polygon meshes: vertex, edge and face counts, triangles/quads/n-gons, connected and closed parts, face tags (top, bottom, side, left, right, front, back), bounds, and lint problems (non-manifold, inconsistent winding, inverted, degenerate, open, loose) with a suggested fix each. Procedural scenes only. Read-only and cached per geometry.', z.strictObject({ ...sessionFields, geometry: identifier.optional().describe('One geometry ID to check, as in mesh_edit.'), geometries: z.array(identifier).min(1).max(16).optional().describe('Geometry IDs to check. Omit both to check the first 16 geometries.') }), readOnly, async ({ geometry: geometryId, geometries, ...rest }) => jsonResult(await runtime.inspectMeshes({ ...rest, ...(geometries || geometryId ? { geometries: [...(geometries ?? []), ...(geometryId ? [geometryId] : [])] } : {}) })));
register('mesh_edit', 'Append edits to a recipe mesh geometry (or replace its edit log), atomically like scene_apply: extrude, inset, delete, flip, translate with proportional falloff, merge by distance, tag, loop cut, bevel, mirror, array, solidify, UV unwrap, set_position and displace driven by field expressions (math, noise, attributes; also a {"field":expr} selection rule), and booleans (union, difference, intersect) with a primitive cutter. Edits that select no faces or break limits fail without changing the scene. Returns the new revision, render status and the mesh report with per-edit results (faces selected, tags created, size after).', z.strictObject({ ...sessionFields, expectedRevision, geometry: identifier.describe('ID of a geometry with type mesh.'), edits: meshEdits.min(1), replace: z.boolean().optional().describe('Replace the whole edit log instead of appending.') }), edit, async argumentsValue => jsonResult(await runtime.editMesh(argumentsValue)));
- register('mesh_stack', 'Set the non-destructive modifier stack of a recipe mesh geometry (mirror, array, solidify, bevel, uv_unwrap, subdivide, set_position, displace), evaluated after its edits with each prefix cached, so changing a late node is cheap. apply: n moves the first n nodes into the edit log, as Blender\'s Apply modifier. Atomic like scene_apply. Returns the revision, render status and mesh report with per-node results.', z.strictObject({ ...sessionFields, expectedRevision, geometry: identifier.describe('ID of a geometry with type mesh.'), stack: meshStack.optional().describe('The whole new stack. Omit to keep the current stack (for example with apply).'), apply: z.number().int().min(0).max(16).optional() }), edit, async argumentsValue => jsonResult(await runtime.setMeshStack(argumentsValue)));
+ register('mesh_stack', 'Set the non-destructive modifier stack of a recipe mesh geometry (mirror, array, solidify, bevel, uv_unwrap, subdivide, set_position, displace, decimate, remesh), evaluated after its edits with each prefix cached, so changing a late node is cheap. apply: n moves the first n nodes into the edit log, as Blender\'s Apply modifier. Atomic like scene_apply. Returns the revision, render status and mesh report with per-node results.', z.strictObject({ ...sessionFields, expectedRevision, geometry: identifier.describe('ID of a geometry with type mesh.'), stack: meshStack.optional().describe('The whole new stack. Omit to keep the current stack (for example with apply).'), apply: z.number().int().min(0).max(16).optional() }), edit, async argumentsValue => jsonResult(await runtime.setMeshStack(argumentsValue)));
register('scene_apply', 'Atomically edit transforms, look, camera or materials. Procedural scenes support membership and set-motion authoring. Imported assets support set-root, set-asset-node, set-motion and absolute set-animation sampling. Successful batches increment revision once.', z.strictObject({ ...sessionFields, expectedRevision, operations: z.array(operation).min(1).max(256).describe('Node/material/camera/root/animation commands use flat fields. Motion, look patches and add commands contain nested records. Backend validates each scene mode before publication.') }), edit, async argumentsValue => jsonResult(await runtime.apply(argumentsValue)));
register('scene_look', 'Render the active scene as a bounded PNG. Optional authored motionTime seeks without changing revision; null restores the authored base pose. Omit to retain the last preview pose.', z.strictObject({ ...sessionFields, motionTime: z.number().min(0).max(3600).nullable().optional(), width: z.number().int().min(64).max(1024).default(768).describe('PNG width in pixels.'), height: z.number().int().min(64).max(1024).default(512).describe('PNG height in pixels.') }), readOnly, async argumentsValue => {
const { data, mimeType, metadata } = await runtime.look(argumentsValue);
diff --git a/skills/build-67js-scene/references/mesh-modeling.md b/skills/build-67js-scene/references/mesh-modeling.md
index f4f881b8..4037ae6b 100644
--- a/skills/build-67js-scene/references/mesh-modeling.md
+++ b/skills/build-67js-scene/references/mesh-modeling.md
@@ -197,6 +197,18 @@ bounds and rescale the node.
] }
```
+Fewer faces: `decimate` keeps a `ratio` of the triangles (counted after triangulation), holds open boundaries and the borders
+between tags where they are, keeps tags, and drops `uv` (so `uv_unwrap` after it). `remesh` rebuilds a closed mesh as
+an even quad surface from a `voxelSize` or a `resolution` (cells along the longest side, at most 192); it drops tags, and
+an open mesh needs `fill_holes` first. Levels of detail for a part are made in code with `generateGeometryLods`.
+
+```json
+{ "id": "boulder", "type": "mesh", "base": { "type": "box", "bevel": 0 }, "stack": [
+ { "op": "subdivide", "levels": 3 },
+ { "op": "decimate", "ratio": 0.3 }
+] }
+```
+
## Fields: noise, gradients and repeats
A field expression is a small JSON formula over each vertex or face. `displace` and `set_position` take one, and
diff --git a/src/agent-mesh-engine.js b/src/agent-mesh-engine.js
index dff14173..04bb728e 100644
--- a/src/agent-mesh-engine.js
+++ b/src/agent-mesh-engine.js
@@ -1,5 +1,6 @@
// Everything the agent scene needs for mesh geometry, behind one on-demand import (see agent-scene-modules.js).
export { meshReport, generateMeshGeometry } from './agent-mesh.js';
export { normalizeMeshEdits, normalizeMeshStack } from './mesh-recipe.js';
+export { generateMeshLods, generateGeometryLods, generateAssetLods } from './mesh-lod.js';
export { expandInstancedNodes } from './mesh-instances.js';
export { loadMeshBooleans, meshBooleansLoaded, setManifoldModuleLoader } from './mesh-boolean.js';
diff --git a/src/mesh-decimate.js b/src/mesh-decimate.js
new file mode 100644
index 00000000..2440b736
--- /dev/null
+++ b/src/mesh-decimate.js
@@ -0,0 +1,373 @@
+import { createMeshData, TAG_PREFIX } from './mesh-data.js';
+import { triangulateMesh } from './mesh-render.js';
+import { faceNormals } from './mesh-normals.js';
+
+// Quadric edge collapse (Garland and Heckbert) on the triangulated mesh. Open boundaries and the borders between
+// faces with different tags are constraints: their vertices only collapse along the constraint, and extra planes
+// through each constraint edge keep it in place. Corner and edge attributes (uv, colour, sharp) are dropped, because
+// a collapse has no single right value for them; run uv_unwrap after decimating.
+
+export const MIN_DECIMATED_TRIANGLES = 4;
+const CONSTRAINT_WEIGHT = 100;
+const MINIMUM_NORMAL_AGREEMENT = 0.2;
+const MAXIMUM_DRIFT_IN_EDGE_LENGTHS = 1.5;
+
+class MinHeap {
+ constructor() {
+ this.entries = [];
+ }
+
+ get size() {
+ return this.entries.length;
+ }
+
+ push(entry) {
+ const entries = this.entries;
+ let index = entries.length;
+ entries.push(entry);
+ while (index > 0) {
+ const parent = (index - 1) >> 1;
+ if (entries[parent].cost <= entry.cost) break;
+ entries[index] = entries[parent];
+ index = parent;
+ }
+ entries[index] = entry;
+ }
+
+ pop() {
+ const entries = this.entries;
+ const top = entries[0];
+ const last = entries.pop();
+ if (entries.length) {
+ let index = 0;
+ for (;;) {
+ let child = index * 2 + 1;
+ if (child >= entries.length) break;
+ if (child + 1 < entries.length && entries[child + 1].cost < entries[child].cost) child++;
+ if (entries[child].cost >= last.cost) break;
+ entries[index] = entries[child];
+ index = child;
+ }
+ entries[index] = last;
+ }
+ return top;
+ }
+}
+
+// A quadric is the symmetric 4x4 matrix of a plane sum, stored as ten numbers: aa ab ac ad bb bc bd cc cd dd.
+function addPlane(quadrics, vertex, nx, ny, nz, d, weight) {
+ const base = vertex * 10;
+ quadrics[base] += weight * nx * nx;
+ quadrics[base + 1] += weight * nx * ny;
+ quadrics[base + 2] += weight * nx * nz;
+ quadrics[base + 3] += weight * nx * d;
+ quadrics[base + 4] += weight * ny * ny;
+ quadrics[base + 5] += weight * ny * nz;
+ quadrics[base + 6] += weight * ny * d;
+ quadrics[base + 7] += weight * nz * nz;
+ quadrics[base + 8] += weight * nz * d;
+ quadrics[base + 9] += weight * d * d;
+}
+
+function quadricError(q, x, y, z) {
+ return q[0] * x * x + 2 * q[1] * x * y + 2 * q[2] * x * z + 2 * q[3] * x +
+ q[4] * y * y + 2 * q[5] * y * z + 2 * q[6] * y +
+ q[7] * z * z + 2 * q[8] * z + q[9];
+}
+
+/** The point minimising the quadric, or null when the system is nearly singular. */
+function optimalPoint(q) {
+ const [a, b, c, d, e, f, g, h, i] = q;
+ const determinant = a * (e * h - f * f) - b * (b * h - f * c) + c * (b * f - e * c);
+ const scale = Math.abs(a) * Math.abs(e) * Math.abs(h);
+ if (Math.abs(determinant) <= 1e-9 * scale || scale === 0) return null;
+ const x = -(d * (e * h - f * f) - b * (g * h - f * i) + c * (g * f - e * i)) / determinant;
+ const y = -(a * (g * h - f * i) - d * (b * h - f * c) + c * (b * i - g * c)) / determinant;
+ const z = -(a * (e * i - g * f) - b * (b * i - g * c) + d * (b * f - e * c)) / determinant;
+ return [x, y, z];
+}
+
+// Math.hypot is several times slower than this in the collapse loop.
+function vectorLength(x, y, z) {
+ return Math.sqrt(x * x + y * y + z * z);
+}
+
+function edgeKey(first, second, vertexCount) {
+ return first < second ? first * vertexCount + second : second * vertexCount + first;
+}
+
+function faceSignatures(mesh) {
+ const tags = Object.entries(mesh.attributes.face).filter(([name]) => name.startsWith(TAG_PREFIX)).map(([, attribute]) => attribute.data);
+ return Uint32Array.from({ length: mesh.faceCount }, (value, face) => {
+ let signature = 0;
+ tags.forEach((data, index) => {
+ signature = (signature * 31 + (data[face] ? index + 1 : 0)) >>> 0;
+ });
+ return signature;
+ });
+}
+
+class Decimator {
+ constructor(mesh) {
+ this.mesh = mesh;
+ this.vertexCount = mesh.vertexCount;
+ this.positions = Float64Array.from(mesh.positions);
+ this.cornerBuffer = new Float64Array(9);
+ this.combinedQuadric = new Float64Array(10);
+ const { triangleCorners, triangleFaces } = triangulateMesh(mesh, faceNormals(mesh).normals);
+ this.triangleCount = triangleFaces.length;
+ this.sourceFaces = triangleFaces;
+ this.triangles = Int32Array.from(triangleCorners, corner => mesh.cornerVertices[corner]);
+ this.alive = new Uint8Array(this.triangleCount).fill(1);
+ this.aliveCount = this.triangleCount;
+ this.vertexAlive = new Uint8Array(this.vertexCount).fill(1);
+ this.vertexTriangles = Array.from({ length: this.vertexCount }, () => []);
+ for (let triangle = 0; triangle < this.triangleCount; triangle++) {
+ for (let corner = 0; corner < 3; corner++) this.vertexTriangles[this.triangles[triangle * 3 + corner]].push(triangle);
+ }
+ this.quadrics = new Float64Array(this.vertexCount * 10);
+ this.constrainedVertex = new Uint8Array(this.vertexCount);
+ this.constraintEdges = new Set();
+ this.buildQuadrics();
+ }
+
+ /** Unnormalised normal of a triangle, with one vertex optionally moved to `replacement`. */
+ triangleNormal(triangle, replaced = -1, replacement = null) {
+ const corners = this.cornerBuffer;
+ for (let corner = 0; corner < 3; corner++) {
+ const vertex = this.triangles[triangle * 3 + corner];
+ const source = vertex === replaced ? replacement : this.positions;
+ const offset = vertex === replaced ? 0 : vertex * 3;
+ corners[corner * 3] = source[offset];
+ corners[corner * 3 + 1] = source[offset + 1];
+ corners[corner * 3 + 2] = source[offset + 2];
+ }
+ const ux = corners[3] - corners[0];
+ const uy = corners[4] - corners[1];
+ const uz = corners[5] - corners[2];
+ const vx = corners[6] - corners[0];
+ const vy = corners[7] - corners[1];
+ const vz = corners[8] - corners[2];
+ return [uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx];
+ }
+
+ buildQuadrics() {
+ const signatures = faceSignatures(this.mesh);
+ const edgeFaces = new Map();
+ for (let triangle = 0; triangle < this.triangleCount; triangle++) {
+ const normal = this.triangleNormal(triangle);
+ const length = Math.hypot(...normal);
+ if (length > 0) {
+ const unit = normal.map(value => value / length);
+ const first = this.triangles[triangle * 3] * 3;
+ const d = -(unit[0] * this.positions[first] + unit[1] * this.positions[first + 1] + unit[2] * this.positions[first + 2]);
+ for (let corner = 0; corner < 3; corner++) addPlane(this.quadrics, this.triangles[triangle * 3 + corner], unit[0], unit[1], unit[2], d, length / 2);
+ }
+ for (let corner = 0; corner < 3; corner++) {
+ const key = edgeKey(this.triangles[triangle * 3 + corner], this.triangles[triangle * 3 + (corner + 1) % 3], this.vertexCount);
+ if (!edgeFaces.has(key)) edgeFaces.set(key, []);
+ edgeFaces.get(key).push(triangle);
+ }
+ }
+ for (const [key, triangles] of edgeFaces) {
+ const sameSignature = triangles.every(triangle => signatures[this.sourceFaces[triangle]] === signatures[this.sourceFaces[triangles[0]]]);
+ if (triangles.length === 2 && sameSignature) continue;
+ this.constraintEdges.add(key);
+ const first = Math.floor(key / this.vertexCount);
+ const second = key - first * this.vertexCount;
+ this.constrainedVertex[first] = 1;
+ this.constrainedVertex[second] = 1;
+ for (const triangle of triangles) this.addConstraintPlane(first, second, triangle);
+ }
+ }
+
+ addConstraintPlane(first, second, triangle) {
+ const edge = [0, 1, 2].map(axis => this.positions[second * 3 + axis] - this.positions[first * 3 + axis]);
+ const face = this.triangleNormal(triangle);
+ const normal = [edge[1] * face[2] - edge[2] * face[1], edge[2] * face[0] - edge[0] * face[2], edge[0] * face[1] - edge[1] * face[0]];
+ const length = Math.hypot(...normal);
+ if (length === 0) return;
+ const unit = normal.map(value => value / length);
+ const d = -(unit[0] * this.positions[first * 3] + unit[1] * this.positions[first * 3 + 1] + unit[2] * this.positions[first * 3 + 2]);
+ const weight = CONSTRAINT_WEIGHT * (edge[0] ** 2 + edge[1] ** 2 + edge[2] ** 2);
+ addPlane(this.quadrics, first, unit[0], unit[1], unit[2], d, weight);
+ addPlane(this.quadrics, second, unit[0], unit[1], unit[2], d, weight);
+ }
+
+ neighbors(vertex) {
+ const found = new Set();
+ for (const triangle of this.vertexTriangles[vertex]) {
+ for (let corner = 0; corner < 3; corner++) found.add(this.triangles[triangle * 3 + corner]);
+ }
+ found.delete(vertex);
+ return found;
+ }
+
+ /** The collapse of `second` into `first`: its target point and cost, or null when it would break the surface. */
+ evaluate(first, second) {
+ const shared = this.vertexTriangles[first].filter(triangle => this.vertexTriangles[second].includes(triangle));
+ if (!shared.length) return null;
+ const firstConstrained = this.constrainedVertex[first] === 1;
+ const secondConstrained = this.constrainedVertex[second] === 1;
+ if (firstConstrained && secondConstrained && !this.constraintEdges.has(edgeKey(first, second, this.vertexCount))) return null;
+ const secondNeighbors = this.neighbors(second);
+ const common = [...this.neighbors(first)].filter(vertex => secondNeighbors.has(vertex));
+ if (common.length !== shared.length) return null;
+ const target = this.chooseTarget(first, second, firstConstrained, secondConstrained);
+ if (!this.keepsOrientation(first, second, shared, target.point)) return null;
+ return target;
+ }
+
+ chooseTarget(first, second, firstConstrained, secondConstrained) {
+ const combined = this.combinedQuadric;
+ for (let slot = 0; slot < 10; slot++) combined[slot] = this.quadrics[first * 10 + slot] + this.quadrics[second * 10 + slot];
+ const at = vertex => [this.positions[vertex * 3], this.positions[vertex * 3 + 1], this.positions[vertex * 3 + 2]];
+ const start = at(first);
+ const end = at(second);
+ const candidates = [];
+ if (firstConstrained !== secondConstrained) {
+ candidates.push(firstConstrained ? start : end);
+ } else {
+ const middle = [(start[0] + end[0]) / 2, (start[1] + end[1]) / 2, (start[2] + end[2]) / 2];
+ candidates.push(start, end, middle);
+ const optimal = firstConstrained ? null : optimalPoint(combined);
+ const drift = optimal && vectorLength(optimal[0] - middle[0], optimal[1] - middle[1], optimal[2] - middle[2]);
+ if (optimal && drift <= MAXIMUM_DRIFT_IN_EDGE_LENGTHS * vectorLength(start[0] - end[0], start[1] - end[1], start[2] - end[2])) {
+ candidates.push(optimal);
+ }
+ }
+ let best = null;
+ for (const point of candidates) {
+ const cost = quadricError(combined, point[0], point[1], point[2]);
+ if (!best || cost < best.cost) best = { point, cost: Math.max(cost, 0) };
+ }
+ return best;
+ }
+
+ keepsOrientation(first, second, shared, point) {
+ for (const vertex of [first, second]) {
+ for (const triangle of this.vertexTriangles[vertex]) {
+ if (shared.includes(triangle)) continue;
+ const before = this.triangleNormal(triangle);
+ const after = this.triangleNormal(triangle, vertex, point);
+ const lengths = vectorLength(before[0], before[1], before[2]) * vectorLength(after[0], after[1], after[2]);
+ if (lengths === 0) return false;
+ const agreement = (before[0] * after[0] + before[1] * after[1] + before[2] * after[2]) / lengths;
+ if (agreement < MINIMUM_NORMAL_AGREEMENT) return false;
+ }
+ }
+ return true;
+ }
+
+ collapse(first, second, point) {
+ for (const triangle of [...this.vertexTriangles[second]]) {
+ const corners = [0, 1, 2].map(corner => this.triangles[triangle * 3 + corner]);
+ if (corners.includes(first)) {
+ this.alive[triangle] = 0;
+ this.aliveCount--;
+ for (const vertex of corners) this.dropTriangle(vertex, triangle);
+ continue;
+ }
+ this.triangles[triangle * 3 + corners.indexOf(second)] = first;
+ this.vertexTriangles[first].push(triangle);
+ }
+ this.moveConstraintEdges(first, second);
+ this.positions.set(point, first * 3);
+ for (let slot = 0; slot < 10; slot++) this.quadrics[first * 10 + slot] += this.quadrics[second * 10 + slot];
+ this.constrainedVertex[first] ||= this.constrainedVertex[second];
+ this.vertexAlive[second] = 0;
+ this.vertexTriangles[second] = [];
+ }
+
+ moveConstraintEdges(first, second) {
+ if (!this.constrainedVertex[second]) return;
+ for (const other of this.neighbors(second)) {
+ const key = edgeKey(second, other, this.vertexCount);
+ if (!this.constraintEdges.has(key)) continue;
+ this.constraintEdges.delete(key);
+ if (other !== first) this.constraintEdges.add(edgeKey(first, other, this.vertexCount));
+ }
+ }
+
+ dropTriangle(vertex, triangle) {
+ const list = this.vertexTriangles[vertex];
+ const index = list.indexOf(triangle);
+ if (index >= 0) {
+ list[index] = list[list.length - 1];
+ list.pop();
+ }
+ }
+
+ run(targetTriangles) {
+ const heap = new MinHeap();
+ // Queued costs are estimates: validity is decided when an entry is popped, which keeps the setup cheap.
+ const queue = (first, second) => {
+ const firstConstrained = this.constrainedVertex[first] === 1;
+ const secondConstrained = this.constrainedVertex[second] === 1;
+ if (firstConstrained && secondConstrained && !this.constraintEdges.has(edgeKey(first, second, this.vertexCount))) return;
+ heap.push({ cost: this.chooseTarget(first, second, firstConstrained, secondConstrained).cost, first, second });
+ };
+ for (let triangle = 0; triangle < this.triangleCount; triangle++) {
+ for (let corner = 0; corner < 3; corner++) {
+ const first = this.triangles[triangle * 3 + corner];
+ const second = this.triangles[triangle * 3 + (corner + 1) % 3];
+ if (first < second || !this.hasTriangleOnOtherSide(first, second, triangle)) queue(first, second);
+ }
+ }
+ while (this.aliveCount > targetTriangles && heap.size) {
+ const { cost, first, second } = heap.pop();
+ if (!this.vertexAlive[first] || !this.vertexAlive[second]) continue;
+ const target = this.evaluate(first, second);
+ if (!target) continue;
+ if (target.cost > cost * 1.0001 + 1e-18) {
+ heap.push({ cost: target.cost, first, second });
+ continue;
+ }
+ this.collapse(first, second, target.point);
+ for (const neighbor of this.neighbors(first)) queue(first, neighbor);
+ }
+ }
+
+ hasTriangleOnOtherSide(first, second, triangle) {
+ return this.vertexTriangles[first].some(other => other !== triangle && this.vertexTriangles[second].includes(other));
+ }
+
+ result() {
+ const vertexMap = new Int32Array(this.vertexCount).fill(-1);
+ const keptTriangles = [];
+ for (let triangle = 0; triangle < this.triangleCount; triangle++) if (this.alive[triangle]) keptTriangles.push(triangle);
+ const positions = [];
+ const cornerVertices = new Uint32Array(keptTriangles.length * 3);
+ keptTriangles.forEach((triangle, slot) => {
+ for (let corner = 0; corner < 3; corner++) {
+ const vertex = this.triangles[triangle * 3 + corner];
+ if (vertexMap[vertex] < 0) {
+ vertexMap[vertex] = positions.length / 3;
+ positions.push(this.positions[vertex * 3], this.positions[vertex * 3 + 1], this.positions[vertex * 3 + 2]);
+ }
+ cornerVertices[slot * 3 + corner] = vertexMap[vertex];
+ }
+ });
+ const faceOffsets = Uint32Array.from({ length: keptTriangles.length + 1 }, (value, index) => index * 3);
+ const face = {};
+ for (const [name, attribute] of Object.entries(this.mesh.attributes.face)) {
+ if (!name.startsWith(TAG_PREFIX)) continue;
+ face[name] = { data: Uint8Array.from(keptTriangles, triangle => attribute.data[this.sourceFaces[triangle]]), size: 1 };
+ }
+ return createMeshData({ positions: Float32Array.from(positions), faceOffsets, cornerVertices, attributes: { face } });
+ }
+}
+
+/**
+ * Reduce a mesh to about `ratio` of its triangles (counted after triangulation, never below four). Returns the
+ * triangle mesh, the triangle counts and whether the target was reached; constraints can stop a collapse early.
+ */
+export function decimateMesh(mesh, { ratio }) {
+ if (typeof ratio !== 'number' || !(ratio > 0) || ratio > 1) throw new RangeError('ratio must be above 0 and at most 1.');
+ const decimator = new Decimator(mesh);
+ const before = decimator.aliveCount;
+ const target = Math.max(MIN_DECIMATED_TRIANGLES, Math.ceil(before * ratio));
+ decimator.run(target);
+ const reduced = decimator.result();
+ return { mesh: reduced, triangles: { before, after: reduced.faceCount }, reachedTarget: reduced.faceCount <= target };
+}
diff --git a/src/mesh-lod.js b/src/mesh-lod.js
new file mode 100644
index 00000000..139f500f
--- /dev/null
+++ b/src/mesh-lod.js
@@ -0,0 +1,100 @@
+import { decimateMesh } from './mesh-decimate.js';
+import { createSurfaceDistance } from './mesh-surface-distance.js';
+import { meshBounds } from './mesh-data.js';
+import { meshFromGeometry } from './mesh-convert.js';
+import { extractRender } from './mesh-render.js';
+
+// Levels of detail for runtime selection (issue 37). Level 0 is the input; each next level keeps the given ratio of
+// the input's triangles. Every level reports the farthest its vertices lie from the input surface, in the input's
+// units, so a renderer can choose the level whose error stays under a pixel at the distance it is drawn.
+
+export const DEFAULT_LOD_RATIOS = Object.freeze([0.5, 0.25, 0.1]);
+export const MAX_LOD_LEVELS = 8;
+
+function checkRatios(ratios) {
+ if (!Array.isArray(ratios) || ratios.length < 1 || ratios.length > MAX_LOD_LEVELS) {
+ throw new RangeError(`ratios needs 1 to ${MAX_LOD_LEVELS} numbers.`);
+ }
+ ratios.forEach((ratio, index) => {
+ if (typeof ratio !== 'number' || !(ratio > 0) || !(ratio < 1) || (index > 0 && ratio >= ratios[index - 1])) {
+ throw new RangeError('ratios must be strictly decreasing numbers above 0 and below 1.');
+ }
+ });
+}
+
+function farthestFromSurface(mesh, surface) {
+ const point = [0, 0, 0];
+ const visited = new Uint8Array(mesh.vertexCount);
+ let farthest = 0;
+ for (const vertex of mesh.cornerVertices) {
+ if (visited[vertex]) continue;
+ visited[vertex] = 1;
+ for (let axis = 0; axis < 3; axis++) point[axis] = mesh.positions[vertex * 3 + axis];
+ farthest = Math.max(farthest, surface.query(point).distance);
+ }
+ return farthest;
+}
+
+/**
+ * Decimate a polygon mesh into levels. Returns [{ level, ratio, mesh, triangles, error, relativeError }], where
+ * relativeError is the error over the diagonal of the input's bounds.
+ */
+export function generateMeshLods(mesh, { ratios = DEFAULT_LOD_RATIOS } = {}) {
+ checkRatios(ratios);
+ const surface = createSurfaceDistance(mesh);
+ const bounds = meshBounds(mesh);
+ const diagonal = Math.hypot(...bounds.max.map((value, axis) => value - bounds.min[axis]));
+ const levels = [{ level: 0, ratio: 1, mesh, triangles: surface.triangleCount, error: 0, relativeError: 0 }];
+ let previousRatio = 1;
+ let previous = mesh;
+ ratios.forEach((ratio, index) => {
+ // Each level continues from the one before, so the work shrinks with the mesh.
+ const reduced = decimateMesh(previous, { ratio: ratio / previousRatio });
+ const error = farthestFromSurface(reduced.mesh, surface);
+ levels.push({ level: index + 1, ratio, mesh: reduced.mesh, triangles: reduced.triangles.after, error, relativeError: error / diagonal });
+ previous = reduced.mesh;
+ previousRatio = ratio;
+ });
+ return levels;
+}
+
+/**
+ * Levels for renderer geometry, such as a recipe part from generateMeshGeometry or an imported asset's part. Each
+ * level carries a geometry made by extractRender, with edges sharper than `smoothAngle` degrees kept hard.
+ */
+export function generateGeometryLods(geometry, { ratios = DEFAULT_LOD_RATIOS, smoothAngle = 30 } = {}) {
+ const mesh = meshFromGeometry(geometry, { quads: false, tags: 'none' });
+ return generateMeshLods(mesh, { ratios }).map(({ mesh: levelMesh, ...rest }) => ({
+ ...rest,
+ geometry: rest.level === 0 ? geometry : extractRender(levelMesh, { sharpAngle: smoothAngle * Math.PI / 180 }).geometry,
+ }));
+}
+
+/**
+ * Levels for an imported asset: each is the asset with every part's geometry replaced by that level's geometry,
+ * so it can be handed to the scene as it is. Parts that share a geometry share its levels. Skinned and morphed
+ * parts are refused, because decimation would break their per-vertex weights.
+ */
+export function generateAssetLods(asset, options = {}) {
+ const parts = asset?.parts;
+ if (!Array.isArray(parts) || !parts.length) throw new TypeError('An asset needs a parts array.');
+ for (const part of parts) {
+ if (part.skin || part.morph) throw new RangeError(`Part ${part.name ?? part.id ?? '?'} is skinned or morphed; LODs support static parts only.`);
+ }
+ const byGeometry = new Map();
+ for (const part of parts) {
+ if (!byGeometry.has(part.geometry)) byGeometry.set(part.geometry, generateGeometryLods(part.geometry, options));
+ }
+ const levelCount = byGeometry.get(parts[0].geometry).length;
+ return Array.from({ length: levelCount }, (value, level) => {
+ const levelParts = parts.map(part => ({ ...part, geometry: byGeometry.get(part.geometry)[level].geometry }));
+ const reports = [...byGeometry.values()].map(levels => levels[level]);
+ return {
+ level,
+ ratio: reports[0].ratio,
+ triangles: reports.reduce((total, report) => total + report.triangles, 0),
+ error: Math.max(...reports.map(report => report.error)),
+ asset: { ...asset, parts: levelParts },
+ };
+ });
+}
diff --git a/src/mesh-operations.js b/src/mesh-operations.js
index 7facf2d7..4ff27814 100644
--- a/src/mesh-operations.js
+++ b/src/mesh-operations.js
@@ -33,10 +33,11 @@ export const MESH_EDIT_OPERATIONS = Object.freeze({
knife_project: { fields: ['name', 'path', 'direction'], tags: ['cut'] },
set_position: { fields: ['select', 'position', 'offset'], tags: [] },
displace: { fields: ['select', 'field', 'strength', 'midlevel', 'direction'], tags: [] },
+ decimate: { fields: ['ratio'], tags: [] },
+ remesh: { fields: ['voxelSize', 'resolution'], tags: [] },
});
-export const STACK_OPERATIONS = Object.freeze(['mirror', 'array', 'solidify', 'bevel', 'uv_unwrap', 'subdivide', 'set_position', 'displace']);
-export const MAX_STACK_NODES = 16;
+export const STACK_OPERATIONS = Object.freeze(['mirror', 'array', 'solidify', 'bevel', 'uv_unwrap', 'subdivide', 'set_position', 'displace', 'decimate', 'remesh']);export const MAX_STACK_NODES = 16;
// Field expressions (mesh-fields.js) and instancing (mesh-instances.js): limits and names as plain data. A test
// keeps FIELD_OPERATOR_NAMES equal to the operators the language really has.
diff --git a/src/mesh-recipe.js b/src/mesh-recipe.js
index 494603ac..a6a9f0a6 100644
--- a/src/mesh-recipe.js
+++ b/src/mesh-recipe.js
@@ -14,6 +14,8 @@ import { unwrapUv } from './mesh-uv.js';
import { validateField } from './mesh-fields.js';
import { setPosition, displaceMesh, DISPLACE_DIRECTIONS } from './mesh-field-edits.js';
import { subdivideMesh, subdivisionSize, MAX_SUBDIVISION_LEVELS, MAX_CREASE_SHARPNESS } from './mesh-subdivide.js';
+import { decimateMesh } from './mesh-decimate.js';
+import { remeshMesh, remeshGridSize, MAX_REMESH_RESOLUTION } from './mesh-remesh.js';
import { MESH_EDIT_OPERATIONS, MAX_MESH_EDITS, STACK_OPERATIONS, MAX_STACK_NODES } from './mesh-operations.js';
export { MESH_EDIT_OPERATIONS, MAX_MESH_EDITS, STACK_OPERATIONS, MAX_STACK_NODES };
@@ -201,6 +203,19 @@ export function normalizeMeshEdits(edits) {
if (edit.direction !== undefined && !DISPLACE_DIRECTIONS.includes(edit.direction)) throw editError(index, `direction must be one of ${DISPLACE_DIRECTIONS.join(', ')}`);
normalized.direction = edit.direction ?? 'normal';
break;
+ case 'decimate':
+ normalized.ratio = finiteNumber(edit.ratio, index, 'ratio', { minimum: 0, maximum: 1, exclusiveMinimum: true });
+ break;
+ case 'remesh':
+ if ((edit.voxelSize === undefined) === (edit.resolution === undefined)) throw editError(index, 'remesh needs exactly one of voxelSize or resolution');
+ if (edit.voxelSize !== undefined) normalized.voxelSize = finiteNumber(edit.voxelSize, index, 'voxelSize', { minimum: 0, exclusiveMinimum: true });
+ if (edit.resolution !== undefined) {
+ if (!Number.isInteger(edit.resolution) || edit.resolution < 4 || edit.resolution > MAX_REMESH_RESOLUTION) {
+ throw editError(index, `resolution must be an integer from 4 to ${MAX_REMESH_RESOLUTION}`);
+ }
+ normalized.resolution = edit.resolution;
+ }
+ break;
case 'merge_by_distance':
normalized.distance =finiteNumber(edit.distance ?? 1e-4, index, 'distance', { minimum: 0, maximum: 1e3 });
break;
@@ -224,6 +239,14 @@ function checkArrayBudget(mesh, edit, limits, index) {
checkSubdivideBudget(mesh, edit, limits, index);
return;
}
+ if (edit.op === 'remesh') {
+ try {
+ remeshGridSize(mesh, edit);
+ } catch (error) {
+ throw new error.constructor(`Mesh edit ${index} (remesh): ${error.message}`);
+ }
+ return;
+ }
if (edit.op !== 'array') return;
const vertices = mesh.vertexCount * edit.count;
const faces = mesh.faceCount * edit.count;
@@ -347,6 +370,27 @@ function runEdit(current, edit, index, { resolveCutter }) {
result.levels = edit.levels;
return { mesh: subdivided, result };
}
+ if (edit.op === 'decimate') {
+ let outcome;
+ try {
+ outcome = decimateMesh(current, edit);
+ } catch (error) {
+ throw new error.constructor(`Mesh edit ${index} (decimate): ${error.message}`);
+ }
+ result.triangles = outcome.triangles;
+ if (!outcome.reachedTarget) result.stoppedEarly = true;
+ return { mesh: outcome.mesh, result };
+ }
+ if (edit.op === 'remesh') {
+ let outcome;
+ try {
+ outcome = remeshMesh(current, edit);
+ } catch (error) {
+ throw new error.constructor(`Mesh edit ${index} (remesh): ${error.message}`);
+ }
+ result.voxelSize = Number(outcome.voxelSize.toPrecision(5));
+ return { mesh: outcome.mesh, result };
+ }
if (edit.op === 'uv_unwrap') {
let outcome;
try {
diff --git a/src/mesh-remesh.js b/src/mesh-remesh.js
new file mode 100644
index 00000000..cc431f6d
--- /dev/null
+++ b/src/mesh-remesh.js
@@ -0,0 +1,209 @@
+import { createMeshData, meshBounds } from './mesh-data.js';
+import { edgeCornerTable } from './mesh-topology.js';
+import { createSurfaceDistance, triangulatedSurface } from './mesh-surface-distance.js';
+
+// Voxel remesh: sample the signed distance to the surface on a grid, then place one vertex in each cell the surface
+// crosses (surface nets) and join the four cells around each crossing grid edge into a quad. The result is a closed
+// quad surface with even cells. Only cells near the surface take a BVH query; the rest are inside or outside by a
+// flood fill from the grid corner. Tags and attributes of the input are not carried over.
+
+export const MAX_REMESH_RESOLUTION = 192;
+export const MAX_REMESH_CELLS = 4_194_304;
+const BAND_VOXELS = 2;
+const PADDING_VOXELS = 3;
+
+function assertClosed(mesh) {
+ const table = edgeCornerTable(mesh);
+ for (let edge = 0; edge < mesh.edgeCount; edge++) {
+ if (table.edgeOffsets[edge + 1] - table.edgeOffsets[edge] !== 2) {
+ throw new RangeError('remesh needs a closed surface: every edge must join exactly two faces. Run fill_holes first.');
+ }
+ }
+}
+
+/** Grid size for a voxel edge length; checked before anything is allocated. */
+export function remeshGridSize(mesh, { voxelSize, resolution }) {
+ const bounds = meshBounds(mesh);
+ const extent = bounds.max.map((value, axis) => value - bounds.min[axis]);
+ const longest = Math.max(...extent);
+ if ((voxelSize === undefined) === (resolution === undefined)) throw new RangeError('remesh takes either voxelSize or resolution.');
+ const edge = voxelSize ?? longest / resolution;
+ if (!(edge > 0) || !(longest > 0)) throw new RangeError('remesh needs a positive voxel size and a mesh with volume.');
+ const points = extent.map(value => Math.ceil(value / edge) + 1 + PADDING_VOXELS * 2);
+ const cells = points.reduce((product, count) => product * (count - 1), 1);
+ if (longest / edge > MAX_REMESH_RESOLUTION || cells > MAX_REMESH_CELLS) {
+ throw new RangeError(`remesh would use ${cells} cells and ${Math.ceil(longest / edge)} along the longest side, over the limits of ${MAX_REMESH_CELLS} cells and ${MAX_REMESH_RESOLUTION} per side. Use a larger voxelSize or a lower resolution.`);
+ }
+ return { bounds, edge, points, cells };
+}
+
+function markBand(surface, grid) {
+ const { positions, indices } = surface;
+ const [pointsX, pointsY, pointsZ] = grid.points;
+ const marked = new Uint8Array(pointsX * pointsY * pointsZ);
+ const low = [0, 0, 0];
+ const high = [0, 0, 0];
+ for (let triangle = 0; triangle < indices.length / 3; triangle++) {
+ for (let axis = 0; axis < 3; axis++) {
+ const values = [0, 1, 2].map(corner => positions[indices[triangle * 3 + corner] * 3 + axis]);
+ const origin = grid.bounds.min[axis] - PADDING_VOXELS * grid.edge;
+ low[axis] = Math.max(0, Math.floor((Math.min(...values) - origin) / grid.edge) - BAND_VOXELS);
+ high[axis] = Math.min(grid.points[axis] - 1, Math.ceil((Math.max(...values) - origin) / grid.edge) + BAND_VOXELS);
+ }
+ for (let z = low[2]; z <= high[2]; z++) {
+ for (let y = low[1]; y <= high[1]; y++) {
+ const row = (z * pointsY + y) * pointsX;
+ marked.fill(1, row + low[0], row + high[0] + 1);
+ }
+ }
+ }
+ return marked;
+}
+
+/** Marks the unmarked points reachable from the grid corner as outside; the remaining unmarked points are inside. */
+function floodOutside(marked, points) {
+ const [pointsX, pointsY, pointsZ] = points;
+ const outside = new Uint8Array(marked.length);
+ const stack = [0];
+ outside[0] = 1;
+ const strides = [1, pointsX, pointsX * pointsY];
+ while (stack.length) {
+ const point = stack.pop();
+ const coordinates = [point % pointsX, Math.floor(point / pointsX) % pointsY, Math.floor(point / (pointsX * pointsY))];
+ for (let axis = 0; axis < 3; axis++) {
+ for (const step of [-1, 1]) {
+ const next = coordinates[axis] + step;
+ if (next < 0 || next >= [pointsX, pointsY, pointsZ][axis]) continue;
+ const neighbor = point + step * strides[axis];
+ if (marked[neighbor] || outside[neighbor]) continue;
+ outside[neighbor] = 1;
+ stack.push(neighbor);
+ }
+ }
+ }
+ return outside;
+}
+
+function sampleDistances(mesh, surface, grid) {
+ const [pointsX, pointsY] = grid.points;
+ const marked = markBand(surface, grid);
+ const outside = floodOutside(marked, grid.points);
+ const distances = new Float32Array(marked.length);
+ const query = createSurfaceDistance(mesh, { signed: true }).query;
+ const farValue = (BAND_VOXELS + 1) * grid.edge;
+ const origin = grid.bounds.min.map(value => value - PADDING_VOXELS * grid.edge);
+ const point = [0, 0, 0];
+ for (let index = 0; index < marked.length; index++) {
+ if (!marked[index]) {
+ distances[index] = outside[index] ? farValue : -farValue;
+ continue;
+ }
+ point[0] = origin[0] + (index % pointsX) * grid.edge;
+ point[1] = origin[1] + (Math.floor(index / pointsX) % pointsY) * grid.edge;
+ point[2] = origin[2] + Math.floor(index / (pointsX * pointsY)) * grid.edge;
+ distances[index] = query(point).distance;
+ }
+ return { distances, origin };
+}
+
+const CELL_CORNERS = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 1], [1, 0, 1], [0, 1, 1], [1, 1, 1]];
+const CELL_EDGES = [[0, 1], [2, 3], [4, 5], [6, 7], [0, 2], [1, 3], [4, 6], [5, 7], [0, 4], [1, 5], [2, 6], [3, 7]];
+
+/** One vertex per crossed cell, at the mean of the edge crossings. Returns the cell-to-vertex map and positions. */
+function placeCellVertices(distances, grid, origin) {
+ const [pointsX, pointsY, pointsZ] = grid.points;
+ const cellsX = pointsX - 1;
+ const cellsY = pointsY - 1;
+ const cellVertex = new Int32Array(cellsX * cellsY * (pointsZ - 1)).fill(-1);
+ const positions = [];
+ const values = new Float64Array(8);
+ for (let z = 0; z < pointsZ - 1; z++) {
+ for (let y = 0; y < cellsY; y++) {
+ for (let x = 0; x < cellsX; x++) {
+ let negative = 0;
+ for (let corner = 0; corner < 8; corner++) {
+ const [dx, dy, dz] = CELL_CORNERS[corner];
+ values[corner] = distances[((z + dz) * pointsY + y + dy) * pointsX + x + dx];
+ if (values[corner] < 0) negative++;
+ }
+ if (negative === 0 || negative === 8) continue;
+ const sum = [0, 0, 0];
+ let crossings = 0;
+ for (const [start, end] of CELL_EDGES) {
+ if ((values[start] < 0) === (values[end] < 0)) continue;
+ const fraction = values[start] / (values[start] - values[end]);
+ for (let axis = 0; axis < 3; axis++) {
+ sum[axis] += CELL_CORNERS[start][axis] + fraction * (CELL_CORNERS[end][axis] - CELL_CORNERS[start][axis]);
+ }
+ crossings++;
+ }
+ cellVertex[(z * cellsY + y) * cellsX + x] = positions.length / 3;
+ positions.push(
+ origin[0] + (x + sum[0] / crossings) * grid.edge,
+ origin[1] + (y + sum[1] / crossings) * grid.edge,
+ origin[2] + (z + sum[2] / crossings) * grid.edge,
+ );
+ }
+ }
+ }
+ return { cellVertex, positions };
+}
+
+// For each axis, its two other axes in cyclic order (u, v). Seen from the positive axis, the four cells around an
+// edge run counterclockwise through (-1,-1), (0,-1), (0,0), (-1,0) in (u, v).
+const AXIS_BASES = [[1, 2], [2, 0], [0, 1]];
+const QUAD_OFFSETS = [[-1, -1], [0, -1], [0, 0], [-1, 0]];
+
+/** One quad of cell vertices per grid edge that crosses the surface, wound so the normal points outward. */
+function quadsAroundEdges(distances, grid, cellVertex) {
+ const cellsPerAxis = grid.points.map(count => count - 1);
+ const [pointsX, pointsY, pointsZ] = grid.points;
+ const strides = [1, pointsX, pointsX * pointsY];
+ const quads = [];
+ const point = [0, 0, 0];
+ for (let z = 0; z < pointsZ; z++) {
+ for (let y = 0; y < pointsY; y++) {
+ for (let x = 0; x < pointsX; x++) {
+ point[0] = x;
+ point[1] = y;
+ point[2] = z;
+ const index = (z * pointsY + y) * pointsX + x;
+ for (let axis = 0; axis < 3; axis++) {
+ const [u, v] = AXIS_BASES[axis];
+ if (point[axis] + 1 >= grid.points[axis] || point[u] === 0 || point[v] === 0) continue;
+ const here = distances[index];
+ if ((here < 0) === (distances[index + strides[axis]] < 0)) continue;
+ const quad = QUAD_OFFSETS.map(([stepU, stepV]) => cellVertexAt(cellVertex, cellsPerAxis, point, axis, u, v, stepU, stepV));
+ if (quad.includes(-1)) continue;
+ quads.push(here < 0 ? quad : quad.reverse());
+ }
+ }
+ }
+ }
+ return quads;
+}
+
+function cellVertexAt(cellVertex, cellsPerAxis, point, axis, u, v, stepU, stepV) {
+ const cell = [point[0], point[1], point[2]];
+ cell[u] += stepU;
+ cell[v] += stepV;
+ if (cell[0] >= cellsPerAxis[0] || cell[1] >= cellsPerAxis[1] || cell[2] >= cellsPerAxis[2]) return -1;
+ return cellVertex[(cell[2] * cellsPerAxis[1] + cell[1]) * cellsPerAxis[0] + cell[0]];
+}
+
+/**
+ * Rebuild a closed mesh as a quad surface on a grid of `voxelSize` (or `resolution` cells along the longest side).
+ * Returns the mesh and the grid it used.
+ */
+export function remeshMesh(mesh, options) {
+ assertClosed(mesh);
+ const grid = remeshGridSize(mesh, options);
+ const surface = triangulatedSurface(mesh);
+ const { distances, origin } = sampleDistances(mesh, surface, grid);
+ const { cellVertex, positions } = placeCellVertices(distances, grid, origin);
+ const quads = quadsAroundEdges(distances, grid, cellVertex);
+ if (!quads.length) throw new RangeError('remesh found no surface: the voxel size is larger than the mesh.');
+ const faceOffsets = Uint32Array.from({ length: quads.length + 1 }, (value, index) => index * 4);
+ const remeshed = createMeshData({ positions: Float32Array.from(positions), faceOffsets, cornerVertices: Uint32Array.from(quads.flat()) });
+ return { mesh: remeshed, voxelSize: grid.edge, cells: grid.cells };
+}
diff --git a/src/mesh-surface-distance.js b/src/mesh-surface-distance.js
new file mode 100644
index 00000000..725f5f75
--- /dev/null
+++ b/src/mesh-surface-distance.js
@@ -0,0 +1,100 @@
+import { buildTriangleBvh, traverseTriangleBvh, pointBoxDistance } from './triangle-bvh.js';
+import { readTriangle, closestPointOnTriangle, barycentricWeights } from './triangle-math.js';
+import { triangulateMesh } from './mesh-render.js';
+import { faceNormals, vertexNormals } from './mesh-normals.js';
+
+// Distance from a point to a polygon mesh through a triangle BVH, signed by the angle-weighted vertex normals
+// interpolated at the nearest point (negative inside a closed mesh). Used by remesh and by the measured error of
+// decimation and generated levels.
+
+/** The mesh as indexed triangles over its own vertices. */
+export function triangulatedSurface(mesh) {
+ const { triangleCorners } = triangulateMesh(mesh, faceNormals(mesh).normals);
+ const indices = new Uint32Array(triangleCorners.length);
+ for (let index = 0; index < indices.length; index++) indices[index] = mesh.cornerVertices[triangleCorners[index]];
+ return { positions: mesh.positions, indices };
+}
+
+export function createSurfaceDistance(mesh, { signed = false } = {}) {
+ const { positions, indices } = triangulatedSurface(mesh);
+ const bvh = buildTriangleBvh(positions, indices);
+ const normals = signed ? vertexNormals(mesh) : null;
+ const triangle = new Float64Array(9);
+ const candidate = [0, 0, 0];
+ const weights = [0, 0, 0];
+
+ function signAt(point, triangleId) {
+ readTriangle(positions, indices, triangleId, triangle);
+ closestPointOnTriangle(point, triangle, candidate);
+ if (!barycentricWeights(candidate, triangle, weights)) return 1;
+ let along = 0;
+ for (let axis = 0; axis < 3; axis++) {
+ let interpolated = 0;
+ for (let corner = 0; corner < 3; corner++) interpolated += weights[corner] * normals[indices[triangleId * 3 + corner] * 3 + axis];
+ along += interpolated * (point[axis] - candidate[axis]);
+ }
+ return along < 0 ? -1 : 1;
+ }
+
+ /** Distance to the surface, and the nearest triangle. With `signed`, the distance is negative inside. */
+ function query(point) {
+ let best = Infinity;
+ let bestTriangle = -1;
+ traverseTriangleBvh(
+ bvh,
+ (bounds, offset) => pointBoxDistance(point, bounds, offset),
+ score => score <= best,
+ triangleId => {
+ readTriangle(positions, indices, triangleId, triangle);
+ closestPointOnTriangle(point, triangle, candidate);
+ const distance = Math.hypot(candidate[0] - point[0], candidate[1] - point[1], candidate[2] - point[2]);
+ if (distance < best) {
+ best = distance;
+ bestTriangle = triangleId;
+ }
+ return false;
+ },
+ );
+ return { distance: signed && bestTriangle >= 0 ? best * signAt(point, bestTriangle) : best, triangle: bestTriangle };
+ }
+
+ return { query, triangleCount: indices.length / 3 };
+}
+
+function farthestVertex(mesh, surface) {
+ const point = [0, 0, 0];
+ const measured = new Uint8Array(mesh.vertexCount);
+ let farthest = 0;
+ for (const vertex of mesh.cornerVertices) {
+ if (measured[vertex]) continue;
+ measured[vertex] = 1;
+ for (let axis = 0; axis < 3; axis++) point[axis] = mesh.positions[vertex * 3 + axis];
+ farthest = Math.max(farthest, surface.query(point).distance);
+ }
+ return farthest;
+}
+
+/**
+ * How far two surfaces are apart, measured at vertices in both directions: `toReference` is the farthest vertex of
+ * `mesh` from `reference`, `fromReference` the other way, and `hausdorff` the larger of the two.
+ */
+export function surfaceDeviation(mesh, reference) {
+ const toReference = farthestVertex(mesh, createSurfaceDistance(reference));
+ const fromReference = farthestVertex(reference, createSurfaceDistance(mesh));
+ return { toReference, fromReference, hausdorff: Math.max(toReference, fromReference) };
+}
+
+/** Signed volume of a closed polygon mesh; positive when faces wind outward. */
+export function signedVolume(mesh) {
+ const { positions, indices } = triangulatedSurface(mesh);
+ let volume = 0;
+ for (let triangle = 0; triangle < indices.length / 3; triangle++) {
+ const [a, b, c] = [0, 1, 2].map(corner => indices[triangle * 3 + corner] * 3);
+ volume += (
+ positions[a] * (positions[b + 1] * positions[c + 2] - positions[b + 2] * positions[c + 1]) +
+ positions[a + 1] * (positions[b + 2] * positions[c] - positions[b] * positions[c + 2]) +
+ positions[a + 2] * (positions[b] * positions[c + 1] - positions[b + 1] * positions[c])
+ ) / 6;
+ }
+ return volume;
+}
diff --git a/src/mesh.js b/src/mesh.js
index de822ebf..4453b964 100644
--- a/src/mesh.js
+++ b/src/mesh.js
@@ -17,6 +17,10 @@ export { mirrorMesh, arrayMesh, solidifyMesh, removeCoincidentFaces } from './me
export { bevelEdges, selectEdges } from './mesh-bevel.js';
export { loopCut } from './mesh-loopcut.js';
export { unwrapUv } from './mesh-uv.js';
+export { decimateMesh } from './mesh-decimate.js';
+export { remeshMesh, MAX_REMESH_RESOLUTION, MAX_REMESH_CELLS } from './mesh-remesh.js';
+export { generateMeshLods, generateGeometryLods, generateAssetLods, DEFAULT_LOD_RATIOS } from './mesh-lod.js';
+export { surfaceDeviation, signedVolume } from './mesh-surface-distance.js';
export { loadMeshBooleans, meshBooleansLoaded, meshBoolean, BOOLEAN_OPERATIONS } from './mesh-boolean.js';
export {
extrudeFaceRegion, extrudeIndividual, insetRegion, insetIndividual, deleteFaces, flipFaces, translateFaces,
diff --git a/tests/blender-golden.test.js b/tests/blender-golden.test.js
index 3341f191..cc44920e 100644
--- a/tests/blender-golden.test.js
+++ b/tests/blender-golden.test.js
@@ -4,6 +4,7 @@ import test from 'node:test';
import { createMeshData } from '../src/mesh.js';
import { loadMeshBooleans } from '../src/mesh-boolean.js';
import { applyMeshEdits } from '../src/mesh-recipe.js';
+import { surfaceDeviation } from '../src/mesh-surface-distance.js';
const FIXTURE_DIRECTORY = new URL('./fixtures/blender/', import.meta.url);
const readFixture = name => JSON.parse(readFileSync(new URL(name, FIXTURE_DIRECTORY), 'utf8'));
@@ -14,6 +15,16 @@ const knownDifferences = readFixture('differences.json');
const POSITION_TOLERANCE = 1e-3;
const MEASURE_TOLERANCE = 1e-3;
const METRICS = ['vertexCount', 'edgeCount', 'faceCount', 'faceSizes', 'volume', 'area', 'positions'];
+// Decimate and remesh approximate their input, so their face counts differ. They are compared by surface: the volume
+// and area within 1.5%, the face count within 2%, and the Hausdorff distance to the input, which must not exceed Blender's by
+// more than a quarter plus a thousandth of a unit.
+const SURFACE_METRICS = ['faceCount', 'volume', 'area', 'hausdorff'];
+const SURFACE_FACE_COUNT_TOLERANCE = 0.02;
+const SURFACE_MEASURE_TOLERANCE = 0.015;
+const HAUSDORFF_FACTOR = 1.25;
+const HAUSDORFF_SLACK = 1e-3;
+const exactCases = cases.filter(({ compare }) => compare !== 'surface');
+const surfaceCases = cases.filter(({ compare }) => compare === 'surface');
await loadMeshBooleans();
@@ -123,13 +134,44 @@ test('every listed difference names a case and a metric', () => {
for (const [id, differences] of Object.entries(knownDifferences)) {
assert.ok(ids.has(id), `Unknown case ${id}`);
for (const [metric, reason] of Object.entries(differences)) {
- assert.ok(METRICS.includes(metric), `Unknown metric ${metric} on ${id}`);
+ assert.ok([...METRICS, 'hausdorff'].includes(metric), `Unknown metric ${metric} on ${id}`);
assert.ok(reason.length > 20, `${id} ${metric} needs a reason`);
}
}
});
-for (const blenderCase of cases) {
+function surfaceMetricDifference(metric, actual, expected) {
+ if (metric === 'hausdorff') {
+ return actual > expected * HAUSDORFF_FACTOR + HAUSDORFF_SLACK ? `${actual.toFixed(5)} against Blender's ${expected.toFixed(5)}` : null;
+ }
+ const tolerance = metric === 'faceCount' ? SURFACE_FACE_COUNT_TOLERANCE : SURFACE_MEASURE_TOLERANCE;
+ const relative = Math.abs(actual - expected) / Math.max(expected, 1e-9);
+ return relative > tolerance ? `${actual.toFixed(5)} against ${expected.toFixed(5)}` : null;
+}
+
+for (const blenderCase of surfaceCases) {
+ test(`${blenderCase.id} is as close to its input as Blender's, apart from its listed differences`, () => {
+ const output = runCase(blenderCase);
+ const measured = measure(output);
+ const actual = {
+ faceCount: measured.faceCount,
+ volume: measured.volume,
+ area: measured.area,
+ hausdorff: surfaceDeviation(output, meshFromInput(inputs[blenderCase.input])).hausdorff,
+ };
+ const expected = golden.results[blenderCase.id];
+ const listed = knownDifferences[blenderCase.id] ?? {};
+ const problems = [];
+ for (const metric of SURFACE_METRICS) {
+ const difference = surfaceMetricDifference(metric, actual[metric], expected[metric]);
+ if (listed[metric] && !difference) problems.push(`${metric} now matches Blender, so remove it from differences.json`);
+ if (!listed[metric] && difference) problems.push(`${metric}: ${difference}`);
+ }
+ assert.deepEqual(problems, []);
+ });
+}
+
+for (const blenderCase of exactCases) {
test(`${blenderCase.id} matches Blender, apart from its listed differences`, () => {
const actual = measure(runCase(blenderCase));
const expected = golden.results[blenderCase.id];
diff --git a/tests/fixtures/blender/cases.json b/tests/fixtures/blender/cases.json
index ca208d30..e7a3a22e 100644
--- a/tests/fixtures/blender/cases.json
+++ b/tests/fixtures/blender/cases.json
@@ -28,7 +28,19 @@
"cube-cut": {"vertices":[[-0.5,-0.5,-0.5],[0.5,-0.5,-0.5],[0.5,0.5,-0.5],[-0.5,0.5,-0.5],[-0.5,-0.5,0.5],[0.5,-0.5,0.5],[0.5,0.5,0.5],[-0.5,0.5,0.5],[-0.5,-0.5,0],[0.5,-0.5,0],[0.5,0.5,0],[-0.5,0.5,0]],"faces":[[0,3,2,1],[4,5,6,7],[0,1,9,8],[8,9,5,4],[1,2,10,9],[9,10,6,5],[2,3,11,10],[10,11,7,6],[3,0,8,11],[11,8,4,7]]},
"grid-hole": {"vertices":[[0,0,0],[1,0,0],[2,0,0],[3,0,0],[4,0,0],[0,1,0],[1,1,0],[2,1,0],[3,1,0],[4,1,0],[0,2,0],[1,2,0],[3,2,0],[4,2,0],[0,3,0],[1,3,0],[2,3,0],[3,3,0],[4,3,0],[0,4,0],[1,4,0],[2,4,0],[3,4,0],[4,4,0]],"faces":[[0,1,6,5],[1,2,7,6],[2,3,8,7],[3,4,9,8],[5,6,11,10],[8,9,13,12],[10,11,15,14],[12,13,18,17],[14,15,20,19],[15,16,21,20],[16,17,22,21],[17,18,23,22]]},
"square-midpoint": {"vertices":[[0,0,0],[2,0,0],[2,2,0],[0,2,0],[1,0,0]],"faces":[[0,4,1,2,3]]},
- "cylinder-open": {"vertices":[[1,0,-1],[0.70710678,0.70710678,-1],[0,1,-1],[-0.70710678,0.70710678,-1],[-1,0,-1],[-0.70710678,-0.70710678,-1],[0,-1,-1],[0.70710678,-0.70710678,-1],[1,0,1],[0.70710678,0.70710678,1],[0,1,1],[-0.70710678,0.70710678,1],[-1,0,1],[-0.70710678,-0.70710678,1],[0,-1,1],[0.70710678,-0.70710678,1]],"faces":[[0,1,9,8],[1,2,10,9],[2,3,11,10],[3,4,12,11],[4,5,13,12],[5,6,14,13],[6,7,15,14],[7,0,8,15],[7,6,5,4,3,2,1,0]]}
+ "cylinder-open": {"vertices":[[1,0,-1],[0.70710678,0.70710678,-1],[0,1,-1],[-0.70710678,0.70710678,-1],[-1,0,-1],[-0.70710678,-0.70710678,-1],[0,-1,-1],[0.70710678,-0.70710678,-1],[1,0,1],[0.70710678,0.70710678,1],[0,1,1],[-0.70710678,0.70710678,1],[-1,0,1],[-0.70710678,-0.70710678,1],[0,-1,1],[0.70710678,-0.70710678,1]],"faces":[[0,1,9,8],[1,2,10,9],[2,3,11,10],[3,4,12,11],[4,5,13,12],[5,6,14,13],[6,7,15,14],[7,0,8,15],[7,6,5,4,3,2,1,0]]},
+ "sphere-bumpy": {
+ "vertices": [[0,0,1],[0.15643,0,0.98769],[0.16093,0.03201,1.03596],[0.15238,0.06312,1.04132],[0.13156,0.08791,0.99901],[0.10602,0.10602,0.94664],[0.0819,0.12257,0.93075],[0.05852,0.14128,0.96547],[0.03152,0.15844,1.01994],[0,0.16563,1.04574],[-0.03152,0.15844,1.01994],[-0.05852,0.14128,0.96547],[-0.0819,0.12257,0.93075],[-0.10602,0.10602,0.94664],[-0.13156,0.08791,0.99901],[-0.15238,0.06312,1.04132],[-0.16093,0.03201,1.03596],[-0.15643,0,0.98769],[-0.14593,-0.02903,0.93942],[-0.13668,-0.05661,0.93405],[-0.12858,-0.08591,0.97636],[-0.11521,-0.11521,1.02874],[-0.09192,-0.13757,1.04463],[-0.06121,-0.14778,1.0099],[-0.02952,-0.14842,0.95543],[0,-0.14724,0.92963],[0.02952,-0.14842,0.95543],[0.06121,-0.14778,1.0099],[0.09192,-0.13757,1.04463],[0.11521,-0.11521,1.02874],[0.12858,-0.08591,0.97636],[0.13668,-0.05661,0.93405],[0.14593,-0.02903,0.93942],[0.30902,0,0.95106],[0.32705,0.06505,1.02626],[0.31058,0.12865,1.03462],[0.26171,0.17487,0.9687],[0.20381,0.20381,0.8871],[0.15567,0.23297,0.86234],[0.11395,0.2751,0.91644],[0.06347,0.31909,1.00131],[0,0.33841,1.04151],[-0.06347,0.31909,1.00131],[-0.11395,0.2751,0.91644],[-0.15567,0.23297,0.86234],[-0.20381,0.20381,0.8871],[-0.26171,0.17487,0.9687],[-0.31058,0.12865,1.03462],[-0.32705,0.06505,1.02626],[-0.30902,0,0.95106],[-0.27911,-0.05552,0.87585],[-0.26041,-0.10787,0.86749],[-0.25217,-0.1685,0.93341],[-0.2332,-0.2332,1.01501],[-0.18769,-0.2809,1.03977],[-0.12256,-0.29589,0.98567],[-0.0571,-0.28707,0.9008],[0,-0.27963,0.86061],[0.0571,-0.28707,0.9008],[0.12256,-0.29589,0.98567],[0.18769,-0.2809,1.03977],[0.2332,-0.2332,1.01501],[0.25217,-0.1685,0.93341],[0.26041,-0.10787,0.86749],[0.27911,-0.05552,0.87585],[0.45399,0,0.89101],[0.48048,0.09557,0.96147],[0.45629,0.189,0.9693],[0.38448,0.2569,0.90754],[0.29943,0.29943,0.83109],[0.2287,0.34227,0.8079],[0.16741,0.40417,0.85858],[0.09325,0.46879,0.93809],[0,0.49717,0.97575],[-0.09325,0.46879,0.93809],[-0.16741,0.40417,0.85858],[-0.2287,0.34227,0.8079],[-0.29943,0.29943,0.83109],[-0.38448,0.2569,0.90754],[-0.45629,0.189,0.9693],[-0.48048,0.09557,0.96147],[-0.45399,0,0.89101],[-0.41006,-0.08157,0.82055],[-0.38258,-0.15847,0.81272],[-0.37048,-0.24754,0.87447],[-0.34261,-0.34261,0.95093],[-0.27575,-0.41269,0.97412],[-0.18006,-0.4347,0.92344],[-0.08389,-0.42174,0.84393],[0,-0.41081,0.80627],[0.08389,-0.42174,0.84393],[0.18006,-0.4347,0.92344],[0.27575,-0.41269,0.97412],[0.34261,-0.34261,0.95093],[0.37048,-0.24754,0.87447],[0.38258,-0.15847,0.81272],[0.41006,-0.08157,0.82055],[0.58779,0,0.80902],[0.60467,0.12028,0.84856],[0.57253,0.23715,0.85295],[0.49433,0.3303,0.81829],[0.39835,0.39835,0.77539],[0.30773,0.46055,0.76238],[0.21988,0.53083,0.79082],[0.11842,0.59532,0.83544],[0,0.62233,0.85657],[-0.11842,0.59532,0.83544],[-0.21988,0.53083,0.79082],[-0.30773,0.46055,0.76238],[-0.39835,0.39835,0.77539],[-0.49433,0.3303,0.81829],[-0.57253,0.23715,0.85295],[-0.60467,0.12028,0.84856],[-0.58779,0,0.80902],[-0.54832,-0.10907,0.76948],[-0.51355,-0.21272,0.76508],[-0.48312,-0.32281,0.79974],[-0.4329,-0.4329,0.84264],[-0.34538,-0.5169,0.85566],[-0.23,-0.55526,0.82721],[-0.11093,-0.55767,0.7826],[0,-0.55324,0.76146],[0.11093,-0.55767,0.7826],[0.23,-0.55526,0.82721],[0.34538,-0.5169,0.85566],[0.4329,-0.4329,0.84264],[0.48312,-0.32281,0.79974],[0.51355,-0.21272,0.76508],[0.54832,-0.10907,0.76948],[0.70711,0,0.70711],[0.69352,0.13795,0.70711],[0.65328,0.2706,0.70711],[0.58794,0.39285,0.70711],[0.5,0.5,0.70711],[0.39285,0.58794,0.70711],[0.2706,0.65328,0.70711],[0.13795,0.69352,0.70711],[0,0.70711,0.70711],[-0.13795,0.69352,0.70711],[-0.2706,0.65328,0.70711],[-0.39285,0.58794,0.70711],[-0.5,0.5,0.70711],[-0.58794,0.39285,0.70711],[-0.65328,0.2706,0.70711],[-0.69352,0.13795,0.70711],[-0.70711,0,0.70711],[-0.69352,-0.13795,0.70711],[-0.65328,-0.2706,0.70711],[-0.58794,-0.39285,0.70711],[-0.5,-0.5,0.70711],[-0.39285,-0.58794,0.70711],[-0.2706,-0.65328,0.70711],[-0.13795,-0.69352,0.70711],[0,-0.70711,0.70711],[0.13795,-0.69352,0.70711],[0.2706,-0.65328,0.70711],[0.39285,-0.58794,0.70711],[0.5,-0.5,0.70711],[0.58794,-0.39285,0.70711],[0.65328,-0.2706,0.70711],[0.69352,-0.13795,0.70711],[0.80902,0,0.58779],[0.75469,0.15012,0.55906],[0.70685,0.29278,0.55587],[0.66496,0.44431,0.58105],[0.59584,0.59584,0.61222],[0.47538,0.71145,0.62167],[0.31656,0.76425,0.60101],[0.15268,0.76756,0.56859],[0,0.76146,0.55324],[-0.15268,0.76756,0.56859],[-0.31656,0.76425,0.60101],[-0.47538,0.71145,0.62167],[-0.59584,0.59584,0.61222],[-0.66496,0.44431,0.58105],[-0.70685,0.29278,0.55587],[-0.75469,0.15012,0.55906],[-0.80902,0,0.58779],[-0.83225,-0.16555,0.61651],[-0.78802,-0.32641,0.6197],[-0.68039,-0.45462,0.59453],[-0.54828,-0.54828,0.56336],[-0.42355,-0.63389,0.5539],[-0.30263,-0.73062,0.57456],[-0.16299,-0.81938,0.60698],[0,-0.85657,0.62233],[0.16299,-0.81938,0.60698],[0.30263,-0.73062,0.57456],[0.42355,-0.63389,0.5539],[0.54828,-0.54828,0.56336],[0.68039,-0.45462,0.59453],[0.78802,-0.32641,0.6197],[0.83225,-0.16555,0.61651],[0.89101,0,0.45399],[0.80478,0.16008,0.41809],[0.75085,0.31101,0.4141],[0.7271,0.48583,0.44557],[0.67241,0.67241,0.48452],[0.54119,0.80995,0.49634],[0.35338,0.85314,0.47051],[0.16464,0.82771,0.43],[0,0.80627,0.41081],[-0.16464,0.82771,0.43],[-0.35338,0.85314,0.47051],[-0.54119,0.80995,0.49634],[-0.67241,0.67241,0.48452],[-0.7271,0.48583,0.44557],[-0.75085,0.31101,0.4141],[-0.80478,0.16008,0.41809],[-0.89101,0,0.45399],[-0.94299,-0.18757,0.48989],[-0.89551,-0.37093,0.49388],[-0.75459,-0.5042,0.46241],[-0.58767,-0.58767,0.42346],[-0.44884,-0.67174,0.41164],[-0.32856,-0.79322,0.43747],[-0.18301,-0.92006,0.47798],[0,-0.97575,0.49717],[0.18301,-0.92006,0.47798],[0.32856,-0.79322,0.43747],[0.44884,-0.67174,0.41164],[0.58767,-0.58767,0.42346],[0.75459,-0.5042,0.46241],[0.89551,-0.37093,0.49388],[0.94299,-0.18757,0.48989],[0.95106,0,0.30902],[0.85902,0.17087,0.28458],[0.80146,0.33197,0.28186],[0.7761,0.51858,0.30328],[0.71772,0.71772,0.3298],[0.57766,0.86454,0.33784],[0.3772,0.91064,0.32026],[0.17574,0.8835,0.29269],[0,0.86061,0.27963],[-0.17574,0.8835,0.29269],[-0.3772,0.91064,0.32026],[-0.57766,0.86454,0.33784],[-0.71772,0.71772,0.3298],[-0.7761,0.51858,0.30328],[-0.80146,0.33197,0.28186],[-0.85902,0.17087,0.28458],[-0.95106,0,0.30902],[-1.00654,-0.20021,0.33345],[-0.95587,-0.39593,0.33617],[-0.80545,-0.53818,0.31475],[-0.62727,-0.62727,0.28824],[-0.47909,-0.71701,0.28019],[-0.35071,-0.84668,0.29777],[-0.19535,-0.98207,0.32534],[0,-1.04151,0.33841],[0.19535,-0.98207,0.32534],[0.35071,-0.84668,0.29777],[0.47909,-0.71701,0.28019],[0.62727,-0.62727,0.28824],[0.80545,-0.53818,0.31475],[0.95587,-0.39593,0.33617],[1.00654,-0.20021,0.33345],[0.98769,0,0.15643],[0.92137,0.18327,0.14879],[0.86295,0.35745,0.14794],[0.81182,0.54244,0.15464],[0.72743,0.72743,0.16294],[0.58036,0.86858,0.16545],[0.38647,0.93303,0.15995],[0.1864,0.93708,0.15133],[0,0.92963,0.14724],[-0.1864,0.93708,0.15133],[-0.38647,0.93303,0.15995],[-0.58036,0.86858,0.16545],[-0.72743,0.72743,0.16294],[-0.81182,0.54244,0.15464],[-0.86295,0.35745,0.14794],[-0.92137,0.18327,0.14879],[-0.98769,0,0.15643],[-1.01605,-0.20211,0.16408],[-0.96206,-0.3985,0.16493],[-0.83065,-0.55502,0.15823],[-0.66937,-0.66937,0.14993],[-0.5171,-0.77389,0.14742],[-0.36947,-0.89198,0.15292],[-0.19898,-1.00034,0.16154],[0,-1.04574,0.16563],[0.19898,-1.00034,0.16154],[0.36947,-0.89198,0.15292],[0.5171,-0.77389,0.14742],[0.66937,-0.66937,0.14993],[0.83065,-0.55502,0.15823],[0.96206,-0.3985,0.16493],[1.01605,-0.20211,0.16408],[1,0,0],[0.98079,0.19509,0],[0.92388,0.38268,0],[0.83147,0.55557,0],[0.70711,0.70711,0],[0.55557,0.83147,0],[0.38268,0.92388,0],[0.19509,0.98079,0],[0,1,0],[-0.19509,0.98079,0],[-0.38268,0.92388,0],[-0.55557,0.83147,0],[-0.70711,0.70711,0],[-0.83147,0.55557,0],[-0.92388,0.38268,0],[-0.98079,0.19509,0],[-1,0,0],[-0.98079,-0.19509,0],[-0.92388,-0.38268,0],[-0.83147,-0.55557,0],[-0.70711,-0.70711,0],[-0.55557,-0.83147,0],[-0.38268,-0.92388,0],[-0.19509,-0.98079,0],[0,-1,0],[0.19509,-0.98079,0],[0.38268,-0.92388,0],[0.55557,-0.83147,0],[0.70711,-0.70711,0],[0.83147,-0.55557,0],[0.92388,-0.38268,0],[0.98079,-0.19509,0],[0.98769,0,-0.15643],[1.01605,0.20211,-0.16408],[0.96206,0.3985,-0.16493],[0.83065,0.55502,-0.15823],[0.66937,0.66937,-0.14993],[0.5171,0.77389,-0.14742],[0.36947,0.89198,-0.15292],[0.19898,1.00034,-0.16154],[0,1.04574,-0.16563],[-0.19898,1.00034,-0.16154],[-0.36947,0.89198,-0.15292],[-0.5171,0.77389,-0.14742],[-0.66937,0.66937,-0.14993],[-0.83065,0.55502,-0.15823],[-0.96206,0.3985,-0.16493],[-1.01605,0.20211,-0.16408],[-0.98769,0,-0.15643],[-0.92137,-0.18327,-0.14879],[-0.86295,-0.35745,-0.14794],[-0.81182,-0.54244,-0.15464],[-0.72743,-0.72743,-0.16294],[-0.58036,-0.86858,-0.16545],[-0.38647,-0.93303,-0.15995],[-0.1864,-0.93708,-0.15133],[0,-0.92963,-0.14724],[0.1864,-0.93708,-0.15133],[0.38647,-0.93303,-0.15995],[0.58036,-0.86858,-0.16545],[0.72743,-0.72743,-0.16294],[0.81182,-0.54244,-0.15464],[0.86295,-0.35745,-0.14794],[0.92137,-0.18327,-0.14879],[0.95106,0,-0.30902],[1.00654,0.20021,-0.33345],[0.95587,0.39593,-0.33617],[0.80545,0.53818,-0.31475],[0.62727,0.62727,-0.28824],[0.47909,0.71701,-0.28019],[0.35071,0.84668,-0.29777],[0.19535,0.98207,-0.32534],[0,1.04151,-0.33841],[-0.19535,0.98207,-0.32534],[-0.35071,0.84668,-0.29777],[-0.47909,0.71701,-0.28019],[-0.62727,0.62727,-0.28824],[-0.80545,0.53818,-0.31475],[-0.95587,0.39593,-0.33617],[-1.00654,0.20021,-0.33345],[-0.95106,0,-0.30902],[-0.85902,-0.17087,-0.28458],[-0.80146,-0.33197,-0.28186],[-0.7761,-0.51858,-0.30328],[-0.71772,-0.71772,-0.3298],[-0.57766,-0.86454,-0.33784],[-0.3772,-0.91064,-0.32026],[-0.17574,-0.8835,-0.29269],[0,-0.86061,-0.27963],[0.17574,-0.8835,-0.29269],[0.3772,-0.91064,-0.32026],[0.57766,-0.86454,-0.33784],[0.71772,-0.71772,-0.3298],[0.7761,-0.51858,-0.30328],[0.80146,-0.33197,-0.28186],[0.85902,-0.17087,-0.28458],[0.89101,0,-0.45399],[0.94299,0.18757,-0.48989],[0.89551,0.37093,-0.49388],[0.75459,0.5042,-0.46241],[0.58767,0.58767,-0.42346],[0.44884,0.67174,-0.41164],[0.32856,0.79322,-0.43747],[0.18301,0.92006,-0.47798],[0,0.97575,-0.49717],[-0.18301,0.92006,-0.47798],[-0.32856,0.79322,-0.43747],[-0.44884,0.67174,-0.41164],[-0.58767,0.58767,-0.42346],[-0.75459,0.5042,-0.46241],[-0.89551,0.37093,-0.49388],[-0.94299,0.18757,-0.48989],[-0.89101,0,-0.45399],[-0.80478,-0.16008,-0.41809],[-0.75085,-0.31101,-0.4141],[-0.7271,-0.48583,-0.44557],[-0.67241,-0.67241,-0.48452],[-0.54119,-0.80995,-0.49634],[-0.35338,-0.85314,-0.47051],[-0.16464,-0.82771,-0.43],[0,-0.80627,-0.41081],[0.16464,-0.82771,-0.43],[0.35338,-0.85314,-0.47051],[0.54119,-0.80995,-0.49634],[0.67241,-0.67241,-0.48452],[0.7271,-0.48583,-0.44557],[0.75085,-0.31101,-0.4141],[0.80478,-0.16008,-0.41809],[0.80902,0,-0.58779],[0.83225,0.16555,-0.61651],[0.78802,0.32641,-0.6197],[0.68039,0.45462,-0.59453],[0.54828,0.54828,-0.56336],[0.42355,0.63389,-0.5539],[0.30263,0.73062,-0.57456],[0.16299,0.81938,-0.60698],[0,0.85657,-0.62233],[-0.16299,0.81938,-0.60698],[-0.30263,0.73062,-0.57456],[-0.42355,0.63389,-0.5539],[-0.54828,0.54828,-0.56336],[-0.68039,0.45462,-0.59453],[-0.78802,0.32641,-0.6197],[-0.83225,0.16555,-0.61651],[-0.80902,0,-0.58779],[-0.75469,-0.15012,-0.55906],[-0.70685,-0.29278,-0.55587],[-0.66496,-0.44431,-0.58105],[-0.59584,-0.59584,-0.61222],[-0.47538,-0.71145,-0.62167],[-0.31656,-0.76425,-0.60101],[-0.15268,-0.76756,-0.56859],[0,-0.76146,-0.55324],[0.15268,-0.76756,-0.56859],[0.31656,-0.76425,-0.60101],[0.47538,-0.71145,-0.62167],[0.59584,-0.59584,-0.61222],[0.66496,-0.44431,-0.58105],[0.70685,-0.29278,-0.55587],[0.75469,-0.15012,-0.55906],[0.70711,0,-0.70711],[0.69352,0.13795,-0.70711],[0.65328,0.2706,-0.70711],[0.58794,0.39285,-0.70711],[0.5,0.5,-0.70711],[0.39285,0.58794,-0.70711],[0.2706,0.65328,-0.70711],[0.13795,0.69352,-0.70711],[0,0.70711,-0.70711],[-0.13795,0.69352,-0.70711],[-0.2706,0.65328,-0.70711],[-0.39285,0.58794,-0.70711],[-0.5,0.5,-0.70711],[-0.58794,0.39285,-0.70711],[-0.65328,0.2706,-0.70711],[-0.69352,0.13795,-0.70711],[-0.70711,0,-0.70711],[-0.69352,-0.13795,-0.70711],[-0.65328,-0.2706,-0.70711],[-0.58794,-0.39285,-0.70711],[-0.5,-0.5,-0.70711],[-0.39285,-0.58794,-0.70711],[-0.2706,-0.65328,-0.70711],[-0.13795,-0.69352,-0.70711],[0,-0.70711,-0.70711],[0.13795,-0.69352,-0.70711],[0.2706,-0.65328,-0.70711],[0.39285,-0.58794,-0.70711],[0.5,-0.5,-0.70711],[0.58794,-0.39285,-0.70711],[0.65328,-0.2706,-0.70711],[0.69352,-0.13795,-0.70711],[0.58779,0,-0.80902],[0.54832,0.10907,-0.76948],[0.51355,0.21272,-0.76508],[0.48312,0.32281,-0.79974],[0.4329,0.4329,-0.84264],[0.34538,0.5169,-0.85566],[0.23,0.55526,-0.82721],[0.11093,0.55767,-0.7826],[0,0.55324,-0.76146],[-0.11093,0.55767,-0.7826],[-0.23,0.55526,-0.82721],[-0.34538,0.5169,-0.85566],[-0.4329,0.4329,-0.84264],[-0.48312,0.32281,-0.79974],[-0.51355,0.21272,-0.76508],[-0.54832,0.10907,-0.76948],[-0.58779,0,-0.80902],[-0.60467,-0.12028,-0.84856],[-0.57253,-0.23715,-0.85295],[-0.49433,-0.3303,-0.81829],[-0.39835,-0.39835,-0.77539],[-0.30773,-0.46055,-0.76238],[-0.21988,-0.53083,-0.79082],[-0.11842,-0.59532,-0.83544],[0,-0.62233,-0.85657],[0.11842,-0.59532,-0.83544],[0.21988,-0.53083,-0.79082],[0.30773,-0.46055,-0.76238],[0.39835,-0.39835,-0.77539],[0.49433,-0.3303,-0.81829],[0.57253,-0.23715,-0.85295],[0.60467,-0.12028,-0.84856],[0.45399,0,-0.89101],[0.41006,0.08157,-0.82055],[0.38258,0.15847,-0.81272],[0.37048,0.24754,-0.87447],[0.34261,0.34261,-0.95093],[0.27575,0.41269,-0.97412],[0.18006,0.4347,-0.92344],[0.08389,0.42174,-0.84393],[0,0.41081,-0.80627],[-0.08389,0.42174,-0.84393],[-0.18006,0.4347,-0.92344],[-0.27575,0.41269,-0.97412],[-0.34261,0.34261,-0.95093],[-0.37048,0.24754,-0.87447],[-0.38258,0.15847,-0.81272],[-0.41006,0.08157,-0.82055],[-0.45399,0,-0.89101],[-0.48048,-0.09557,-0.96147],[-0.45629,-0.189,-0.9693],[-0.38448,-0.2569,-0.90754],[-0.29943,-0.29943,-0.83109],[-0.2287,-0.34227,-0.8079],[-0.16741,-0.40417,-0.85858],[-0.09325,-0.46879,-0.93809],[0,-0.49717,-0.97575],[0.09325,-0.46879,-0.93809],[0.16741,-0.40417,-0.85858],[0.2287,-0.34227,-0.8079],[0.29943,-0.29943,-0.83109],[0.38448,-0.2569,-0.90754],[0.45629,-0.189,-0.9693],[0.48048,-0.09557,-0.96147],[0.30902,0,-0.95106],[0.27911,0.05552,-0.87585],[0.26041,0.10787,-0.86749],[0.25217,0.1685,-0.93341],[0.2332,0.2332,-1.01501],[0.18769,0.2809,-1.03977],[0.12256,0.29589,-0.98567],[0.0571,0.28707,-0.9008],[0,0.27963,-0.86061],[-0.0571,0.28707,-0.9008],[-0.12256,0.29589,-0.98567],[-0.18769,0.2809,-1.03977],[-0.2332,0.2332,-1.01501],[-0.25217,0.1685,-0.93341],[-0.26041,0.10787,-0.86749],[-0.27911,0.05552,-0.87585],[-0.30902,0,-0.95106],[-0.32705,-0.06505,-1.02626],[-0.31058,-0.12865,-1.03462],[-0.26171,-0.17487,-0.9687],[-0.20381,-0.20381,-0.8871],[-0.15567,-0.23297,-0.86234],[-0.11395,-0.2751,-0.91644],[-0.06347,-0.31909,-1.00131],[0,-0.33841,-1.04151],[0.06347,-0.31909,-1.00131],[0.11395,-0.2751,-0.91644],[0.15567,-0.23297,-0.86234],[0.20381,-0.20381,-0.8871],[0.26171,-0.17487,-0.9687],[0.31058,-0.12865,-1.03462],[0.32705,-0.06505,-1.02626],[0.15643,0,-0.98769],[0.14593,0.02903,-0.93942],[0.13668,0.05661,-0.93405],[0.12858,0.08591,-0.97636],[0.11521,0.11521,-1.02874],[0.09192,0.13757,-1.04463],[0.06121,0.14778,-1.0099],[0.02952,0.14842,-0.95543],[0,0.14724,-0.92963],[-0.02952,0.14842,-0.95543],[-0.06121,0.14778,-1.0099],[-0.09192,0.13757,-1.04463],[-0.11521,0.11521,-1.02874],[-0.12858,0.08591,-0.97636],[-0.13668,0.05661,-0.93405],[-0.14593,0.02903,-0.93942],[-0.15643,0,-0.98769],[-0.16093,-0.03201,-1.03596],[-0.15238,-0.06312,-1.04132],[-0.13156,-0.08791,-0.99901],[-0.10602,-0.10602,-0.94664],[-0.0819,-0.12257,-0.93075],[-0.05852,-0.14128,-0.96547],[-0.03152,-0.15844,-1.01994],[0,-0.16563,-1.04574],[0.03152,-0.15844,-1.01994],[0.05852,-0.14128,-0.96547],[0.0819,-0.12257,-0.93075],[0.10602,-0.10602,-0.94664],[0.13156,-0.08791,-0.99901],[0.15238,-0.06312,-1.04132],[0.16093,-0.03201,-1.03596],[0,0,-1]],
+ "faces": [[0,1,2],[0,2,3],[0,3,4],[0,4,5],[0,5,6],[0,6,7],[0,7,8],[0,8,9],[0,9,10],[0,10,11],[0,11,12],[0,12,13],[0,13,14],[0,14,15],[0,15,16],[0,16,17],[0,17,18],[0,18,19],[0,19,20],[0,20,21],[0,21,22],[0,22,23],[0,23,24],[0,24,25],[0,25,26],[0,26,27],[0,27,28],[0,28,29],[0,29,30],[0,30,31],[0,31,32],[0,32,1],[1,33,34,2],[2,34,35,3],[3,35,36,4],[4,36,37,5],[5,37,38,6],[6,38,39,7],[7,39,40,8],[8,40,41,9],[9,41,42,10],[10,42,43,11],[11,43,44,12],[12,44,45,13],[13,45,46,14],[14,46,47,15],[15,47,48,16],[16,48,49,17],[17,49,50,18],[18,50,51,19],[19,51,52,20],[20,52,53,21],[21,53,54,22],[22,54,55,23],[23,55,56,24],[24,56,57,25],[25,57,58,26],[26,58,59,27],[27,59,60,28],[28,60,61,29],[29,61,62,30],[30,62,63,31],[31,63,64,32],[32,64,33,1],[33,65,66,34],[34,66,67,35],[35,67,68,36],[36,68,69,37],[37,69,70,38],[38,70,71,39],[39,71,72,40],[40,72,73,41],[41,73,74,42],[42,74,75,43],[43,75,76,44],[44,76,77,45],[45,77,78,46],[46,78,79,47],[47,79,80,48],[48,80,81,49],[49,81,82,50],[50,82,83,51],[51,83,84,52],[52,84,85,53],[53,85,86,54],[54,86,87,55],[55,87,88,56],[56,88,89,57],[57,89,90,58],[58,90,91,59],[59,91,92,60],[60,92,93,61],[61,93,94,62],[62,94,95,63],[63,95,96,64],[64,96,65,33],[65,97,98,66],[66,98,99,67],[67,99,100,68],[68,100,101,69],[69,101,102,70],[70,102,103,71],[71,103,104,72],[72,104,105,73],[73,105,106,74],[74,106,107,75],[75,107,108,76],[76,108,109,77],[77,109,110,78],[78,110,111,79],[79,111,112,80],[80,112,113,81],[81,113,114,82],[82,114,115,83],[83,115,116,84],[84,116,117,85],[85,117,118,86],[86,118,119,87],[87,119,120,88],[88,120,121,89],[89,121,122,90],[90,122,123,91],[91,123,124,92],[92,124,125,93],[93,125,126,94],[94,126,127,95],[95,127,128,96],[96,128,97,65],[97,129,130,98],[98,130,131,99],[99,131,132,100],[100,132,133,101],[101,133,134,102],[102,134,135,103],[103,135,136,104],[104,136,137,105],[105,137,138,106],[106,138,139,107],[107,139,140,108],[108,140,141,109],[109,141,142,110],[110,142,143,111],[111,143,144,112],[112,144,145,113],[113,145,146,114],[114,146,147,115],[115,147,148,116],[116,148,149,117],[117,149,150,118],[118,150,151,119],[119,151,152,120],[120,152,153,121],[121,153,154,122],[122,154,155,123],[123,155,156,124],[124,156,157,125],[125,157,158,126],[126,158,159,127],[127,159,160,128],[128,160,129,97],[129,161,162,130],[130,162,163,131],[131,163,164,132],[132,164,165,133],[133,165,166,134],[134,166,167,135],[135,167,168,136],[136,168,169,137],[137,169,170,138],[138,170,171,139],[139,171,172,140],[140,172,173,141],[141,173,174,142],[142,174,175,143],[143,175,176,144],[144,176,177,145],[145,177,178,146],[146,178,179,147],[147,179,180,148],[148,180,181,149],[149,181,182,150],[150,182,183,151],[151,183,184,152],[152,184,185,153],[153,185,186,154],[154,186,187,155],[155,187,188,156],[156,188,189,157],[157,189,190,158],[158,190,191,159],[159,191,192,160],[160,192,161,129],[161,193,194,162],[162,194,195,163],[163,195,196,164],[164,196,197,165],[165,197,198,166],[166,198,199,167],[167,199,200,168],[168,200,201,169],[169,201,202,170],[170,202,203,171],[171,203,204,172],[172,204,205,173],[173,205,206,174],[174,206,207,175],[175,207,208,176],[176,208,209,177],[177,209,210,178],[178,210,211,179],[179,211,212,180],[180,212,213,181],[181,213,214,182],[182,214,215,183],[183,215,216,184],[184,216,217,185],[185,217,218,186],[186,218,219,187],[187,219,220,188],[188,220,221,189],[189,221,222,190],[190,222,223,191],[191,223,224,192],[192,224,193,161],[193,225,226,194],[194,226,227,195],[195,227,228,196],[196,228,229,197],[197,229,230,198],[198,230,231,199],[199,231,232,200],[200,232,233,201],[201,233,234,202],[202,234,235,203],[203,235,236,204],[204,236,237,205],[205,237,238,206],[206,238,239,207],[207,239,240,208],[208,240,241,209],[209,241,242,210],[210,242,243,211],[211,243,244,212],[212,244,245,213],[213,245,246,214],[214,246,247,215],[215,247,248,216],[216,248,249,217],[217,249,250,218],[218,250,251,219],[219,251,252,220],[220,252,253,221],[221,253,254,222],[222,254,255,223],[223,255,256,224],[224,256,225,193],[225,257,258,226],[226,258,259,227],[227,259,260,228],[228,260,261,229],[229,261,262,230],[230,262,263,231],[231,263,264,232],[232,264,265,233],[233,265,266,234],[234,266,267,235],[235,267,268,236],[236,268,269,237],[237,269,270,238],[238,270,271,239],[239,271,272,240],[240,272,273,241],[241,273,274,242],[242,274,275,243],[243,275,276,244],[244,276,277,245],[245,277,278,246],[246,278,279,247],[247,279,280,248],[248,280,281,249],[249,281,282,250],[250,282,283,251],[251,283,284,252],[252,284,285,253],[253,285,286,254],[254,286,287,255],[255,287,288,256],[256,288,257,225],[257,289,290,258],[258,290,291,259],[259,291,292,260],[260,292,293,261],[261,293,294,262],[262,294,295,263],[263,295,296,264],[264,296,297,265],[265,297,298,266],[266,298,299,267],[267,299,300,268],[268,300,301,269],[269,301,302,270],[270,302,303,271],[271,303,304,272],[272,304,305,273],[273,305,306,274],[274,306,307,275],[275,307,308,276],[276,308,309,277],[277,309,310,278],[278,310,311,279],[279,311,312,280],[280,312,313,281],[281,313,314,282],[282,314,315,283],[283,315,316,284],[284,316,317,285],[285,317,318,286],[286,318,319,287],[287,319,320,288],[288,320,289,257],[289,321,322,290],[290,322,323,291],[291,323,324,292],[292,324,325,293],[293,325,326,294],[294,326,327,295],[295,327,328,296],[296,328,329,297],[297,329,330,298],[298,330,331,299],[299,331,332,300],[300,332,333,301],[301,333,334,302],[302,334,335,303],[303,335,336,304],[304,336,337,305],[305,337,338,306],[306,338,339,307],[307,339,340,308],[308,340,341,309],[309,341,342,310],[310,342,343,311],[311,343,344,312],[312,344,345,313],[313,345,346,314],[314,346,347,315],[315,347,348,316],[316,348,349,317],[317,349,350,318],[318,350,351,319],[319,351,352,320],[320,352,321,289],[321,353,354,322],[322,354,355,323],[323,355,356,324],[324,356,357,325],[325,357,358,326],[326,358,359,327],[327,359,360,328],[328,360,361,329],[329,361,362,330],[330,362,363,331],[331,363,364,332],[332,364,365,333],[333,365,366,334],[334,366,367,335],[335,367,368,336],[336,368,369,337],[337,369,370,338],[338,370,371,339],[339,371,372,340],[340,372,373,341],[341,373,374,342],[342,374,375,343],[343,375,376,344],[344,376,377,345],[345,377,378,346],[346,378,379,347],[347,379,380,348],[348,380,381,349],[349,381,382,350],[350,382,383,351],[351,383,384,352],[352,384,353,321],[353,385,386,354],[354,386,387,355],[355,387,388,356],[356,388,389,357],[357,389,390,358],[358,390,391,359],[359,391,392,360],[360,392,393,361],[361,393,394,362],[362,394,395,363],[363,395,396,364],[364,396,397,365],[365,397,398,366],[366,398,399,367],[367,399,400,368],[368,400,401,369],[369,401,402,370],[370,402,403,371],[371,403,404,372],[372,404,405,373],[373,405,406,374],[374,406,407,375],[375,407,408,376],[376,408,409,377],[377,409,410,378],[378,410,411,379],[379,411,412,380],[380,412,413,381],[381,413,414,382],[382,414,415,383],[383,415,416,384],[384,416,385,353],[385,417,418,386],[386,418,419,387],[387,419,420,388],[388,420,421,389],[389,421,422,390],[390,422,423,391],[391,423,424,392],[392,424,425,393],[393,425,426,394],[394,426,427,395],[395,427,428,396],[396,428,429,397],[397,429,430,398],[398,430,431,399],[399,431,432,400],[400,432,433,401],[401,433,434,402],[402,434,435,403],[403,435,436,404],[404,436,437,405],[405,437,438,406],[406,438,439,407],[407,439,440,408],[408,440,441,409],[409,441,442,410],[410,442,443,411],[411,443,444,412],[412,444,445,413],[413,445,446,414],[414,446,447,415],[415,447,448,416],[416,448,417,385],[417,449,450,418],[418,450,451,419],[419,451,452,420],[420,452,453,421],[421,453,454,422],[422,454,455,423],[423,455,456,424],[424,456,457,425],[425,457,458,426],[426,458,459,427],[427,459,460,428],[428,460,461,429],[429,461,462,430],[430,462,463,431],[431,463,464,432],[432,464,465,433],[433,465,466,434],[434,466,467,435],[435,467,468,436],[436,468,469,437],[437,469,470,438],[438,470,471,439],[439,471,472,440],[440,472,473,441],[441,473,474,442],[442,474,475,443],[443,475,476,444],[444,476,477,445],[445,477,478,446],[446,478,479,447],[447,479,480,448],[448,480,449,417],[449,481,482,450],[450,482,483,451],[451,483,484,452],[452,484,485,453],[453,485,486,454],[454,486,487,455],[455,487,488,456],[456,488,489,457],[457,489,490,458],[458,490,491,459],[459,491,492,460],[460,492,493,461],[461,493,494,462],[462,494,495,463],[463,495,496,464],[464,496,497,465],[465,497,498,466],[466,498,499,467],[467,499,500,468],[468,500,501,469],[469,501,502,470],[470,502,503,471],[471,503,504,472],[472,504,505,473],[473,505,506,474],[474,506,507,475],[475,507,508,476],[476,508,509,477],[477,509,510,478],[478,510,511,479],[479,511,512,480],[480,512,481,449],[481,513,514,482],[482,514,515,483],[483,515,516,484],[484,516,517,485],[485,517,518,486],[486,518,519,487],[487,519,520,488],[488,520,521,489],[489,521,522,490],[490,522,523,491],[491,523,524,492],[492,524,525,493],[493,525,526,494],[494,526,527,495],[495,527,528,496],[496,528,529,497],[497,529,530,498],[498,530,531,499],[499,531,532,500],[500,532,533,501],[501,533,534,502],[502,534,535,503],[503,535,536,504],[504,536,537,505],[505,537,538,506],[506,538,539,507],[507,539,540,508],[508,540,541,509],[509,541,542,510],[510,542,543,511],[511,543,544,512],[512,544,513,481],[513,545,546,514],[514,546,547,515],[515,547,548,516],[516,548,549,517],[517,549,550,518],[518,550,551,519],[519,551,552,520],[520,552,553,521],[521,553,554,522],[522,554,555,523],[523,555,556,524],[524,556,557,525],[525,557,558,526],[526,558,559,527],[527,559,560,528],[528,560,561,529],[529,561,562,530],[530,562,563,531],[531,563,564,532],[532,564,565,533],[533,565,566,534],[534,566,567,535],[535,567,568,536],[536,568,569,537],[537,569,570,538],[538,570,571,539],[539,571,572,540],[540,572,573,541],[541,573,574,542],[542,574,575,543],[543,575,576,544],[544,576,545,513],[545,577,578,546],[546,578,579,547],[547,579,580,548],[548,580,581,549],[549,581,582,550],[550,582,583,551],[551,583,584,552],[552,584,585,553],[553,585,586,554],[554,586,587,555],[555,587,588,556],[556,588,589,557],[557,589,590,558],[558,590,591,559],[559,591,592,560],[560,592,593,561],[561,593,594,562],[562,594,595,563],[563,595,596,564],[564,596,597,565],[565,597,598,566],[566,598,599,567],[567,599,600,568],[568,600,601,569],[569,601,602,570],[570,602,603,571],[571,603,604,572],[572,604,605,573],[573,605,606,574],[574,606,607,575],[575,607,608,576],[576,608,577,545],[609,578,577],[609,579,578],[609,580,579],[609,581,580],[609,582,581],[609,583,582],[609,584,583],[609,585,584],[609,586,585],[609,587,586],[609,588,587],[609,589,588],[609,590,589],[609,591,590],[609,592,591],[609,593,592],[609,594,593],[609,595,594],[609,596,595],[609,597,596],[609,598,597],[609,599,598],[609,600,599],[609,601,600],[609,602,601],[609,603,602],[609,604,603],[609,605,604],[609,606,605],[609,607,606],[609,608,607],[609,577,608]]
+ },
+ "torus-fine": {
+ "vertices": [[1.35,0,0],[1.32336,0,0.13394],[1.24749,0,0.24749],[1.13394,0,0.32336],[1,0,0.35],[0.86606,0,0.32336],[0.75251,0,0.24749],[0.67664,0,0.13394],[0.65,0,0],[0.67664,0,-0.13394],[0.75251,0,-0.24749],[0.86606,0,-0.32336],[1,0,-0.35],[1.13394,0,-0.32336],[1.24749,0,-0.24749],[1.32336,0,-0.13394],[1.32406,0.26337,0],[1.29793,0.25817,0.13394],[1.22352,0.24337,0.24749],[1.11215,0.22122,0.32336],[0.98079,0.19509,0.35],[0.84942,0.16896,0.32336],[0.73805,0.14681,0.24749],[0.66364,0.13201,0.13394],[0.63751,0.12681,0],[0.66364,0.13201,-0.13394],[0.73805,0.14681,-0.24749],[0.84942,0.16896,-0.32336],[0.98079,0.19509,-0.35],[1.11215,0.22122,-0.32336],[1.22352,0.24337,-0.24749],[1.29793,0.25817,-0.13394],[1.24724,0.51662,0],[1.22262,0.50643,0.13394],[1.15253,0.47739,0.24749],[1.04762,0.43394,0.32336],[0.92388,0.38268,0.35],[0.80014,0.33143,0.32336],[0.69523,0.28797,0.24749],[0.62514,0.25894,0.13394],[0.60052,0.24874,0],[0.62514,0.25894,-0.13394],[0.69523,0.28797,-0.24749],[0.80014,0.33143,-0.32336],[0.92388,0.38268,-0.35],[1.04762,0.43394,-0.32336],[1.15253,0.47739,-0.24749],[1.22262,0.50643,-0.13394],[1.12248,0.75002,0],[1.10033,0.73522,0.13394],[1.03725,0.69307,0.24749],[0.94284,0.62998,0.32336],[0.83147,0.55557,0.35],[0.7201,0.48116,0.32336],[0.62569,0.41807,0.24749],[0.56261,0.37592,0.13394],[0.54046,0.36112,0],[0.56261,0.37592,-0.13394],[0.62569,0.41807,-0.24749],[0.7201,0.48116,-0.32336],[0.83147,0.55557,-0.35],[0.94284,0.62998,-0.32336],[1.03725,0.69307,-0.24749],[1.10033,0.73522,-0.13394],[0.95459,0.95459,0],[0.93576,0.93576,0.13394],[0.88211,0.88211,0.24749],[0.80182,0.80182,0.32336],[0.70711,0.70711,0.35],[0.6124,0.6124,0.32336],[0.53211,0.53211,0.24749],[0.47846,0.47846,0.13394],[0.45962,0.45962,0],[0.47846,0.47846,-0.13394],[0.53211,0.53211,-0.24749],[0.6124,0.6124,-0.32336],[0.70711,0.70711,-0.35],[0.80182,0.80182,-0.32336],[0.88211,0.88211,-0.24749],[0.93576,0.93576,-0.13394],[0.75002,1.12248,0],[0.73522,1.10033,0.13394],[0.69307,1.03725,0.24749],[0.62998,0.94284,0.32336],[0.55557,0.83147,0.35],[0.48116,0.7201,0.32336],[0.41807,0.62569,0.24749],[0.37592,0.56261,0.13394],[0.36112,0.54046,0],[0.37592,0.56261,-0.13394],[0.41807,0.62569,-0.24749],[0.48116,0.7201,-0.32336],[0.55557,0.83147,-0.35],[0.62998,0.94284,-0.32336],[0.69307,1.03725,-0.24749],[0.73522,1.10033,-0.13394],[0.51662,1.24724,0],[0.50643,1.22262,0.13394],[0.47739,1.15253,0.24749],[0.43394,1.04762,0.32336],[0.38268,0.92388,0.35],[0.33143,0.80014,0.32336],[0.28797,0.69523,0.24749],[0.25894,0.62514,0.13394],[0.24874,0.60052,0],[0.25894,0.62514,-0.13394],[0.28797,0.69523,-0.24749],[0.33143,0.80014,-0.32336],[0.38268,0.92388,-0.35],[0.43394,1.04762,-0.32336],[0.47739,1.15253,-0.24749],[0.50643,1.22262,-0.13394],[0.26337,1.32406,0],[0.25817,1.29793,0.13394],[0.24337,1.22352,0.24749],[0.22122,1.11215,0.32336],[0.19509,0.98079,0.35],[0.16896,0.84942,0.32336],[0.14681,0.73805,0.24749],[0.13201,0.66364,0.13394],[0.12681,0.63751,0],[0.13201,0.66364,-0.13394],[0.14681,0.73805,-0.24749],[0.16896,0.84942,-0.32336],[0.19509,0.98079,-0.35],[0.22122,1.11215,-0.32336],[0.24337,1.22352,-0.24749],[0.25817,1.29793,-0.13394],[0,1.35,0],[0,1.32336,0.13394],[0,1.24749,0.24749],[0,1.13394,0.32336],[0,1,0.35],[0,0.86606,0.32336],[0,0.75251,0.24749],[0,0.67664,0.13394],[0,0.65,0],[0,0.67664,-0.13394],[0,0.75251,-0.24749],[0,0.86606,-0.32336],[0,1,-0.35],[0,1.13394,-0.32336],[0,1.24749,-0.24749],[0,1.32336,-0.13394],[-0.26337,1.32406,0],[-0.25817,1.29793,0.13394],[-0.24337,1.22352,0.24749],[-0.22122,1.11215,0.32336],[-0.19509,0.98079,0.35],[-0.16896,0.84942,0.32336],[-0.14681,0.73805,0.24749],[-0.13201,0.66364,0.13394],[-0.12681,0.63751,0],[-0.13201,0.66364,-0.13394],[-0.14681,0.73805,-0.24749],[-0.16896,0.84942,-0.32336],[-0.19509,0.98079,-0.35],[-0.22122,1.11215,-0.32336],[-0.24337,1.22352,-0.24749],[-0.25817,1.29793,-0.13394],[-0.51662,1.24724,0],[-0.50643,1.22262,0.13394],[-0.47739,1.15253,0.24749],[-0.43394,1.04762,0.32336],[-0.38268,0.92388,0.35],[-0.33143,0.80014,0.32336],[-0.28797,0.69523,0.24749],[-0.25894,0.62514,0.13394],[-0.24874,0.60052,0],[-0.25894,0.62514,-0.13394],[-0.28797,0.69523,-0.24749],[-0.33143,0.80014,-0.32336],[-0.38268,0.92388,-0.35],[-0.43394,1.04762,-0.32336],[-0.47739,1.15253,-0.24749],[-0.50643,1.22262,-0.13394],[-0.75002,1.12248,0],[-0.73522,1.10033,0.13394],[-0.69307,1.03725,0.24749],[-0.62998,0.94284,0.32336],[-0.55557,0.83147,0.35],[-0.48116,0.7201,0.32336],[-0.41807,0.62569,0.24749],[-0.37592,0.56261,0.13394],[-0.36112,0.54046,0],[-0.37592,0.56261,-0.13394],[-0.41807,0.62569,-0.24749],[-0.48116,0.7201,-0.32336],[-0.55557,0.83147,-0.35],[-0.62998,0.94284,-0.32336],[-0.69307,1.03725,-0.24749],[-0.73522,1.10033,-0.13394],[-0.95459,0.95459,0],[-0.93576,0.93576,0.13394],[-0.88211,0.88211,0.24749],[-0.80182,0.80182,0.32336],[-0.70711,0.70711,0.35],[-0.6124,0.6124,0.32336],[-0.53211,0.53211,0.24749],[-0.47846,0.47846,0.13394],[-0.45962,0.45962,0],[-0.47846,0.47846,-0.13394],[-0.53211,0.53211,-0.24749],[-0.6124,0.6124,-0.32336],[-0.70711,0.70711,-0.35],[-0.80182,0.80182,-0.32336],[-0.88211,0.88211,-0.24749],[-0.93576,0.93576,-0.13394],[-1.12248,0.75002,0],[-1.10033,0.73522,0.13394],[-1.03725,0.69307,0.24749],[-0.94284,0.62998,0.32336],[-0.83147,0.55557,0.35],[-0.7201,0.48116,0.32336],[-0.62569,0.41807,0.24749],[-0.56261,0.37592,0.13394],[-0.54046,0.36112,0],[-0.56261,0.37592,-0.13394],[-0.62569,0.41807,-0.24749],[-0.7201,0.48116,-0.32336],[-0.83147,0.55557,-0.35],[-0.94284,0.62998,-0.32336],[-1.03725,0.69307,-0.24749],[-1.10033,0.73522,-0.13394],[-1.24724,0.51662,0],[-1.22262,0.50643,0.13394],[-1.15253,0.47739,0.24749],[-1.04762,0.43394,0.32336],[-0.92388,0.38268,0.35],[-0.80014,0.33143,0.32336],[-0.69523,0.28797,0.24749],[-0.62514,0.25894,0.13394],[-0.60052,0.24874,0],[-0.62514,0.25894,-0.13394],[-0.69523,0.28797,-0.24749],[-0.80014,0.33143,-0.32336],[-0.92388,0.38268,-0.35],[-1.04762,0.43394,-0.32336],[-1.15253,0.47739,-0.24749],[-1.22262,0.50643,-0.13394],[-1.32406,0.26337,0],[-1.29793,0.25817,0.13394],[-1.22352,0.24337,0.24749],[-1.11215,0.22122,0.32336],[-0.98079,0.19509,0.35],[-0.84942,0.16896,0.32336],[-0.73805,0.14681,0.24749],[-0.66364,0.13201,0.13394],[-0.63751,0.12681,0],[-0.66364,0.13201,-0.13394],[-0.73805,0.14681,-0.24749],[-0.84942,0.16896,-0.32336],[-0.98079,0.19509,-0.35],[-1.11215,0.22122,-0.32336],[-1.22352,0.24337,-0.24749],[-1.29793,0.25817,-0.13394],[-1.35,0,0],[-1.32336,0,0.13394],[-1.24749,0,0.24749],[-1.13394,0,0.32336],[-1,0,0.35],[-0.86606,0,0.32336],[-0.75251,0,0.24749],[-0.67664,0,0.13394],[-0.65,0,0],[-0.67664,0,-0.13394],[-0.75251,0,-0.24749],[-0.86606,0,-0.32336],[-1,0,-0.35],[-1.13394,0,-0.32336],[-1.24749,0,-0.24749],[-1.32336,0,-0.13394],[-1.32406,-0.26337,0],[-1.29793,-0.25817,0.13394],[-1.22352,-0.24337,0.24749],[-1.11215,-0.22122,0.32336],[-0.98079,-0.19509,0.35],[-0.84942,-0.16896,0.32336],[-0.73805,-0.14681,0.24749],[-0.66364,-0.13201,0.13394],[-0.63751,-0.12681,0],[-0.66364,-0.13201,-0.13394],[-0.73805,-0.14681,-0.24749],[-0.84942,-0.16896,-0.32336],[-0.98079,-0.19509,-0.35],[-1.11215,-0.22122,-0.32336],[-1.22352,-0.24337,-0.24749],[-1.29793,-0.25817,-0.13394],[-1.24724,-0.51662,0],[-1.22262,-0.50643,0.13394],[-1.15253,-0.47739,0.24749],[-1.04762,-0.43394,0.32336],[-0.92388,-0.38268,0.35],[-0.80014,-0.33143,0.32336],[-0.69523,-0.28797,0.24749],[-0.62514,-0.25894,0.13394],[-0.60052,-0.24874,0],[-0.62514,-0.25894,-0.13394],[-0.69523,-0.28797,-0.24749],[-0.80014,-0.33143,-0.32336],[-0.92388,-0.38268,-0.35],[-1.04762,-0.43394,-0.32336],[-1.15253,-0.47739,-0.24749],[-1.22262,-0.50643,-0.13394],[-1.12248,-0.75002,0],[-1.10033,-0.73522,0.13394],[-1.03725,-0.69307,0.24749],[-0.94284,-0.62998,0.32336],[-0.83147,-0.55557,0.35],[-0.7201,-0.48116,0.32336],[-0.62569,-0.41807,0.24749],[-0.56261,-0.37592,0.13394],[-0.54046,-0.36112,0],[-0.56261,-0.37592,-0.13394],[-0.62569,-0.41807,-0.24749],[-0.7201,-0.48116,-0.32336],[-0.83147,-0.55557,-0.35],[-0.94284,-0.62998,-0.32336],[-1.03725,-0.69307,-0.24749],[-1.10033,-0.73522,-0.13394],[-0.95459,-0.95459,0],[-0.93576,-0.93576,0.13394],[-0.88211,-0.88211,0.24749],[-0.80182,-0.80182,0.32336],[-0.70711,-0.70711,0.35],[-0.6124,-0.6124,0.32336],[-0.53211,-0.53211,0.24749],[-0.47846,-0.47846,0.13394],[-0.45962,-0.45962,0],[-0.47846,-0.47846,-0.13394],[-0.53211,-0.53211,-0.24749],[-0.6124,-0.6124,-0.32336],[-0.70711,-0.70711,-0.35],[-0.80182,-0.80182,-0.32336],[-0.88211,-0.88211,-0.24749],[-0.93576,-0.93576,-0.13394],[-0.75002,-1.12248,0],[-0.73522,-1.10033,0.13394],[-0.69307,-1.03725,0.24749],[-0.62998,-0.94284,0.32336],[-0.55557,-0.83147,0.35],[-0.48116,-0.7201,0.32336],[-0.41807,-0.62569,0.24749],[-0.37592,-0.56261,0.13394],[-0.36112,-0.54046,0],[-0.37592,-0.56261,-0.13394],[-0.41807,-0.62569,-0.24749],[-0.48116,-0.7201,-0.32336],[-0.55557,-0.83147,-0.35],[-0.62998,-0.94284,-0.32336],[-0.69307,-1.03725,-0.24749],[-0.73522,-1.10033,-0.13394],[-0.51662,-1.24724,0],[-0.50643,-1.22262,0.13394],[-0.47739,-1.15253,0.24749],[-0.43394,-1.04762,0.32336],[-0.38268,-0.92388,0.35],[-0.33143,-0.80014,0.32336],[-0.28797,-0.69523,0.24749],[-0.25894,-0.62514,0.13394],[-0.24874,-0.60052,0],[-0.25894,-0.62514,-0.13394],[-0.28797,-0.69523,-0.24749],[-0.33143,-0.80014,-0.32336],[-0.38268,-0.92388,-0.35],[-0.43394,-1.04762,-0.32336],[-0.47739,-1.15253,-0.24749],[-0.50643,-1.22262,-0.13394],[-0.26337,-1.32406,0],[-0.25817,-1.29793,0.13394],[-0.24337,-1.22352,0.24749],[-0.22122,-1.11215,0.32336],[-0.19509,-0.98079,0.35],[-0.16896,-0.84942,0.32336],[-0.14681,-0.73805,0.24749],[-0.13201,-0.66364,0.13394],[-0.12681,-0.63751,0],[-0.13201,-0.66364,-0.13394],[-0.14681,-0.73805,-0.24749],[-0.16896,-0.84942,-0.32336],[-0.19509,-0.98079,-0.35],[-0.22122,-1.11215,-0.32336],[-0.24337,-1.22352,-0.24749],[-0.25817,-1.29793,-0.13394],[0,-1.35,0],[0,-1.32336,0.13394],[0,-1.24749,0.24749],[0,-1.13394,0.32336],[0,-1,0.35],[0,-0.86606,0.32336],[0,-0.75251,0.24749],[0,-0.67664,0.13394],[0,-0.65,0],[0,-0.67664,-0.13394],[0,-0.75251,-0.24749],[0,-0.86606,-0.32336],[0,-1,-0.35],[0,-1.13394,-0.32336],[0,-1.24749,-0.24749],[0,-1.32336,-0.13394],[0.26337,-1.32406,0],[0.25817,-1.29793,0.13394],[0.24337,-1.22352,0.24749],[0.22122,-1.11215,0.32336],[0.19509,-0.98079,0.35],[0.16896,-0.84942,0.32336],[0.14681,-0.73805,0.24749],[0.13201,-0.66364,0.13394],[0.12681,-0.63751,0],[0.13201,-0.66364,-0.13394],[0.14681,-0.73805,-0.24749],[0.16896,-0.84942,-0.32336],[0.19509,-0.98079,-0.35],[0.22122,-1.11215,-0.32336],[0.24337,-1.22352,-0.24749],[0.25817,-1.29793,-0.13394],[0.51662,-1.24724,0],[0.50643,-1.22262,0.13394],[0.47739,-1.15253,0.24749],[0.43394,-1.04762,0.32336],[0.38268,-0.92388,0.35],[0.33143,-0.80014,0.32336],[0.28797,-0.69523,0.24749],[0.25894,-0.62514,0.13394],[0.24874,-0.60052,0],[0.25894,-0.62514,-0.13394],[0.28797,-0.69523,-0.24749],[0.33143,-0.80014,-0.32336],[0.38268,-0.92388,-0.35],[0.43394,-1.04762,-0.32336],[0.47739,-1.15253,-0.24749],[0.50643,-1.22262,-0.13394],[0.75002,-1.12248,0],[0.73522,-1.10033,0.13394],[0.69307,-1.03725,0.24749],[0.62998,-0.94284,0.32336],[0.55557,-0.83147,0.35],[0.48116,-0.7201,0.32336],[0.41807,-0.62569,0.24749],[0.37592,-0.56261,0.13394],[0.36112,-0.54046,0],[0.37592,-0.56261,-0.13394],[0.41807,-0.62569,-0.24749],[0.48116,-0.7201,-0.32336],[0.55557,-0.83147,-0.35],[0.62998,-0.94284,-0.32336],[0.69307,-1.03725,-0.24749],[0.73522,-1.10033,-0.13394],[0.95459,-0.95459,0],[0.93576,-0.93576,0.13394],[0.88211,-0.88211,0.24749],[0.80182,-0.80182,0.32336],[0.70711,-0.70711,0.35],[0.6124,-0.6124,0.32336],[0.53211,-0.53211,0.24749],[0.47846,-0.47846,0.13394],[0.45962,-0.45962,0],[0.47846,-0.47846,-0.13394],[0.53211,-0.53211,-0.24749],[0.6124,-0.6124,-0.32336],[0.70711,-0.70711,-0.35],[0.80182,-0.80182,-0.32336],[0.88211,-0.88211,-0.24749],[0.93576,-0.93576,-0.13394],[1.12248,-0.75002,0],[1.10033,-0.73522,0.13394],[1.03725,-0.69307,0.24749],[0.94284,-0.62998,0.32336],[0.83147,-0.55557,0.35],[0.7201,-0.48116,0.32336],[0.62569,-0.41807,0.24749],[0.56261,-0.37592,0.13394],[0.54046,-0.36112,0],[0.56261,-0.37592,-0.13394],[0.62569,-0.41807,-0.24749],[0.7201,-0.48116,-0.32336],[0.83147,-0.55557,-0.35],[0.94284,-0.62998,-0.32336],[1.03725,-0.69307,-0.24749],[1.10033,-0.73522,-0.13394],[1.24724,-0.51662,0],[1.22262,-0.50643,0.13394],[1.15253,-0.47739,0.24749],[1.04762,-0.43394,0.32336],[0.92388,-0.38268,0.35],[0.80014,-0.33143,0.32336],[0.69523,-0.28797,0.24749],[0.62514,-0.25894,0.13394],[0.60052,-0.24874,0],[0.62514,-0.25894,-0.13394],[0.69523,-0.28797,-0.24749],[0.80014,-0.33143,-0.32336],[0.92388,-0.38268,-0.35],[1.04762,-0.43394,-0.32336],[1.15253,-0.47739,-0.24749],[1.22262,-0.50643,-0.13394],[1.32406,-0.26337,0],[1.29793,-0.25817,0.13394],[1.22352,-0.24337,0.24749],[1.11215,-0.22122,0.32336],[0.98079,-0.19509,0.35],[0.84942,-0.16896,0.32336],[0.73805,-0.14681,0.24749],[0.66364,-0.13201,0.13394],[0.63751,-0.12681,0],[0.66364,-0.13201,-0.13394],[0.73805,-0.14681,-0.24749],[0.84942,-0.16896,-0.32336],[0.98079,-0.19509,-0.35],[1.11215,-0.22122,-0.32336],[1.22352,-0.24337,-0.24749],[1.29793,-0.25817,-0.13394]],
+ "faces": [[0,16,17,1],[1,17,18,2],[2,18,19,3],[3,19,20,4],[4,20,21,5],[5,21,22,6],[6,22,23,7],[7,23,24,8],[8,24,25,9],[9,25,26,10],[10,26,27,11],[11,27,28,12],[12,28,29,13],[13,29,30,14],[14,30,31,15],[15,31,16,0],[16,32,33,17],[17,33,34,18],[18,34,35,19],[19,35,36,20],[20,36,37,21],[21,37,38,22],[22,38,39,23],[23,39,40,24],[24,40,41,25],[25,41,42,26],[26,42,43,27],[27,43,44,28],[28,44,45,29],[29,45,46,30],[30,46,47,31],[31,47,32,16],[32,48,49,33],[33,49,50,34],[34,50,51,35],[35,51,52,36],[36,52,53,37],[37,53,54,38],[38,54,55,39],[39,55,56,40],[40,56,57,41],[41,57,58,42],[42,58,59,43],[43,59,60,44],[44,60,61,45],[45,61,62,46],[46,62,63,47],[47,63,48,32],[48,64,65,49],[49,65,66,50],[50,66,67,51],[51,67,68,52],[52,68,69,53],[53,69,70,54],[54,70,71,55],[55,71,72,56],[56,72,73,57],[57,73,74,58],[58,74,75,59],[59,75,76,60],[60,76,77,61],[61,77,78,62],[62,78,79,63],[63,79,64,48],[64,80,81,65],[65,81,82,66],[66,82,83,67],[67,83,84,68],[68,84,85,69],[69,85,86,70],[70,86,87,71],[71,87,88,72],[72,88,89,73],[73,89,90,74],[74,90,91,75],[75,91,92,76],[76,92,93,77],[77,93,94,78],[78,94,95,79],[79,95,80,64],[80,96,97,81],[81,97,98,82],[82,98,99,83],[83,99,100,84],[84,100,101,85],[85,101,102,86],[86,102,103,87],[87,103,104,88],[88,104,105,89],[89,105,106,90],[90,106,107,91],[91,107,108,92],[92,108,109,93],[93,109,110,94],[94,110,111,95],[95,111,96,80],[96,112,113,97],[97,113,114,98],[98,114,115,99],[99,115,116,100],[100,116,117,101],[101,117,118,102],[102,118,119,103],[103,119,120,104],[104,120,121,105],[105,121,122,106],[106,122,123,107],[107,123,124,108],[108,124,125,109],[109,125,126,110],[110,126,127,111],[111,127,112,96],[112,128,129,113],[113,129,130,114],[114,130,131,115],[115,131,132,116],[116,132,133,117],[117,133,134,118],[118,134,135,119],[119,135,136,120],[120,136,137,121],[121,137,138,122],[122,138,139,123],[123,139,140,124],[124,140,141,125],[125,141,142,126],[126,142,143,127],[127,143,128,112],[128,144,145,129],[129,145,146,130],[130,146,147,131],[131,147,148,132],[132,148,149,133],[133,149,150,134],[134,150,151,135],[135,151,152,136],[136,152,153,137],[137,153,154,138],[138,154,155,139],[139,155,156,140],[140,156,157,141],[141,157,158,142],[142,158,159,143],[143,159,144,128],[144,160,161,145],[145,161,162,146],[146,162,163,147],[147,163,164,148],[148,164,165,149],[149,165,166,150],[150,166,167,151],[151,167,168,152],[152,168,169,153],[153,169,170,154],[154,170,171,155],[155,171,172,156],[156,172,173,157],[157,173,174,158],[158,174,175,159],[159,175,160,144],[160,176,177,161],[161,177,178,162],[162,178,179,163],[163,179,180,164],[164,180,181,165],[165,181,182,166],[166,182,183,167],[167,183,184,168],[168,184,185,169],[169,185,186,170],[170,186,187,171],[171,187,188,172],[172,188,189,173],[173,189,190,174],[174,190,191,175],[175,191,176,160],[176,192,193,177],[177,193,194,178],[178,194,195,179],[179,195,196,180],[180,196,197,181],[181,197,198,182],[182,198,199,183],[183,199,200,184],[184,200,201,185],[185,201,202,186],[186,202,203,187],[187,203,204,188],[188,204,205,189],[189,205,206,190],[190,206,207,191],[191,207,192,176],[192,208,209,193],[193,209,210,194],[194,210,211,195],[195,211,212,196],[196,212,213,197],[197,213,214,198],[198,214,215,199],[199,215,216,200],[200,216,217,201],[201,217,218,202],[202,218,219,203],[203,219,220,204],[204,220,221,205],[205,221,222,206],[206,222,223,207],[207,223,208,192],[208,224,225,209],[209,225,226,210],[210,226,227,211],[211,227,228,212],[212,228,229,213],[213,229,230,214],[214,230,231,215],[215,231,232,216],[216,232,233,217],[217,233,234,218],[218,234,235,219],[219,235,236,220],[220,236,237,221],[221,237,238,222],[222,238,239,223],[223,239,224,208],[224,240,241,225],[225,241,242,226],[226,242,243,227],[227,243,244,228],[228,244,245,229],[229,245,246,230],[230,246,247,231],[231,247,248,232],[232,248,249,233],[233,249,250,234],[234,250,251,235],[235,251,252,236],[236,252,253,237],[237,253,254,238],[238,254,255,239],[239,255,240,224],[240,256,257,241],[241,257,258,242],[242,258,259,243],[243,259,260,244],[244,260,261,245],[245,261,262,246],[246,262,263,247],[247,263,264,248],[248,264,265,249],[249,265,266,250],[250,266,267,251],[251,267,268,252],[252,268,269,253],[253,269,270,254],[254,270,271,255],[255,271,256,240],[256,272,273,257],[257,273,274,258],[258,274,275,259],[259,275,276,260],[260,276,277,261],[261,277,278,262],[262,278,279,263],[263,279,280,264],[264,280,281,265],[265,281,282,266],[266,282,283,267],[267,283,284,268],[268,284,285,269],[269,285,286,270],[270,286,287,271],[271,287,272,256],[272,288,289,273],[273,289,290,274],[274,290,291,275],[275,291,292,276],[276,292,293,277],[277,293,294,278],[278,294,295,279],[279,295,296,280],[280,296,297,281],[281,297,298,282],[282,298,299,283],[283,299,300,284],[284,300,301,285],[285,301,302,286],[286,302,303,287],[287,303,288,272],[288,304,305,289],[289,305,306,290],[290,306,307,291],[291,307,308,292],[292,308,309,293],[293,309,310,294],[294,310,311,295],[295,311,312,296],[296,312,313,297],[297,313,314,298],[298,314,315,299],[299,315,316,300],[300,316,317,301],[301,317,318,302],[302,318,319,303],[303,319,304,288],[304,320,321,305],[305,321,322,306],[306,322,323,307],[307,323,324,308],[308,324,325,309],[309,325,326,310],[310,326,327,311],[311,327,328,312],[312,328,329,313],[313,329,330,314],[314,330,331,315],[315,331,332,316],[316,332,333,317],[317,333,334,318],[318,334,335,319],[319,335,320,304],[320,336,337,321],[321,337,338,322],[322,338,339,323],[323,339,340,324],[324,340,341,325],[325,341,342,326],[326,342,343,327],[327,343,344,328],[328,344,345,329],[329,345,346,330],[330,346,347,331],[331,347,348,332],[332,348,349,333],[333,349,350,334],[334,350,351,335],[335,351,336,320],[336,352,353,337],[337,353,354,338],[338,354,355,339],[339,355,356,340],[340,356,357,341],[341,357,358,342],[342,358,359,343],[343,359,360,344],[344,360,361,345],[345,361,362,346],[346,362,363,347],[347,363,364,348],[348,364,365,349],[349,365,366,350],[350,366,367,351],[351,367,352,336],[352,368,369,353],[353,369,370,354],[354,370,371,355],[355,371,372,356],[356,372,373,357],[357,373,374,358],[358,374,375,359],[359,375,376,360],[360,376,377,361],[361,377,378,362],[362,378,379,363],[363,379,380,364],[364,380,381,365],[365,381,382,366],[366,382,383,367],[367,383,368,352],[368,384,385,369],[369,385,386,370],[370,386,387,371],[371,387,388,372],[372,388,389,373],[373,389,390,374],[374,390,391,375],[375,391,392,376],[376,392,393,377],[377,393,394,378],[378,394,395,379],[379,395,396,380],[380,396,397,381],[381,397,398,382],[382,398,399,383],[383,399,384,368],[384,400,401,385],[385,401,402,386],[386,402,403,387],[387,403,404,388],[388,404,405,389],[389,405,406,390],[390,406,407,391],[391,407,408,392],[392,408,409,393],[393,409,410,394],[394,410,411,395],[395,411,412,396],[396,412,413,397],[397,413,414,398],[398,414,415,399],[399,415,400,384],[400,416,417,401],[401,417,418,402],[402,418,419,403],[403,419,420,404],[404,420,421,405],[405,421,422,406],[406,422,423,407],[407,423,424,408],[408,424,425,409],[409,425,426,410],[410,426,427,411],[411,427,428,412],[412,428,429,413],[413,429,430,414],[414,430,431,415],[415,431,416,400],[416,432,433,417],[417,433,434,418],[418,434,435,419],[419,435,436,420],[420,436,437,421],[421,437,438,422],[422,438,439,423],[423,439,440,424],[424,440,441,425],[425,441,442,426],[426,442,443,427],[427,443,444,428],[428,444,445,429],[429,445,446,430],[430,446,447,431],[431,447,432,416],[432,448,449,433],[433,449,450,434],[434,450,451,435],[435,451,452,436],[436,452,453,437],[437,453,454,438],[438,454,455,439],[439,455,456,440],[440,456,457,441],[441,457,458,442],[442,458,459,443],[443,459,460,444],[444,460,461,445],[445,461,462,446],[446,462,463,447],[447,463,448,432],[448,464,465,449],[449,465,466,450],[450,466,467,451],[451,467,468,452],[452,468,469,453],[453,469,470,454],[454,470,471,455],[455,471,472,456],[456,472,473,457],[457,473,474,458],[458,474,475,459],[459,475,476,460],[460,476,477,461],[461,477,478,462],[462,478,479,463],[463,479,464,448],[464,480,481,465],[465,481,482,466],[466,482,483,467],[467,483,484,468],[468,484,485,469],[469,485,486,470],[470,486,487,471],[471,487,488,472],[472,488,489,473],[473,489,490,474],[474,490,491,475],[475,491,492,476],[476,492,493,477],[477,493,494,478],[478,494,495,479],[479,495,480,464],[480,496,497,481],[481,497,498,482],[482,498,499,483],[483,499,500,484],[484,500,501,485],[485,501,502,486],[486,502,503,487],[487,503,504,488],[488,504,505,489],[489,505,506,490],[490,506,507,491],[491,507,508,492],[492,508,509,493],[493,509,510,494],[494,510,511,495],[495,511,496,480],[496,0,1,497],[497,1,2,498],[498,2,3,499],[499,3,4,500],[500,4,5,501],[501,5,6,502],[502,6,7,503],[503,7,8,504],[504,8,9,505],[505,9,10,506],[506,10,11,507],[507,11,12,508],[508,12,13,509],[509,13,14,510],[510,14,15,511],[511,15,0,496]]
+ },
+ "bowl-open": {
+ "vertices": [[0.15643,0,0.98769],[0.15718,0.03126,1.01182],[0.14845,0.06149,1.01451],[0.13082,0.08741,0.99335],[0.10832,0.10832,0.96716],[0.08441,0.12632,0.95922],[0.05919,0.1429,0.97658],[0.03102,0.15593,1.00382],[0,0.16103,1.01672],[-0.03102,0.15593,1.00382],[-0.05919,0.1429,0.97658],[-0.08441,0.12632,0.95922],[-0.10832,0.10832,0.96716],[-0.13082,0.08741,0.99335],[-0.14845,0.06149,1.01451],[-0.15718,0.03126,1.01182],[-0.15643,0,0.98769],[-0.14968,-0.02977,0.96355],[-0.1406,-0.05824,0.96087],[-0.12932,-0.08641,0.98203],[-0.11291,-0.11291,1.00821],[-0.08942,-0.13382,1.01616],[-0.06054,-0.14615,0.9988],[-0.03002,-0.15092,0.97156],[0,-0.15184,0.95866],[0.03002,-0.15092,0.97156],[0.06054,-0.14615,0.9988],[0.08942,-0.13382,1.01616],[0.11291,-0.11291,1.00821],[0.12932,-0.08641,0.98203],[0.1406,-0.05824,0.96087],[0.14968,-0.02977,0.96355],[0.30902,0,0.95106],[0.31506,0.06267,0.98866],[0.29804,0.12345,0.99284],[0.25932,0.17327,0.95988],[0.21116,0.21116,0.91908],[0.16367,0.24495,0.9067],[0.1161,0.2803,0.93375],[0.06188,0.31109,0.97618],[0,0.32371,0.99628],[-0.06188,0.31109,0.97618],[-0.1161,0.2803,0.93375],[-0.16367,0.24495,0.9067],[-0.21116,0.21116,0.91908],[-0.25932,0.17327,0.95988],[-0.29804,0.12345,0.99284],[-0.31506,0.06267,0.98866],[-0.30902,0,0.95106],[-0.2911,-0.0579,0.91345],[-0.27295,-0.11306,0.90927],[-0.25455,-0.17009,0.94223],[-0.22586,-0.22586,0.98304],[-0.17969,-0.26892,0.99541],[-0.12041,-0.29069,0.96836],[-0.05869,-0.29507,0.92593],[0,-0.29432,0.90583],[0.05869,-0.29507,0.92593],[0.12041,-0.29069,0.96836],[0.17969,-0.26892,0.99541],[0.22586,-0.22586,0.98304],[0.25455,-0.17009,0.94223],[0.27295,-0.11306,0.90927],[0.2911,-0.0579,0.91345],[0.45399,0,0.89101],[0.46287,0.09207,0.92624],[0.43786,0.18137,0.93015],[0.38098,0.25456,0.89927],[0.31023,0.31023,0.86105],[0.24046,0.35987,0.84945],[0.17057,0.4118,0.87479],[0.09091,0.45703,0.91455],[0,0.47558,0.93338],[-0.09091,0.45703,0.91455],[-0.17057,0.4118,0.87479],[-0.24046,0.35987,0.84945],[-0.31023,0.31023,0.86105],[-0.38098,0.25456,0.89927],[-0.43786,0.18137,0.93015],[-0.46287,0.09207,0.92624],[-0.45399,0,0.89101],[-0.42766,-0.08507,0.85578],[-0.40101,-0.1661,0.85186],[-0.37398,-0.24988,0.88274],[-0.33181,-0.33181,0.92097],[-0.26399,-0.39508,0.93256],[-0.1769,-0.42707,0.90722],[-0.08623,-0.4335,0.86747],[0,-0.4324,0.84864],[0.08623,-0.4335,0.86747],[0.1769,-0.42707,0.90722],[0.26399,-0.39508,0.93256],[0.33181,-0.33181,0.92097],[0.37398,-0.24988,0.88274],[0.40101,-0.1661,0.85186],[0.42766,-0.08507,0.85578],[0.58779,0,0.80902],[0.59058,0.11747,0.82879],[0.55779,0.23104,0.83098],[0.49153,0.32843,0.81366],[0.40699,0.40699,0.7922],[0.31714,0.47464,0.7857],[0.22241,0.53694,0.79992],[0.11654,0.5859,0.82223],[0,0.60506,0.83279],[-0.11654,0.5859,0.82223],[-0.22241,0.53694,0.79992],[-0.31714,0.47464,0.7857],[-0.40699,0.40699,0.7922],[-0.49153,0.32843,0.81366],[-0.55779,0.23104,0.83098],[-0.59058,0.11747,0.82879],[-0.58779,0,0.80902],[-0.5624,-0.11187,0.78925],[-0.5283,-0.21883,0.78705],[-0.48592,-0.32468,0.80438],[-0.42426,-0.42426,0.82583],[-0.33597,-0.50281,0.83234],[-0.22747,-0.54915,0.81812],[-0.1128,-0.56708,0.79581],[0,-0.57051,0.78524],[0.1128,-0.56708,0.79581],[0.22747,-0.54915,0.81812],[0.33597,-0.50281,0.83234],[0.42426,-0.42426,0.82583],[0.48592,-0.32468,0.80438],[0.5283,-0.21883,0.78705],[0.5624,-0.11187,0.78925],[0.70711,0,0.70711],[0.69352,0.13795,0.70711],[0.65328,0.2706,0.70711],[0.58794,0.39285,0.70711],[0.5,0.5,0.70711],[0.39285,0.58794,0.70711],[0.2706,0.65328,0.70711],[0.13795,0.69352,0.70711],[0,0.70711,0.70711],[-0.13795,0.69352,0.70711],[-0.2706,0.65328,0.70711],[-0.39285,0.58794,0.70711],[-0.5,0.5,0.70711],[-0.58794,0.39285,0.70711],[-0.65328,0.2706,0.70711],[-0.69352,0.13795,0.70711],[-0.70711,0,0.70711],[-0.69352,-0.13795,0.70711],[-0.65328,-0.2706,0.70711],[-0.58794,-0.39285,0.70711],[-0.5,-0.5,0.70711],[-0.39285,-0.58794,0.70711],[-0.2706,-0.65328,0.70711],[-0.13795,-0.69352,0.70711],[0,-0.70711,0.70711],[0.13795,-0.69352,0.70711],[0.2706,-0.65328,0.70711],[0.39285,-0.58794,0.70711],[0.5,-0.5,0.70711],[0.58794,-0.39285,0.70711],[0.65328,-0.2706,0.70711],[0.69352,-0.13795,0.70711],[0.80902,0,0.58779],[0.77408,0.15397,0.57342],[0.72714,0.30119,0.57183],[0.66882,0.44689,0.58442],[0.58395,0.58395,0.6],[0.46242,0.69206,0.60473],[0.31308,0.75584,0.5944],[0.15525,0.78052,0.57819],[0,0.78524,0.57051],[-0.15525,0.78052,0.57819],[-0.31308,0.75584,0.5944],[-0.46242,0.69206,0.60473],[-0.58395,0.58395,0.6],[-0.66882,0.44689,0.58442],[-0.72714,0.30119,0.57183],[-0.77408,0.15397,0.57342],[-0.80902,0,0.58779],[-0.81286,-0.16169,0.60215],[-0.76773,-0.318,0.60374],[-0.67653,-0.45204,0.59116],[-0.56017,-0.56017,0.57557],[-0.43651,-0.65328,0.57084],[-0.30612,-0.73903,0.58117],[-0.16041,-0.80643,0.59738],[0,-0.83279,0.60506],[0.16041,-0.80643,0.59738],[0.30612,-0.73903,0.58117],[0.43651,-0.65328,0.57084],[0.56017,-0.56017,0.57557],[0.67653,-0.45204,0.59116],[0.76773,-0.318,0.60374],[0.81286,-0.16169,0.60215],[0.89101,0,0.45399],[0.83933,0.16695,0.43604],[0.78702,0.32599,0.43405],[0.73397,0.49042,0.44978],[0.65122,0.65122,0.46926],[0.5181,0.7754,0.47516],[0.34718,0.83816,0.46225],[0.16923,0.8508,0.442],[0,0.84864,0.4324],[-0.16923,0.8508,0.442],[-0.34718,0.83816,0.46225],[-0.5181,0.7754,0.47516],[-0.65122,0.65122,0.46926],[-0.73397,0.49042,0.44978],[-0.78702,0.32599,0.43405],[-0.83933,0.16695,0.43604],[-0.89101,0,0.45399],[-0.90844,-0.1807,0.47194],[-0.85935,-0.35595,0.47394],[-0.74772,-0.49961,0.4582],[-0.60885,-0.60885,0.43873],[-0.47193,-0.70629,0.43282],[-0.33477,-0.8082,0.44573],[-0.17842,-0.89697,0.46598],[0,-0.93338,0.47558],[0.17842,-0.89697,0.46598],[0.33477,-0.8082,0.44573],[0.47193,-0.70629,0.43282],[0.60885,-0.60885,0.43873],[0.74772,-0.49961,0.4582],[0.85935,-0.35595,0.47394],[0.90844,-0.1807,0.47194],[0.95106,0,0.30902],[0.8959,0.17821,0.2968],[0.84006,0.34796,0.29544],[0.78344,0.52348,0.30615],[0.69511,0.69511,0.31941],[0.55302,0.82766,0.32343],[0.37058,0.89465,0.31464],[0.18064,0.90814,0.30085],[0,0.90583,0.29432],[-0.18064,0.90814,0.30085],[-0.37058,0.89465,0.31464],[-0.55302,0.82766,0.32343],[-0.69511,0.69511,0.31941],[-0.78344,0.52348,0.30615],[-0.84006,0.34796,0.29544],[-0.8959,0.17821,0.2968],[-0.95106,0,0.30902],[-0.96966,-0.19288,0.32124],[-0.91726,-0.37994,0.32259],[-0.79811,-0.53328,0.31188],[-0.64989,-0.64989,0.29863],[-0.50374,-0.75389,0.2946],[-0.35733,-0.86267,0.30339],[-0.19044,-0.95743,0.31718],[0,-0.99628,0.32371],[0.19044,-0.95743,0.31718],[0.35733,-0.86267,0.30339],[0.50374,-0.75389,0.2946],[0.64989,-0.64989,0.29863],[0.79811,-0.53328,0.31188],[0.91726,-0.37994,0.32259],[0.96966,-0.19288,0.32124],[0.98769,0,0.15643],[0.94504,0.18798,0.15261],[0.88773,0.36771,0.15219],[0.81652,0.54558,0.15554],[0.71291,0.71291,0.15969],[0.56455,0.8449,0.16094],[0.38222,0.92277,0.15819],[0.18954,0.95289,0.15388],[0,0.95866,0.15184],[-0.18954,0.95289,0.15388],[-0.38222,0.92277,0.15819],[-0.56455,0.8449,0.16094],[-0.71291,0.71291,0.15969],[-0.81652,0.54558,0.15554],[-0.88773,0.36771,0.15219],[-0.94504,0.18798,0.15261],[-0.98769,0,0.15643],[-0.99238,-0.1974,0.16026],[-0.93728,-0.38823,0.16068],[-0.82594,-0.55188,0.15733],[-0.68389,-0.68389,0.15318],[-0.53291,-0.79756,0.15193],[-0.37372,-0.90224,0.15468],[-0.19583,-0.98453,0.15899],[0,-1.01672,0.16103],[0.19583,-0.98453,0.15899],[0.37372,-0.90224,0.15468],[0.53291,-0.79756,0.15193],[0.68389,-0.68389,0.15318],[0.82594,-0.55188,0.15733],[0.93728,-0.38823,0.16068],[0.99238,-0.1974,0.16026],[1,0,0],[0.98079,0.19509,0],[0.92388,0.38268,0],[0.83147,0.55557,0],[0.70711,0.70711,0],[0.55557,0.83147,0],[0.38268,0.92388,0],[0.19509,0.98079,0],[0,1,0],[-0.19509,0.98079,0],[-0.38268,0.92388,0],[-0.55557,0.83147,0],[-0.70711,0.70711,0],[-0.83147,0.55557,0],[-0.92388,0.38268,0],[-0.98079,0.19509,0],[-1,0,0],[-0.98079,-0.19509,0],[-0.92388,-0.38268,0],[-0.83147,-0.55557,0],[-0.70711,-0.70711,0],[-0.55557,-0.83147,0],[-0.38268,-0.92388,0],[-0.19509,-0.98079,0],[0,-1,0],[0.19509,-0.98079,0],[0.38268,-0.92388,0],[0.55557,-0.83147,0],[0.70711,-0.70711,0],[0.83147,-0.55557,0],[0.92388,-0.38268,0],[0.98079,-0.19509,0],[0.98769,0,-0.15643],[0.99238,0.1974,-0.16026],[0.93728,0.38823,-0.16068],[0.82594,0.55188,-0.15733],[0.68389,0.68389,-0.15318],[0.53291,0.79756,-0.15193],[0.37372,0.90224,-0.15468],[0.19583,0.98453,-0.15899],[0,1.01672,-0.16103],[-0.19583,0.98453,-0.15899],[-0.37372,0.90224,-0.15468],[-0.53291,0.79756,-0.15193],[-0.68389,0.68389,-0.15318],[-0.82594,0.55188,-0.15733],[-0.93728,0.38823,-0.16068],[-0.99238,0.1974,-0.16026],[-0.98769,0,-0.15643],[-0.94504,-0.18798,-0.15261],[-0.88773,-0.36771,-0.15219],[-0.81652,-0.54558,-0.15554],[-0.71291,-0.71291,-0.15969],[-0.56455,-0.8449,-0.16094],[-0.38222,-0.92277,-0.15819],[-0.18954,-0.95289,-0.15388],[0,-0.95866,-0.15184],[0.18954,-0.95289,-0.15388],[0.38222,-0.92277,-0.15819],[0.56455,-0.8449,-0.16094],[0.71291,-0.71291,-0.15969],[0.81652,-0.54558,-0.15554],[0.88773,-0.36771,-0.15219],[0.94504,-0.18798,-0.15261],[0.95106,0,-0.30902],[0.96966,0.19288,-0.32124],[0.91726,0.37994,-0.32259],[0.79811,0.53328,-0.31188],[0.64989,0.64989,-0.29863],[0.50374,0.75389,-0.2946],[0.35733,0.86267,-0.30339],[0.19044,0.95743,-0.31718],[0,0.99628,-0.32371],[-0.19044,0.95743,-0.31718],[-0.35733,0.86267,-0.30339],[-0.50374,0.75389,-0.2946],[-0.64989,0.64989,-0.29863],[-0.79811,0.53328,-0.31188],[-0.91726,0.37994,-0.32259],[-0.96966,0.19288,-0.32124],[-0.95106,0,-0.30902],[-0.8959,-0.17821,-0.2968],[-0.84006,-0.34796,-0.29544],[-0.78344,-0.52348,-0.30615],[-0.69511,-0.69511,-0.31941],[-0.55302,-0.82766,-0.32343],[-0.37058,-0.89465,-0.31464],[-0.18064,-0.90814,-0.30085],[0,-0.90583,-0.29432],[0.18064,-0.90814,-0.30085],[0.37058,-0.89465,-0.31464],[0.55302,-0.82766,-0.32343],[0.69511,-0.69511,-0.31941],[0.78344,-0.52348,-0.30615],[0.84006,-0.34796,-0.29544],[0.8959,-0.17821,-0.2968],[0.89101,0,-0.45399],[0.90844,0.1807,-0.47194],[0.85935,0.35595,-0.47394],[0.74772,0.49961,-0.4582],[0.60885,0.60885,-0.43873],[0.47193,0.70629,-0.43282],[0.33477,0.8082,-0.44573],[0.17842,0.89697,-0.46598],[0,0.93338,-0.47558],[-0.17842,0.89697,-0.46598],[-0.33477,0.8082,-0.44573],[-0.47193,0.70629,-0.43282],[-0.60885,0.60885,-0.43873],[-0.74772,0.49961,-0.4582],[-0.85935,0.35595,-0.47394],[-0.90844,0.1807,-0.47194],[-0.89101,0,-0.45399],[-0.83933,-0.16695,-0.43604],[-0.78702,-0.32599,-0.43405],[-0.73397,-0.49042,-0.44978],[-0.65122,-0.65122,-0.46926],[-0.5181,-0.7754,-0.47516],[-0.34718,-0.83816,-0.46225],[-0.16923,-0.8508,-0.442],[0,-0.84864,-0.4324],[0.16923,-0.8508,-0.442],[0.34718,-0.83816,-0.46225],[0.5181,-0.7754,-0.47516],[0.65122,-0.65122,-0.46926],[0.73397,-0.49042,-0.44978],[0.78702,-0.32599,-0.43405],[0.83933,-0.16695,-0.43604],[0.80902,0,-0.58779],[0.81286,0.16169,-0.60215],[0.76773,0.318,-0.60374],[0.67653,0.45204,-0.59116],[0.56017,0.56017,-0.57557],[0.43651,0.65328,-0.57084],[0.30612,0.73903,-0.58117],[0.16041,0.80643,-0.59738],[0,0.83279,-0.60506],[-0.16041,0.80643,-0.59738],[-0.30612,0.73903,-0.58117],[-0.43651,0.65328,-0.57084],[-0.56017,0.56017,-0.57557],[-0.67653,0.45204,-0.59116],[-0.76773,0.318,-0.60374],[-0.81286,0.16169,-0.60215],[-0.80902,0,-0.58779],[-0.77408,-0.15397,-0.57342],[-0.72714,-0.30119,-0.57183],[-0.66882,-0.44689,-0.58442],[-0.58395,-0.58395,-0.6],[-0.46242,-0.69206,-0.60473],[-0.31308,-0.75584,-0.5944],[-0.15525,-0.78052,-0.57819],[0,-0.78524,-0.57051],[0.15525,-0.78052,-0.57819],[0.31308,-0.75584,-0.5944],[0.46242,-0.69206,-0.60473],[0.58395,-0.58395,-0.6],[0.66882,-0.44689,-0.58442],[0.72714,-0.30119,-0.57183],[0.77408,-0.15397,-0.57342],[0.70711,0,-0.70711],[0.69352,0.13795,-0.70711],[0.65328,0.2706,-0.70711],[0.58794,0.39285,-0.70711],[0.5,0.5,-0.70711],[0.39285,0.58794,-0.70711],[0.2706,0.65328,-0.70711],[0.13795,0.69352,-0.70711],[0,0.70711,-0.70711],[-0.13795,0.69352,-0.70711],[-0.2706,0.65328,-0.70711],[-0.39285,0.58794,-0.70711],[-0.5,0.5,-0.70711],[-0.58794,0.39285,-0.70711],[-0.65328,0.2706,-0.70711],[-0.69352,0.13795,-0.70711],[-0.70711,0,-0.70711],[-0.69352,-0.13795,-0.70711],[-0.65328,-0.2706,-0.70711],[-0.58794,-0.39285,-0.70711],[-0.5,-0.5,-0.70711],[-0.39285,-0.58794,-0.70711],[-0.2706,-0.65328,-0.70711],[-0.13795,-0.69352,-0.70711],[0,-0.70711,-0.70711],[0.13795,-0.69352,-0.70711],[0.2706,-0.65328,-0.70711],[0.39285,-0.58794,-0.70711],[0.5,-0.5,-0.70711],[0.58794,-0.39285,-0.70711],[0.65328,-0.2706,-0.70711],[0.69352,-0.13795,-0.70711],[0.58779,0,-0.80902],[0.5624,0.11187,-0.78925],[0.5283,0.21883,-0.78705],[0.48592,0.32468,-0.80438],[0.42426,0.42426,-0.82583],[0.33597,0.50281,-0.83234],[0.22747,0.54915,-0.81812],[0.1128,0.56708,-0.79581],[0,0.57051,-0.78524],[-0.1128,0.56708,-0.79581],[-0.22747,0.54915,-0.81812],[-0.33597,0.50281,-0.83234],[-0.42426,0.42426,-0.82583],[-0.48592,0.32468,-0.80438],[-0.5283,0.21883,-0.78705],[-0.5624,0.11187,-0.78925],[-0.58779,0,-0.80902],[-0.59058,-0.11747,-0.82879],[-0.55779,-0.23104,-0.83098],[-0.49153,-0.32843,-0.81366],[-0.40699,-0.40699,-0.7922],[-0.31714,-0.47464,-0.7857],[-0.22241,-0.53694,-0.79992],[-0.11654,-0.5859,-0.82223],[0,-0.60506,-0.83279],[0.11654,-0.5859,-0.82223],[0.22241,-0.53694,-0.79992],[0.31714,-0.47464,-0.7857],[0.40699,-0.40699,-0.7922],[0.49153,-0.32843,-0.81366],[0.55779,-0.23104,-0.83098],[0.59058,-0.11747,-0.82879],[0.45399,0,-0.89101],[0.42766,0.08507,-0.85578],[0.40101,0.1661,-0.85186],[0.37398,0.24988,-0.88274],[0.33181,0.33181,-0.92097],[0.26399,0.39508,-0.93256],[0.1769,0.42707,-0.90722],[0.08623,0.4335,-0.86747],[0,0.4324,-0.84864],[-0.08623,0.4335,-0.86747],[-0.1769,0.42707,-0.90722],[-0.26399,0.39508,-0.93256],[-0.33181,0.33181,-0.92097],[-0.37398,0.24988,-0.88274],[-0.40101,0.1661,-0.85186],[-0.42766,0.08507,-0.85578],[-0.45399,0,-0.89101],[-0.46287,-0.09207,-0.92624],[-0.43786,-0.18137,-0.93015],[-0.38098,-0.25456,-0.89927],[-0.31023,-0.31023,-0.86105],[-0.24046,-0.35987,-0.84945],[-0.17057,-0.4118,-0.87479],[-0.09091,-0.45703,-0.91455],[0,-0.47558,-0.93338],[0.09091,-0.45703,-0.91455],[0.17057,-0.4118,-0.87479],[0.24046,-0.35987,-0.84945],[0.31023,-0.31023,-0.86105],[0.38098,-0.25456,-0.89927],[0.43786,-0.18137,-0.93015],[0.46287,-0.09207,-0.92624],[0.30902,0,-0.95106],[0.2911,0.0579,-0.91345],[0.27295,0.11306,-0.90927],[0.25455,0.17009,-0.94223],[0.22586,0.22586,-0.98304],[0.17969,0.26892,-0.99541],[0.12041,0.29069,-0.96836],[0.05869,0.29507,-0.92593],[0,0.29432,-0.90583],[-0.05869,0.29507,-0.92593],[-0.12041,0.29069,-0.96836],[-0.17969,0.26892,-0.99541],[-0.22586,0.22586,-0.98304],[-0.25455,0.17009,-0.94223],[-0.27295,0.11306,-0.90927],[-0.2911,0.0579,-0.91345],[-0.30902,0,-0.95106],[-0.31506,-0.06267,-0.98866],[-0.29804,-0.12345,-0.99284],[-0.25932,-0.17327,-0.95988],[-0.21116,-0.21116,-0.91908],[-0.16367,-0.24495,-0.9067],[-0.1161,-0.2803,-0.93375],[-0.06188,-0.31109,-0.97618],[0,-0.32371,-0.99628],[0.06188,-0.31109,-0.97618],[0.1161,-0.2803,-0.93375],[0.16367,-0.24495,-0.9067],[0.21116,-0.21116,-0.91908],[0.25932,-0.17327,-0.95988],[0.29804,-0.12345,-0.99284],[0.31506,-0.06267,-0.98866],[0.15643,0,-0.98769],[0.14968,0.02977,-0.96355],[0.1406,0.05824,-0.96087],[0.12932,0.08641,-0.98203],[0.11291,0.11291,-1.00821],[0.08942,0.13382,-1.01616],[0.06054,0.14615,-0.9988],[0.03002,0.15092,-0.97156],[0,0.15184,-0.95866],[-0.03002,0.15092,-0.97156],[-0.06054,0.14615,-0.9988],[-0.08942,0.13382,-1.01616],[-0.11291,0.11291,-1.00821],[-0.12932,0.08641,-0.98203],[-0.1406,0.05824,-0.96087],[-0.14968,0.02977,-0.96355],[-0.15643,0,-0.98769],[-0.15718,-0.03126,-1.01182],[-0.14845,-0.06149,-1.01451],[-0.13082,-0.08741,-0.99335],[-0.10832,-0.10832,-0.96716],[-0.08441,-0.12632,-0.95922],[-0.05919,-0.1429,-0.97658],[-0.03102,-0.15593,-1.00382],[0,-0.16103,-1.01672],[0.03102,-0.15593,-1.00382],[0.05919,-0.1429,-0.97658],[0.08441,-0.12632,-0.95922],[0.10832,-0.10832,-0.96716],[0.13082,-0.08741,-0.99335],[0.14845,-0.06149,-1.01451],[0.15718,-0.03126,-1.01182],[0,0,-1]],
+ "faces": [[0,32,33,1],[1,33,34,2],[2,34,35,3],[3,35,36,4],[4,36,37,5],[5,37,38,6],[6,38,39,7],[7,39,40,8],[8,40,41,9],[9,41,42,10],[10,42,43,11],[11,43,44,12],[12,44,45,13],[13,45,46,14],[14,46,47,15],[15,47,48,16],[16,48,49,17],[17,49,50,18],[18,50,51,19],[19,51,52,20],[20,52,53,21],[21,53,54,22],[22,54,55,23],[23,55,56,24],[24,56,57,25],[25,57,58,26],[26,58,59,27],[27,59,60,28],[28,60,61,29],[29,61,62,30],[30,62,63,31],[31,63,32,0],[32,64,65,33],[33,65,66,34],[34,66,67,35],[35,67,68,36],[36,68,69,37],[37,69,70,38],[38,70,71,39],[39,71,72,40],[40,72,73,41],[41,73,74,42],[42,74,75,43],[43,75,76,44],[44,76,77,45],[45,77,78,46],[46,78,79,47],[47,79,80,48],[48,80,81,49],[49,81,82,50],[50,82,83,51],[51,83,84,52],[52,84,85,53],[53,85,86,54],[54,86,87,55],[55,87,88,56],[56,88,89,57],[57,89,90,58],[58,90,91,59],[59,91,92,60],[60,92,93,61],[61,93,94,62],[62,94,95,63],[63,95,64,32],[64,96,97,65],[65,97,98,66],[66,98,99,67],[67,99,100,68],[68,100,101,69],[69,101,102,70],[70,102,103,71],[71,103,104,72],[72,104,105,73],[73,105,106,74],[74,106,107,75],[75,107,108,76],[76,108,109,77],[77,109,110,78],[78,110,111,79],[79,111,112,80],[80,112,113,81],[81,113,114,82],[82,114,115,83],[83,115,116,84],[84,116,117,85],[85,117,118,86],[86,118,119,87],[87,119,120,88],[88,120,121,89],[89,121,122,90],[90,122,123,91],[91,123,124,92],[92,124,125,93],[93,125,126,94],[94,126,127,95],[95,127,96,64],[96,128,129,97],[97,129,130,98],[98,130,131,99],[99,131,132,100],[100,132,133,101],[101,133,134,102],[102,134,135,103],[103,135,136,104],[104,136,137,105],[105,137,138,106],[106,138,139,107],[107,139,140,108],[108,140,141,109],[109,141,142,110],[110,142,143,111],[111,143,144,112],[112,144,145,113],[113,145,146,114],[114,146,147,115],[115,147,148,116],[116,148,149,117],[117,149,150,118],[118,150,151,119],[119,151,152,120],[120,152,153,121],[121,153,154,122],[122,154,155,123],[123,155,156,124],[124,156,157,125],[125,157,158,126],[126,158,159,127],[127,159,128,96],[128,160,161,129],[129,161,162,130],[130,162,163,131],[131,163,164,132],[132,164,165,133],[133,165,166,134],[134,166,167,135],[135,167,168,136],[136,168,169,137],[137,169,170,138],[138,170,171,139],[139,171,172,140],[140,172,173,141],[141,173,174,142],[142,174,175,143],[143,175,176,144],[144,176,177,145],[145,177,178,146],[146,178,179,147],[147,179,180,148],[148,180,181,149],[149,181,182,150],[150,182,183,151],[151,183,184,152],[152,184,185,153],[153,185,186,154],[154,186,187,155],[155,187,188,156],[156,188,189,157],[157,189,190,158],[158,190,191,159],[159,191,160,128],[160,192,193,161],[161,193,194,162],[162,194,195,163],[163,195,196,164],[164,196,197,165],[165,197,198,166],[166,198,199,167],[167,199,200,168],[168,200,201,169],[169,201,202,170],[170,202,203,171],[171,203,204,172],[172,204,205,173],[173,205,206,174],[174,206,207,175],[175,207,208,176],[176,208,209,177],[177,209,210,178],[178,210,211,179],[179,211,212,180],[180,212,213,181],[181,213,214,182],[182,214,215,183],[183,215,216,184],[184,216,217,185],[185,217,218,186],[186,218,219,187],[187,219,220,188],[188,220,221,189],[189,221,222,190],[190,222,223,191],[191,223,192,160],[192,224,225,193],[193,225,226,194],[194,226,227,195],[195,227,228,196],[196,228,229,197],[197,229,230,198],[198,230,231,199],[199,231,232,200],[200,232,233,201],[201,233,234,202],[202,234,235,203],[203,235,236,204],[204,236,237,205],[205,237,238,206],[206,238,239,207],[207,239,240,208],[208,240,241,209],[209,241,242,210],[210,242,243,211],[211,243,244,212],[212,244,245,213],[213,245,246,214],[214,246,247,215],[215,247,248,216],[216,248,249,217],[217,249,250,218],[218,250,251,219],[219,251,252,220],[220,252,253,221],[221,253,254,222],[222,254,255,223],[223,255,224,192],[224,256,257,225],[225,257,258,226],[226,258,259,227],[227,259,260,228],[228,260,261,229],[229,261,262,230],[230,262,263,231],[231,263,264,232],[232,264,265,233],[233,265,266,234],[234,266,267,235],[235,267,268,236],[236,268,269,237],[237,269,270,238],[238,270,271,239],[239,271,272,240],[240,272,273,241],[241,273,274,242],[242,274,275,243],[243,275,276,244],[244,276,277,245],[245,277,278,246],[246,278,279,247],[247,279,280,248],[248,280,281,249],[249,281,282,250],[250,282,283,251],[251,283,284,252],[252,284,285,253],[253,285,286,254],[254,286,287,255],[255,287,256,224],[256,288,289,257],[257,289,290,258],[258,290,291,259],[259,291,292,260],[260,292,293,261],[261,293,294,262],[262,294,295,263],[263,295,296,264],[264,296,297,265],[265,297,298,266],[266,298,299,267],[267,299,300,268],[268,300,301,269],[269,301,302,270],[270,302,303,271],[271,303,304,272],[272,304,305,273],[273,305,306,274],[274,306,307,275],[275,307,308,276],[276,308,309,277],[277,309,310,278],[278,310,311,279],[279,311,312,280],[280,312,313,281],[281,313,314,282],[282,314,315,283],[283,315,316,284],[284,316,317,285],[285,317,318,286],[286,318,319,287],[287,319,288,256],[288,320,321,289],[289,321,322,290],[290,322,323,291],[291,323,324,292],[292,324,325,293],[293,325,326,294],[294,326,327,295],[295,327,328,296],[296,328,329,297],[297,329,330,298],[298,330,331,299],[299,331,332,300],[300,332,333,301],[301,333,334,302],[302,334,335,303],[303,335,336,304],[304,336,337,305],[305,337,338,306],[306,338,339,307],[307,339,340,308],[308,340,341,309],[309,341,342,310],[310,342,343,311],[311,343,344,312],[312,344,345,313],[313,345,346,314],[314,346,347,315],[315,347,348,316],[316,348,349,317],[317,349,350,318],[318,350,351,319],[319,351,320,288],[320,352,353,321],[321,353,354,322],[322,354,355,323],[323,355,356,324],[324,356,357,325],[325,357,358,326],[326,358,359,327],[327,359,360,328],[328,360,361,329],[329,361,362,330],[330,362,363,331],[331,363,364,332],[332,364,365,333],[333,365,366,334],[334,366,367,335],[335,367,368,336],[336,368,369,337],[337,369,370,338],[338,370,371,339],[339,371,372,340],[340,372,373,341],[341,373,374,342],[342,374,375,343],[343,375,376,344],[344,376,377,345],[345,377,378,346],[346,378,379,347],[347,379,380,348],[348,380,381,349],[349,381,382,350],[350,382,383,351],[351,383,352,320],[352,384,385,353],[353,385,386,354],[354,386,387,355],[355,387,388,356],[356,388,389,357],[357,389,390,358],[358,390,391,359],[359,391,392,360],[360,392,393,361],[361,393,394,362],[362,394,395,363],[363,395,396,364],[364,396,397,365],[365,397,398,366],[366,398,399,367],[367,399,400,368],[368,400,401,369],[369,401,402,370],[370,402,403,371],[371,403,404,372],[372,404,405,373],[373,405,406,374],[374,406,407,375],[375,407,408,376],[376,408,409,377],[377,409,410,378],[378,410,411,379],[379,411,412,380],[380,412,413,381],[381,413,414,382],[382,414,415,383],[383,415,384,352],[384,416,417,385],[385,417,418,386],[386,418,419,387],[387,419,420,388],[388,420,421,389],[389,421,422,390],[390,422,423,391],[391,423,424,392],[392,424,425,393],[393,425,426,394],[394,426,427,395],[395,427,428,396],[396,428,429,397],[397,429,430,398],[398,430,431,399],[399,431,432,400],[400,432,433,401],[401,433,434,402],[402,434,435,403],[403,435,436,404],[404,436,437,405],[405,437,438,406],[406,438,439,407],[407,439,440,408],[408,440,441,409],[409,441,442,410],[410,442,443,411],[411,443,444,412],[412,444,445,413],[413,445,446,414],[414,446,447,415],[415,447,416,384],[416,448,449,417],[417,449,450,418],[418,450,451,419],[419,451,452,420],[420,452,453,421],[421,453,454,422],[422,454,455,423],[423,455,456,424],[424,456,457,425],[425,457,458,426],[426,458,459,427],[427,459,460,428],[428,460,461,429],[429,461,462,430],[430,462,463,431],[431,463,464,432],[432,464,465,433],[433,465,466,434],[434,466,467,435],[435,467,468,436],[436,468,469,437],[437,469,470,438],[438,470,471,439],[439,471,472,440],[440,472,473,441],[441,473,474,442],[442,474,475,443],[443,475,476,444],[444,476,477,445],[445,477,478,446],[446,478,479,447],[447,479,448,416],[448,480,481,449],[449,481,482,450],[450,482,483,451],[451,483,484,452],[452,484,485,453],[453,485,486,454],[454,486,487,455],[455,487,488,456],[456,488,489,457],[457,489,490,458],[458,490,491,459],[459,491,492,460],[460,492,493,461],[461,493,494,462],[462,494,495,463],[463,495,496,464],[464,496,497,465],[465,497,498,466],[466,498,499,467],[467,499,500,468],[468,500,501,469],[469,501,502,470],[470,502,503,471],[471,503,504,472],[472,504,505,473],[473,505,506,474],[474,506,507,475],[475,507,508,476],[476,508,509,477],[477,509,510,478],[478,510,511,479],[479,511,480,448],[480,512,513,481],[481,513,514,482],[482,514,515,483],[483,515,516,484],[484,516,517,485],[485,517,518,486],[486,518,519,487],[487,519,520,488],[488,520,521,489],[489,521,522,490],[490,522,523,491],[491,523,524,492],[492,524,525,493],[493,525,526,494],[494,526,527,495],[495,527,528,496],[496,528,529,497],[497,529,530,498],[498,530,531,499],[499,531,532,500],[500,532,533,501],[501,533,534,502],[502,534,535,503],[503,535,536,504],[504,536,537,505],[505,537,538,506],[506,538,539,507],[507,539,540,508],[508,540,541,509],[509,541,542,510],[510,542,543,511],[511,543,512,480],[512,544,545,513],[513,545,546,514],[514,546,547,515],[515,547,548,516],[516,548,549,517],[517,549,550,518],[518,550,551,519],[519,551,552,520],[520,552,553,521],[521,553,554,522],[522,554,555,523],[523,555,556,524],[524,556,557,525],[525,557,558,526],[526,558,559,527],[527,559,560,528],[528,560,561,529],[529,561,562,530],[530,562,563,531],[531,563,564,532],[532,564,565,533],[533,565,566,534],[534,566,567,535],[535,567,568,536],[536,568,569,537],[537,569,570,538],[538,570,571,539],[539,571,572,540],[540,572,573,541],[541,573,574,542],[542,574,575,543],[543,575,544,512],[544,576,577,545],[545,577,578,546],[546,578,579,547],[547,579,580,548],[548,580,581,549],[549,581,582,550],[550,582,583,551],[551,583,584,552],[552,584,585,553],[553,585,586,554],[554,586,587,555],[555,587,588,556],[556,588,589,557],[557,589,590,558],[558,590,591,559],[559,591,592,560],[560,592,593,561],[561,593,594,562],[562,594,595,563],[563,595,596,564],[564,596,597,565],[565,597,598,566],[566,598,599,567],[567,599,600,568],[568,600,601,569],[569,601,602,570],[570,602,603,571],[571,603,604,572],[572,604,605,573],[573,605,606,574],[574,606,607,575],[575,607,576,544],[608,577,576],[608,578,577],[608,579,578],[608,580,579],[608,581,580],[608,582,581],[608,583,582],[608,584,583],[608,585,584],[608,586,585],[608,587,586],[608,588,587],[608,589,588],[608,590,589],[608,591,590],[608,592,591],[608,593,592],[608,594,593],[608,595,594],[608,596,595],[608,597,596],[608,598,597],[608,599,598],[608,600,599],[608,601,600],[608,602,601],[608,603,602],[608,604,603],[608,605,604],[608,606,605],[608,607,606],[608,576,607]]
+ }
},
"cases": [
{ "id": "extrude-region-cube-top", "input": "cube", "edit": { "op": "extrude_face_region", "select": { "normal": [0,0,1] }, "offset": 0.5 } },
@@ -103,6 +115,12 @@
{ "id": "set-position-cube-scale-sum", "input": "cube", "edit": {"op":"set_position","offset":{"vec":[{"sub":[{"attr":"position","component":"z"},{"attr":"position","component":"x"}]},{"add":[{"mul":[{"attr":"position","component":"y"},2]},0.25]},0]}} },
{ "id": "displace-cube-constant-normal", "input": "cube", "edit": {"op":"displace","field":1,"strength":0.4,"midlevel":0.5,"direction":"normal"} },
{ "id": "displace-cube-gradient-z", "input": "cube", "edit": {"op":"displace","field":{"mul":[{"add":[{"attr":"position","component":"x"},1]},0.5]},"strength":0.8,"midlevel":0.5,"direction":"z"} },
- { "id": "displace-grid-gradient-normal", "input": "grid", "edit": {"op":"displace","field":{"mul":[{"add":[{"attr":"position","component":"x"},1]},0.5]},"strength":-0.6,"midlevel":0.25,"direction":"normal"} }
+ { "id": "displace-grid-gradient-normal", "input": "grid", "edit": {"op":"displace","field":{"mul":[{"add":[{"attr":"position","component":"x"},1]},0.5]},"strength":-0.6,"midlevel":0.25,"direction":"normal"} },
+ { "id": "decimate-sphere-half", "input": "sphere-bumpy", "compare": "surface", "edit": {"op":"decimate","ratio":0.5} },
+ { "id": "decimate-sphere-tenth", "input": "sphere-bumpy", "compare": "surface", "edit": {"op":"decimate","ratio":0.1} },
+ { "id": "decimate-torus-quarter", "input": "torus-fine", "compare": "surface", "edit": {"op":"decimate","ratio":0.25} },
+ { "id": "decimate-bowl-half", "input": "bowl-open", "compare": "surface", "edit": {"op":"decimate","ratio":0.5} },
+ { "id": "remesh-sphere", "input": "sphere-bumpy", "compare": "surface", "edit": {"op":"remesh","voxelSize":0.1} },
+ { "id": "remesh-torus", "input": "torus-fine", "compare": "surface", "edit": {"op":"remesh","voxelSize":0.08} }
]
}
diff --git a/tests/fixtures/blender/differences.json b/tests/fixtures/blender/differences.json
index 7c790193..8d3f49f7 100644
--- a/tests/fixtures/blender/differences.json
+++ b/tests/fixtures/blender/differences.json
@@ -46,5 +46,11 @@
"edgeCount": "Blender's check here is a plane through the line that holds the projection direction, which also cuts the two faces that run along that direction. 67.js cuts only faces the projection can see side-on to the line, so those two faces keep their edges and gain the cut points as corners.",
"faceCount": "The two faces that run along the projection direction are not split by the knife, so 67.js has two faces fewer than the plane cut.",
"faceSizes": "Those two faces stay whole with the cut points inserted, so they become hexagons where Blender has four quads."
+ },
+ "remesh-sphere": {
+ "faceCount": "Both build a quad surface on a grid of the same voxel size, but the grids start at different points and Blender's OpenVDB mesher and the surface nets of 67.js cut the surface into different cells, so the counts differ by 2.2%. Volume, area and Hausdorff distance agree."
+ },
+ "remesh-torus": {
+ "faceCount": "Both build a quad surface on a grid of the same voxel size, but the grids start at different points and Blender's OpenVDB mesher and the surface nets of 67.js cut the surface into different cells, so 67.js has 6.6% fewer quads. Volume, area and Hausdorff distance agree."
}
}
diff --git a/tests/fixtures/blender/golden.json b/tests/fixtures/blender/golden.json
index 31aff9b7..b887e059 100644
--- a/tests/fixtures/blender/golden.json
+++ b/tests/fixtures/blender/golden.json
@@ -23224,6 +23224,42 @@
-1.05
]
]
+ },
+ "decimate-sphere-half": {
+ "faceCount": 608,
+ "volume": 4.143237,
+ "area": 13.725116,
+ "hausdorff": 0.027064
+ },
+ "decimate-sphere-tenth": {
+ "faceCount": 120,
+ "volume": 4.084994,
+ "area": 13.793516,
+ "hausdorff": 0.063438
+ },
+ "decimate-torus-quarter": {
+ "faceCount": 256,
+ "volume": 2.301407,
+ "area": 13.776178,
+ "hausdorff": 0.030366
+ },
+ "decimate-bowl-half": {
+ "faceCount": 592,
+ "volume": 4.097792,
+ "area": 12.71941,
+ "hausdorff": 0.016792
+ },
+ "remesh-sphere": {
+ "faceCount": 2066,
+ "volume": 4.12985,
+ "area": 13.104959,
+ "hausdorff": 0.070482
+ },
+ "remesh-torus": {
+ "faceCount": 3144,
+ "volume": 2.302192,
+ "area": 13.48201,
+ "hausdorff": 0.012668
}
}
}
diff --git a/tests/mesh-decimate.test.js b/tests/mesh-decimate.test.js
new file mode 100644
index 00000000..1db74c79
--- /dev/null
+++ b/tests/mesh-decimate.test.js
@@ -0,0 +1,154 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { createMeshData, applyMeshEdits, evaluateMeshStack, meshTags, facesWithTag, validateTopology, editMesh } from '../src/mesh.js';
+import { decimateMesh } from '../src/mesh-decimate.js';
+import { remeshMesh } from '../src/mesh-remesh.js';
+import { generateMeshLods, generateGeometryLods, generateAssetLods } from '../src/mesh-lod.js';
+import { surfaceDeviation, signedVolume } from '../src/mesh-surface-distance.js';
+import { withFaceAttributes } from '../src/mesh-convert.js';
+import { extractRender } from '../src/mesh-render.js';
+
+function sphere(columns, rows, { open = false } = {}) {
+ const positions = [0, 0, 1];
+ for (let row = 1; row < rows; row++) {
+ for (let column = 0; column < columns; column++) {
+ const polar = Math.PI * row / rows;
+ const azimuth = 2 * Math.PI * column / columns;
+ positions.push(Math.sin(polar) * Math.cos(azimuth), Math.sin(polar) * Math.sin(azimuth), Math.cos(polar));
+ }
+ }
+ positions.push(0, 0, -1);
+ const ring = (row, column) => 1 + (row - 1) * columns + (column % columns);
+ const bottom = positions.length / 3 - 1;
+ const faces = [];
+ if (!open) for (let column = 0; column < columns; column++) faces.push([0, ring(1, column), ring(1, column + 1)]);
+ for (let row = 1; row < rows - 1; row++) {
+ for (let column = 0; column < columns; column++) faces.push([ring(row, column), ring(row + 1, column), ring(row + 1, column + 1), ring(row, column + 1)]);
+ }
+ for (let column = 0; column < columns; column++) faces.push([bottom, ring(rows - 1, column + 1), ring(rows - 1, column)]);
+ const faceOffsets = new Uint32Array(faces.length + 1);
+ faces.forEach((face, index) => {
+ faceOffsets[index + 1] = faceOffsets[index] + face.length;
+ });
+ return createMeshData({ positions: new Float32Array(positions), faceOffsets, cornerVertices: new Uint32Array(faces.flat()) });
+}
+
+function tagUpperHalf(mesh) {
+ const data = new Uint8Array(mesh.faceCount);
+ for (let face = 0; face < mesh.faceCount; face++) {
+ let height = 0;
+ for (let corner = mesh.faceOffsets[face]; corner < mesh.faceOffsets[face + 1]; corner++) height += mesh.positions[mesh.cornerVertices[corner] * 3 + 2];
+ data[face] = height > 0 ? 1 : 0;
+ }
+ return withFaceAttributes(mesh, { 'tag:top': { data, size: 1 } });
+}
+
+function openBoundaryVertices(mesh) {
+ const counts = new Map();
+ for (let face = 0; face < mesh.faceCount; face++) {
+ const start = mesh.faceOffsets[face];
+ const end = mesh.faceOffsets[face + 1];
+ for (let corner = start; corner < end; corner++) {
+ const first = mesh.cornerVertices[corner];
+ const second = mesh.cornerVertices[corner + 1 === end ? start : corner + 1];
+ const key = first < second ? `${first},${second}` : `${second},${first}`;
+ counts.set(key, (counts.get(key) ?? 0) + 1);
+ }
+ }
+ const boundary = new Set();
+ for (const [key, count] of counts) if (count === 1) key.split(',').forEach(vertex => boundary.add(Number(vertex)));
+ return [...boundary].map(vertex => Array.from(mesh.positions.subarray(vertex * 3, vertex * 3 + 3)));
+}
+
+test('decimate reaches its ratio, keeps the surface close and the mesh valid', () => {
+ const source = sphere(40, 24);
+ const { mesh, triangles, reachedTarget } = decimateMesh(source, { ratio: 0.25 });
+ assert.equal(reachedTarget, true);
+ assert.ok(mesh.faceCount <= Math.ceil(triangles.before * 0.25));
+ assert.equal(validateTopology(editMesh(mesh)).euler, 2);
+ assert.ok(surfaceDeviation(mesh, source).hausdorff < 0.04);
+ assert.ok(Math.abs(signedVolume(mesh) - signedVolume(source)) / signedVolume(source) < 0.03);
+});
+
+test('decimate keeps the open boundary where it was', () => {
+ const source = sphere(40, 24, { open: true });
+ const { mesh } = decimateMesh(source, { ratio: 0.2 });
+ const rim = openBoundaryVertices(mesh);
+ assert.ok(rim.length >= 3);
+ const rimHeight = Math.cos(Math.PI / 24);
+ const rimRadius = Math.sin(Math.PI / 24);
+ for (const [x, y, z] of rim) {
+ assert.ok(Math.abs(z - rimHeight) < 1e-4, 'the rim stays in its plane');
+ assert.ok(Math.hypot(x, y) <= rimRadius + 1e-4 && Math.hypot(x, y) > rimRadius * 0.9, 'the rim stays on its circle');
+ }
+});
+
+test('decimate keeps tags and the border between them', () => {
+ const source = tagUpperHalf(sphere(40, 24));
+ const { mesh } = decimateMesh(source, { ratio: 0.2 });
+ assert.deepEqual(meshTags(mesh), ['top']);
+ const top = facesWithTag(mesh, 'top');
+ assert.ok(top.length > 0 && top.length < mesh.faceCount);
+ for (const face of top) {
+ for (let corner = mesh.faceOffsets[face]; corner < mesh.faceOffsets[face + 1]; corner++) {
+ assert.ok(mesh.positions[mesh.cornerVertices[corner] * 3 + 2] > -0.2, 'the top tag stays in the upper part');
+ }
+ }
+});
+
+test('decimate rejects a bad ratio and stops at four triangles', () => {
+ const source = sphere(8, 6);
+ assert.throws(() => decimateMesh(source, { ratio: 0 }), /ratio/);
+ assert.throws(() => decimateMesh(source, { ratio: 1.5 }), /ratio/);
+ assert.ok(decimateMesh(source, { ratio: 0.001 }).mesh.faceCount >= 4);
+});
+
+test('decimate and remesh run as edits and as stack nodes with a budget', () => {
+ const source = sphere(40, 24);
+ const edited = applyMeshEdits(source, [{ op: 'decimate', ratio: 0.5 }]);
+ assert.equal(edited.results[0].triangles.before, 40 * 22 * 2 + 40 * 2);
+ const stacked = evaluateMeshStack(source, [{ op: 'remesh', resolution: 20 }]);
+ assert.ok(stacked.mesh.faceCount > 100);
+ assert.throws(() => applyMeshEdits(source, [{ op: 'decimate', ratio: 2 }]), /ratio/);
+ assert.throws(() => applyMeshEdits(source, [{ op: 'remesh', voxelSize: 0.1, resolution: 20 }]), /exactly one/);
+ assert.throws(() => applyMeshEdits(source, [{ op: 'remesh', resolution: 500 }]), /resolution/);
+ assert.throws(() => applyMeshEdits(source, [{ op: 'remesh', voxelSize: 0.001 }]), /over the limits/);
+});
+
+test('remesh makes a closed quad surface with positive volume near the input', () => {
+ const source = sphere(40, 24);
+ const { mesh, voxelSize } = remeshMesh(source, { resolution: 32 });
+ assert.equal(validateTopology(editMesh(mesh)).euler, 2);
+ assert.equal(mesh.faceOffsets[1] - mesh.faceOffsets[0], 4);
+ assert.ok(signedVolume(mesh) > 0);
+ assert.ok(surfaceDeviation(mesh, source).hausdorff < voxelSize);
+ assert.ok(Math.abs(signedVolume(mesh) - signedVolume(source)) / signedVolume(source) < 0.03);
+});
+
+test('remesh refuses an open surface and a mesh smaller than a voxel', () => {
+ assert.throws(() => remeshMesh(sphere(16, 10, { open: true }), { resolution: 16 }), /closed/);
+ assert.throws(() => remeshMesh(sphere(16, 10), { voxelSize: 100 }), /no surface|voxel/);
+});
+
+test('generated levels shrink, report a growing error and share the input as level 0', () => {
+ const source = sphere(40, 24);
+ const levels = generateMeshLods(source, { ratios: [0.5, 0.2] });
+ assert.deepEqual(levels.map(level => level.level), [0, 1, 2]);
+ assert.equal(levels[0].mesh, source);
+ assert.ok(levels[1].triangles < levels[0].triangles && levels[2].triangles < levels[1].triangles);
+ assert.ok(levels[1].error > 0 && levels[2].error >= levels[1].error);
+ assert.throws(() => generateMeshLods(source, { ratios: [0.2, 0.5] }), /decreasing/);
+});
+
+test('geometry and asset levels return renderer geometry, and refuse skinned parts', () => {
+ const geometry = extractRender(sphere(40, 24)).geometry;
+ const levels = generateGeometryLods(geometry, { ratios: [0.25] });
+ assert.equal(levels[0].geometry, geometry);
+ assert.ok(levels[1].geometry.indices.length < geometry.indices.length);
+ assert.ok(levels[1].geometry.normals.length === levels[1].geometry.positions.length);
+ const asset = { parts: [{ name: 'ball', geometry }, { name: 'twin', geometry }] };
+ const assetLevels = generateAssetLods(asset, { ratios: [0.25] });
+ assert.equal(assetLevels.length, 2);
+ assert.equal(assetLevels[1].asset.parts[0].geometry, assetLevels[1].asset.parts[1].geometry);
+ assert.throws(() => generateAssetLods({ parts: [{ name: 'arm', geometry, skin: {} }] }), /skinned/);
+});