@toolpath/viewer 0.2.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/LICENSE +21 -0
- package/README.md +121 -0
- package/dist/chunk-7NQBV7EQ.js +2537 -0
- package/dist/engine/index.d.ts +118 -0
- package/dist/engine/index.js +30 -0
- package/dist/index.d.ts +637 -0
- package/dist/index.js +676 -0
- package/dist/normalize-B0HBvzGu.d.ts +868 -0
- package/package.json +68 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { P as PartModel, a as PartMeshRefs } from '../normalize-B0HBvzGu.js';
|
|
2
|
+
export { E as EnginePart, b as EnginePartProps, M as MIN_KERNEL_VERSION, c as assertSupportedKernelVersion, n as normalizePartReport, s as smoothRegionNormals } from '../normalize-B0HBvzGu.js';
|
|
3
|
+
import { BufferGeometry } from 'three';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
/** What the cache needs of a part: the artifact to fetch, and how to shade it. */
|
|
7
|
+
type CacheablePart = Pick<PartModel, 'mesh' | 'regions'>;
|
|
8
|
+
interface EngineGeometryResource {
|
|
9
|
+
status: 'pending' | 'fulfilled' | 'rejected';
|
|
10
|
+
promise: Promise<void>;
|
|
11
|
+
geometry?: BufferGeometry;
|
|
12
|
+
error?: Error;
|
|
13
|
+
references: number;
|
|
14
|
+
lastAccess: number;
|
|
15
|
+
}
|
|
16
|
+
interface EngineGeometryCache {
|
|
17
|
+
get(part: CacheablePart): EngineGeometryResource;
|
|
18
|
+
retain(resource: EngineGeometryResource): void;
|
|
19
|
+
release(resource: EngineGeometryResource): void;
|
|
20
|
+
clear(): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The cache key.
|
|
24
|
+
*
|
|
25
|
+
* Deliberately not the presigned URL: those carry a signature and an expiry, so
|
|
26
|
+
* two reports of the same part fetched a minute apart would miss every time.
|
|
27
|
+
* The path is the artifact's identity and the query string is not.
|
|
28
|
+
*/
|
|
29
|
+
declare function engineGeometryResourceKey(mesh: PartMeshRefs): string;
|
|
30
|
+
/**
|
|
31
|
+
* A small reference-aware LRU cache for Engine mesh artifacts. Rendered parts
|
|
32
|
+
* retain their source geometry; released entries are evicted and disposed once
|
|
33
|
+
* the cache exceeds its capacity.
|
|
34
|
+
*/
|
|
35
|
+
declare function createEngineGeometryCache(loadGeometry?: (part: CacheablePart) => Promise<BufferGeometry>, maximumEntries?: number): EngineGeometryCache;
|
|
36
|
+
declare const engineGeometryCache: EngineGeometryCache;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A mesh that cannot be paired with its report.
|
|
40
|
+
*
|
|
41
|
+
* Every case is a contract mismatch caught at load, which is the whole point:
|
|
42
|
+
* the alternative is a report and a mesh that disagree about which triangle is
|
|
43
|
+
* which, and that surfaces as *the wrong surface highlighting* — a shader bug
|
|
44
|
+
* to anyone debugging it, hours from its cause.
|
|
45
|
+
*/
|
|
46
|
+
declare class PartMeshError extends Error {
|
|
47
|
+
readonly name = "PartMeshError";
|
|
48
|
+
}
|
|
49
|
+
/** What the report says the mesh contains. Checked, never trusted. */
|
|
50
|
+
type PartMeshExpectation = Pick<PartMeshRefs, 'pointCount' | 'triangleCount'>;
|
|
51
|
+
type MeshFormat = 'glb' | 'stl';
|
|
52
|
+
interface MeshAsset {
|
|
53
|
+
format: MeshFormat;
|
|
54
|
+
url: string;
|
|
55
|
+
}
|
|
56
|
+
type FetchLike = (url: string, init?: {
|
|
57
|
+
signal?: AbortSignal;
|
|
58
|
+
}) => Promise<Response>;
|
|
59
|
+
interface LoadPartGeometryOptions {
|
|
60
|
+
/** Inject to route through a backend, or to serve a fixture in a test. */
|
|
61
|
+
readonly fetch?: FetchLike;
|
|
62
|
+
readonly signal?: AbortSignal;
|
|
63
|
+
}
|
|
64
|
+
/** The mesh artifacts to try, in order: GLB first, STL as a fallback. */
|
|
65
|
+
declare function partMeshAssets(mesh: Pick<PartMeshRefs, 'glbUrl' | 'stlUrl'>): MeshAsset[];
|
|
66
|
+
/**
|
|
67
|
+
* Fetches a part's mesh and prepares it for rendering and picking.
|
|
68
|
+
*
|
|
69
|
+
* The URL is passed separately rather than read off `PartMeshRefs` because it
|
|
70
|
+
* is the one field that goes stale: presigns live fifteen minutes, so the
|
|
71
|
+
* caller decides what to fetch and when.
|
|
72
|
+
*/
|
|
73
|
+
declare function loadPartGeometry(url: string, mesh: PartMeshExpectation, options?: LoadPartGeometryOptions & {
|
|
74
|
+
format?: MeshFormat;
|
|
75
|
+
}): Promise<BufferGeometry>;
|
|
76
|
+
/**
|
|
77
|
+
* Loads whichever mesh artifact a report actually carries, preferring GLB.
|
|
78
|
+
*
|
|
79
|
+
* The STL fallback is not redundancy for its own sake: a report can carry one
|
|
80
|
+
* URL and not the other, and an STL still satisfies the triangle-order contract
|
|
81
|
+
* the region ranges depend on. Every attempt's failure is kept, because "the
|
|
82
|
+
* GLB 403'd and the STL was not a mesh" is two different problems and a caller
|
|
83
|
+
* shown only the second would chase the wrong one.
|
|
84
|
+
*/
|
|
85
|
+
declare function loadPartMesh(mesh: PartMeshRefs, options?: LoadPartGeometryOptions): Promise<BufferGeometry>;
|
|
86
|
+
/**
|
|
87
|
+
* Parses a mesh into the geometry the renderer and the region index share.
|
|
88
|
+
*
|
|
89
|
+
* Three things happen here, and each one is load-bearing:
|
|
90
|
+
*
|
|
91
|
+
* - **De-index, always.** The Engine writes an indexed GLB with shared vertices
|
|
92
|
+
* (the cube: 8 vertices, 36 indices). The region highlight is a *per-vertex*
|
|
93
|
+
* attribute, and a shared corner vertex belongs to three regions at once, so
|
|
94
|
+
* there is no value to write into it. Non-indexed is not an optimization
|
|
95
|
+
* here, it is what makes region attributes expressible.
|
|
96
|
+
* - **Compute normals, if the mesh ships none.** The GLB currently ships
|
|
97
|
+
* `POSITION` only. Doing this *after* de-indexing is what gives faceted CAD
|
|
98
|
+
* shading; the other order smooth-shades a cube, which reads as a rendering
|
|
99
|
+
* bug rather than the data-handling one it is.
|
|
100
|
+
* - **Check the counts.** The report's region ranges index this triangle
|
|
101
|
+
* buffer. If the two disagree about how many triangles there are, they are
|
|
102
|
+
* not the same artifact and nothing downstream can be trusted.
|
|
103
|
+
*
|
|
104
|
+
* Coordinates are passed through untouched: the Engine emits millimetres, Z-up,
|
|
105
|
+
* usually with a corner at the origin, and `GLTFLoader` does not rotate a scene
|
|
106
|
+
* to the glTF Y-up convention. Centring and framing are the camera's business,
|
|
107
|
+
* not the loader's — region geometry is quoted in part space, so part space is
|
|
108
|
+
* what gets rendered.
|
|
109
|
+
*
|
|
110
|
+
* `toNonIndexed()` renumbers nothing at the triangle level: it walks the index
|
|
111
|
+
* buffer in order, three vertices at a time, so triangle `i` stays triangle
|
|
112
|
+
* `i`. That is what makes it safe to apply before region ranges, and it is
|
|
113
|
+
* asserted against the real cube in `geometry.test.ts` because it looks
|
|
114
|
+
* dangerous and is not.
|
|
115
|
+
*/
|
|
116
|
+
declare function parsePartGeometry(data: ArrayBuffer, mesh: PartMeshExpectation, format?: MeshFormat): Promise<BufferGeometry>;
|
|
117
|
+
|
|
118
|
+
export { type CacheablePart, type EngineGeometryCache, type EngineGeometryResource, type FetchLike, type LoadPartGeometryOptions, type MeshAsset, type MeshFormat, PartMeshError, type PartMeshExpectation, createEngineGeometryCache, engineGeometryCache, engineGeometryResourceKey, loadPartGeometry, loadPartMesh, parsePartGeometry, partMeshAssets };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EnginePart,
|
|
3
|
+
MIN_KERNEL_VERSION,
|
|
4
|
+
PartMeshError,
|
|
5
|
+
assertSupportedKernelVersion,
|
|
6
|
+
createEngineGeometryCache,
|
|
7
|
+
engineGeometryCache,
|
|
8
|
+
engineGeometryResourceKey,
|
|
9
|
+
loadPartGeometry,
|
|
10
|
+
loadPartMesh,
|
|
11
|
+
normalizePartReport,
|
|
12
|
+
parsePartGeometry,
|
|
13
|
+
partMeshAssets,
|
|
14
|
+
smoothRegionNormals
|
|
15
|
+
} from "../chunk-7NQBV7EQ.js";
|
|
16
|
+
export {
|
|
17
|
+
EnginePart,
|
|
18
|
+
MIN_KERNEL_VERSION,
|
|
19
|
+
PartMeshError,
|
|
20
|
+
assertSupportedKernelVersion,
|
|
21
|
+
createEngineGeometryCache,
|
|
22
|
+
engineGeometryCache,
|
|
23
|
+
engineGeometryResourceKey,
|
|
24
|
+
loadPartGeometry,
|
|
25
|
+
loadPartMesh,
|
|
26
|
+
normalizePartReport,
|
|
27
|
+
parsePartGeometry,
|
|
28
|
+
partMeshAssets,
|
|
29
|
+
smoothRegionNormals
|
|
30
|
+
};
|