Skip to content

Commit

Permalink
file renames
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinatzo committed Jun 5, 2024
1 parent d3bab95 commit f79c813
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 40 deletions.
13 changes: 8 additions & 5 deletions packages/abstract-3d/src/abstract-3d.ts
Original file line number Diff line number Diff line change
@@ -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<Group>;
readonly rotation?: Vec3;
readonly dimensions?: Dimensions;
readonly hotSpots?: ReadonlyArray<HotSpot>;
readonly data?: Record<string, string>;
// should be removed
readonly center_deprecated?: Vec3;
readonly rotation_deprecated?: Vec3;
// might be removed
readonly dimensions_deprecated?: Dimensions;
readonly hotSpots_deprecated?: ReadonlyArray<HotSpot>;
};

export type Renderer = "react" | "ai_schematic" | "ai_detailed" | "dxf";
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 14 additions & 3 deletions packages/abstract-3d/src/renderers/dxf/dxf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
36 changes: 30 additions & 6 deletions packages/abstract-3d/src/renderers/react/react-camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
34 changes: 26 additions & 8 deletions packages/abstract-3d/src/renderers/react/react-scene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,16 @@ export function ReactScene({
const [hoveredId, setHoveredId] = React.useState<string | undefined>(undefined);
return (
<group
rotation={[scene.rotation?.x ?? 0, scene.rotation?.y ?? 0, scene.rotation?.z ?? 0]}
position={[-scene.center.x, -scene.center.y, -scene.center.z]}
rotation={[
scene.rotation_deprecated?.x ?? 0,
scene.rotation_deprecated?.y ?? 0,
scene.rotation_deprecated?.z ?? 0,
]}
position={[
-(scene.center_deprecated?.x ?? 0),
-(scene.center_deprecated?.y ?? 0),
-(scene.center_deprecated?.z ?? 0),
]}
>
{scene.groups.map((g, i) => {
const id = createGroupId ? createGroupId(g) : "";
Expand All @@ -115,16 +123,26 @@ export function ReactScene({
);
})}
<group
rotation={[-(scene.rotation?.x ?? 0), -(scene.rotation?.y ?? 0), -(scene.rotation?.z ?? 0)]}
position={[-scene.center.x, -scene.center.y, -scene.center.z]}
rotation={[
-(scene.rotation_deprecated?.x ?? 0),
-(scene.rotation_deprecated?.y ?? 0),
-(scene.rotation_deprecated?.z ?? 0),
]}
position={[
-(scene.center_deprecated?.x ?? 0),
-(scene.center_deprecated?.y ?? 0),
-(scene.center_deprecated?.z ?? 0),
]}
>
<group position={[scene.center.x, scene.center.y, scene.center.z]}>
<ReactDimensions dimensions={scene.dimensions} showDimensions={showDimensions} />
<group
position={[scene.center_deprecated?.x ?? 0, scene.center_deprecated?.y ?? 0, scene.center_deprecated?.z ?? 0]}
>
<ReactDimensions dimensions={scene.dimensions_deprecated} showDimensions={showDimensions} />
</group>
</group>
<ReactHotSpots
hotSpots={scene.hotSpots}
hotSpotZAdjPos={scene.size.z / 2}
hotSpots={scene.hotSpots_deprecated}
hotSpotZAdjPos={scene.size_deprecated.z / 2}
activeHotSpots={activeHotSpots}
hotSpotTexts={hotSpotTexts}
hoveredId={hoveredId}
Expand Down
12 changes: 6 additions & 6 deletions packages/abstract-3d/src/renderers/react/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ export const toReact = memo(
<ambientLight intensity={0.7} />
<directionalLight
position={[
-scene.center.x + 0.7 * scene.size.x,
-scene.center.y + 1.4 * scene.size.y,
-scene.center.z + 3 * scene.size.z,
-(scene.center_deprecated?.x ?? 0) + 0.7 * scene.size_deprecated.x,
-(scene.center_deprecated?.y ?? 0) + 1.4 * scene.size_deprecated.y,
-(scene.center_deprecated?.z ?? 0) + 3 * scene.size_deprecated.z,
]}
intensity={3.3}
/>
<directionalLight
position={[
-scene.center.x - 0.7 * scene.size.x,
-scene.center.y - 1.1 * scene.size.y,
-scene.center.z - 3 * scene.size.z,
-(scene.center_deprecated?.x ?? 0) - 0.7 * scene.size_deprecated.x,
-(scene.center_deprecated?.y ?? 0) - 1.1 * scene.size_deprecated.y,
-(scene.center_deprecated?.z ?? 0) - 3 * scene.size_deprecated.z,
]}
intensity={3.3}
/>
Expand Down
6 changes: 5 additions & 1 deletion packages/abstract-3d/src/renderers/stl/stl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 16 additions & 9 deletions packages/abstract-3d/src/renderers/svg/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -79,7 +86,7 @@ export function toSvg(
point,
view,
factor,
scene.dimensions?.material.normal ?? "",
scene.dimensions_deprecated?.material.normal ?? "",
false,
false,
onlyStrokeFill,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f79c813

Please sign in to comment.