topotopo 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +10 -10
- package/README.md +460 -117
- package/dist/cli.js +327 -147
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/bake.d.ts +14 -3
- package/dist/core/bake.js +153 -4
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +76 -3
- package/dist/core/decimate.d.ts +65 -0
- package/dist/core/decimate.js +409 -3
- package/dist/core/erosion.d.ts +37 -0
- package/dist/core/erosion.js +41 -1
- package/dist/core/geometry.d.ts +5 -1
- package/dist/core/geometry.js +203 -3
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/intrinsics.d.ts +7 -0
- package/dist/core/intrinsics.js +94 -0
- package/dist/core/manifold.d.ts +12 -1
- package/dist/core/manifold.js +78 -6
- package/dist/core/materials.d.ts +7 -0
- package/dist/core/materials.js +45 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/repair.d.ts +2 -0
- package/dist/core/repair.js +2 -0
- package/dist/core/report.d.ts +70 -0
- package/dist/core/report.js +275 -0
- package/dist/core/scene.js +2 -1
- package/dist/core/sha256.d.ts +4 -0
- package/dist/core/sha256.js +69 -0
- package/dist/core/shapes.d.ts +3 -0
- package/dist/core/shapes.js +34 -0
- package/dist/core/snippet-lib.d.ts +14 -1
- package/dist/core/snippet-lib.js +39 -13
- package/dist/core/tangents.d.ts +2 -0
- package/dist/core/tangents.js +5 -1
- package/dist/core/texnoise.d.ts +6 -1
- package/dist/core/texnoise.js +6 -2
- package/dist/core/texsdf.d.ts +131 -0
- package/dist/core/texsdf.js +637 -0
- package/dist/core/texture.d.ts +163 -9
- package/dist/core/texture.js +844 -20
- package/dist/core/topology.d.ts +10 -0
- package/dist/core/topology.js +168 -0
- package/dist/core/unwrap.d.ts +72 -0
- package/dist/core/unwrap.js +800 -0
- package/dist/core/usercode.d.ts +27 -0
- package/dist/core/usercode.js +87 -0
- package/dist/core/uv.d.ts +4 -18
- package/dist/core/uv.js +35 -188
- package/dist/core/uvislands.d.ts +62 -0
- package/dist/core/uvislands.js +574 -0
- package/dist/core/uvoverlap.d.ts +58 -0
- package/dist/core/uvoverlap.js +220 -0
- package/dist/core/uvpack.d.ts +64 -0
- package/dist/core/uvpack.js +628 -0
- package/dist/core/uvreport.d.ts +61 -0
- package/dist/core/uvreport.js +207 -143
- package/dist/core/wrangle.d.ts +6 -1
- package/dist/core/wrangle.js +27 -16
- package/dist/core/xatlas.d.ts +16 -1
- package/dist/core/xatlas.js +66 -62
- package/dist/engines.d.ts +63 -0
- package/dist/engines.js +180 -0
- package/dist/explain.d.ts +4 -3
- package/dist/explain.js +129 -12
- package/dist/graph/engine.d.ts +92 -29
- package/dist/graph/engine.js +298 -148
- package/dist/graph/expr.d.ts +6 -3
- package/dist/graph/expr.js +18 -8
- package/dist/graph/outputs.d.ts +23 -0
- package/dist/graph/outputs.js +41 -0
- package/dist/graph/packages.d.ts +72 -0
- package/dist/graph/packages.js +261 -0
- package/dist/graph/parallel.d.ts +3 -1
- package/dist/graph/parallel.js +4 -1
- package/dist/graph/params.d.ts +6 -0
- package/dist/graph/params.js +34 -7
- package/dist/graph/scope.d.ts +55 -0
- package/dist/graph/scope.js +14 -0
- package/dist/graph/types.d.ts +75 -12
- package/dist/graph/types.js +4 -2
- package/dist/graph/vars.d.ts +16 -0
- package/dist/graph/vars.js +80 -0
- package/dist/host/artifacts.d.ts +10 -1
- package/dist/host/artifacts.js +37 -6
- package/dist/host/cook.d.ts +241 -0
- package/dist/host/cook.js +844 -0
- package/dist/host/export-targets.d.ts +42 -5
- package/dist/host/export-targets.js +72 -13
- package/dist/host/godot-commands.d.ts +4 -0
- package/dist/host/godot-commands.js +21 -0
- package/dist/host/godot.d.ts +183 -0
- package/dist/host/godot.js +916 -0
- package/dist/host/node.d.ts +12 -7
- package/dist/host/node.js +27 -9
- package/dist/host/pool.js +51 -2
- package/dist/host/sidecars.d.ts +8 -0
- package/dist/host/sidecars.js +50 -0
- package/dist/host/types.d.ts +19 -6
- package/dist/host/version.d.ts +1 -0
- package/dist/host/version.js +3 -0
- package/dist/host/worker.js +5 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/inspect.d.ts +80 -2
- package/dist/inspect.js +265 -30
- package/dist/io/common.d.ts +25 -5
- package/dist/io/export.js +2 -1
- package/dist/io/files.d.ts +23 -4
- package/dist/io/files.js +60 -8
- package/dist/io/gltf.js +134 -47
- package/dist/io/heightmap.d.ts +3 -0
- package/dist/io/heightmap.js +1 -0
- package/dist/io/import.js +10 -0
- package/dist/io/inspect-scene.d.ts +55 -0
- package/dist/io/inspect-scene.js +155 -0
- package/dist/io/kinds.d.ts +81 -0
- package/dist/io/kinds.js +163 -0
- package/dist/io/points.d.ts +2 -1
- package/dist/io/points.js +3 -1
- package/dist/io/sidecars.d.ts +24 -0
- package/dist/io/sidecars.js +57 -0
- package/dist/io/source.d.ts +65 -0
- package/dist/io/source.js +112 -0
- package/dist/io/targets.d.ts +47 -3
- package/dist/io/targets.js +148 -13
- package/dist/io/textures.js +21 -1
- package/dist/io/unreal.js +5 -1
- package/dist/mcp/docs.d.ts +10 -1
- package/dist/mcp/docs.js +786 -143
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +56 -27
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +198 -103
- package/dist/mcp/verify.d.ts +2 -2
- package/dist/mcp/verify.js +1 -1
- package/dist/mcp/workspace.d.ts +15 -0
- package/dist/mcp/workspace.js +349 -0
- package/dist/nodes/attributes.js +198 -1
- package/dist/nodes/bake.js +151 -47
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +51 -3
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +21 -9
- package/dist/nodes/curves.js +433 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +12 -38
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.js +16 -19
- package/dist/nodes/index.d.ts +1 -0
- package/dist/nodes/index.js +1 -0
- package/dist/nodes/material.js +89 -24
- package/dist/nodes/measure.js +43 -17
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.js +4 -2
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/splines.d.ts +15 -1
- package/dist/nodes/splines.js +112 -105
- package/dist/nodes/texture.d.ts +21 -6
- package/dist/nodes/texture.js +1318 -185
- package/dist/nodes/topology.d.ts +7 -0
- package/dist/nodes/topology.js +133 -6
- package/dist/nodes/transform.js +6 -2
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +5 -1
- package/dist/open.d.ts +19 -0
- package/dist/open.js +12 -0
- package/dist/package.d.ts +288 -0
- package/dist/package.js +772 -0
- package/dist/packages/check.d.ts +32 -0
- package/dist/packages/check.js +169 -0
- package/dist/packages/commands.d.ts +57 -0
- package/dist/packages/commands.js +537 -0
- package/dist/packages/registry.d.ts +796 -0
- package/dist/packages/registry.js +2998 -0
- package/dist/packages/update.d.ts +124 -0
- package/dist/packages/update.js +476 -0
- package/dist/render/options.d.ts +2 -0
- package/dist/render/options.js +57 -5
- package/dist/render/preview.d.ts +17 -4
- package/dist/render/preview.js +6 -4
- package/dist/render/raster.d.ts +74 -5
- package/dist/render/raster.js +527 -143
- package/dist/render/texview.d.ts +6 -0
- package/dist/render/texview.js +27 -0
- package/dist/scan.d.ts +61 -0
- package/dist/scan.js +228 -0
- package/dist/session.d.ts +311 -0
- package/dist/session.js +849 -0
- package/dist/viewer/app/api.js +48 -6
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +27 -7
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +5 -1
- package/dist/viewer/app/guides.js +122 -0
- package/dist/viewer/app/keymap.js +6 -3
- package/dist/viewer/app/layers.js +4 -4
- package/dist/viewer/app/main.js +185 -52
- package/dist/viewer/app/markers.js +60 -0
- package/dist/viewer/app/outliner.js +72 -27
- package/dist/viewer/app/output-info.js +45 -0
- package/dist/viewer/app/outputs.css +147 -8
- package/dist/viewer/app/outputs.js +168 -54
- package/dist/viewer/app/packages.js +614 -0
- package/dist/viewer/app/props.js +176 -52
- package/dist/viewer/app/scene.js +30 -5
- package/dist/viewer/app/select.js +4 -3
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +65 -7
- package/dist/viewer/app/vars.js +47 -0
- package/dist/viewer/app/welcome.js +72 -0
- package/dist/viewer/graph-file.d.ts +62 -0
- package/dist/viewer/graph-file.js +175 -0
- package/dist/viewer/index.html +23 -10
- package/dist/viewer/json-edit.d.ts +13 -0
- package/dist/viewer/json-edit.js +274 -0
- package/dist/viewer/outputs.d.ts +49 -5
- package/dist/viewer/outputs.js +264 -56
- package/dist/viewer/packages.d.ts +121 -0
- package/dist/viewer/packages.js +584 -0
- package/dist/viewer/server.d.ts +14 -9
- package/dist/viewer/server.js +266 -28
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/{gallery → web}/bake.d.ts +4 -4
- package/dist/{gallery → web}/bake.js +24 -15
- package/dist/web/folder-page.d.ts +101 -0
- package/dist/web/folder-page.js +146 -0
- package/dist/web/folders.d.ts +280 -0
- package/dist/web/folders.js +970 -0
- package/dist/web/library.d.ts +91 -0
- package/dist/web/library.js +228 -0
- package/dist/web/markdown.d.ts +45 -0
- package/dist/web/markdown.js +677 -0
- package/dist/web/pages.d.ts +258 -0
- package/dist/web/pages.js +301 -0
- package/dist/web/server.d.ts +24 -0
- package/dist/web/server.js +1068 -0
- package/dist/workspace.d.ts +88 -118
- package/dist/workspace.js +358 -460
- package/integrations/godot/addons/topotopo/LICENSE +202 -0
- package/integrations/godot/addons/topotopo/README.md +57 -0
- package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
- package/integrations/godot/addons/topotopo/dock.gd +266 -0
- package/integrations/godot/addons/topotopo/dock.tscn +72 -0
- package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
- package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
- package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
- package/integrations/godot/addons/topotopo/inspector.gd +38 -0
- package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
- package/integrations/godot/addons/topotopo/package.gd +23 -0
- package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
- package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
- package/integrations/godot/addons/topotopo/plugin.gd +970 -0
- package/integrations/godot/addons/topotopo/record.gd +435 -0
- package/integrations/godot/addons/topotopo/runner.gd +458 -0
- package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
- package/integrations/godot/addons/topotopo/watcher.gd +199 -0
- package/kernels/pkg/README.md +2 -1
- package/kernels/pkg-simd/README.md +2 -1
- package/library/architecture/versions/1.0/architecture.topo +12 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
- package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
- package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
- package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
- package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
- package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
- package/library/architecture/versions/1.0/version.json +1119 -0
- package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
- package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
- package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
- package/library/nature/versions/1.0/graphs/lineup.json +24 -0
- package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
- package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
- package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
- package/library/nature/versions/1.0/nature.topo +12 -0
- package/library/nature/versions/1.0/version.json +534 -0
- package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
- package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
- package/library/props/versions/1.0/graphs/lineup.json +18 -0
- package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
- package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
- package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
- package/library/props/versions/1.0/props.topo +12 -0
- package/library/props/versions/1.0/version.json +336 -0
- package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
- package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
- package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
- package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
- package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
- package/library/street/versions/1.0/graphs/lineup.json +22 -0
- package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
- package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
- package/library/street/versions/1.0/street.topo +12 -0
- package/library/street/versions/1.0/version.json +421 -0
- package/package.json +13 -8
- package/dist/gallery/app/gallery.css +0 -100
- package/dist/gallery/app/gallery.js +0 -80
- package/dist/gallery/cli.d.ts +0 -4
- package/dist/gallery/cli.js +0 -157
- package/dist/gallery/library.d.ts +0 -124
- package/dist/gallery/library.js +0 -366
- package/dist/gallery/pages.d.ts +0 -94
- package/dist/gallery/pages.js +0 -148
- package/dist/gallery/server.d.ts +0 -21
- package/dist/gallery/server.js +0 -391
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/dist/mcp/library.d.ts +0 -12
- package/dist/mcp/library.js +0 -159
- package/shelf/index.json +0 -190
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** The web app's port when the config names none. */
|
|
2
|
+
export declare const DEFAULT_PORT = 7340;
|
|
3
|
+
export interface LibraryRef {
|
|
4
|
+
name: string;
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* TopoTopo's built-in library: TopoTopo's own packages (owner "topotopo"), shipped in library/ beside src/ and dist/.
|
|
9
|
+
* Every package looks in it without listing it, and no other library takes its name. Its folder <name> holds the
|
|
10
|
+
* versions of topotopo/<name> (versions/<version>/); in TopoTopo's repository it is the package's working folder as well,
|
|
11
|
+
* a package, while an installed TopoTopo ships the versions alone (src/packages/registry.ts reads it).
|
|
12
|
+
*/
|
|
13
|
+
export declare const BUILTIN_LIBRARY: LibraryRef;
|
|
14
|
+
export interface WebConfig {
|
|
15
|
+
/** the config file read (or the one `library add` writes) */
|
|
16
|
+
file: string;
|
|
17
|
+
libraries: LibraryRef[];
|
|
18
|
+
/** the workspaces (games) registered, by name: the web app's front page lists them */
|
|
19
|
+
workspaces: LibraryRef[];
|
|
20
|
+
web: {
|
|
21
|
+
port: number;
|
|
22
|
+
cors: string[];
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare function configFile(): string;
|
|
26
|
+
/** The user's config with defaults filled in; libraries from $TOPOTOPO_LIBRARIES come after the file's. */
|
|
27
|
+
export declare function loadConfig(): WebConfig;
|
|
28
|
+
/** Add (or re-point) a library in the config file, keeping its other keys. */
|
|
29
|
+
export declare function addLibrary(name: string, dir: string): WebConfig;
|
|
30
|
+
/** Remove a library from the config file (its folder stays as it is); throws for a name not registered. */
|
|
31
|
+
export declare function removeLibrary(name: string): WebConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Register (or re-point) a workspace in the config file by its name, keeping the file's other keys; a folder is
|
|
34
|
+
* registered once (registered again under a new name, the old entry goes).
|
|
35
|
+
*/
|
|
36
|
+
export declare function addWorkspace(name: string, dir: string): WebConfig;
|
|
37
|
+
/** Where an engine plugin finds TopoTopo on this machine: absolute paths of node and of the CLI it runs. */
|
|
38
|
+
export interface InstallRecord {
|
|
39
|
+
node: string;
|
|
40
|
+
cli: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Record in the config file (keeping its other keys) where TopoTopo is installed, "install": {node, cli}: an engine
|
|
44
|
+
* plugin that runs cooks reads it when nothing else names TopoTopo (topotopo godot setup writes it). Returns the file.
|
|
45
|
+
*/
|
|
46
|
+
export declare function setInstall(install: InstallRecord): string;
|
|
47
|
+
/** The install record of the config file, or null when it has none. */
|
|
48
|
+
export declare function readInstall(): InstallRecord | null;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// The user's config: the libraries and workspaces registered by name (one set of names for both), the web app's
|
|
2
|
+
// settings, and TopoTopo's built-in library.
|
|
3
|
+
// ~/.topotopo/config.json (or $TOPOTOPO_CONFIG) {libraries: [{name, path}], workspaces: [{name, path}], web: {port, cors: [origins]},
|
|
4
|
+
// install: {node, cli} (where engine plugins find TopoTopo: topotopo godot setup)}
|
|
5
|
+
// $TOPOTOPO_LIBRARIES more libraries: name=path entries separated by path.delimiter
|
|
6
|
+
// TopoTopo carries a library of its own, its built-in library (BUILTIN_LIBRARY), which every package looks in without
|
|
7
|
+
// listing it. A package in a workspace finds packages in the workspace and the libraries its file lists; outside a
|
|
8
|
+
// workspace, in every registered library.
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import os from 'node:os';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import { ID_RE } from './graph/scope.js';
|
|
14
|
+
import { slugify } from './package.js';
|
|
15
|
+
/** The web app's port when the config names none. */
|
|
16
|
+
export const DEFAULT_PORT = 7340;
|
|
17
|
+
/**
|
|
18
|
+
* TopoTopo's built-in library: TopoTopo's own packages (owner "topotopo"), shipped in library/ beside src/ and dist/.
|
|
19
|
+
* Every package looks in it without listing it, and no other library takes its name. Its folder <name> holds the
|
|
20
|
+
* versions of topotopo/<name> (versions/<version>/); in TopoTopo's repository it is the package's working folder as well,
|
|
21
|
+
* a package, while an installed TopoTopo ships the versions alone (src/packages/registry.ts reads it).
|
|
22
|
+
*/
|
|
23
|
+
export const BUILTIN_LIBRARY = { name: 'topotopo', path: fileURLToPath(new URL('../library', import.meta.url)) };
|
|
24
|
+
const builtinName = (name, from) => `${from}"${name}" is the name of TopoTopo's built-in library, which every package looks in: give this library another name`;
|
|
25
|
+
// ---------------------------------------------------------------------------------------------------------- config
|
|
26
|
+
export function configFile() {
|
|
27
|
+
return path.resolve(process.env.TOPOTOPO_CONFIG ?? path.join(os.homedir(), '.topotopo', 'config.json'));
|
|
28
|
+
}
|
|
29
|
+
/** The user's config with defaults filled in; libraries from $TOPOTOPO_LIBRARIES come after the file's. */
|
|
30
|
+
export function loadConfig() {
|
|
31
|
+
const file = configFile();
|
|
32
|
+
let raw = {};
|
|
33
|
+
if (fs.existsSync(file)) {
|
|
34
|
+
try {
|
|
35
|
+
raw = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
throw new Error(`${file}: ${e.message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const libraries = [];
|
|
42
|
+
const add = (name, p, from) => {
|
|
43
|
+
if (!ID_RE.test(name))
|
|
44
|
+
throw new Error(`${from}: library name "${name}" must match ${ID_RE}`);
|
|
45
|
+
if (name === BUILTIN_LIBRARY.name)
|
|
46
|
+
throw new Error(builtinName(name, `${from}: `));
|
|
47
|
+
if (libraries.some((l) => l.name === name))
|
|
48
|
+
return;
|
|
49
|
+
libraries.push({ name, path: path.resolve(path.dirname(file), p) });
|
|
50
|
+
};
|
|
51
|
+
for (const l of Array.isArray(raw.libraries) ? raw.libraries : []) {
|
|
52
|
+
if (!l || typeof l.name !== 'string' || typeof l.path !== 'string')
|
|
53
|
+
throw new Error(`${file}: each library is {"name": "...", "path": "..."}`);
|
|
54
|
+
add(l.name, l.path, file);
|
|
55
|
+
}
|
|
56
|
+
for (const entry of (process.env.TOPOTOPO_LIBRARIES ?? '').split(path.delimiter).filter(Boolean)) {
|
|
57
|
+
const i = entry.indexOf('=');
|
|
58
|
+
// "name=path", or a bare path named after its folder ("C:\x" has no "=" before the drive colon)
|
|
59
|
+
if (i > 0)
|
|
60
|
+
add(entry.slice(0, i), entry.slice(i + 1), 'TOPOTOPO_LIBRARIES');
|
|
61
|
+
else
|
|
62
|
+
add(slugify(path.basename(path.resolve(entry))) || 'library', entry, 'TOPOTOPO_LIBRARIES');
|
|
63
|
+
}
|
|
64
|
+
const workspaces = [];
|
|
65
|
+
for (const w of Array.isArray(raw.workspaces) ? raw.workspaces : []) {
|
|
66
|
+
if (!w || typeof w.name !== 'string' || typeof w.path !== 'string' || !ID_RE.test(w.name))
|
|
67
|
+
throw new Error(`${file}: each workspace is {"name": "...", "path": "..."} (a name of lower-case letters, digits, - and _)`);
|
|
68
|
+
if (!workspaces.some((x) => x.name === w.name))
|
|
69
|
+
workspaces.push({ name: w.name, path: path.resolve(path.dirname(file), w.path) });
|
|
70
|
+
}
|
|
71
|
+
const g = raw.web ?? {};
|
|
72
|
+
return {
|
|
73
|
+
file, libraries, workspaces,
|
|
74
|
+
web: {
|
|
75
|
+
port: Number.isInteger(g.port) ? g.port : DEFAULT_PORT,
|
|
76
|
+
cors: Array.isArray(g.cors) ? g.cors.filter((o) => typeof o === 'string') : [],
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** The config file as it is on disk (an object; {} for none), to change and write back keeping its other keys. */
|
|
81
|
+
function rawConfig(file) {
|
|
82
|
+
if (!fs.existsSync(file))
|
|
83
|
+
return {};
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(fs.readFileSync(file, 'utf8')) ?? {};
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
throw new Error(`${file}: ${e.message}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function writeConfig(file, raw) {
|
|
92
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
93
|
+
fs.writeFileSync(file, JSON.stringify(raw, null, 2) + '\n');
|
|
94
|
+
}
|
|
95
|
+
/** A registered name of the other kind: workspaces and libraries share one set of names (a web app address /p/<name>/<id> means one thing). */
|
|
96
|
+
function nameTaken(raw, name, kind) {
|
|
97
|
+
const other = kind === 'library' ? raw.workspaces : raw.libraries;
|
|
98
|
+
const hit = (Array.isArray(other) ? other : []).find((x) => x?.name === name);
|
|
99
|
+
return hit ? `"${name}" is the name of a registered ${kind === 'library' ? 'workspace' : 'library'} (${hit.path}): workspaces and libraries share one set of names; give the ${kind} another name` : null;
|
|
100
|
+
}
|
|
101
|
+
/** Add (or re-point) a library in the config file, keeping its other keys. */
|
|
102
|
+
export function addLibrary(name, dir) {
|
|
103
|
+
if (!ID_RE.test(name))
|
|
104
|
+
throw new Error(`library name "${name}" must match ${ID_RE} (e.g. "${slugify(name) || 'game'}")`);
|
|
105
|
+
if (name === BUILTIN_LIBRARY.name)
|
|
106
|
+
throw new Error(builtinName(name, ''));
|
|
107
|
+
const file = configFile();
|
|
108
|
+
const raw = rawConfig(file);
|
|
109
|
+
const taken = nameTaken(raw, name, 'library');
|
|
110
|
+
if (taken)
|
|
111
|
+
throw new Error(taken);
|
|
112
|
+
const libs = (Array.isArray(raw.libraries) ? raw.libraries : []).filter((l) => l?.name !== name);
|
|
113
|
+
libs.push({ name, path: path.resolve(dir) });
|
|
114
|
+
raw.libraries = libs;
|
|
115
|
+
fs.mkdirSync(path.resolve(dir), { recursive: true });
|
|
116
|
+
writeConfig(file, raw);
|
|
117
|
+
return loadConfig();
|
|
118
|
+
}
|
|
119
|
+
/** Remove a library from the config file (its folder stays as it is); throws for a name not registered. */
|
|
120
|
+
export function removeLibrary(name) {
|
|
121
|
+
const file = configFile();
|
|
122
|
+
const raw = rawConfig(file);
|
|
123
|
+
const libs = Array.isArray(raw.libraries) ? raw.libraries : [];
|
|
124
|
+
if (!libs.some((l) => l?.name === name))
|
|
125
|
+
throw new Error(`no library "${name}" is registered in ${file}${libs.length ? ` (it has ${libs.map((l) => l.name).join(', ')})` : ''}`);
|
|
126
|
+
raw.libraries = libs.filter((l) => l?.name !== name);
|
|
127
|
+
writeConfig(file, raw);
|
|
128
|
+
return loadConfig();
|
|
129
|
+
}
|
|
130
|
+
/** Two paths name the same folder (without case on Windows and macOS). */
|
|
131
|
+
const sameFolder = (a, b) => (process.platform === 'linux' ? path.resolve(a) === path.resolve(b) : path.resolve(a).toLowerCase() === path.resolve(b).toLowerCase());
|
|
132
|
+
/**
|
|
133
|
+
* Register (or re-point) a workspace in the config file by its name, keeping the file's other keys; a folder is
|
|
134
|
+
* registered once (registered again under a new name, the old entry goes).
|
|
135
|
+
*/
|
|
136
|
+
export function addWorkspace(name, dir) {
|
|
137
|
+
if (!ID_RE.test(name))
|
|
138
|
+
throw new Error(`workspace name "${name}" must match ${ID_RE}`);
|
|
139
|
+
if (name === BUILTIN_LIBRARY.name)
|
|
140
|
+
throw new Error(`"${name}" is the name of TopoTopo's built-in library: give the workspace another name`);
|
|
141
|
+
const file = configFile();
|
|
142
|
+
const raw = rawConfig(file);
|
|
143
|
+
const taken = nameTaken(raw, name, 'workspace');
|
|
144
|
+
if (taken)
|
|
145
|
+
throw new Error(taken);
|
|
146
|
+
const list = (Array.isArray(raw.workspaces) ? raw.workspaces : []).filter((w) => w?.name !== name && !(typeof w?.path === 'string' && sameFolder(path.resolve(path.dirname(file), w.path), dir)));
|
|
147
|
+
list.push({ name, path: path.resolve(dir) });
|
|
148
|
+
raw.workspaces = list;
|
|
149
|
+
writeConfig(file, raw);
|
|
150
|
+
return loadConfig();
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Record in the config file (keeping its other keys) where TopoTopo is installed, "install": {node, cli}: an engine
|
|
154
|
+
* plugin that runs cooks reads it when nothing else names TopoTopo (topotopo godot setup writes it). Returns the file.
|
|
155
|
+
*/
|
|
156
|
+
export function setInstall(install) {
|
|
157
|
+
const file = configFile();
|
|
158
|
+
const raw = rawConfig(file);
|
|
159
|
+
raw.install = { node: path.resolve(install.node), cli: path.resolve(install.cli) };
|
|
160
|
+
writeConfig(file, raw);
|
|
161
|
+
return file;
|
|
162
|
+
}
|
|
163
|
+
/** The install record of the config file, or null when it has none. */
|
|
164
|
+
export function readInstall() {
|
|
165
|
+
const file = configFile();
|
|
166
|
+
if (!fs.existsSync(file))
|
|
167
|
+
return null;
|
|
168
|
+
const i = rawConfig(file)?.install;
|
|
169
|
+
return i && typeof i.node === 'string' && typeof i.cli === 'string' ? { node: i.node, cli: i.cli } : null;
|
|
170
|
+
}
|
package/dist/core/bake.d.ts
CHANGED
|
@@ -89,7 +89,8 @@ export interface ProjectArgs {
|
|
|
89
89
|
/**
|
|
90
90
|
* For samples [start, end): cast a ray from P + N·cage along -N over 2·cage against the high-res scene and write the
|
|
91
91
|
* signed height of the nearest hit above the low surface (D = cage - t; NaN on a miss) and, when HN (the high mesh's
|
|
92
|
-
* point normals) is given, the hit's interpolated normal into NO (in the low normal's hemisphere).
|
|
92
|
+
* point normals) is given, the hit's interpolated normal into NO (in the low normal's hemisphere). A per-sample cage
|
|
93
|
+
* C (one value per sample), when given, replaces a.cage.
|
|
93
94
|
*/
|
|
94
95
|
export declare function projectRange(a: ProjectArgs, A: Record<string, any>, scene: RayScene, start: number, end: number): void;
|
|
95
96
|
export interface CurvatureEdges {
|
|
@@ -103,8 +104,18 @@ export interface CurvatureEdges {
|
|
|
103
104
|
FN: Float64Array;
|
|
104
105
|
count: number;
|
|
105
106
|
}
|
|
106
|
-
/**
|
|
107
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Edges between two polygons (points matched by position, tolerance `tol`) with a bend of at least minAngle degrees.
|
|
109
|
+
* With `intersections`, also the creases where separate parts cut into each other (a bolt through a plate, a box sunk
|
|
110
|
+
* into another: triangles that cross without sharing a point), as concave edges: there the surface of the whole folds
|
|
111
|
+
* inward by the angle between the two faces. `counts` receives how many of each were found and whether the pair
|
|
112
|
+
* search stopped at its cap.
|
|
113
|
+
*/
|
|
114
|
+
export declare function curvatureEdges(g: Geometry, tol: number, minAngle?: number, intersections?: boolean, counts?: {
|
|
115
|
+
shared: number;
|
|
116
|
+
crossing: number;
|
|
117
|
+
capped: boolean;
|
|
118
|
+
}): CurvatureEdges;
|
|
108
119
|
export interface EdgeGrid {
|
|
109
120
|
origin: [number, number, number];
|
|
110
121
|
cell: number;
|
package/dist/core/bake.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { distanceTransform } from './heightfield.js';
|
|
2
2
|
import { hash32 } from './random.js';
|
|
3
3
|
import { primNormals } from './topology.js';
|
|
4
|
+
import { TriBVH } from './spatial.js';
|
|
4
5
|
/**
|
|
5
6
|
* Rasterise triangles (vertex index triples into `uv`, 2 floats per vertex) into a w × h texel grid. Centre-inside
|
|
6
7
|
* texels first; then, with conservative, texels within half a texel diagonal of a triangle that no triangle covers
|
|
@@ -399,13 +400,15 @@ export function idColor(id, seed = 0) {
|
|
|
399
400
|
/**
|
|
400
401
|
* For samples [start, end): cast a ray from P + N·cage along -N over 2·cage against the high-res scene and write the
|
|
401
402
|
* signed height of the nearest hit above the low surface (D = cage - t; NaN on a miss) and, when HN (the high mesh's
|
|
402
|
-
* point normals) is given, the hit's interpolated normal into NO (in the low normal's hemisphere).
|
|
403
|
+
* point normals) is given, the hit's interpolated normal into NO (in the low normal's hemisphere). A per-sample cage
|
|
404
|
+
* C (one value per sample), when given, replaces a.cage.
|
|
403
405
|
*/
|
|
404
406
|
export function projectRange(a, A, scene, start, end) {
|
|
405
407
|
const P = A.P, N = A.N, D = A.D, NO = A.NO;
|
|
406
408
|
const HN = A.HN, Tri = A.T, triPt = A.triPt;
|
|
407
|
-
const
|
|
409
|
+
const C = A.C && A.C.length ? A.C : undefined;
|
|
408
410
|
for (let i = start; i < end; i++) {
|
|
411
|
+
const cage = C ? C[i] : a.cage;
|
|
409
412
|
const nx = N[i * 3], ny = N[i * 3 + 1], nz = N[i * 3 + 2];
|
|
410
413
|
if (!(nx || ny || nz)) {
|
|
411
414
|
D[i] = NaN;
|
|
@@ -447,8 +450,14 @@ export function projectRange(a, A, scene, start, end) {
|
|
|
447
450
|
NO[i * 3 + 2] = hz;
|
|
448
451
|
}
|
|
449
452
|
}
|
|
450
|
-
/**
|
|
451
|
-
|
|
453
|
+
/**
|
|
454
|
+
* Edges between two polygons (points matched by position, tolerance `tol`) with a bend of at least minAngle degrees.
|
|
455
|
+
* With `intersections`, also the creases where separate parts cut into each other (a bolt through a plate, a box sunk
|
|
456
|
+
* into another: triangles that cross without sharing a point), as concave edges: there the surface of the whole folds
|
|
457
|
+
* inward by the angle between the two faces. `counts` receives how many of each were found and whether the pair
|
|
458
|
+
* search stopped at its cap.
|
|
459
|
+
*/
|
|
460
|
+
export function curvatureEdges(g, tol, minAngle = 0.5, intersections = false, counts) {
|
|
452
461
|
const P = g.P, np = g.numPoints;
|
|
453
462
|
const canon = new Int32Array(np);
|
|
454
463
|
const ids = new Map();
|
|
@@ -514,6 +523,15 @@ export function curvatureEdges(g, tol, minAngle = 0.5) {
|
|
|
514
523
|
K.push((s <= 0 ? 1 : -1) * (Math.acos(c) / (Math.PI / 2)));
|
|
515
524
|
FN.push(n1x, n1y, n1z, n2x, n2y, n2z);
|
|
516
525
|
}
|
|
526
|
+
const shared = K.length;
|
|
527
|
+
let capped = false;
|
|
528
|
+
if (intersections)
|
|
529
|
+
capped = crossingCreases(g, canon, tol, cosMin, E, K, FN);
|
|
530
|
+
if (counts) {
|
|
531
|
+
counts.shared = shared;
|
|
532
|
+
counts.crossing = K.length - shared;
|
|
533
|
+
counts.capped = capped;
|
|
534
|
+
}
|
|
517
535
|
const D = new Float64Array(K.length * 4);
|
|
518
536
|
for (let e = 0; e < K.length; e++) {
|
|
519
537
|
const ux = E[e * 6 + 3] - E[e * 6], uy = E[e * 6 + 4] - E[e * 6 + 1], uz = E[e * 6 + 5] - E[e * 6 + 2];
|
|
@@ -525,6 +543,137 @@ export function curvatureEdges(g, tol, minAngle = 0.5) {
|
|
|
525
543
|
}
|
|
526
544
|
return { E: Float64Array.from(E), D, K: Float64Array.from(K), FN: Float64Array.from(FN), count: K.length };
|
|
527
545
|
}
|
|
546
|
+
/**
|
|
547
|
+
* Creases where triangles that share no point (by position: `canon`) cross: the segment the two have in common becomes a
|
|
548
|
+
* concave edge (bend = −(angle between their normals) / 90°) with the two normals as its faces. Nearly parallel pairs
|
|
549
|
+
* (closer than the bend threshold `cosMin`) and coplanar overlaps are skipped. Appends to E, K, FN; returns true when the
|
|
550
|
+
* pair search stopped at `maxTests` candidate pairs.
|
|
551
|
+
*/
|
|
552
|
+
function crossingCreases(g, canon, tol, cosMin, E, K, FN, maxTests = 4_000_000) {
|
|
553
|
+
const bvh = new TriBVH(g);
|
|
554
|
+
const T = bvh.T, tp = bvh.triPt, nodes = bvh.nodes, child = bvh.child, order = bvh.order, nt = T.length / 9;
|
|
555
|
+
if (nt < 2)
|
|
556
|
+
return false;
|
|
557
|
+
const N = new Float64Array(nt * 3);
|
|
558
|
+
for (let t = 0; t < nt; t++) {
|
|
559
|
+
const o = t * 9;
|
|
560
|
+
const ux = T[o + 3] - T[o], uy = T[o + 4] - T[o + 1], uz = T[o + 5] - T[o + 2], vx = T[o + 6] - T[o], vy = T[o + 7] - T[o + 1], vz = T[o + 8] - T[o + 2];
|
|
561
|
+
const nx = uy * vz - uz * vy, ny = uz * vx - ux * vz, nz = ux * vy - uy * vx, l = Math.hypot(nx, ny, nz);
|
|
562
|
+
if (l > 1e-300) {
|
|
563
|
+
N[t * 3] = nx / l;
|
|
564
|
+
N[t * 3 + 1] = ny / l;
|
|
565
|
+
N[t * 3 + 2] = nz / l;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
const stack = new Int32Array(512), seg = new Float64Array(6);
|
|
569
|
+
let tested = 0;
|
|
570
|
+
for (let i = 0; i < nt; i++) {
|
|
571
|
+
if (!N[i * 3] && !N[i * 3 + 1] && !N[i * 3 + 2])
|
|
572
|
+
continue;
|
|
573
|
+
const o = i * 9;
|
|
574
|
+
const mnx = Math.min(T[o], T[o + 3], T[o + 6]) - tol, mxx = Math.max(T[o], T[o + 3], T[o + 6]) + tol;
|
|
575
|
+
const mny = Math.min(T[o + 1], T[o + 4], T[o + 7]) - tol, mxy = Math.max(T[o + 1], T[o + 4], T[o + 7]) + tol;
|
|
576
|
+
const mnz = Math.min(T[o + 2], T[o + 5], T[o + 8]) - tol, mxz = Math.max(T[o + 2], T[o + 5], T[o + 8]) + tol;
|
|
577
|
+
const a0 = canon[tp[i * 3]], a1 = canon[tp[i * 3 + 1]], a2 = canon[tp[i * 3 + 2]];
|
|
578
|
+
let sp = 0;
|
|
579
|
+
stack[sp++] = 0;
|
|
580
|
+
while (sp > 0) {
|
|
581
|
+
const n = stack[--sp], b = n * 6;
|
|
582
|
+
if (nodes[b] > mxx || nodes[b + 3] < mnx || nodes[b + 1] > mxy || nodes[b + 4] < mny || nodes[b + 2] > mxz || nodes[b + 5] < mnz)
|
|
583
|
+
continue;
|
|
584
|
+
const c0 = child[n * 2], c1 = child[n * 2 + 1];
|
|
585
|
+
if (c0 >= 0) {
|
|
586
|
+
stack[sp++] = c0;
|
|
587
|
+
stack[sp++] = c1;
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
const s = -1 - c0;
|
|
591
|
+
for (let k = s; k < s + c1; k++) {
|
|
592
|
+
const j = order[k];
|
|
593
|
+
if (j <= i || (!N[j * 3] && !N[j * 3 + 1] && !N[j * 3 + 2]))
|
|
594
|
+
continue;
|
|
595
|
+
const b0 = canon[tp[j * 3]], b1 = canon[tp[j * 3 + 1]], b2 = canon[tp[j * 3 + 2]];
|
|
596
|
+
if (b0 === a0 || b0 === a1 || b0 === a2 || b1 === a0 || b1 === a1 || b1 === a2 || b2 === a0 || b2 === a1 || b2 === a2)
|
|
597
|
+
continue;
|
|
598
|
+
const q = j * 9;
|
|
599
|
+
if (Math.min(T[q], T[q + 3], T[q + 6]) > mxx || Math.max(T[q], T[q + 3], T[q + 6]) < mnx ||
|
|
600
|
+
Math.min(T[q + 1], T[q + 4], T[q + 7]) > mxy || Math.max(T[q + 1], T[q + 4], T[q + 7]) < mny ||
|
|
601
|
+
Math.min(T[q + 2], T[q + 5], T[q + 8]) > mxz || Math.max(T[q + 2], T[q + 5], T[q + 8]) < mnz)
|
|
602
|
+
continue;
|
|
603
|
+
const c = N[i * 3] * N[j * 3] + N[i * 3 + 1] * N[j * 3 + 1] + N[i * 3 + 2] * N[j * 3 + 2];
|
|
604
|
+
if (c > cosMin || c < -cosMin)
|
|
605
|
+
continue; // (anti)parallel: no crease worth a bend
|
|
606
|
+
if (++tested > maxTests)
|
|
607
|
+
return true;
|
|
608
|
+
if (!crossSegment(T, o, q, N, i, j, tol, seg))
|
|
609
|
+
continue;
|
|
610
|
+
E.push(seg[0], seg[1], seg[2], seg[3], seg[4], seg[5]);
|
|
611
|
+
K.push(-Math.acos(Math.max(-1, Math.min(1, c))) / (Math.PI / 2));
|
|
612
|
+
FN.push(N[i * 3], N[i * 3 + 1], N[i * 3 + 2], N[j * 3], N[j * 3 + 1], N[j * 3 + 2]);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
/** Scratch of crossSegment: the points where a triangle meets the other's plane. */
|
|
619
|
+
const CS = new Float64Array(12);
|
|
620
|
+
/**
|
|
621
|
+
* The segment two non-coplanar triangles (offsets a, b in T; unit normals of triangles i, j in N) have in common, into
|
|
622
|
+
* out (two endpoints); false when they do not cross along a segment longer than eps.
|
|
623
|
+
*/
|
|
624
|
+
function crossSegment(T, a, b, N, i, j, eps, out) {
|
|
625
|
+
// where triangle `t` meets the plane through point `p` with normal n (two points into CS at `at`), or false
|
|
626
|
+
const onPlane = (t, p, n, at) => {
|
|
627
|
+
const d = [0, 0, 0];
|
|
628
|
+
for (let k = 0; k < 3; k++) {
|
|
629
|
+
const x = (T[t + k * 3] - T[p]) * N[n] + (T[t + k * 3 + 1] - T[p + 1]) * N[n + 1] + (T[t + k * 3 + 2] - T[p + 2]) * N[n + 2];
|
|
630
|
+
d[k] = Math.abs(x) <= eps ? 0 : x;
|
|
631
|
+
}
|
|
632
|
+
if ((d[0] > 0 && d[1] > 0 && d[2] > 0) || (d[0] < 0 && d[1] < 0 && d[2] < 0) || (!d[0] && !d[1] && !d[2]))
|
|
633
|
+
return false;
|
|
634
|
+
let m = 0;
|
|
635
|
+
const put = (x, y, z) => { if (m < 2) {
|
|
636
|
+
CS[at + m * 3] = x;
|
|
637
|
+
CS[at + m * 3 + 1] = y;
|
|
638
|
+
CS[at + m * 3 + 2] = z;
|
|
639
|
+
} m++; };
|
|
640
|
+
for (let k = 0; k < 3; k++) {
|
|
641
|
+
const k2 = (k + 1) % 3, o1 = t + k * 3, o2 = t + k2 * 3;
|
|
642
|
+
if (!d[k])
|
|
643
|
+
put(T[o1], T[o1 + 1], T[o1 + 2]);
|
|
644
|
+
if (d[k] * d[k2] < 0) {
|
|
645
|
+
const s = d[k] / (d[k] - d[k2]);
|
|
646
|
+
put(T[o1] + (T[o2] - T[o1]) * s, T[o1 + 1] + (T[o2 + 1] - T[o1 + 1]) * s, T[o1 + 2] + (T[o2 + 2] - T[o1 + 2]) * s);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
return m === 2;
|
|
650
|
+
};
|
|
651
|
+
if (!onPlane(a, b, j * 3, 0) || !onPlane(b, a, i * 3, 6))
|
|
652
|
+
return false;
|
|
653
|
+
// both segments lie on the line where the planes meet: overlap their intervals along it
|
|
654
|
+
const dx = N[i * 3 + 1] * N[j * 3 + 2] - N[i * 3 + 2] * N[j * 3 + 1], dy = N[i * 3 + 2] * N[j * 3] - N[i * 3] * N[j * 3 + 2], dz = N[i * 3] * N[j * 3 + 1] - N[i * 3 + 1] * N[j * 3];
|
|
655
|
+
const dl = Math.hypot(dx, dy, dz);
|
|
656
|
+
if (!(dl > 1e-12))
|
|
657
|
+
return false;
|
|
658
|
+
const at = (k) => (CS[k] * dx + CS[k + 1] * dy + CS[k + 2] * dz) / dl;
|
|
659
|
+
let a0 = at(0), a1 = at(3), sA = 0;
|
|
660
|
+
if (a1 < a0) {
|
|
661
|
+
const t = a0;
|
|
662
|
+
a0 = a1;
|
|
663
|
+
a1 = t;
|
|
664
|
+
sA = 1;
|
|
665
|
+
}
|
|
666
|
+
const b0 = Math.min(at(6), at(9)), b1 = Math.max(at(6), at(9));
|
|
667
|
+
const lo = Math.max(a0, b0), hi = Math.min(a1, b1);
|
|
668
|
+
if (!(hi - lo > eps) || !(a1 - a0 > 0))
|
|
669
|
+
return false;
|
|
670
|
+
// points of segment A at lo and hi
|
|
671
|
+
const p0 = sA ? 3 : 0, p1 = sA ? 0 : 3;
|
|
672
|
+
for (const [w, o] of [[(lo - a0) / (a1 - a0), 0], [(hi - a0) / (a1 - a0), 3]])
|
|
673
|
+
for (let c = 0; c < 3; c++)
|
|
674
|
+
out[o + c] = CS[p0 + c] + (CS[p1 + c] - CS[p0 + c]) * w;
|
|
675
|
+
return true;
|
|
676
|
+
}
|
|
528
677
|
/** A uniform grid over the edges (each edge listed in every cell its box overlaps); cells at least `minCell` wide. */
|
|
529
678
|
export function edgeGrid(e, minCell) {
|
|
530
679
|
const E = e.E, m = e.count;
|
package/dist/core/bevel.d.ts
CHANGED
|
@@ -41,8 +41,10 @@ export declare function pointFan(he: HalfEdgeMesh, v: number): PointFan | null;
|
|
|
41
41
|
export declare function shapeExponent(shape: number): number;
|
|
42
42
|
/** Point at parameter s (0..1) of the profile from p0 to p1 with control point c (see the header). */
|
|
43
43
|
export declare function profilePoint(p0: V3, p1: V3, c: V3, s: number, r: number): V3;
|
|
44
|
+
/** Edges whose two faces bend less than this (degrees) are flat: the default selection leaves them alone. */
|
|
45
|
+
export declare const FLAT_EDGE_DEG = 0.01;
|
|
44
46
|
/**
|
|
45
|
-
* Bevel the given edges (point pairs; null = every edge used by two polygons). Boundary, non-manifold and
|
|
47
|
+
* Bevel the given edges (point pairs; null = every edge used by two polygons where the surface bends). Boundary, non-manifold and
|
|
46
48
|
* inconsistently wound edges, and edges at non-manifold points, are skipped with a warning. Returns the input object
|
|
47
49
|
* itself when nothing is bevelled.
|
|
48
50
|
*/
|
package/dist/core/bevel.js
CHANGED
|
@@ -430,7 +430,72 @@ class Ctx {
|
|
|
430
430
|
}
|
|
431
431
|
// ---------------------------------------------------------------- edge bevel
|
|
432
432
|
/**
|
|
433
|
-
*
|
|
433
|
+
* Offsets of bevelled edges of one face that face each other (running opposite ways, each on the other's inner side,
|
|
434
|
+
* overlapping along their length) are scaled down until they add up to the gap between the edges. Returns how many
|
|
435
|
+
* pairs were scaled.
|
|
436
|
+
*/
|
|
437
|
+
function clampFacing(g, he, bevE, offE) {
|
|
438
|
+
const P = g.P;
|
|
439
|
+
const pt = (i) => [P[i * 3], P[i * 3 + 1], P[i * 3 + 2]];
|
|
440
|
+
let pairs = 0;
|
|
441
|
+
const nrm = [0, 0, 0];
|
|
442
|
+
for (let f = 0; f < g.numPrims; f++) {
|
|
443
|
+
const hs = he.faceHalfEdges(f).filter((h) => bevE[he.heEdge[h]]);
|
|
444
|
+
if (hs.length < 2)
|
|
445
|
+
continue;
|
|
446
|
+
primNewell(g, f, nrm);
|
|
447
|
+
const N = unit(nrm, [0, 0, 1]);
|
|
448
|
+
const seg = hs.map((h) => {
|
|
449
|
+
const a = pt(he.heOrigin[h]), b = pt(he.dest(h)), d = unit(sub(b, a), [1, 0, 0]);
|
|
450
|
+
return { e: he.heEdge[h], a, b, d, m: cross3(N, d), A: he.heOrigin[h], B: he.dest(h) };
|
|
451
|
+
});
|
|
452
|
+
for (let i = 0; i < seg.length; i++)
|
|
453
|
+
for (let j = i + 1; j < seg.length; j++) {
|
|
454
|
+
const s1 = seg[i], s2 = seg[j];
|
|
455
|
+
if (s1.A === s2.A || s1.A === s2.B || s1.B === s2.A || s1.B === s2.B)
|
|
456
|
+
continue;
|
|
457
|
+
if (dot(s1.d, s2.d) > -0.8)
|
|
458
|
+
continue; // not facing: corners between them are the corner clamp's
|
|
459
|
+
// each on the other's inner side, and overlapping along the first one's direction
|
|
460
|
+
const mid1 = scale(add(s1.a, s1.b), 0.5), mid2 = scale(add(s2.a, s2.b), 0.5);
|
|
461
|
+
if (dot(s1.m, sub(mid2, mid1)) <= 0 || dot(s2.m, sub(mid1, mid2)) <= 0)
|
|
462
|
+
continue;
|
|
463
|
+
const t0 = dot(sub(s2.a, s1.a), s1.d), t1 = dot(sub(s2.b, s1.a), s1.d), L = len(sub(s1.b, s1.a));
|
|
464
|
+
if (Math.max(t0, t1) <= 0 || Math.min(t0, t1) >= L)
|
|
465
|
+
continue;
|
|
466
|
+
const gap = segmentGap(s1.a, s1.b, s2.a, s2.b);
|
|
467
|
+
const need = offE[s1.e] + offE[s2.e];
|
|
468
|
+
if (!(need > gap) || !(gap > 0))
|
|
469
|
+
continue;
|
|
470
|
+
const k = (gap / need) * 0.999;
|
|
471
|
+
offE[s1.e] *= k;
|
|
472
|
+
offE[s2.e] *= k;
|
|
473
|
+
pairs++;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return pairs;
|
|
477
|
+
}
|
|
478
|
+
/** Smallest distance between segments ab and cd. */
|
|
479
|
+
function segmentGap(a, b, c, d) {
|
|
480
|
+
const u = sub(b, a), v = sub(d, c), w = sub(a, c);
|
|
481
|
+
const A = dot(u, u), B = dot(u, v), Cc = dot(v, v), D = dot(u, w), E = dot(v, w), den = A * Cc - B * B;
|
|
482
|
+
let s = den > 1e-30 ? (B * E - Cc * D) / den : 0, t;
|
|
483
|
+
s = Math.max(0, Math.min(1, s));
|
|
484
|
+
t = Cc > 1e-30 ? (B * s + E) / Cc : 0;
|
|
485
|
+
if (t < 0) {
|
|
486
|
+
t = 0;
|
|
487
|
+
s = A > 1e-30 ? Math.max(0, Math.min(1, -D / A)) : 0;
|
|
488
|
+
}
|
|
489
|
+
else if (t > 1) {
|
|
490
|
+
t = 1;
|
|
491
|
+
s = A > 1e-30 ? Math.max(0, Math.min(1, (B - D) / A)) : 0;
|
|
492
|
+
}
|
|
493
|
+
return len(sub(add(a, scale(u, s)), add(c, scale(v, t))));
|
|
494
|
+
}
|
|
495
|
+
/** Edges whose two faces bend less than this (degrees) are flat: the default selection leaves them alone. */
|
|
496
|
+
export const FLAT_EDGE_DEG = 0.01;
|
|
497
|
+
/**
|
|
498
|
+
* Bevel the given edges (point pairs; null = every edge used by two polygons where the surface bends). Boundary, non-manifold and
|
|
434
499
|
* inconsistently wound edges, and edges at non-manifold points, are skipped with a warning. Returns the input object
|
|
435
500
|
* itself when nothing is bevelled.
|
|
436
501
|
*/
|
|
@@ -463,7 +528,8 @@ export function bevelEdges(g, sel, opts) {
|
|
|
463
528
|
continue;
|
|
464
529
|
if (he.nonManifoldEdges.has(e))
|
|
465
530
|
nNonManifold++;
|
|
466
|
-
|
|
531
|
+
// an edge inside a flat area (a face split in two, a boolean's cut face) has nothing to bevel
|
|
532
|
+
else if (!(he.dihedralAngle(e) < FLAT_EDGE_DEG))
|
|
467
533
|
bevE[e] = 1;
|
|
468
534
|
}
|
|
469
535
|
if (nBoundary)
|
|
@@ -491,7 +557,7 @@ export function bevelEdges(g, sel, opts) {
|
|
|
491
557
|
for (let e = 0; e < ne; e++)
|
|
492
558
|
count += bevE[e];
|
|
493
559
|
if (!count) {
|
|
494
|
-
warnings.push('no edges to bevel: geometry unchanged');
|
|
560
|
+
warnings.push(sel ? 'no edges to bevel: geometry unchanged' : 'no edges to bevel: every edge is flat (both faces in one plane) or open; geometry unchanged');
|
|
495
561
|
return { geo: g, warnings, count: 0, scale: 1 };
|
|
496
562
|
}
|
|
497
563
|
const offsetMode = opts.offsetMode ?? 'distance';
|
|
@@ -507,6 +573,11 @@ export function bevelEdges(g, sel, opts) {
|
|
|
507
573
|
for (let e = 0; e < ne; e++)
|
|
508
574
|
if (bevE[e])
|
|
509
575
|
offE[e] = offsetMode === 'fraction' ? opts.offset * Math.min(minFanLen(he.edgeA[e]), minFanLen(he.edgeB[e])) : opts.offset;
|
|
576
|
+
// two bevelled edges facing each other across a narrow part of a face (the rims of a thin band) share no point, so
|
|
577
|
+
// the corner clamp below never sees them: their offsets may add up to at most the gap between them
|
|
578
|
+
let nFacing = 0;
|
|
579
|
+
if (opts.clamp ?? true)
|
|
580
|
+
nFacing = clampFacing(g, he, bevE, offE);
|
|
510
581
|
const C = new Ctx(g, opts.divisions ?? 0, opts.shape ?? 0);
|
|
511
582
|
const n = C.n;
|
|
512
583
|
// Pass A and the crossing constraints at the current offsets: each constraint is [largest scale, its two points].
|
|
@@ -668,6 +739,8 @@ export function bevelEdges(g, sel, opts) {
|
|
|
668
739
|
reduced++;
|
|
669
740
|
minLocal = Math.min(minLocal, offE[e] / off0[e]);
|
|
670
741
|
}
|
|
742
|
+
if (nFacing)
|
|
743
|
+
warnings.push(`offset reduced at ${nFacing} pair(s) of edges facing each other across a narrow face (a thin band or rim), so their bevels meet instead of crossing`);
|
|
671
744
|
if (reduced)
|
|
672
745
|
warnings.push(`offset reduced at ${reduced} edge(s) (to ${(minLocal * 100).toFixed(1)}% at least) so neighbouring bevels do not overlap; the other edges keep the full offset`);
|
|
673
746
|
if (nDropped)
|
package/dist/core/decimate.d.ts
CHANGED
|
@@ -35,6 +35,8 @@ export interface DecimateResult {
|
|
|
35
35
|
/** attributes that were used to steer, and requested ones that could not be */
|
|
36
36
|
used: string[];
|
|
37
37
|
skipped: string[];
|
|
38
|
+
/** input point of each output point */
|
|
39
|
+
srcPoint: Int32Array;
|
|
38
40
|
}
|
|
39
41
|
export declare class DecimateError extends Error {
|
|
40
42
|
}
|
|
@@ -45,6 +47,16 @@ export declare class DecimateError extends Error {
|
|
|
45
47
|
export declare function parseSteerAttribs(spec: string): SteerAttrib[];
|
|
46
48
|
/** Decimate the (selected) polygons of g to triangles with meshoptimizer; other prims pass through. */
|
|
47
49
|
export declare function decimateMesh(g: Geometry, o: DecimateOptions): DecimateResult;
|
|
50
|
+
/**
|
|
51
|
+
* What keeps the polygons of g from reducing freely (decimateMesh keeps every discontinuity of a render vertex): per
|
|
52
|
+
* cause, how many points hold one. Causes: a vertex attribute whose corners differ at a point ('uv seams', 'hard
|
|
53
|
+
* normals (vertex N)', 'vertex <name>'), a string prim attribute or prim group that changes across it ('prim "<name>"
|
|
54
|
+
* borders', 'group "<name>" borders') and 'open borders' (edges used by one polygon). Largest first.
|
|
55
|
+
*/
|
|
56
|
+
export declare function reductionLocks(g: Geometry): {
|
|
57
|
+
cause: string;
|
|
58
|
+
points: number;
|
|
59
|
+
}[];
|
|
48
60
|
export interface PointDecimateOptions {
|
|
49
61
|
ratio: number;
|
|
50
62
|
targetCount: number;
|
|
@@ -57,3 +69,56 @@ export declare function decimatePoints(g: Geometry, o: PointDecimateOptions): {
|
|
|
57
69
|
kept: number;
|
|
58
70
|
used: string[];
|
|
59
71
|
};
|
|
72
|
+
export interface UVFolds {
|
|
73
|
+
/** overlapping uv triangle pairs, and triangles wound against the rest of their chart (flipped) */
|
|
74
|
+
pairs: number;
|
|
75
|
+
flipped: number;
|
|
76
|
+
/** per triangle of tris: in an overlapping pair or flipped */
|
|
77
|
+
bad: Uint8Array;
|
|
78
|
+
/** the largest overlapping pair (triangle ids), or null */
|
|
79
|
+
largest: [number, number] | null;
|
|
80
|
+
tris: Uint32Array;
|
|
81
|
+
triPrim: Uint32Array;
|
|
82
|
+
uv: Float64Array;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Where the uv of g overlaps itself or flips: overlapping triangle pairs (exact, core/uvoverlap.ts) and triangles
|
|
86
|
+
* whose uv winding is opposite to the majority of their chart (charts: triangles joined by uv-continuous edges, so a
|
|
87
|
+
* mirrored island as a whole is not flipped). null without uv.
|
|
88
|
+
*/
|
|
89
|
+
export declare function uvFolds(g: Geometry): UVFolds | null;
|
|
90
|
+
export interface UVKept {
|
|
91
|
+
/** the input uv had no overlaps, so the output was checked */
|
|
92
|
+
checked: boolean;
|
|
93
|
+
/** reduction steps taken, and steps dropped because they folded the uv even with the points around the folds locked */
|
|
94
|
+
steps: number;
|
|
95
|
+
dropped: number;
|
|
96
|
+
/** decimations run, and points locked around folds */
|
|
97
|
+
runs: number;
|
|
98
|
+
locked: number;
|
|
99
|
+
/** a plain (one-step) reduction of the input: its triangle count and its folds (null when it kept the uv clean) */
|
|
100
|
+
plainTris: number;
|
|
101
|
+
plainFolds: UVFolds | null;
|
|
102
|
+
plainGeo: Geometry | null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* decimateMesh that keeps a clean uv atlas clean. meshoptimizer rejects flips in 3D only, and a kept corner keeps its
|
|
106
|
+
* uv, so a collapse can fold the uv around it (most of all where the uv map bends: bevels, curved chart borders).
|
|
107
|
+
* When the input uv has no overlaps and the plain decimation folds it (uvFolds), the reduction runs again in up to
|
|
108
|
+
* KEEP_UV_STEPS steps, the triangle count falling by the same factor each step. A step that folds the uv runs again
|
|
109
|
+
* with the points it removed around its folds locked, the rings growing (KEEP_UV_RINGS); a step that still folds is
|
|
110
|
+
* dropped (its locks stay for the next try on the same mesh; a step taken starts the next one with only the caller's
|
|
111
|
+
* locks, since the danger moves with the mesh). Every step taken is checked, so the result has no folds the input did
|
|
112
|
+
* not have; the price is a triangle count above the target where the uv held the reduction (kept.plainTris says what
|
|
113
|
+
* a plain reduction reached). keep false: the plain reduction, unchecked.
|
|
114
|
+
*/
|
|
115
|
+
export declare function decimateKeepUV(g: Geometry, o: DecimateOptions, keep?: boolean): DecimateResult & {
|
|
116
|
+
uv: UVKept;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Where and why decimateKeepUV held the reduction back, in words (the parts a plain reduction folds and its largest
|
|
120
|
+
* fold), or '' when it did not: the plain reduction kept the uv clean, or the steps reached about the same count.
|
|
121
|
+
*/
|
|
122
|
+
export declare function uvKeptText(r: DecimateResult & {
|
|
123
|
+
uv: UVKept;
|
|
124
|
+
}): string;
|