@selvajs/visualization 1.8.0-beta.6 → 1.8.0-beta.7
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/dist/parse.cjs +34 -6
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.d.cts +19 -25
- package/dist/parse.d.ts +19 -25
- package/dist/parse.js +34 -6
- package/dist/parse.js.map +1 -1
- package/package.json +1 -1
package/dist/parse.d.cts
CHANGED
|
@@ -6,27 +6,6 @@ export declare const meshPolicy: {
|
|
|
6
6
|
release(meshes: THREE.Object3D[]): void;
|
|
7
7
|
byteSize(meshes: THREE.Object3D[]): number;
|
|
8
8
|
};
|
|
9
|
-
/**
|
|
10
|
-
* Declared structurally rather than imported from `@selvajs/compute` — this package converts
|
|
11
|
-
* meshes, it doesn't need a Rhino.Compute client dependency to describe the shape a caller hands
|
|
12
|
-
* it. Callers can pass their own `GrasshopperComputeResponse` shape here; the compute package's
|
|
13
|
-
* response type is a superset and stays assignable to this local contract.
|
|
14
|
-
*/
|
|
15
|
-
interface DisplayDataItem {
|
|
16
|
-
/** Namespaced wire type token, e.g. `Selva.GH.Features.Display.Services.DisplayBatch`. */
|
|
17
|
-
type: string;
|
|
18
|
-
data: string;
|
|
19
|
-
}
|
|
20
|
-
interface GrasshopperResponseValue {
|
|
21
|
-
InnerTree: {
|
|
22
|
-
[branchPath: string]: DisplayDataItem[];
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
interface GrasshopperComputeResponse {
|
|
26
|
-
values: GrasshopperResponseValue[];
|
|
27
|
-
/** Rhino `UnitSystem` name driving unit scaling (see `SCALE_FACTORS`); unrecognized/absent scales 1. */
|
|
28
|
-
modelunits: string;
|
|
29
|
-
}
|
|
30
9
|
interface DisplayIdentity {
|
|
31
10
|
/** The item's identity — the writer-minted opaque id, same contract as mesh ids. Distinct from `name` so renaming doesn't change identity. */
|
|
32
11
|
id: string;
|
|
@@ -158,9 +137,8 @@ interface MaterialGroup {
|
|
|
158
137
|
/**
|
|
159
138
|
* One Display component's payload, ready for Three.js rendering.
|
|
160
139
|
*
|
|
161
|
-
* `compressedData` is the binary "SLVA" blob
|
|
162
|
-
*
|
|
163
|
-
* without changing this shape.
|
|
140
|
+
* `compressedData` is the binary "SLVA" blob: base64 inside a JSON response, raw bytes when the
|
|
141
|
+
* response came as a binary frame.
|
|
164
142
|
*
|
|
165
143
|
* Named `DisplayBatch` rather than `MeshBatch` because it's the seam non-mesh display items
|
|
166
144
|
* (curves, points, later labels/icons) also travel through — those ride as JSON alongside the mesh
|
|
@@ -169,7 +147,7 @@ interface MaterialGroup {
|
|
|
169
147
|
interface DisplayBatch {
|
|
170
148
|
materials: SerializableMaterial[];
|
|
171
149
|
groups: MaterialGroup[];
|
|
172
|
-
compressedData: string;
|
|
150
|
+
compressedData: string | Uint8Array;
|
|
173
151
|
/** Non-mesh display items — see {@link DisplayItem}. Parsed by the separate `display-items`
|
|
174
152
|
* path, not the SLVA mesh parser. Omitted when there are none. */
|
|
175
153
|
items?: DisplayItem[];
|
|
@@ -201,6 +179,22 @@ interface MeshExtractionOptions {
|
|
|
201
179
|
groundAxis?: 'x' | 'y' | 'z';
|
|
202
180
|
debug?: boolean;
|
|
203
181
|
}
|
|
182
|
+
interface DisplayDataItem {
|
|
183
|
+
/** Namespaced wire type token, e.g. `Selva.GH.Features.Display.Services.DisplayBatch`. */
|
|
184
|
+
type: string;
|
|
185
|
+
/** A JSON string of the batch, or the batch itself once a binary response was decoded. */
|
|
186
|
+
data: string | DisplayBatch;
|
|
187
|
+
}
|
|
188
|
+
interface GrasshopperResponseValue {
|
|
189
|
+
InnerTree: {
|
|
190
|
+
[branchPath: string]: DisplayDataItem[];
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
interface GrasshopperComputeResponse {
|
|
194
|
+
values: GrasshopperResponseValue[];
|
|
195
|
+
/** Rhino `UnitSystem` name driving unit scaling (see `SCALE_FACTORS`); unrecognized/absent scales 1. */
|
|
196
|
+
modelunits: string;
|
|
197
|
+
}
|
|
204
198
|
/**
|
|
205
199
|
* Metres per model unit, keyed by Rhino `UnitSystem` name (the `modelunits` string on the compute
|
|
206
200
|
* response). Imperial factors are the exact international definitions. Units missing from this
|
package/dist/parse.d.ts
CHANGED
|
@@ -6,27 +6,6 @@ export declare const meshPolicy: {
|
|
|
6
6
|
release(meshes: THREE.Object3D[]): void;
|
|
7
7
|
byteSize(meshes: THREE.Object3D[]): number;
|
|
8
8
|
};
|
|
9
|
-
/**
|
|
10
|
-
* Declared structurally rather than imported from `@selvajs/compute` — this package converts
|
|
11
|
-
* meshes, it doesn't need a Rhino.Compute client dependency to describe the shape a caller hands
|
|
12
|
-
* it. Callers can pass their own `GrasshopperComputeResponse` shape here; the compute package's
|
|
13
|
-
* response type is a superset and stays assignable to this local contract.
|
|
14
|
-
*/
|
|
15
|
-
interface DisplayDataItem {
|
|
16
|
-
/** Namespaced wire type token, e.g. `Selva.GH.Features.Display.Services.DisplayBatch`. */
|
|
17
|
-
type: string;
|
|
18
|
-
data: string;
|
|
19
|
-
}
|
|
20
|
-
interface GrasshopperResponseValue {
|
|
21
|
-
InnerTree: {
|
|
22
|
-
[branchPath: string]: DisplayDataItem[];
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
interface GrasshopperComputeResponse {
|
|
26
|
-
values: GrasshopperResponseValue[];
|
|
27
|
-
/** Rhino `UnitSystem` name driving unit scaling (see `SCALE_FACTORS`); unrecognized/absent scales 1. */
|
|
28
|
-
modelunits: string;
|
|
29
|
-
}
|
|
30
9
|
interface DisplayIdentity {
|
|
31
10
|
/** The item's identity — the writer-minted opaque id, same contract as mesh ids. Distinct from `name` so renaming doesn't change identity. */
|
|
32
11
|
id: string;
|
|
@@ -158,9 +137,8 @@ interface MaterialGroup {
|
|
|
158
137
|
/**
|
|
159
138
|
* One Display component's payload, ready for Three.js rendering.
|
|
160
139
|
*
|
|
161
|
-
* `compressedData` is the binary "SLVA" blob
|
|
162
|
-
*
|
|
163
|
-
* without changing this shape.
|
|
140
|
+
* `compressedData` is the binary "SLVA" blob: base64 inside a JSON response, raw bytes when the
|
|
141
|
+
* response came as a binary frame.
|
|
164
142
|
*
|
|
165
143
|
* Named `DisplayBatch` rather than `MeshBatch` because it's the seam non-mesh display items
|
|
166
144
|
* (curves, points, later labels/icons) also travel through — those ride as JSON alongside the mesh
|
|
@@ -169,7 +147,7 @@ interface MaterialGroup {
|
|
|
169
147
|
interface DisplayBatch {
|
|
170
148
|
materials: SerializableMaterial[];
|
|
171
149
|
groups: MaterialGroup[];
|
|
172
|
-
compressedData: string;
|
|
150
|
+
compressedData: string | Uint8Array;
|
|
173
151
|
/** Non-mesh display items — see {@link DisplayItem}. Parsed by the separate `display-items`
|
|
174
152
|
* path, not the SLVA mesh parser. Omitted when there are none. */
|
|
175
153
|
items?: DisplayItem[];
|
|
@@ -201,6 +179,22 @@ interface MeshExtractionOptions {
|
|
|
201
179
|
groundAxis?: 'x' | 'y' | 'z';
|
|
202
180
|
debug?: boolean;
|
|
203
181
|
}
|
|
182
|
+
interface DisplayDataItem {
|
|
183
|
+
/** Namespaced wire type token, e.g. `Selva.GH.Features.Display.Services.DisplayBatch`. */
|
|
184
|
+
type: string;
|
|
185
|
+
/** A JSON string of the batch, or the batch itself once a binary response was decoded. */
|
|
186
|
+
data: string | DisplayBatch;
|
|
187
|
+
}
|
|
188
|
+
interface GrasshopperResponseValue {
|
|
189
|
+
InnerTree: {
|
|
190
|
+
[branchPath: string]: DisplayDataItem[];
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
interface GrasshopperComputeResponse {
|
|
194
|
+
values: GrasshopperResponseValue[];
|
|
195
|
+
/** Rhino `UnitSystem` name driving unit scaling (see `SCALE_FACTORS`); unrecognized/absent scales 1. */
|
|
196
|
+
modelunits: string;
|
|
197
|
+
}
|
|
204
198
|
/**
|
|
205
199
|
* Metres per model unit, keyed by Rhino `UnitSystem` name (the `modelunits` string on the compute
|
|
206
200
|
* response). Imperial factors are the exact international definitions. Units missing from this
|
package/dist/parse.js
CHANGED
|
@@ -1524,10 +1524,17 @@ function finishGeometry(geometry, members) {
|
|
|
1524
1524
|
const tangents = creased.uvs ? grainTangents(creased.positions, creased.normals, creased.indices, creased.uvs) : null;
|
|
1525
1525
|
return {
|
|
1526
1526
|
...creased,
|
|
1527
|
+
normals: packNormals(creased.normals),
|
|
1527
1528
|
closed,
|
|
1528
1529
|
tangents
|
|
1529
1530
|
};
|
|
1530
1531
|
}
|
|
1532
|
+
/** Self-contained: stringified into the assembly worker. */
|
|
1533
|
+
function packNormals(normals) {
|
|
1534
|
+
const packed = new Int16Array(normals.length);
|
|
1535
|
+
for (let i = 0; i < normals.length; i++) packed[i] = Math.round(normals[i] * 32767);
|
|
1536
|
+
return packed;
|
|
1537
|
+
}
|
|
1531
1538
|
function assembleGeometries(input) {
|
|
1532
1539
|
const { isFloat32, deltaEncoded, planarByteSplit, uint16Indices, origin, scale, uvs, colors, jobs } = input;
|
|
1533
1540
|
const unzigzag = (zz) => zz >>> 1 ^ -(zz & 1);
|
|
@@ -1674,6 +1681,7 @@ function meshAssemblyWorkerSource() {
|
|
|
1674
1681
|
`const isClosedSolid = ${isClosedSolid.toString()};`,
|
|
1675
1682
|
`const splitCreases = ${splitCreases.toString()};`,
|
|
1676
1683
|
`const grainTangents = ${grainTangents.toString()};`,
|
|
1684
|
+
`const packNormals = ${packNormals.toString()};`,
|
|
1677
1685
|
`self.onmessage = (event) => {`,
|
|
1678
1686
|
` const { id, input } = event.data;`,
|
|
1679
1687
|
` try {`,
|
|
@@ -1685,7 +1693,7 @@ function meshAssemblyWorkerSource() {
|
|
|
1685
1693
|
` : isClosedSolid(g.positions, g.indices, windows.map((w) => w.indexCount));`,
|
|
1686
1694
|
` const c = splitCreases(g.positions, g.indices, g.uvs, g.colors);`,
|
|
1687
1695
|
` const tangents = c.uvs ? grainTangents(c.positions, c.normals, c.indices, c.uvs) : null;`,
|
|
1688
|
-
` return { ...c, closed, tangents };`,
|
|
1696
|
+
` return { ...c, normals: packNormals(c.normals), closed, tangents };`,
|
|
1689
1697
|
` });`,
|
|
1690
1698
|
` const transfer = [];`,
|
|
1691
1699
|
` for (const g of geometries) {`,
|
|
@@ -2490,7 +2498,7 @@ function createMergedMesh(group, allVertices, allIndices, pickMaterial, allUvs =
|
|
|
2490
2498
|
function geometryFrom(finished) {
|
|
2491
2499
|
const geometry = new THREE.BufferGeometry();
|
|
2492
2500
|
geometry.setAttribute("position", new THREE.BufferAttribute(finished.positions, 3));
|
|
2493
|
-
geometry.setAttribute("normal", new THREE.BufferAttribute(finished.normals, 3));
|
|
2501
|
+
geometry.setAttribute("normal", new THREE.BufferAttribute(finished.normals, 3, true));
|
|
2494
2502
|
geometry.setIndex(new THREE.BufferAttribute(finished.indices, 1));
|
|
2495
2503
|
if (finished.uvs) geometry.setAttribute("uv", new THREE.BufferAttribute(finished.uvs, 2));
|
|
2496
2504
|
if (finished.tangents) geometry.setAttribute("tangent", new THREE.BufferAttribute(finished.tangents, 4));
|
|
@@ -2724,7 +2732,7 @@ async function parseMeshBatchObject(batch, options, telemetry) {
|
|
|
2724
2732
|
parseTime,
|
|
2725
2733
|
decodeTime: performance.now() - decodeStart,
|
|
2726
2734
|
perfStart,
|
|
2727
|
-
blobBytes: debug ? approximateBase64DecodedBytes(batch.compressedData) :
|
|
2735
|
+
blobBytes: !debug ? 0 : typeof batch.compressedData === "string" ? approximateBase64DecodedBytes(batch.compressedData) : batch.compressedData.byteLength,
|
|
2728
2736
|
fallback: {
|
|
2729
2737
|
materials: batch.materials,
|
|
2730
2738
|
groups: batch.groups
|
|
@@ -3043,6 +3051,9 @@ const SCALE_FACTORS = {
|
|
|
3043
3051
|
const DISPLAY_COMPONENT_TYPE = "Display";
|
|
3044
3052
|
const DISPLAY_BATCH_TYPE = "DisplayBatch";
|
|
3045
3053
|
/**
|
|
3054
|
+
* Must match `isDisplayItemType` in `@selvajs/solve/shared`, which picks the batches a binary
|
|
3055
|
+
* response carries as raw bytes.
|
|
3056
|
+
*
|
|
3046
3057
|
* True when a wire `type` denotes a Display payload: one of its dot-separated tokens is exactly
|
|
3047
3058
|
* `Display` or `DisplayBatch`. Matches the bare `Display` used by older servers and the namespaced
|
|
3048
3059
|
* `Selva.GH.Features.Display.Services.DisplayBatch`, but not e.g. `System.DisplayText` — matching
|
|
@@ -3075,7 +3086,7 @@ async function getThreeObjectsFromComputeResponse(data, options) {
|
|
|
3075
3086
|
handleError(error, objects);
|
|
3076
3087
|
throw error;
|
|
3077
3088
|
} finally {
|
|
3078
|
-
if (debug) logProcessingTime(startTime);
|
|
3089
|
+
if (debug) logProcessingTime(startTime, objects);
|
|
3079
3090
|
}
|
|
3080
3091
|
}
|
|
3081
3092
|
/**
|
|
@@ -3151,9 +3162,26 @@ function handleError(error, meshes) {
|
|
|
3151
3162
|
function disposeMeshes(meshes) {
|
|
3152
3163
|
for (const mesh of meshes) disposeObjectTree(mesh);
|
|
3153
3164
|
}
|
|
3154
|
-
|
|
3165
|
+
/** Time plus what the result costs to hold: the same bytes again on the GPU once uploaded. */
|
|
3166
|
+
function logProcessingTime(startTime, objects) {
|
|
3155
3167
|
const elapsed = performance.now() - startTime;
|
|
3156
|
-
|
|
3168
|
+
let triangles = 0;
|
|
3169
|
+
let vertices = 0;
|
|
3170
|
+
let bytes = 0;
|
|
3171
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3172
|
+
for (const root of objects) root.traverse((object) => {
|
|
3173
|
+
const geometry = object.geometry;
|
|
3174
|
+
if (!geometry?.isBufferGeometry || seen.has(geometry)) return;
|
|
3175
|
+
seen.add(geometry);
|
|
3176
|
+
const position = geometry.getAttribute("position");
|
|
3177
|
+
if (!position) return;
|
|
3178
|
+
vertices += position.count;
|
|
3179
|
+
if (object.isMesh) triangles += (geometry.index ? geometry.index.count : position.count) / 3;
|
|
3180
|
+
for (const attribute of Object.values(geometry.attributes)) bytes += attribute.array.byteLength;
|
|
3181
|
+
if (geometry.index) bytes += geometry.index.array.byteLength;
|
|
3182
|
+
});
|
|
3183
|
+
const mb = (bytes / 1048576).toFixed(1);
|
|
3184
|
+
getLogger().info(`Time to process meshes: ${elapsed.toFixed(2)}ms | ${triangles.toLocaleString("en")} triangles, ${vertices.toLocaleString("en")} vertices, ${mb} MB of geometry`);
|
|
3157
3185
|
}
|
|
3158
3186
|
export { SCALE_FACTORS, clearGeometryCache, getThreeObjectsFromComputeResponse, meshPolicy, parseDisplayItems, parseMeshBatchBlob, parseMeshBatchObject, setTextureAnisotropy };
|
|
3159
3187
|
|