diff --git a/packages/abstract-3d/src/abstract-3d.ts b/packages/abstract-3d/src/abstract-3d.ts index eb947f42..17fae429 100644 --- a/packages/abstract-3d/src/abstract-3d.ts +++ b/packages/abstract-3d/src/abstract-3d.ts @@ -1,13 +1,15 @@ import * as THREE from "three"; export type Scene = { - readonly center: Vec3; - readonly size: Vec3; + readonly size_deprecated: Vec3; // Move size calculation to every renderer?? readonly groups: ReadonlyArray; - readonly rotation?: Vec3; - readonly dimensions?: Dimensions; - readonly hotSpots?: ReadonlyArray; readonly data?: Record; + // should be removed + readonly center_deprecated?: Vec3; + readonly rotation_deprecated?: Vec3; + // might be removed + readonly dimensions_deprecated?: Dimensions; + readonly hotSpots_deprecated?: ReadonlyArray; }; export type Renderer = "react" | "ai_schematic" | "ai_detailed" | "dxf"; @@ -54,6 +56,7 @@ export type Mesh = { readonly geometry: Cylinder | Cone | Box | Line | Text | Polygon | Plane | Tube | Sphere | Shape; }; +// Refactor to THREE.MeshStandardMaterial | DXF export type Material = { readonly type: MaterialType; readonly normal: string; diff --git a/packages/abstract-3d/src/renderers/dxf/dxf.ts b/packages/abstract-3d/src/renderers/dxf/dxf.ts index 94035a1a..58557347 100644 --- a/packages/abstract-3d/src/renderers/dxf/dxf.ts +++ b/packages/abstract-3d/src/renderers/dxf/dxf.ts @@ -8,9 +8,20 @@ import { dxfPolygon } from "./dxf-geometries/dxf-polygon"; import { dimBoundZero, rotationForCameraPos, sizeCenterForCameraPos } from "../shared"; export const toDxf = (scene: A3D.Scene, view: A3D.View): string => { - const unitRot = A3D.vec3RotCombine(rotationForCameraPos(view), scene.rotation ?? A3D.vec3Zero); - const rotatedCenter = A3D.vec3Rot(scene.center, A3D.vec3Zero, scene.rotation ?? A3D.vec3Zero); - const [size, center] = sizeCenterForCameraPos(scene.size, rotatedCenter, dimBoundZero, A3D.vec3Zero, view, 1); + const unitRot = A3D.vec3RotCombine(rotationForCameraPos(view), scene.rotation_deprecated ?? A3D.vec3Zero); + const rotatedCenter = A3D.vec3Rot( + scene.center_deprecated ?? A3D.vec3Zero, + A3D.vec3Zero, + scene.rotation_deprecated ?? A3D.vec3Zero + ); + const [size, center] = sizeCenterForCameraPos( + scene.size_deprecated, + rotatedCenter, + dimBoundZero, + A3D.vec3Zero, + view, + 1 + ); return dxfHeader(size, center) + scene.groups.reduce((a, c) => a + dxfGroup(c, center, unitRot), "") + dxfFooter; }; diff --git a/packages/abstract-3d/src/renderers/react/react-camera.tsx b/packages/abstract-3d/src/renderers/react/react-camera.tsx index 6ec7842c..2c232c64 100644 --- a/packages/abstract-3d/src/renderers/react/react-camera.tsx +++ b/packages/abstract-3d/src/renderers/react/react-camera.tsx @@ -75,17 +75,41 @@ export function ReactCamera({ const [posX, posY, posZ, size, sceneAspect] = (() => { switch (view) { case "front": - return [0, 0, 1, scene.size, scene.size.x / scene.size.y]; + return [0, 0, 1, scene.size_deprecated, scene.size_deprecated.x / scene.size_deprecated.y]; case "back": - return [0, 0, -1, scene.size, scene.size.x / scene.size.y]; + return [0, 0, -1, scene.size_deprecated, scene.size_deprecated.x / scene.size_deprecated.y]; case "top": - return [0, 1, 0, vec3(scene.size.x, scene.size.z, scene.size.y), scene.size.x / scene.size.z]; + return [ + 0, + 1, + 0, + vec3(scene.size_deprecated.x, scene.size_deprecated.z, scene.size_deprecated.y), + scene.size_deprecated.x / scene.size_deprecated.z, + ]; case "bottom": - return [0, -1, 0, vec3(scene.size.x, scene.size.z, scene.size.y), scene.size.x / scene.size.z]; + return [ + 0, + -1, + 0, + vec3(scene.size_deprecated.x, scene.size_deprecated.z, scene.size_deprecated.y), + scene.size_deprecated.x / scene.size_deprecated.z, + ]; case "right": - return [1, 0, 0, vec3(scene.size.z, scene.size.y, scene.size.x), scene.size.z / scene.size.y]; + return [ + 1, + 0, + 0, + vec3(scene.size_deprecated.z, scene.size_deprecated.y, scene.size_deprecated.x), + scene.size_deprecated.z / scene.size_deprecated.y, + ]; case "left": - return [-1, 0, 0, vec3(scene.size.z, scene.size.y, scene.size.x), scene.size.z / scene.size.y]; + return [ + -1, + 0, + 0, + vec3(scene.size_deprecated.z, scene.size_deprecated.y, scene.size_deprecated.x), + scene.size_deprecated.z / scene.size_deprecated.y, + ]; default: return exhaustiveCheck(view); } diff --git a/packages/abstract-3d/src/renderers/react/react-scene.tsx b/packages/abstract-3d/src/renderers/react/react-scene.tsx index 5000e85a..5ac0f9ba 100644 --- a/packages/abstract-3d/src/renderers/react/react-scene.tsx +++ b/packages/abstract-3d/src/renderers/react/react-scene.tsx @@ -90,8 +90,16 @@ export function ReactScene({ const [hoveredId, setHoveredId] = React.useState(undefined); return ( {scene.groups.map((g, i) => { const id = createGroupId ? createGroupId(g) : ""; @@ -115,16 +123,26 @@ export function ReactScene({ ); })} - - + + diff --git a/packages/abstract-3d/src/renderers/stl/stl.ts b/packages/abstract-3d/src/renderers/stl/stl.ts index b5f9bc26..bd8a20c1 100644 --- a/packages/abstract-3d/src/renderers/stl/stl.ts +++ b/packages/abstract-3d/src/renderers/stl/stl.ts @@ -7,7 +7,11 @@ import { stlPolygon } from "./stl-geometries/stl-polygon"; export const toStl = (scene: A3D.Scene): string => `solid -` + scene.groups.reduce((a, c) => a + stlGroup(c, scene.center, scene.rotation ?? A3D.vec3Zero), ""); +` + + scene.groups.reduce( + (a, c) => a + stlGroup(c, scene.center_deprecated ?? A3D.vec3Zero, scene.rotation_deprecated ?? A3D.vec3Zero), + "" + ); function stlGroup(g: A3D.Group, parentPos: A3D.Vec3, parentRot: A3D.Vec3): string { const pos = A3D.vec3TransRot(g.pos, parentPos, parentRot); diff --git a/packages/abstract-3d/src/renderers/svg/svg.ts b/packages/abstract-3d/src/renderers/svg/svg.ts index b45f2b85..7e0b63d1 100644 --- a/packages/abstract-3d/src/renderers/svg/svg.ts +++ b/packages/abstract-3d/src/renderers/svg/svg.ts @@ -41,15 +41,22 @@ export function toSvg( ? scale.size / (scale.scaleByWidth ? view === "right" || view === "left" - ? scene.size.z - : scene.size.x + ? scene.size_deprecated.z + : scene.size_deprecated.x : view === "top" || view === "bottom" - ? scene.size.z - : scene.size.y) + ? scene.size_deprecated.z + : scene.size_deprecated.y) : 1; - const unitRot = vec3RotCombine(rotationForCameraPos(view), scene.rotation ?? vec3Zero); - const unitPos = vec3Rot(scene.center, vec3Zero, scene.rotation ?? vec3Zero); - const [size, center] = sizeCenterForCameraPos(scene.size, unitPos, scene.dimensions?.bounds, unitRot, view, factor); + const unitRot = vec3RotCombine(rotationForCameraPos(view), scene.rotation_deprecated ?? vec3Zero); + const unitPos = vec3Rot(scene.center_deprecated ?? vec3Zero, vec3Zero, scene.rotation_deprecated ?? vec3Zero); + const [size, center] = sizeCenterForCameraPos( + scene.size_deprecated, + unitPos, + scene.dimensions_deprecated?.bounds, + unitRot, + view, + factor + ); const unitHalfSize = vec3Scale(size, 0.5); const centerAdj = vec3(center.x - stroke * 0.75, center.y + stroke * 0.75, center.z); const width = size.x + 1.5 * stroke; @@ -66,7 +73,7 @@ export function toSvg( } elements.sort((a, b) => a.zOrder - b.zOrder); - for (const d of scene.dimensions?.dimensions ?? []) { + for (const d of scene.dimensions_deprecated?.dimensions ?? []) { if (d.views[0] === view) { const pos = vec3Rot(d.pos, unitPos, unitRot); const rot = vec3RotCombine(unitRot, d.rot); @@ -79,7 +86,7 @@ export function toSvg( point, view, factor, - scene.dimensions?.material.normal ?? "", + scene.dimensions_deprecated?.material.normal ?? "", false, false, onlyStrokeFill, diff --git a/packages/abstract-visuals-example/src/app/abstract-3d-example.tsx b/packages/abstract-visuals-example/src/app/abstract-3d-example.tsx index 18f05e62..9a1bae71 100644 --- a/packages/abstract-visuals-example/src/app/abstract-3d-example.tsx +++ b/packages/abstract-visuals-example/src/app/abstract-3d-example.tsx @@ -33,8 +33,8 @@ export function Abstract3DExample(): React.ReactNode { } const scene: A3D.Scene = { - center: A3D.vec3Zero, - size: A3D.vec3(40, 40, 40), + center_deprecated: A3D.vec3Zero, + size_deprecated: A3D.vec3(40, 40, 40), groups: [ { pos: A3D.vec3Zero,