topotopo 0.4.0 → 0.5.0
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 +323 -146
- 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 +196 -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 +44 -5
- package/dist/render/preview.d.ts +15 -4
- package/dist/render/preview.js +6 -4
- package/dist/render/raster.d.ts +66 -5
- package/dist/render/raster.js +506 -138
- 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 +17 -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/core/wrangle.js
CHANGED
|
@@ -6,14 +6,17 @@
|
|
|
6
6
|
// i[]@nbrs = nearpoints(0, @P, 0.5); // array attributes: f[] i[] s[] (read = copy, written back)
|
|
7
7
|
// if (@P.y < 0) removepoint(0, @ptnum);
|
|
8
8
|
// @group_top = @N.y > 0.9; // group membership
|
|
9
|
+
// @P.y += height * 0.5; // graph vars by their bare name, read-only
|
|
9
10
|
//
|
|
10
11
|
// The snippet is compiled into a kernel that loops over elements, binding each
|
|
11
|
-
// referenced attribute to a local variable and writing it back afterwards.
|
|
12
|
+
// referenced attribute to a local variable and writing it back afterwards. The graph vars
|
|
13
|
+
// the snippet names are constants of a scope around the kernel, so its own names come first.
|
|
12
14
|
import { Attribute, Geometry, defaultValueFor, isArrayType } from './geometry.js';
|
|
13
15
|
import { primCentroid, primNormals, pointNeighbors, pointPrims } from './topology.js';
|
|
16
|
+
import { primIntrinsic } from './intrinsics.js';
|
|
14
17
|
import { KDTree, TriBVH } from './spatial.js';
|
|
15
|
-
import { GEOMETRY_FUNCTIONS, REALM_CONTROL } from './snippet-lib.js';
|
|
16
|
-
import { runUserCode } from './usercode.js';
|
|
18
|
+
import { GEOMETRY_FUNCTIONS, REALM_CONTROL, scriptVarsGuard } from './snippet-lib.js';
|
|
19
|
+
import { codeVarDecl, codeVarNames, codeVarValues, runUserCode } from './usercode.js';
|
|
17
20
|
const CLASS_OF = { points: 'point', prims: 'prim', vertices: 'vertex', detail: 'detail' };
|
|
18
21
|
const PREFIX_TYPE = {
|
|
19
22
|
f: { type: 'float', size: 1 }, i: { type: 'int', size: 1 }, v: { type: 'float', size: 3 },
|
|
@@ -34,6 +37,8 @@ const KNOWN = {
|
|
|
34
37
|
};
|
|
35
38
|
const SPECIAL = new Set(['ptnum', 'primnum', 'vtxnum', 'elemnum', 'numpt', 'numprim', 'numvtx', 'numelem', 'Frame', 'Time', 'TimeInc']);
|
|
36
39
|
const TIME_REFS = ['Frame', 'Time', 'TimeInc'];
|
|
40
|
+
/** The names every wrangle defines (@ptnum … @TimeInc, also readable without the @): a graph var cannot take one. */
|
|
41
|
+
export const WRANGLE_NAMES = SPECIAL;
|
|
37
42
|
const REF = /(?<![\w$.@])([fivpus](?:\[\])?)?@([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
38
43
|
/** compiled kernels per host: a kernel belongs to its host's realm (its library globals and geometry API live there) */
|
|
39
44
|
const kernelCaches = new WeakMap();
|
|
@@ -62,7 +67,6 @@ export function runWrangle(geo, opts) {
|
|
|
62
67
|
return finishWrangle(w);
|
|
63
68
|
}
|
|
64
69
|
const CROSS_ELEMENT = new RegExp(String.raw `\b(${GEOMETRY_FUNCTIONS.join('|')}|globalThis|this|eval|Function)\b`);
|
|
65
|
-
const WRITES_VARS = /\bvars\b[^;\n]*?((?<![=!<>])=(?!=)|\+\+|--)/;
|
|
66
70
|
/**
|
|
67
71
|
* Run a wrangle, letting `par` execute a point wrangle in chunks: par(job, serial) runs the job on worker threads
|
|
68
72
|
* (or calls serial() to run it here) and may return a promise. Same result as runWrangle, bit for bit: chunks run the
|
|
@@ -81,7 +85,7 @@ export function runWrangleParallel(geo, opts, par) {
|
|
|
81
85
|
function wrangleJob(w, opts) {
|
|
82
86
|
if (w.runOver !== 'points' || w.n < 2)
|
|
83
87
|
return null;
|
|
84
|
-
if (CROSS_ELEMENT.test(w.body)
|
|
88
|
+
if (CROSS_ELEMENT.test(w.body))
|
|
85
89
|
return null;
|
|
86
90
|
const inputs = {}, outputs = {};
|
|
87
91
|
for (let i = 0; i < w.bindings.length; i++) {
|
|
@@ -95,13 +99,6 @@ function wrangleJob(w, opts) {
|
|
|
95
99
|
else
|
|
96
100
|
outputs['b' + i] = b.data;
|
|
97
101
|
}
|
|
98
|
-
let vars;
|
|
99
|
-
try {
|
|
100
|
-
vars = structuredClone(opts.vars);
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
102
|
if (opts.mask)
|
|
106
103
|
inputs.mask = opts.mask;
|
|
107
104
|
const e = w.env;
|
|
@@ -109,7 +106,8 @@ function wrangleJob(w, opts) {
|
|
|
109
106
|
count: w.n, inputs, outputs,
|
|
110
107
|
args: {
|
|
111
108
|
source: w.source, bindings: w.bindings.length, n: w.n, numpt: e.numpt, numprim: e.numprim, numvtx: e.numvtx,
|
|
112
|
-
|
|
109
|
+
// the vars the snippet reads (plain data; the worker freezes its copy)
|
|
110
|
+
frame: e.frame, time: e.time, timeInc: e.timeInc, vars: e.vars, timeoutMs: opts.timeoutMs, bodyLine: w.bodyLine, code: opts.code,
|
|
113
111
|
},
|
|
114
112
|
};
|
|
115
113
|
}
|
|
@@ -219,12 +217,16 @@ function prepareWrangle(geo, opts) {
|
|
|
219
217
|
}
|
|
220
218
|
}
|
|
221
219
|
// ---- generate kernel source
|
|
220
|
+
// the graph vars the snippet names (iteration, numiterations in a loop body …): constants of the outer function,
|
|
221
|
+
// so the kernel's own names and the snippet's locals come first
|
|
222
|
+
const varNames = codeVarNames(opts.code, opts.vars);
|
|
222
223
|
const src = [];
|
|
223
224
|
src.push('(function(__env){', '"use strict";');
|
|
225
|
+
src.push(codeVarDecl(varNames, '__env.vars', '__env.varsGuard'));
|
|
226
|
+
src.push('return (function(){');
|
|
224
227
|
// __s/__e: the element range of a chunk (the whole range when absent); numelem stays the total
|
|
225
228
|
src.push('const __n=__env.n, __s=__env.s|0, __e=__env.e===undefined?__env.n:__env.e, __mask=__env.mask, __vp=__env.vp, __vprim=__env.vprim, __B=__env.B;');
|
|
226
229
|
src.push('const numpt=__env.numpt, numprim=__env.numprim, numvtx=__env.numvtx, numelem=__n, Frame=__env.frame, Time=__env.time, TimeInc=__env.timeInc;');
|
|
227
|
-
src.push('const vars=__env.vars, iteration=vars.iteration, numiterations=vars.numiterations;');
|
|
228
230
|
src.push('let ptnum=0, primnum=0, vtxnum=0, elemnum=0;');
|
|
229
231
|
bindings.forEach((b, i) => src.push(`const __d${i}=__B[${i}].data; let ${b.local};`));
|
|
230
232
|
// user code inside a closure so `return` exits just this element
|
|
@@ -283,7 +285,7 @@ function prepareWrangle(geo, opts) {
|
|
|
283
285
|
else
|
|
284
286
|
src.push(`__wf(__d${i},${ix},${b.size},${b.local});`);
|
|
285
287
|
});
|
|
286
|
-
src.push('}', '})');
|
|
288
|
+
src.push('}', '})();', '})');
|
|
287
289
|
const source = src.join('\n');
|
|
288
290
|
let kernelCache = kernelCaches.get(opts.host);
|
|
289
291
|
if (!kernelCache)
|
|
@@ -312,7 +314,8 @@ function prepareWrangle(geo, opts) {
|
|
|
312
314
|
n, mask: runOver === 'detail' ? null : opts.mask, vp: g.vertexPoint, vprim,
|
|
313
315
|
B: bindings, numpt: g.numPoints, numprim: g.numPrims, numvtx: g.numVertices,
|
|
314
316
|
frame: opts.time?.frame ?? opts.vars.frame ?? 1, time: opts.time?.time ?? opts.vars.time ?? 0,
|
|
315
|
-
timeInc: opts.time?.timeInc ?? opts.vars.timeInc ?? 1 / 24,
|
|
317
|
+
timeInc: opts.time?.timeInc ?? opts.vars.timeInc ?? 1 / 24,
|
|
318
|
+
vars: codeVarValues(opts.vars, varNames), varsGuard: scriptVarsGuard(opts.host),
|
|
316
319
|
centroid: (p) => primCentroid(g, p),
|
|
317
320
|
};
|
|
318
321
|
return { g, n, runOver, bindings, log, kernel, source, body, bodyLine, env, api };
|
|
@@ -539,6 +542,14 @@ export class WrangleAPI {
|
|
|
539
542
|
return a.get(idx);
|
|
540
543
|
}
|
|
541
544
|
primpoints(i, p) { return this.geo(i).primPoints(p); }
|
|
545
|
+
primintrinsic(i, name, p) {
|
|
546
|
+
try {
|
|
547
|
+
return primIntrinsic(this.geo(i), Number(p), String(name));
|
|
548
|
+
}
|
|
549
|
+
catch (e) {
|
|
550
|
+
throw new Error(`primintrinsic(${i}, ${JSON.stringify(String(name))}, ${p}): ${e.message}`);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
542
553
|
pointprims(i, pt) {
|
|
543
554
|
let m = this.pp.get(i);
|
|
544
555
|
if (!m) {
|
package/dist/core/xatlas.d.ts
CHANGED
|
@@ -40,6 +40,22 @@ export interface XatlasResult {
|
|
|
40
40
|
chartCount: number;
|
|
41
41
|
utilization: number[];
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* xatlas charts of a set of triangles (vertex triples into g). A corner's input vertex is keyOf(v) (its point, or a
|
|
45
|
+
* seam-split key); triangles of different group(t) never share a chart. The triangles are scaled on their own to a
|
|
46
|
+
* bounding-box diagonal of XATLAS_SIZE, so a small part of a large model is charted as finely as it would be alone.
|
|
47
|
+
* Returns the chart per triangle (-1: xatlas dropped it, e.g. no area) and the uv per triangle corner in xatlas texel
|
|
48
|
+
* space: each chart's shape (where xatlas placed it is not used).
|
|
49
|
+
*/
|
|
50
|
+
export declare function xatlasCharts(X: any, g: Geometry, tris: ArrayLike<number>, o: {
|
|
51
|
+
keyOf: (v: number) => number;
|
|
52
|
+
group?: ((t: number) => number) | null;
|
|
53
|
+
chart: XatlasChartOptions;
|
|
54
|
+
}): {
|
|
55
|
+
triChart: Int32Array;
|
|
56
|
+
cornerUV: Float64Array;
|
|
57
|
+
chartCount: number;
|
|
58
|
+
};
|
|
43
59
|
/**
|
|
44
60
|
* Run xatlas on the closed polygons of g (prims outside primMask are skipped). Input vertices are the
|
|
45
61
|
* geometry points, or per-vertex keys (`vertexKey[v]`, e.g. split along seams); `faceGroup[prim]`
|
|
@@ -49,5 +65,4 @@ export declare function runXatlas(X: any, g: Geometry, chart: XatlasChartOptions
|
|
|
49
65
|
vertexKey?: Int32Array | null;
|
|
50
66
|
faceGroup?: Int32Array | null;
|
|
51
67
|
primMask?: ArrayLike<number> | null;
|
|
52
|
-
unmirror?: boolean;
|
|
53
68
|
}): XatlasResult;
|
package/dist/core/xatlas.js
CHANGED
|
@@ -26,6 +26,71 @@ function xatlasScale(pos) {
|
|
|
26
26
|
const d = Math.hypot(hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]);
|
|
27
27
|
return d > 0 && d < XATLAS_SIZE ? XATLAS_SIZE / d : 1;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* xatlas charts of a set of triangles (vertex triples into g). A corner's input vertex is keyOf(v) (its point, or a
|
|
31
|
+
* seam-split key); triangles of different group(t) never share a chart. The triangles are scaled on their own to a
|
|
32
|
+
* bounding-box diagonal of XATLAS_SIZE, so a small part of a large model is charted as finely as it would be alone.
|
|
33
|
+
* Returns the chart per triangle (-1: xatlas dropped it, e.g. no area) and the uv per triangle corner in xatlas texel
|
|
34
|
+
* space: each chart's shape (where xatlas placed it is not used).
|
|
35
|
+
*/
|
|
36
|
+
export function xatlasCharts(X, g, tris, o) {
|
|
37
|
+
const nt = Math.floor(tris.length / 3), P = g.P;
|
|
38
|
+
const remap = new Map(), pos = [], idx = new Uint32Array(nt * 3);
|
|
39
|
+
for (let i = 0; i < nt * 3; i++) {
|
|
40
|
+
const v = tris[i], key = o.keyOf(v);
|
|
41
|
+
let x = remap.get(key);
|
|
42
|
+
if (x === undefined) {
|
|
43
|
+
x = pos.length / 3;
|
|
44
|
+
remap.set(key, x);
|
|
45
|
+
const pt = g.vertexPoint[v];
|
|
46
|
+
pos.push(P[pt * 3], P[pt * 3 + 1], P[pt * 3 + 2]);
|
|
47
|
+
}
|
|
48
|
+
idx[i] = x;
|
|
49
|
+
}
|
|
50
|
+
const res = { triChart: new Int32Array(nt).fill(-1), cornerUV: new Float64Array(nt * 6), chartCount: 0 };
|
|
51
|
+
if (!nt)
|
|
52
|
+
return res;
|
|
53
|
+
let chart = o.chart;
|
|
54
|
+
const k = xatlasScale(pos);
|
|
55
|
+
if (k !== 1) {
|
|
56
|
+
for (let i = 0; i < pos.length; i++)
|
|
57
|
+
pos[i] *= k;
|
|
58
|
+
chart = { ...chart };
|
|
59
|
+
if (chart.maxChartArea)
|
|
60
|
+
chart.maxChartArea *= k * k;
|
|
61
|
+
if (chart.maxBoundaryLength)
|
|
62
|
+
chart.maxBoundaryLength *= k;
|
|
63
|
+
}
|
|
64
|
+
const atlas = X.createAtlas();
|
|
65
|
+
try {
|
|
66
|
+
const decl = { positions: Float32Array.from(pos), indices: idx };
|
|
67
|
+
if (o.group)
|
|
68
|
+
decl.faceMaterialData = Uint32Array.from({ length: nt }, (_, t) => Math.max(0, o.group(t)));
|
|
69
|
+
const err = atlas.addMesh(decl);
|
|
70
|
+
if (err !== 0)
|
|
71
|
+
throw new Error(`xatlas addMesh failed: ${X.addMeshErrorString ? X.addMeshErrorString(err) : err}`);
|
|
72
|
+
atlas.computeCharts(chart);
|
|
73
|
+
// xatlas writes uv only when it packs; the placement is thrown away, so the atlas is as small as keeps the shapes
|
|
74
|
+
// precise (its cost grows with its area)
|
|
75
|
+
atlas.packCharts({ resolution: Math.max(64, Math.min(1024, Math.round(Math.sqrt(nt) * 8))), padding: 0, rotateCharts: false, rotateChartsToAxis: false, blockAlign: true });
|
|
76
|
+
const m = atlas.getMesh(0);
|
|
77
|
+
res.chartCount = m.chartCount;
|
|
78
|
+
const out = m.indices;
|
|
79
|
+
const verts = m.vertices;
|
|
80
|
+
for (let i = 0; i < out.length && i < nt * 3; i++) {
|
|
81
|
+
const ov = verts[out[i]];
|
|
82
|
+
res.cornerUV[i * 2] = ov.uv[0];
|
|
83
|
+
res.cornerUV[i * 2 + 1] = ov.uv[1];
|
|
84
|
+
const t = (i / 3) | 0;
|
|
85
|
+
if (ov.chartIndex >= 0 && res.triChart[t] < 0)
|
|
86
|
+
res.triChart[t] = ov.chartIndex;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
atlas.destroy();
|
|
91
|
+
}
|
|
92
|
+
return res;
|
|
93
|
+
}
|
|
29
94
|
/**
|
|
30
95
|
* Run xatlas on the closed polygons of g (prims outside primMask are skipped). Input vertices are the
|
|
31
96
|
* geometry points, or per-vertex keys (`vertexKey[v]`, e.g. split along seams); `faceGroup[prim]`
|
|
@@ -60,7 +125,7 @@ export function runXatlas(X, g, chart, pack, opts = {}) {
|
|
|
60
125
|
// xatlas compares positions and areas against absolute epsilons (about 1e-4 and 1.2e-7), so on a model a few
|
|
61
126
|
// centimetres across it welds bevel corners and drops small faces as degenerate. Scale small inputs up to a
|
|
62
127
|
// bounding-box diagonal of XATLAS_SIZE; the world-unit options scale with them, so the result is unchanged.
|
|
63
|
-
const k = xatlasScale(pos)
|
|
128
|
+
const k = xatlasScale(pos);
|
|
64
129
|
if (k !== 1) {
|
|
65
130
|
for (let i = 0; i < pos.length; i++)
|
|
66
131
|
pos[i] *= k;
|
|
@@ -101,70 +166,9 @@ export function runXatlas(X, g, chart, pack, opts = {}) {
|
|
|
101
166
|
result.triAtlas[t] = ov.atlasIndex;
|
|
102
167
|
}
|
|
103
168
|
}
|
|
104
|
-
if (opts.unmirror && repack)
|
|
105
|
-
unmirrorAndRepack(X, result, out, verts.length, repack);
|
|
106
169
|
}
|
|
107
170
|
finally {
|
|
108
171
|
atlas.destroy();
|
|
109
172
|
}
|
|
110
173
|
return result;
|
|
111
174
|
}
|
|
112
|
-
/**
|
|
113
|
-
* xatlas charts come out in either orientation (its texel space is y-down and LSCM/planar charts are not
|
|
114
|
-
* winding-aware). Mirror the charts whose uv winding disagrees with the polygon winding, then repack all
|
|
115
|
-
* charts with xatlas's UV-mesh packer so the packing stays tight and overlap-free.
|
|
116
|
-
*/
|
|
117
|
-
function unmirrorAndRepack(X, r, out, nOut, pack) {
|
|
118
|
-
const nt = r.triChart.length;
|
|
119
|
-
const signed = new Map();
|
|
120
|
-
for (let t = 0; t < nt; t++) {
|
|
121
|
-
const c = r.triChart[t];
|
|
122
|
-
if (c < 0)
|
|
123
|
-
continue;
|
|
124
|
-
const u = r.cornerUV, i = t * 6;
|
|
125
|
-
const a = (u[i + 2] - u[i]) * (u[i + 5] - u[i + 1]) - (u[i + 3] - u[i + 1]) * (u[i + 4] - u[i]);
|
|
126
|
-
signed.set(c, (signed.get(c) ?? 0) + a);
|
|
127
|
-
}
|
|
128
|
-
let mirrored = 0;
|
|
129
|
-
for (const [, a] of signed)
|
|
130
|
-
if (a < 0)
|
|
131
|
-
mirrored++;
|
|
132
|
-
if (!mirrored)
|
|
133
|
-
return;
|
|
134
|
-
const uvs = new Float32Array(nOut * 2);
|
|
135
|
-
for (let i = 0; i < out.length; i++) {
|
|
136
|
-
const c = r.triChart[(i / 3) | 0];
|
|
137
|
-
const flip = c >= 0 && signed.get(c) < 0;
|
|
138
|
-
uvs[out[i] * 2] = flip ? -r.cornerUV[i * 2] : r.cornerUV[i * 2];
|
|
139
|
-
uvs[out[i] * 2 + 1] = r.cornerUV[i * 2 + 1];
|
|
140
|
-
}
|
|
141
|
-
const b = X.createAtlas();
|
|
142
|
-
try {
|
|
143
|
-
const err = b.addUvMesh({ uvs, indices: out, faceMaterialData: Uint32Array.from(r.triChart, (c) => c + 1) });
|
|
144
|
-
if (err !== 0)
|
|
145
|
-
return;
|
|
146
|
-
b.computeCharts();
|
|
147
|
-
b.packCharts(pack);
|
|
148
|
-
const m = b.getMesh(0);
|
|
149
|
-
const o2 = m.indices;
|
|
150
|
-
const v2 = m.vertices;
|
|
151
|
-
if (o2.length !== out.length)
|
|
152
|
-
return;
|
|
153
|
-
for (let i = 0; i < o2.length; i++) {
|
|
154
|
-
const ov = v2[o2[i]];
|
|
155
|
-
r.cornerUV[i * 2] = ov.uv[0];
|
|
156
|
-
r.cornerUV[i * 2 + 1] = ov.uv[1];
|
|
157
|
-
if (i % 3 === 0)
|
|
158
|
-
r.triAtlas[i / 3] = ov.atlasIndex;
|
|
159
|
-
}
|
|
160
|
-
r.width = b.width;
|
|
161
|
-
r.height = b.height;
|
|
162
|
-
r.atlasCount = b.atlasCount;
|
|
163
|
-
r.utilization = [];
|
|
164
|
-
for (let a = 0; a < b.atlasCount; a++)
|
|
165
|
-
r.utilization.push(b.getUtilization(a));
|
|
166
|
-
}
|
|
167
|
-
finally {
|
|
168
|
-
b.destroy();
|
|
169
|
-
}
|
|
170
|
-
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export type EngineType = 'godot' | 'unreal';
|
|
2
|
+
/** The game engine a workspace builds with: its project file, written from the workspace ("game/project.godot", "../Game.uproject"). */
|
|
3
|
+
export interface EngineLink {
|
|
4
|
+
type: EngineType;
|
|
5
|
+
project: string;
|
|
6
|
+
}
|
|
7
|
+
/** The engine type a project file's name says, or null. */
|
|
8
|
+
export declare const engineTypeOf: (file: string) => EngineType | null;
|
|
9
|
+
/**
|
|
10
|
+
* Files an engine writes beside the files it imports, which never count as TopoTopo's: Godot's *.import, *.uid and
|
|
11
|
+
* *.translation, Unreal's *.uasset, and TopoTopo's own .gdignore. Versions, their hashes, input listings, bake keys and
|
|
12
|
+
* the viewer's saved outputs leave them out, so a package inside an engine project publishes what it would elsewhere.
|
|
13
|
+
*/
|
|
14
|
+
export declare const isEngineFile: (name: string) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The nearest engine project at or above a folder: project.godot in the folder or above it, a *.uproject the same;
|
|
17
|
+
* null when there is none. A folder holding both answers Godot's (the one a workspace there sees first).
|
|
18
|
+
*/
|
|
19
|
+
export declare function engineAbove(dir: string): {
|
|
20
|
+
file: string;
|
|
21
|
+
type: EngineType;
|
|
22
|
+
} | null;
|
|
23
|
+
/** The engine projects below a folder (project.godot, *.uproject), nearest first, at most 4 levels down; paths from `dir`. */
|
|
24
|
+
export declare function findEngines(dir: string): EngineLink[];
|
|
25
|
+
/**
|
|
26
|
+
* The engine project a workspace at `dir` builds with when none is named: the nearest at or above it (the workspace
|
|
27
|
+
* inside the engine's content folder), else the nearest below it; `found` says how many there were below, when that
|
|
28
|
+
* is where it came from.
|
|
29
|
+
*/
|
|
30
|
+
export declare function detectEngine(dir: string): {
|
|
31
|
+
link: EngineLink;
|
|
32
|
+
below: EngineLink[];
|
|
33
|
+
} | null;
|
|
34
|
+
/**
|
|
35
|
+
* Whether Unreal sees a folder of its project: Unreal imports only what lies under the project's Content/ folder or a
|
|
36
|
+
* plugin's (Plugins/…/Content/). `uproject`: the project file.
|
|
37
|
+
*/
|
|
38
|
+
export declare function unrealSees(folder: string, uproject: string): boolean;
|
|
39
|
+
/** The Godot project a folder lies in: the folder holding the nearest project.godot at or above it; null for none. */
|
|
40
|
+
export declare function godotProjectOf(dir: string): string | null;
|
|
41
|
+
/** TopoTopo's working folders of a package, which are not game content: Godot imports none of them (a .gdignore in each). */
|
|
42
|
+
export declare const GODOT_IGNORED: string[];
|
|
43
|
+
/** With the import addon, cooked outputs replace these working folders as Godot's source assets. */
|
|
44
|
+
export declare const GODOT_PLUGIN_IGNORED: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Inside a Godot project (project.godot at or above the package), keep Godot's importer out of a package's working
|
|
47
|
+
* folders: an empty .gdignore in each of versions/, packages/ and inputs/ that is there, and in the folders of `make`
|
|
48
|
+
* (made when they are not there yet), so the file is in place before the first version or copy lands. Nothing outside a
|
|
49
|
+
* Godot project. With the TopoTopo addon installed, also hide the package's graphs/, assets/ and exports/ as they
|
|
50
|
+
* appear (for example when the viewer opens after setup). Returns the files it added (none when they were all there).
|
|
51
|
+
*/
|
|
52
|
+
export declare function godotIgnore(pkgDir: string, make?: string[]): string[];
|
|
53
|
+
/** The .gdignore files a package inside a Godot project lacks in the working folders it has (godotIgnore adds them); none outside one. */
|
|
54
|
+
export declare function godotIgnoreMissing(pkgDir: string): string[];
|
|
55
|
+
/** What a Godot export preset should exclude so that it ships none of TopoTopo's files. */
|
|
56
|
+
export declare const GODOT_EXCLUDES: string[];
|
|
57
|
+
/**
|
|
58
|
+
* The export presets of a Godot project (export_presets.cfg in `projectDir`) that would ship TopoTopo's files: one that
|
|
59
|
+
* exports every resource (export_filter="all_resources", or "exclude": all but the files checked) or includes *.json or
|
|
60
|
+
* *.txt files, with the exclude_filter entries it lacks. Nothing is edited. One line each; none when the file is missing
|
|
61
|
+
* or every preset excludes them.
|
|
62
|
+
*/
|
|
63
|
+
export declare function godotPresetReport(projectDir: string): string[];
|
package/dist/engines.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Game engine projects (Godot, Unreal) as TopoTopo meets them: finding the project a workspace builds with (the nearest
|
|
2
|
+
// one at or above the workspace, else one below it), whether Unreal sees a workspace (under the project's Content/ or a
|
|
3
|
+
// plugin's), the files engines write beside TopoTopo's (never TopoTopo's: left out of versions, hashes, listings and
|
|
4
|
+
// bake keys), the .gdignore files that keep TopoTopo's working folders out of Godot's importer, and the Godot export
|
|
5
|
+
// presets that would ship TopoTopo's files.
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
const ENGINE_FILES = [[/^project\.godot$/, 'godot'], [/\.uproject$/i, 'unreal']];
|
|
9
|
+
/** The engine type a project file's name says, or null. */
|
|
10
|
+
export const engineTypeOf = (file) => ENGINE_FILES.find(([re]) => re.test(path.basename(file)))?.[1] ?? null;
|
|
11
|
+
/** Folders an engine search below a folder never enters (besides dot folders). */
|
|
12
|
+
const SKIP_BELOW = new Set(['node_modules', 'binaries', 'intermediate', 'saved', 'deriveddatacache', 'versions', 'packages', 'topotopo-packages']);
|
|
13
|
+
/**
|
|
14
|
+
* Files an engine writes beside the files it imports, which never count as TopoTopo's: Godot's *.import, *.uid and
|
|
15
|
+
* *.translation, Unreal's *.uasset, and TopoTopo's own .gdignore. Versions, their hashes, input listings, bake keys and
|
|
16
|
+
* the viewer's saved outputs leave them out, so a package inside an engine project publishes what it would elsewhere.
|
|
17
|
+
*/
|
|
18
|
+
export const isEngineFile = (name) => name === '.gdignore' || /\.(import|uid|translation|uasset)$/i.test(name);
|
|
19
|
+
const rel = (from, to) => path.relative(path.resolve(from), path.resolve(to)).split(path.sep).join('/') || '.';
|
|
20
|
+
/** The engine project files directly in a folder. */
|
|
21
|
+
function projectsIn(dir) {
|
|
22
|
+
try {
|
|
23
|
+
return fs.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isFile() && engineTypeOf(e.name)).map((e) => e.name).sort();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The nearest engine project at or above a folder: project.godot in the folder or above it, a *.uproject the same;
|
|
31
|
+
* null when there is none. A folder holding both answers Godot's (the one a workspace there sees first).
|
|
32
|
+
*/
|
|
33
|
+
export function engineAbove(dir) {
|
|
34
|
+
for (let d = path.resolve(dir);;) {
|
|
35
|
+
const found = projectsIn(d).sort((a, b) => (engineTypeOf(a) === 'godot' ? -1 : engineTypeOf(b) === 'godot' ? 1 : 0));
|
|
36
|
+
if (found.length)
|
|
37
|
+
return { file: path.join(d, found[0]), type: engineTypeOf(found[0]) };
|
|
38
|
+
const up = path.dirname(d);
|
|
39
|
+
if (up === d)
|
|
40
|
+
return null;
|
|
41
|
+
d = up;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** The engine projects below a folder (project.godot, *.uproject), nearest first, at most 4 levels down; paths from `dir`. */
|
|
45
|
+
export function findEngines(dir) {
|
|
46
|
+
const out = [];
|
|
47
|
+
const walk = (d, depth) => {
|
|
48
|
+
let entries;
|
|
49
|
+
try {
|
|
50
|
+
entries = fs.readdirSync(d, { withFileTypes: true });
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
for (const e of entries) {
|
|
56
|
+
const type = e.isFile() ? engineTypeOf(e.name) : null;
|
|
57
|
+
if (type)
|
|
58
|
+
out.push({ link: { type, project: rel(dir, path.join(d, e.name)) }, depth });
|
|
59
|
+
}
|
|
60
|
+
if (depth >= 4)
|
|
61
|
+
return;
|
|
62
|
+
for (const e of entries)
|
|
63
|
+
if (e.isDirectory() && !e.name.startsWith('.') && !SKIP_BELOW.has(e.name.toLowerCase()))
|
|
64
|
+
walk(path.join(d, e.name), depth + 1);
|
|
65
|
+
};
|
|
66
|
+
walk(path.resolve(dir), 0);
|
|
67
|
+
return out.sort((a, b) => a.depth - b.depth || (a.link.project < b.link.project ? -1 : 1)).map((x) => x.link);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The engine project a workspace at `dir` builds with when none is named: the nearest at or above it (the workspace
|
|
71
|
+
* inside the engine's content folder), else the nearest below it; `found` says how many there were below, when that
|
|
72
|
+
* is where it came from.
|
|
73
|
+
*/
|
|
74
|
+
export function detectEngine(dir) {
|
|
75
|
+
const above = engineAbove(dir);
|
|
76
|
+
if (above)
|
|
77
|
+
return { link: { type: above.type, project: rel(dir, above.file) }, below: [] };
|
|
78
|
+
const below = findEngines(dir);
|
|
79
|
+
return below.length ? { link: below[0], below } : null;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether Unreal sees a folder of its project: Unreal imports only what lies under the project's Content/ folder or a
|
|
83
|
+
* plugin's (Plugins/…/Content/). `uproject`: the project file.
|
|
84
|
+
*/
|
|
85
|
+
export function unrealSees(folder, uproject) {
|
|
86
|
+
const r = path.relative(path.dirname(path.resolve(uproject)), path.resolve(folder));
|
|
87
|
+
if (!r || r.startsWith('..') || path.isAbsolute(r))
|
|
88
|
+
return false;
|
|
89
|
+
const parts = r.split(path.sep).map((s) => s.toLowerCase());
|
|
90
|
+
if (parts[0] === 'content')
|
|
91
|
+
return true;
|
|
92
|
+
return parts[0] === 'plugins' && parts.indexOf('content') > 1;
|
|
93
|
+
}
|
|
94
|
+
/** The Godot project a folder lies in: the folder holding the nearest project.godot at or above it; null for none. */
|
|
95
|
+
export function godotProjectOf(dir) {
|
|
96
|
+
for (let d = path.resolve(dir);;) {
|
|
97
|
+
if (fs.statSync(path.join(d, 'project.godot'), { throwIfNoEntry: false })?.isFile())
|
|
98
|
+
return d;
|
|
99
|
+
const up = path.dirname(d);
|
|
100
|
+
if (up === d)
|
|
101
|
+
return null;
|
|
102
|
+
d = up;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** TopoTopo's working folders of a package, which are not game content: Godot imports none of them (a .gdignore in each). */
|
|
106
|
+
export const GODOT_IGNORED = ['versions', 'packages', 'inputs'];
|
|
107
|
+
/** With the import addon, cooked outputs replace these working folders as Godot's source assets. */
|
|
108
|
+
export const GODOT_PLUGIN_IGNORED = ['graphs', 'assets', 'inputs', 'exports', 'versions', 'packages'];
|
|
109
|
+
function godotIgnoredFolders(pkgDir) {
|
|
110
|
+
const project = godotProjectOf(pkgDir);
|
|
111
|
+
if (!project)
|
|
112
|
+
return [];
|
|
113
|
+
// A package at the project root is unsupported by the addon: never hide the game's assets/ there.
|
|
114
|
+
return path.resolve(pkgDir) !== project && fs.statSync(path.join(project, 'addons', 'topotopo', 'plugin.cfg'), { throwIfNoEntry: false })?.isFile()
|
|
115
|
+
? GODOT_PLUGIN_IGNORED : GODOT_IGNORED;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Inside a Godot project (project.godot at or above the package), keep Godot's importer out of a package's working
|
|
119
|
+
* folders: an empty .gdignore in each of versions/, packages/ and inputs/ that is there, and in the folders of `make`
|
|
120
|
+
* (made when they are not there yet), so the file is in place before the first version or copy lands. Nothing outside a
|
|
121
|
+
* Godot project. With the TopoTopo addon installed, also hide the package's graphs/, assets/ and exports/ as they
|
|
122
|
+
* appear (for example when the viewer opens after setup). Returns the files it added (none when they were all there).
|
|
123
|
+
*/
|
|
124
|
+
export function godotIgnore(pkgDir, make = []) {
|
|
125
|
+
const added = [];
|
|
126
|
+
for (const d of godotIgnoredFolders(pkgDir)) {
|
|
127
|
+
const folder = path.join(pkgDir, d), f = path.join(folder, '.gdignore');
|
|
128
|
+
if (fs.existsSync(f) || (!make.includes(d) && !fs.statSync(folder, { throwIfNoEntry: false })?.isDirectory()))
|
|
129
|
+
continue;
|
|
130
|
+
try {
|
|
131
|
+
fs.mkdirSync(folder, { recursive: true });
|
|
132
|
+
fs.writeFileSync(f, '');
|
|
133
|
+
added.push(f);
|
|
134
|
+
}
|
|
135
|
+
catch { /* Godot imports them: harmless */ }
|
|
136
|
+
}
|
|
137
|
+
return added;
|
|
138
|
+
}
|
|
139
|
+
/** The .gdignore files a package inside a Godot project lacks in the working folders it has (godotIgnore adds them); none outside one. */
|
|
140
|
+
export function godotIgnoreMissing(pkgDir) {
|
|
141
|
+
return godotIgnoredFolders(pkgDir).filter((d) => fs.statSync(path.join(pkgDir, d), { throwIfNoEntry: false })?.isDirectory()).map((d) => path.join(pkgDir, d, '.gdignore')).filter((f) => !fs.existsSync(f));
|
|
142
|
+
}
|
|
143
|
+
/** What a Godot export preset should exclude so that it ships none of TopoTopo's files. */
|
|
144
|
+
export const GODOT_EXCLUDES = ['*/attachments/*', '*/graphs/*', '*/inputs/*', '*.topo', '*/exports/*.source.json', '*/exports/.outputs.json'];
|
|
145
|
+
/**
|
|
146
|
+
* The export presets of a Godot project (export_presets.cfg in `projectDir`) that would ship TopoTopo's files: one that
|
|
147
|
+
* exports every resource (export_filter="all_resources", or "exclude": all but the files checked) or includes *.json or
|
|
148
|
+
* *.txt files, with the exclude_filter entries it lacks. Nothing is edited. One line each; none when the file is missing
|
|
149
|
+
* or every preset excludes them.
|
|
150
|
+
*/
|
|
151
|
+
export function godotPresetReport(projectDir) {
|
|
152
|
+
let text;
|
|
153
|
+
try {
|
|
154
|
+
text = fs.readFileSync(path.join(projectDir, 'export_presets.cfg'), 'utf8');
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
const out = [];
|
|
160
|
+
// [preset.N] sections; their keys are key="value" lines
|
|
161
|
+
for (const block of text.split(/^\[preset\.\d+\]\s*$/m).slice(1)) {
|
|
162
|
+
const body = block.split(/^\[/m)[0];
|
|
163
|
+
const key = (k) => new RegExp(`^${k}\\s*=\\s*"((?:[^"\\\\]|\\\\.)*)"`, 'm').exec(body)?.[1] ?? '';
|
|
164
|
+
const name = key('name') || '(unnamed)', filter = key('export_filter'), include = key('include_filter'), exclude = key('exclude_filter');
|
|
165
|
+
const includes = include.split(',').map((s) => s.trim()).filter(Boolean);
|
|
166
|
+
// "all_resources": every resource; "exclude": every resource but the files checked in the dialog
|
|
167
|
+
const every = filter === 'all_resources' || filter === 'exclude';
|
|
168
|
+
const ships = every || includes.some((p) => /\*\.(json|txt)$/i.test(p) || p === '*' || p === '*.*');
|
|
169
|
+
if (!ships)
|
|
170
|
+
continue;
|
|
171
|
+
const have = new Set(exclude.split(',').map((s) => s.trim()).filter(Boolean));
|
|
172
|
+
const missing = GODOT_EXCLUDES.filter((e) => !have.has(e));
|
|
173
|
+
if (!missing.length)
|
|
174
|
+
continue;
|
|
175
|
+
const why = filter === 'all_resources' ? 'exports every resource' : filter === 'exclude' ? 'exports every resource but the files it leaves out'
|
|
176
|
+
: `includes ${includes.filter((p) => /\*\.(json|txt)$/i.test(p) || p === '*' || p === '*.*').join(', ')}`;
|
|
177
|
+
out.push(`export preset "${name}" ${why}, so it would ship TopoTopo's files: add to its exclude_filter (Project > Export > Resources > Filters to exclude) ${missing.join(', ')}`);
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
}
|
package/dist/explain.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface DiffResult {
|
|
|
10
10
|
mean: number;
|
|
11
11
|
identical: boolean;
|
|
12
12
|
}
|
|
13
|
-
/** What changed from a to b: counts, bbox, topology, attribute schema, groups, sampled Hausdorff and mean distance. */
|
|
13
|
+
/** What changed from a to b: counts, bbox, topology, attribute schema, groups, volumes, sampled Hausdorff and mean distance. */
|
|
14
14
|
export declare function diffGeometry(a: Geometry, b: Geometry, labels?: [string, string], samples?: number): DiffResult;
|
|
15
15
|
/** Colours of the diff overlay. */
|
|
16
16
|
export declare const DIFF_COLORS: {
|
|
@@ -19,7 +19,8 @@ export declare const DIFF_COLORS: {
|
|
|
19
19
|
a: number[];
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
|
-
* One geometry for the renderer: b
|
|
23
|
-
*
|
|
22
|
+
* One geometry for the renderer: b (grey where it lies on a, blue where it moved or is new), and in orange the polygons
|
|
23
|
+
* of a that do not lie on b. Those that do are left out, b's grey stands for both there: two coincident surfaces mix
|
|
24
|
+
* their colours in the renderer. So grey = unchanged, blue = only b, orange = only a.
|
|
24
25
|
*/
|
|
25
26
|
export declare function diffOverlay(a: Geometry, b: Geometry): Geometry;
|