@tscircuit/3d-viewer 0.0.507 → 0.0.509
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/index.js +64 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28078,7 +28078,7 @@ function occtMeshesToGroup(meshes) {
|
|
|
28078
28078
|
}
|
|
28079
28079
|
return group;
|
|
28080
28080
|
}
|
|
28081
|
-
async function
|
|
28081
|
+
async function convertStepUrlToGlb(stepUrl) {
|
|
28082
28082
|
const response = await fetch(stepUrl);
|
|
28083
28083
|
if (!response.ok) {
|
|
28084
28084
|
throw new Error(`Failed to fetch STEP file: ${response.statusText}`);
|
|
@@ -28107,7 +28107,7 @@ async function convertStepUrlToGlbUrl(stepUrl) {
|
|
|
28107
28107
|
{ binary: true }
|
|
28108
28108
|
);
|
|
28109
28109
|
});
|
|
28110
|
-
return
|
|
28110
|
+
return glb;
|
|
28111
28111
|
}
|
|
28112
28112
|
var CACHE_PREFIX = "step-glb-cache:";
|
|
28113
28113
|
function arrayBufferToBase64(buffer) {
|
|
@@ -28148,6 +28148,16 @@ function setCachedGlb(stepUrl, glb) {
|
|
|
28148
28148
|
console.warn("Failed to write STEP GLB cache", error);
|
|
28149
28149
|
}
|
|
28150
28150
|
}
|
|
28151
|
+
function getStepUrlConversionRegistry() {
|
|
28152
|
+
const globalScope = globalThis;
|
|
28153
|
+
if (!globalScope.stepUrlToGltfModelConversions) {
|
|
28154
|
+
globalScope.stepUrlToGltfModelConversions = {
|
|
28155
|
+
inProgress: /* @__PURE__ */ new Map(),
|
|
28156
|
+
completed: /* @__PURE__ */ new Map()
|
|
28157
|
+
};
|
|
28158
|
+
}
|
|
28159
|
+
return globalScope.stepUrlToGltfModelConversions;
|
|
28160
|
+
}
|
|
28151
28161
|
var StepModel = ({
|
|
28152
28162
|
stepUrl,
|
|
28153
28163
|
position,
|
|
@@ -28162,31 +28172,66 @@ var StepModel = ({
|
|
|
28162
28172
|
useEffect10(() => {
|
|
28163
28173
|
let isActive = true;
|
|
28164
28174
|
let objectUrl = null;
|
|
28175
|
+
let shouldRevokeObjectUrl = true;
|
|
28176
|
+
const registry = getStepUrlConversionRegistry();
|
|
28165
28177
|
const cachedGlb = getCachedGlb(stepUrl);
|
|
28166
28178
|
if (cachedGlb) {
|
|
28167
|
-
|
|
28168
|
-
|
|
28169
|
-
|
|
28170
|
-
|
|
28179
|
+
const cachedConverted = {
|
|
28180
|
+
arrayBuffer: cachedGlb,
|
|
28181
|
+
blobUrl: URL.createObjectURL(
|
|
28182
|
+
new Blob([cachedGlb], { type: "model/gltf-binary" })
|
|
28183
|
+
)
|
|
28184
|
+
};
|
|
28185
|
+
registry.completed.set(stepUrl, cachedConverted);
|
|
28186
|
+
objectUrl = cachedConverted.blobUrl;
|
|
28187
|
+
shouldRevokeObjectUrl = false;
|
|
28188
|
+
setStepGltfUrl(cachedConverted.blobUrl);
|
|
28171
28189
|
return () => {
|
|
28172
28190
|
isActive = false;
|
|
28173
|
-
if (objectUrl) {
|
|
28191
|
+
if (objectUrl && shouldRevokeObjectUrl) {
|
|
28174
28192
|
URL.revokeObjectURL(objectUrl);
|
|
28175
28193
|
}
|
|
28176
28194
|
};
|
|
28177
28195
|
}
|
|
28178
|
-
|
|
28196
|
+
const existingCompleted = registry.completed.get(stepUrl);
|
|
28197
|
+
if (existingCompleted) {
|
|
28198
|
+
objectUrl = existingCompleted.blobUrl;
|
|
28199
|
+
shouldRevokeObjectUrl = false;
|
|
28200
|
+
setStepGltfUrl(existingCompleted.blobUrl);
|
|
28201
|
+
setCachedGlb(stepUrl, existingCompleted.arrayBuffer);
|
|
28202
|
+
return () => {
|
|
28203
|
+
isActive = false;
|
|
28204
|
+
if (objectUrl && shouldRevokeObjectUrl) {
|
|
28205
|
+
URL.revokeObjectURL(objectUrl);
|
|
28206
|
+
}
|
|
28207
|
+
};
|
|
28208
|
+
}
|
|
28209
|
+
let conversionPromise = registry.inProgress.get(stepUrl);
|
|
28210
|
+
if (!conversionPromise) {
|
|
28211
|
+
conversionPromise = convertStepUrlToGlb(stepUrl).then((glbBuffer) => {
|
|
28212
|
+
const converted = {
|
|
28213
|
+
arrayBuffer: glbBuffer,
|
|
28214
|
+
blobUrl: URL.createObjectURL(
|
|
28215
|
+
new Blob([glbBuffer], { type: "model/gltf-binary" })
|
|
28216
|
+
)
|
|
28217
|
+
};
|
|
28218
|
+
registry.completed.set(stepUrl, converted);
|
|
28219
|
+
registry.inProgress.delete(stepUrl);
|
|
28220
|
+
return converted;
|
|
28221
|
+
}).catch((error) => {
|
|
28222
|
+
registry.inProgress.delete(stepUrl);
|
|
28223
|
+
throw error;
|
|
28224
|
+
});
|
|
28225
|
+
registry.inProgress.set(stepUrl, conversionPromise);
|
|
28226
|
+
}
|
|
28227
|
+
void conversionPromise.then((converted) => {
|
|
28179
28228
|
if (!isActive) {
|
|
28180
|
-
URL.revokeObjectURL(generatedUrl);
|
|
28181
28229
|
return;
|
|
28182
28230
|
}
|
|
28183
|
-
objectUrl =
|
|
28184
|
-
|
|
28185
|
-
|
|
28186
|
-
|
|
28187
|
-
}).catch((error) => {
|
|
28188
|
-
console.warn("Failed to cache STEP GLB", error);
|
|
28189
|
-
});
|
|
28231
|
+
objectUrl = converted.blobUrl;
|
|
28232
|
+
shouldRevokeObjectUrl = false;
|
|
28233
|
+
setStepGltfUrl(converted.blobUrl);
|
|
28234
|
+
setCachedGlb(stepUrl, converted.arrayBuffer);
|
|
28190
28235
|
}).catch((error) => {
|
|
28191
28236
|
console.error("Failed to convert STEP file to GLB", error);
|
|
28192
28237
|
if (isActive) {
|
|
@@ -28195,7 +28240,7 @@ var StepModel = ({
|
|
|
28195
28240
|
});
|
|
28196
28241
|
return () => {
|
|
28197
28242
|
isActive = false;
|
|
28198
|
-
if (objectUrl) {
|
|
28243
|
+
if (objectUrl && shouldRevokeObjectUrl) {
|
|
28199
28244
|
URL.revokeObjectURL(objectUrl);
|
|
28200
28245
|
}
|
|
28201
28246
|
};
|
|
@@ -28274,12 +28319,11 @@ var AnyCadComponent = ({
|
|
|
28274
28319
|
}, [cad_component.rotation, layer]);
|
|
28275
28320
|
const adjustedPosition = useMemo8(() => {
|
|
28276
28321
|
if (!cad_component.position) return void 0;
|
|
28277
|
-
const bottomLayerOffset = 0.55;
|
|
28278
28322
|
let z18;
|
|
28279
28323
|
if (layer === "top") {
|
|
28280
28324
|
z18 = pcbThickness / 2;
|
|
28281
28325
|
} else if (layer === "bottom") {
|
|
28282
|
-
z18 = -(pcbThickness / 2)
|
|
28326
|
+
z18 = -(pcbThickness / 2);
|
|
28283
28327
|
} else {
|
|
28284
28328
|
z18 = cad_component.position.z;
|
|
28285
28329
|
}
|
|
@@ -28403,7 +28447,7 @@ import * as THREE16 from "three";
|
|
|
28403
28447
|
// package.json
|
|
28404
28448
|
var package_default = {
|
|
28405
28449
|
name: "@tscircuit/3d-viewer",
|
|
28406
|
-
version: "0.0.
|
|
28450
|
+
version: "0.0.508",
|
|
28407
28451
|
main: "./dist/index.js",
|
|
28408
28452
|
module: "./dist/index.js",
|
|
28409
28453
|
type: "module",
|