Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix: revert changes to model viewer

Brad Barbine116ddcc2e81
diff --git a/examples/upload-3d-model/app/components/ModelUpload.tsx b/examples/upload-3d-model/app/components/ModelUpload.tsx
index 24cc407e8f..d2b9fbcbe1 100644
--- a/examples/upload-3d-model/app/components/ModelUpload.tsx
+++ b/examples/upload-3d-model/app/components/ModelUpload.tsx
@@ -1,5 +1,5 @@
import { cn, Spinner, toast } from "@carbon/react";
-import { convertKbToString, getFileSizeLimit } from "@carbon/utils";
+import { convertKbToString } from "@carbon/utils";
import { useDropzone } from "react-dropzone";
import { LuCloudUpload } from "react-icons/lu";
@@ -10,7 +10,7 @@ type ModelUploadProps = {
onFileChange: (file: File | null) => void;
};
-const SIZE_LIMIT = getFileSizeLimit("CAD_MODEL_UPLOAD");
+const fileSizeLimitMb = 120;
const supportedModelTypes = ["stp", "step"];
export const ModelUpload = ({
@@ -27,9 +27,10 @@ export const ModelUpload = ({
},
disabled: hasFile,
multiple: false,
- maxSize: SIZE_LIMIT.bytes,
+ maxSize: fileSizeLimitMb * 1024 * 1024, // 50 MB
onDropAccepted: (acceptedFiles) => {
const file = acceptedFiles[0];
+ const fileSizeLimit = fileSizeLimitMb * 1024 * 1024;
const fileExtension = file.name.split(".").pop()?.toLowerCase();
if (!fileExtension || !supportedModelTypes.includes(fileExtension)) {
@@ -38,8 +39,8 @@ export const ModelUpload = ({
return;
}
- if (file.size > SIZE_LIMIT.bytes) {
- toast.error(`File size too big (max. ${SIZE_LIMIT.format()})`);
+ if (file.size > fileSizeLimit) {
+ toast.error(`File size too big (max. ${fileSizeLimitMb} MB)`);
return;
}
@@ -49,7 +50,7 @@ export const ModelUpload = ({
const { errors } = fileRejections[0];
let message;
if (errors[0].code === "file-too-large") {
- message = `File size too big (max. ${SIZE_LIMIT.format()})`;
+ message = `File size too big (max. ${fileSizeLimitMb} MB)`;
} else if (errors[0].code === "file-invalid-type") {
message = "File type not supported";
} else {
diff --git a/package-lock.json b/package-lock.json
index 15685974f9..d641d8b998 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -19237,21 +19237,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
- "node_modules/online-3d-viewer": {
- "version": "0.18.0",
- "resolved": "https://registry.npmjs.org/online-3d-viewer/-/online-3d-viewer-0.18.0.tgz",
- "integrity": "sha512-y7ZlV/zkakNUyjqcXz6XecA7vXgLEUnaAey9tyx8o6/wcdV64RfjXAQOjGXGY2JOZoDi4Cg1ic9icSWMWAvRQA==",
- "license": "MIT",
- "dependencies": {
- "@simonwep/pickr": "1.9.0",
- "fflate": "0.8.2",
- "three": "0.176.0"
- }
- },
- "node_modules/online-3d-viewer/node_modules/fflate": {
- "version": "0.8.2",
- "license": "MIT"
- },
"node_modules/open": {
"version": "7.4.2",
"dev": true,
@@ -23721,12 +23706,6 @@
"node": ">=0.8"
}
},
- "node_modules/three": {
- "version": "0.176.0",
- "resolved": "https://registry.npmjs.org/three/-/three-0.176.0.tgz",
- "integrity": "sha512-PWRKYWQo23ojf9oZSlRGH8K09q7nRSWx6LY/HF/UUrMdYgN9i1e2OwJYHoQjwc6HF/4lvvYLC5YC1X8UJL2ZpA==",
- "license": "MIT"
- },
"node_modules/throat": {
"version": "5.0.0",
"license": "MIT"
@@ -27696,7 +27675,7 @@
"input-otp": "^1.4.2",
"intl-parse-accept-language": "^1.0.0",
"is-hotkey": "^0.2.0",
- "online-3d-viewer": "0.18.0",
+ "online-3d-viewer": "0.15.0",
"prism-react-renderer": "^2.3.1",
"react-aria-components": "1.0.1",
"react-colorful": "^5.6.1",
@@ -27765,6 +27744,23 @@
"@tiptap/core": "^2.0.0"
}
},
+ "packages/react/node_modules/fflate": {
+ "version": "0.8.2",
+ "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz",
+ "integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==",
+ "license": "MIT"
+ },
+ "packages/react/node_modules/online-3d-viewer": {
+ "version": "0.15.0",
+ "resolved": "https://registry.npmjs.org/online-3d-viewer/-/online-3d-viewer-0.15.0.tgz",
+ "integrity": "sha512-Pp6SCn7Q+T4LlEPq/AHJW+Y4B9Yzc7L8XvVlIf/XFEUhmbPqYd7bOW+fKKXl4d/uosDvrsoHYdIlrPJTLrtGYQ==",
+ "license": "MIT",
+ "dependencies": {
+ "@simonwep/pickr": "1.9.0",
+ "fflate": "0.8.2",
+ "three": "0.163.0"
+ }
+ },
"packages/react/node_modules/prosemirror-trailing-node": {
"version": "2.0.9",
"license": "MIT",
@@ -27778,6 +27774,12 @@
"prosemirror-view": "^1.33.8"
}
},
+ "packages/react/node_modules/three": {
+ "version": "0.163.0",
+ "resolved": "https://registry.npmjs.org/three/-/three-0.163.0.tgz",
+ "integrity": "sha512-HlMgCb2TF/dTLRtknBnjUTsR8FsDqBY43itYop2+Zg822I+Kd0Ua2vs8CvfBVefXkBdNDrLMoRTGCIIpfCuDew==",
+ "license": "MIT"
+ },
"packages/remix": {
"name": "@carbon/remix",
"version": "*",
diff --git a/packages/react/package.json b/packages/react/package.json
index ff42496ffe..1766665f7e 100644
--- a/packages/react/package.json
+++ b/packages/react/package.json
@@ -65,7 +65,7 @@
"input-otp": "^1.4.2",
"intl-parse-accept-language": "^1.0.0",
"is-hotkey": "^0.2.0",
- "online-3d-viewer": "0.18.0",
+ "online-3d-viewer": "0.15.0",
"prism-react-renderer": "^2.3.1",
"react-aria-components": "1.0.1",
"react-colorful": "^5.6.1",
diff --git a/packages/react/src/ModelViewer.tsx b/packages/react/src/ModelViewer.tsx
index f1547f9ab1..7b762f95af 100644
--- a/packages/react/src/ModelViewer.tsx
+++ b/packages/react/src/ModelViewer.tsx
@@ -1,5 +1,5 @@
import * as OV from "online-3d-viewer";
-import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import { useEffect, useMemo, useRef, useState } from "react";
import { useLocale } from "react-aria-components";
import * as THREE from "three";
import { useMount } from "./hooks";
@@ -34,13 +34,12 @@ export function ModelViewer({
}) {
const parentDiv = useRef<HTMLDivElement>(null);
const viewerRef = useRef<OV.EmbeddedViewer | null>(null);
- const animationFrameRef = useRef<number | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [unitSystem, setUnitSystem] = useState<UnitSystem>("metric");
const [modelInfo, setModelInfo] = useState<{
+ surfaceArea: number;
+ volume: number;
dimensions: { x: number; y: number; z: number };
- surfaceArea: number | null;
- volume: number | null;
} | null>(null);
useMount(() => {
@@ -113,8 +112,10 @@ export function ModelViewer({
}
if (model) {
- // Calculate only dimensions (fast) - surface area and volume are on-demand
+ // Calculate model dimensions and properties
const boundingBox = OV.GetBoundingBox(model);
+ const surfaceArea = OV.CalculateSurfaceArea(model);
+ const volume = OV.CalculateVolume(model);
const dimensions = {
x: boundingBox.max.x - boundingBox.min.x,
y: boundingBox.max.y - boundingBox.min.y,
@@ -122,9 +123,9 @@ export function ModelViewer({
};
setModelInfo({
- dimensions,
- surfaceArea: null,
- volume: null
+ surfaceArea,
+ volume,
+ dimensions
});
}
}
@@ -137,19 +138,14 @@ export function ModelViewer({
if (file) {
loadFile(file);
- } else if (url) {
+ }
+ if (url) {
loadUrl(url);
}
}
}
return () => {
- // Cancel any ongoing animations
- if (animationFrameRef.current) {
- cancelAnimationFrame(animationFrameRef.current);
- animationFrameRef.current = null;
- }
-
if (viewerRef.current !== null && parentDiv.current !== null) {
delete viewerRef.current.model;
viewerRef.current.viewer.renderer.resetState();
@@ -168,65 +164,6 @@ export function ModelViewer({
};
});
- // Smooth camera animation helper
- const animateCamera = useCallback(
- (
- targetEye: OV.Coord3D,
- targetCenter: OV.Coord3D,
- targetUp: OV.Coord3D,
- duration: number = 300
- ) => {
- if (!viewerRef.current) return;
-
- const viewer3D = viewerRef.current.GetViewer();
- const camera = viewer3D.GetCamera();
- const startEye = camera.eye;
- const startCenter = camera.center;
- const startUp = camera.up;
- const startTime = Date.now();
-
- const animate = () => {
- const elapsed = Date.now() - startTime;
- const progress = Math.min(elapsed / duration, 1);
-
- // Easing function (ease-out cubic)
- const eased = 1 - Math.pow(1 - progress, 3);
-
- camera.eye = new OV.Coord3D(
- startEye.x + (targetEye.x - startEye.x) * eased,
- startEye.y + (targetEye.y - startEye.y) * eased,
- startEye.z + (targetEye.z - startEye.z) * eased
- );
-
- camera.center = new OV.Coord3D(
- startCenter.x + (targetCenter.x - startCenter.x) * eased,
- startCenter.y + (targetCenter.y - startCenter.y) * eased,
- startCenter.z + (targetCenter.z - startCenter.z) * eased
- );
-
- camera.up = new OV.Coord3D(
- startUp.x + (targetUp.x - startUp.x) * eased,
- startUp.y + (targetUp.y - startUp.y) * eased,
- startUp.z + (targetUp.z - startUp.z) * eased
- );
-
- viewer3D.SetCamera(camera);
-
- if (progress < 1) {
- animationFrameRef.current = requestAnimationFrame(animate);
- }
- };
-
- // Cancel any ongoing animation
- if (animationFrameRef.current) {
- cancelAnimationFrame(animationFrameRef.current);
- }
-
- animate();
- },
- []
- );
-
function resetZoom() {
if (!viewerRef.current) return;
@@ -236,67 +173,24 @@ export function ModelViewer({
parentDiv.current?.clientHeight
);
- const boundingSphere = viewer3D.GetBoundingSphere(() => true);
+ const boundingSphere = viewer3D.GetBoundingSphere((meshUserData) => true);
if (boundingSphere) {
const center = boundingSphere.center;
const radius = boundingSphere.radius;
+ const camera = viewer3D.GetCamera();
const direction = new OV.Coord3D(1, 1, 1);
const eye = new OV.Coord3D(
center.x + direction.x * radius * 1.5,
center.y + direction.y * radius * 1.5,
center.z + direction.z * radius * 1.5
);
- const up = new OV.Coord3D(0, 1, 0);
-
- // Animate to the reset position
- animateCamera(eye, center, up, 400);
+ camera.center = center;
+ camera.eye = eye;
+ camera.up = new OV.Coord3D(0, 1, 0);
+ viewer3D.SetCamera(camera);
}
}
- const setCameraView = useCallback(
- (viewType: "front" | "top" | "side" | "isometric") => {
- if (!viewerRef.current) return;
-
- const viewer3D = viewerRef.current.GetViewer();
- const boundingSphere = viewer3D.GetBoundingSphere(() => true);
- if (!boundingSphere) return;
-
- const center = boundingSphere.center;
- const radius = boundingSphere.radius;
- const distance = radius * 2.5;
-
- let eye: OV.Coord3D;
- let up: OV.Coord3D;
-
- switch (viewType) {
- case "front":
- eye = new OV.Coord3D(center.x, center.y, center.z + distance);
- up = new OV.Coord3D(0, 1, 0);
- break;
- case "top":
- eye = new OV.Coord3D(center.x, center.y + distance, center.z);
- up = new OV.Coord3D(0, 0, -1);
- break;
- case "side":
- eye = new OV.Coord3D(center.x + distance, center.y, center.z);
- up = new OV.Coord3D(0, 1, 0);
- break;
- case "isometric":
- default:
- eye = new OV.Coord3D(
- center.x + radius * 1.5,
- center.y + radius * 1.5,
- center.z + radius * 1.5
- );
- up = new OV.Coord3D(0, 1, 0);
- break;
- }
-
- animateCamera(eye, center, up, 500);
- },
- [animateCamera]
- );
-
function loadFile(file: File) {
if (!file) return;
if (!viewerRef.current) return;
@@ -442,50 +336,31 @@ export function ModelViewer({
<>
<pre id="model-viewer-canvas" aria-hidden className="sr-only" />
{resetZoomButton && (
- <div className="absolute bottom-2 right-2 z-20 flex gap-1">
- <IconButton
- aria-label="Reset zoom"
- icon={
- <svg
- xmlns="http://www.w3.org/2000/svg"
- width="24"
- height="24"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- strokeWidth="2"
- strokeLinecap="round"
- strokeLinejoin="round"
- >
- <path d="M3 7V5a2 2 0 0 1 2-2h2" />
- <path d="M17 3h2a2 2 0 0 1 2 2v2" />
- <path d="M21 17v2a2 2 0 0 1-2 2h-2" />
- <path d="M7 21H5a2 2 0 0 1-2-2v-2" />
- <rect width="10" height="8" x="7" y="8" rx="1" />
- </svg>
- }
- variant="ghost"
- onClick={resetZoom}
- />
- <IconButton
- aria-label="Front view"
- icon={<span className="text-xs font-bold">F</span>}
- variant="ghost"
- onClick={() => setCameraView("front")}
- />
- <IconButton
- aria-label="Top view"
- icon={<span className="text-xs font-bold">T</span>}
- variant="ghost"
- onClick={() => setCameraView("top")}
- />
- <IconButton
- aria-label="Side view"
- icon={<span className="text-xs font-bold">S</span>}
- variant="ghost"
- onClick={() => setCameraView("side")}
- />
- </div>
+ <IconButton
+ aria-label="Reset zoom"
+ className="absolute top-2 right-2"
+ icon={
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ >
+ <path d="M3 7V5a2 2 0 0 1 2-2h2" />
+ <path d="M17 3h2a2 2 0 0 1 2 2v2" />
+ <path d="M21 17v2a2 2 0 0 1-2 2h-2" />
+ <path d="M7 21H5a2 2 0 0 1-2-2v-2" />
+ <rect width="10" height="8" x="7" y="8" rx="1" />
+ </svg>
+ }
+ variant="ghost"
+ onClick={resetZoom}
+ />
)}
{modelInfo && withProperties && (
<>