@tscircuit/3d-viewer 0.0.570 → 0.0.571
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 +94 -33
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31205,12 +31205,15 @@ function GltfModel({
|
|
|
31205
31205
|
useEffect7(() => {
|
|
31206
31206
|
if (!model) return;
|
|
31207
31207
|
model.traverse((child) => {
|
|
31208
|
-
if (child instanceof THREE7.Mesh
|
|
31208
|
+
if (!(child instanceof THREE7.Mesh)) return;
|
|
31209
|
+
const materials = Array.isArray(child.material) ? child.material : [child.material];
|
|
31210
|
+
for (const material of materials) {
|
|
31211
|
+
if (!(material instanceof THREE7.MeshStandardMaterial)) continue;
|
|
31209
31212
|
if (isHovered) {
|
|
31210
|
-
|
|
31211
|
-
|
|
31213
|
+
material.emissive.setHex(255);
|
|
31214
|
+
material.emissiveIntensity = 0.2;
|
|
31212
31215
|
} else {
|
|
31213
|
-
|
|
31216
|
+
material.emissiveIntensity = 0;
|
|
31214
31217
|
}
|
|
31215
31218
|
}
|
|
31216
31219
|
});
|
|
@@ -31486,6 +31489,9 @@ function MixedStlModel({
|
|
|
31486
31489
|
|
|
31487
31490
|
// src/three-components/StepModel.tsx
|
|
31488
31491
|
import { useEffect as useEffect10, useState as useState6 } from "react";
|
|
31492
|
+
import { GLTFExporter } from "three-stdlib";
|
|
31493
|
+
|
|
31494
|
+
// src/three-components/step-mesh-to-group.ts
|
|
31489
31495
|
import {
|
|
31490
31496
|
BufferGeometry as BufferGeometry2,
|
|
31491
31497
|
Color as Color3,
|
|
@@ -31494,7 +31500,88 @@ import {
|
|
|
31494
31500
|
Mesh as Mesh6,
|
|
31495
31501
|
MeshStandardMaterial as MeshStandardMaterial5
|
|
31496
31502
|
} from "three";
|
|
31497
|
-
|
|
31503
|
+
var DEFAULT_COLOR = new Color3(0.82, 0.82, 0.82);
|
|
31504
|
+
var createMaterial = (color) => new MeshStandardMaterial5({
|
|
31505
|
+
color: color ? new Color3(color[0], color[1], color[2]) : DEFAULT_COLOR
|
|
31506
|
+
});
|
|
31507
|
+
function applyFaceColorGroups(geometry, mesh) {
|
|
31508
|
+
const defaultMaterial = createMaterial(mesh.color);
|
|
31509
|
+
const brepFaces = mesh.brep_faces ?? [];
|
|
31510
|
+
if (brepFaces.length === 0) {
|
|
31511
|
+
return [defaultMaterial];
|
|
31512
|
+
}
|
|
31513
|
+
const sortedBrepFaces = brepFaces.length > 1 ? [...brepFaces].sort((a, b) => a.first - b.first) : brepFaces;
|
|
31514
|
+
const materials = [defaultMaterial];
|
|
31515
|
+
const materialIndexByColor = /* @__PURE__ */ new Map();
|
|
31516
|
+
const triangleCount = mesh.index.array.length / 3;
|
|
31517
|
+
let triangleIndex = 0;
|
|
31518
|
+
let faceIndex = 0;
|
|
31519
|
+
const getMaterialIndexForFace = (color) => {
|
|
31520
|
+
if (!color) return 0;
|
|
31521
|
+
const key = color.join(",");
|
|
31522
|
+
const existingIndex = materialIndexByColor.get(key);
|
|
31523
|
+
if (existingIndex !== void 0) {
|
|
31524
|
+
return existingIndex;
|
|
31525
|
+
}
|
|
31526
|
+
const nextIndex = materials.length;
|
|
31527
|
+
materials.push(createMaterial(color));
|
|
31528
|
+
materialIndexByColor.set(key, nextIndex);
|
|
31529
|
+
return nextIndex;
|
|
31530
|
+
};
|
|
31531
|
+
while (triangleIndex < triangleCount) {
|
|
31532
|
+
const currentFace = sortedBrepFaces[faceIndex];
|
|
31533
|
+
let lastTriangleExclusive = triangleCount;
|
|
31534
|
+
let materialIndex = 0;
|
|
31535
|
+
if (currentFace) {
|
|
31536
|
+
if (triangleIndex < currentFace.first) {
|
|
31537
|
+
lastTriangleExclusive = currentFace.first;
|
|
31538
|
+
} else {
|
|
31539
|
+
lastTriangleExclusive = currentFace.last + 1;
|
|
31540
|
+
materialIndex = getMaterialIndexForFace(currentFace.color);
|
|
31541
|
+
faceIndex += 1;
|
|
31542
|
+
}
|
|
31543
|
+
}
|
|
31544
|
+
if (lastTriangleExclusive > triangleIndex) {
|
|
31545
|
+
geometry.addGroup(
|
|
31546
|
+
triangleIndex * 3,
|
|
31547
|
+
(lastTriangleExclusive - triangleIndex) * 3,
|
|
31548
|
+
materialIndex
|
|
31549
|
+
);
|
|
31550
|
+
}
|
|
31551
|
+
triangleIndex = lastTriangleExclusive;
|
|
31552
|
+
}
|
|
31553
|
+
return materials;
|
|
31554
|
+
}
|
|
31555
|
+
function occtMeshesToGroup(meshes) {
|
|
31556
|
+
const group = new Group3();
|
|
31557
|
+
for (const mesh of meshes) {
|
|
31558
|
+
const positions = mesh.attributes.position?.array ?? [];
|
|
31559
|
+
const indices = mesh.index?.array ?? [];
|
|
31560
|
+
if (!positions.length || !indices.length) {
|
|
31561
|
+
continue;
|
|
31562
|
+
}
|
|
31563
|
+
const geometry = new BufferGeometry2();
|
|
31564
|
+
geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
|
|
31565
|
+
const normals = mesh.attributes.normal?.array ?? [];
|
|
31566
|
+
if (normals.length) {
|
|
31567
|
+
geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
31568
|
+
} else {
|
|
31569
|
+
geometry.computeVertexNormals();
|
|
31570
|
+
}
|
|
31571
|
+
geometry.setIndex(indices);
|
|
31572
|
+
geometry.clearGroups();
|
|
31573
|
+
const materials = applyFaceColorGroups(geometry, mesh);
|
|
31574
|
+
const threeMesh = new Mesh6(
|
|
31575
|
+
geometry,
|
|
31576
|
+
materials.length > 1 ? materials : materials[0]
|
|
31577
|
+
);
|
|
31578
|
+
threeMesh.name = mesh.name;
|
|
31579
|
+
group.add(threeMesh);
|
|
31580
|
+
}
|
|
31581
|
+
return group;
|
|
31582
|
+
}
|
|
31583
|
+
|
|
31584
|
+
// src/three-components/StepModel.tsx
|
|
31498
31585
|
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
31499
31586
|
var occtImportPromise;
|
|
31500
31587
|
var OCCT_CDN_BASE_URL = "https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";
|
|
@@ -31520,32 +31607,6 @@ async function loadOcctImport() {
|
|
|
31520
31607
|
}
|
|
31521
31608
|
return occtImportPromise;
|
|
31522
31609
|
}
|
|
31523
|
-
function occtMeshesToGroup(meshes) {
|
|
31524
|
-
const group = new Group3();
|
|
31525
|
-
for (const mesh of meshes) {
|
|
31526
|
-
const positions = mesh.attributes.position?.array ?? [];
|
|
31527
|
-
const indices = mesh.index?.array ?? [];
|
|
31528
|
-
if (!positions.length || !indices.length) {
|
|
31529
|
-
continue;
|
|
31530
|
-
}
|
|
31531
|
-
const geometry = new BufferGeometry2();
|
|
31532
|
-
geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
|
|
31533
|
-
const normals = mesh.attributes.normal?.array ?? [];
|
|
31534
|
-
if (normals.length) {
|
|
31535
|
-
geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
31536
|
-
} else {
|
|
31537
|
-
geometry.computeVertexNormals();
|
|
31538
|
-
}
|
|
31539
|
-
geometry.setIndex(indices);
|
|
31540
|
-
const material = new MeshStandardMaterial5({
|
|
31541
|
-
color: mesh.color ? new Color3(mesh.color[0], mesh.color[1], mesh.color[2]) : new Color3(0.82, 0.82, 0.82)
|
|
31542
|
-
});
|
|
31543
|
-
const threeMesh = new Mesh6(geometry, material);
|
|
31544
|
-
threeMesh.name = mesh.name;
|
|
31545
|
-
group.add(threeMesh);
|
|
31546
|
-
}
|
|
31547
|
-
return group;
|
|
31548
|
-
}
|
|
31549
31610
|
async function convertStepUrlToGlb(stepUrl) {
|
|
31550
31611
|
const response = await fetch(stepUrl);
|
|
31551
31612
|
if (!response.ok) {
|
|
@@ -31577,7 +31638,7 @@ async function convertStepUrlToGlb(stepUrl) {
|
|
|
31577
31638
|
});
|
|
31578
31639
|
return glb;
|
|
31579
31640
|
}
|
|
31580
|
-
var CACHE_PREFIX = "step-glb-cache:";
|
|
31641
|
+
var CACHE_PREFIX = "step-glb-cache:v2:";
|
|
31581
31642
|
function arrayBufferToBase64(buffer) {
|
|
31582
31643
|
const bytes = new Uint8Array(buffer);
|
|
31583
31644
|
const chunkSize = 32768;
|
|
@@ -32337,7 +32398,7 @@ import * as THREE20 from "three";
|
|
|
32337
32398
|
// package.json
|
|
32338
32399
|
var package_default = {
|
|
32339
32400
|
name: "@tscircuit/3d-viewer",
|
|
32340
|
-
version: "0.0.
|
|
32401
|
+
version: "0.0.570",
|
|
32341
32402
|
main: "./dist/index.js",
|
|
32342
32403
|
module: "./dist/index.js",
|
|
32343
32404
|
type: "module",
|