@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.cjs
CHANGED
|
@@ -1526,10 +1526,17 @@ function finishGeometry(geometry, members) {
|
|
|
1526
1526
|
const tangents = creased.uvs ? grainTangents(creased.positions, creased.normals, creased.indices, creased.uvs) : null;
|
|
1527
1527
|
return {
|
|
1528
1528
|
...creased,
|
|
1529
|
+
normals: packNormals(creased.normals),
|
|
1529
1530
|
closed,
|
|
1530
1531
|
tangents
|
|
1531
1532
|
};
|
|
1532
1533
|
}
|
|
1534
|
+
/** Self-contained: stringified into the assembly worker. */
|
|
1535
|
+
function packNormals(normals) {
|
|
1536
|
+
const packed = new Int16Array(normals.length);
|
|
1537
|
+
for (let i = 0; i < normals.length; i++) packed[i] = Math.round(normals[i] * 32767);
|
|
1538
|
+
return packed;
|
|
1539
|
+
}
|
|
1533
1540
|
function assembleGeometries(input) {
|
|
1534
1541
|
const { isFloat32, deltaEncoded, planarByteSplit, uint16Indices, origin, scale, uvs, colors, jobs } = input;
|
|
1535
1542
|
const unzigzag = (zz) => zz >>> 1 ^ -(zz & 1);
|
|
@@ -1676,6 +1683,7 @@ function meshAssemblyWorkerSource() {
|
|
|
1676
1683
|
`const isClosedSolid = ${isClosedSolid.toString()};`,
|
|
1677
1684
|
`const splitCreases = ${splitCreases.toString()};`,
|
|
1678
1685
|
`const grainTangents = ${grainTangents.toString()};`,
|
|
1686
|
+
`const packNormals = ${packNormals.toString()};`,
|
|
1679
1687
|
`self.onmessage = (event) => {`,
|
|
1680
1688
|
` const { id, input } = event.data;`,
|
|
1681
1689
|
` try {`,
|
|
@@ -1687,7 +1695,7 @@ function meshAssemblyWorkerSource() {
|
|
|
1687
1695
|
` : isClosedSolid(g.positions, g.indices, windows.map((w) => w.indexCount));`,
|
|
1688
1696
|
` const c = splitCreases(g.positions, g.indices, g.uvs, g.colors);`,
|
|
1689
1697
|
` const tangents = c.uvs ? grainTangents(c.positions, c.normals, c.indices, c.uvs) : null;`,
|
|
1690
|
-
` return { ...c, closed, tangents };`,
|
|
1698
|
+
` return { ...c, normals: packNormals(c.normals), closed, tangents };`,
|
|
1691
1699
|
` });`,
|
|
1692
1700
|
` const transfer = [];`,
|
|
1693
1701
|
` for (const g of geometries) {`,
|
|
@@ -2492,7 +2500,7 @@ function createMergedMesh(group, allVertices, allIndices, pickMaterial, allUvs =
|
|
|
2492
2500
|
function geometryFrom(finished) {
|
|
2493
2501
|
const geometry = new three.BufferGeometry();
|
|
2494
2502
|
geometry.setAttribute("position", new three.BufferAttribute(finished.positions, 3));
|
|
2495
|
-
geometry.setAttribute("normal", new three.BufferAttribute(finished.normals, 3));
|
|
2503
|
+
geometry.setAttribute("normal", new three.BufferAttribute(finished.normals, 3, true));
|
|
2496
2504
|
geometry.setIndex(new three.BufferAttribute(finished.indices, 1));
|
|
2497
2505
|
if (finished.uvs) geometry.setAttribute("uv", new three.BufferAttribute(finished.uvs, 2));
|
|
2498
2506
|
if (finished.tangents) geometry.setAttribute("tangent", new three.BufferAttribute(finished.tangents, 4));
|
|
@@ -2726,7 +2734,7 @@ async function parseMeshBatchObject(batch, options, telemetry) {
|
|
|
2726
2734
|
parseTime,
|
|
2727
2735
|
decodeTime: performance.now() - decodeStart,
|
|
2728
2736
|
perfStart,
|
|
2729
|
-
blobBytes: debug ? approximateBase64DecodedBytes(batch.compressedData) :
|
|
2737
|
+
blobBytes: !debug ? 0 : typeof batch.compressedData === "string" ? approximateBase64DecodedBytes(batch.compressedData) : batch.compressedData.byteLength,
|
|
2730
2738
|
fallback: {
|
|
2731
2739
|
materials: batch.materials,
|
|
2732
2740
|
groups: batch.groups
|
|
@@ -3045,6 +3053,9 @@ const SCALE_FACTORS = {
|
|
|
3045
3053
|
const DISPLAY_COMPONENT_TYPE = "Display";
|
|
3046
3054
|
const DISPLAY_BATCH_TYPE = "DisplayBatch";
|
|
3047
3055
|
/**
|
|
3056
|
+
* Must match `isDisplayItemType` in `@selvajs/solve/shared`, which picks the batches a binary
|
|
3057
|
+
* response carries as raw bytes.
|
|
3058
|
+
*
|
|
3048
3059
|
* True when a wire `type` denotes a Display payload: one of its dot-separated tokens is exactly
|
|
3049
3060
|
* `Display` or `DisplayBatch`. Matches the bare `Display` used by older servers and the namespaced
|
|
3050
3061
|
* `Selva.GH.Features.Display.Services.DisplayBatch`, but not e.g. `System.DisplayText` — matching
|
|
@@ -3077,7 +3088,7 @@ async function getThreeObjectsFromComputeResponse(data, options) {
|
|
|
3077
3088
|
handleError(error, objects);
|
|
3078
3089
|
throw error;
|
|
3079
3090
|
} finally {
|
|
3080
|
-
if (debug) logProcessingTime(startTime);
|
|
3091
|
+
if (debug) logProcessingTime(startTime, objects);
|
|
3081
3092
|
}
|
|
3082
3093
|
}
|
|
3083
3094
|
/**
|
|
@@ -3153,9 +3164,26 @@ function handleError(error, meshes) {
|
|
|
3153
3164
|
function disposeMeshes(meshes) {
|
|
3154
3165
|
for (const mesh of meshes) require_gpu_dispose.disposeObjectTree(mesh);
|
|
3155
3166
|
}
|
|
3156
|
-
|
|
3167
|
+
/** Time plus what the result costs to hold: the same bytes again on the GPU once uploaded. */
|
|
3168
|
+
function logProcessingTime(startTime, objects) {
|
|
3157
3169
|
const elapsed = performance.now() - startTime;
|
|
3158
|
-
|
|
3170
|
+
let triangles = 0;
|
|
3171
|
+
let vertices = 0;
|
|
3172
|
+
let bytes = 0;
|
|
3173
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3174
|
+
for (const root of objects) root.traverse((object) => {
|
|
3175
|
+
const geometry = object.geometry;
|
|
3176
|
+
if (!geometry?.isBufferGeometry || seen.has(geometry)) return;
|
|
3177
|
+
seen.add(geometry);
|
|
3178
|
+
const position = geometry.getAttribute("position");
|
|
3179
|
+
if (!position) return;
|
|
3180
|
+
vertices += position.count;
|
|
3181
|
+
if (object.isMesh) triangles += (geometry.index ? geometry.index.count : position.count) / 3;
|
|
3182
|
+
for (const attribute of Object.values(geometry.attributes)) bytes += attribute.array.byteLength;
|
|
3183
|
+
if (geometry.index) bytes += geometry.index.array.byteLength;
|
|
3184
|
+
});
|
|
3185
|
+
const mb = (bytes / 1048576).toFixed(1);
|
|
3186
|
+
require_gpu_dispose.getLogger().info(`Time to process meshes: ${elapsed.toFixed(2)}ms | ${triangles.toLocaleString("en")} triangles, ${vertices.toLocaleString("en")} vertices, ${mb} MB of geometry`);
|
|
3159
3187
|
}
|
|
3160
3188
|
exports.SCALE_FACTORS = SCALE_FACTORS;
|
|
3161
3189
|
exports.clearGeometryCache = clearGeometryCache;
|