Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinatzo committed Jun 4, 2024
1 parent fc7c109 commit eebde4b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/abstract-3d/src/renderers/dxf/dxf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { dxfPolygon } from "./dxf-geometries/dxf-polygon.js";
import { dimBoundZero, rotationForCameraPos, sizeCenterForCameraPos } from "../shared.js";

export const toDxf = (scene: A3D.Scene, view: A3D.View): string => {
const unitRot = A3D.vec3RotCombine(rotationForCameraPos(view), scene.rotation);
const rotatedCenter = A3D.vec3Rot(scene.center, A3D.vec3Zero, scene.rotation);
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);
return dxfHeader(size, center) + scene.groups.reduce((a, c) => a + dxfGroup(c, center, unitRot), "") + dxfFooter;
};
Expand Down
9 changes: 6 additions & 3 deletions packages/abstract-3d/src/renderers/react/react-dimension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ export const ReactDimensions = React.memo(
dimensions,
showDimensions,
}: {
readonly dimensions: A3d.Dimensions;
readonly dimensions: A3d.Dimensions | undefined;
readonly showDimensions: boolean;
}): JSX.Element => {
const dimensionMaterial = React.useMemo(() => <ReactMaterial material={dimensions.material} />, []);
const dimensionMaterial = React.useMemo(
() => (dimensions?.material ? <ReactMaterial material={dimensions?.material} /> : <></>),
[]
);
return (
<>
{dimensions.dimensions.map((dimension, i) => (
{dimensions?.dimensions.map((dimension, i) => (
<ReactDimension key={i} d={dimension} visible={showDimensions}>
{dimensionMaterial}
</ReactDimension>
Expand Down
4 changes: 2 additions & 2 deletions packages/abstract-3d/src/renderers/react/react-hotspot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const ReactHotSpots = React.memo(
onClickHotSpot,
setHoveredId,
}: {
readonly hotSpots: ReadonlyArray<A3d.HotSpot>;
readonly hotSpots?: ReadonlyArray<A3d.HotSpot>;
readonly showHotSpotTexts: boolean;
readonly hotSpotZAdjPos: number;
readonly hotSpotTexts?: Record<string, string>;
Expand All @@ -35,7 +35,7 @@ export const ReactHotSpots = React.memo(
}): JSX.Element => {
return (
<>
{hotSpots.map((h) => (
{hotSpots?.map((h) => (
<ReactHotSpot
key={h.id}
h={h}
Expand Down
4 changes: 2 additions & 2 deletions packages/abstract-3d/src/renderers/react/react-scene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function ReactScene({
const [hoveredId, setHoveredId] = React.useState<string | undefined>(undefined);
return (
<group
rotation={[scene.rotation.x, scene.rotation.y, scene.rotation.z]}
rotation={[scene.rotation?.x ?? 0, scene.rotation?.y ?? 0, scene.rotation?.z ?? 0]}
position={[-scene.center.x, -scene.center.y, -scene.center.z]}
>
{scene.groups.map((g, i) => {
Expand All @@ -110,7 +110,7 @@ export function ReactScene({
);
})}
<group
rotation={[-scene.rotation.x, -scene.rotation.y, -scene.rotation.z]}
rotation={[-scene.rotation?.x ?? 0, -scene.rotation?.y ?? 0, -scene.rotation?.z ?? 0]}
position={[-scene.center.x, -scene.center.y, -scene.center.z]}
>
<group position={[scene.center.x, scene.center.y, scene.center.z]}>
Expand Down
2 changes: 1 addition & 1 deletion packages/abstract-3d/src/renderers/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
export function sizeCenterForCameraPos(
size: Vec3,
center: Vec3,
_dimBound: DimensionBounds,
_dimBound: DimensionBounds | undefined,
rotation: Vec3,
_view: View,
factor: number
Expand Down
2 changes: 1 addition & 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,7 @@ import { stlPolygon } from "./stl-geometries/stl-polygon.js";

export const toStl = (scene: A3D.Scene): string =>
`solid
` + scene.groups.reduce((a, c) => a + stlGroup(c, scene.center, scene.rotation), "");
` + scene.groups.reduce((a, c) => a + stlGroup(c, scene.center, scene.rotation ?? A3D.vec3Zero), "");

function stlGroup(g: A3D.Group, parentPos: A3D.Vec3, parentRot: A3D.Vec3): string {
const pos = A3D.vec3TransRot(g.pos, parentPos, parentRot);
Expand Down
8 changes: 4 additions & 4 deletions packages/abstract-3d/src/renderers/svg/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export function toSvg(
? scene.size.z
: scene.size.y)
: 1;
const unitRot = vec3RotCombine(rotationForCameraPos(view), scene.rotation);
const unitPos = vec3Rot(scene.center, vec3Zero, scene.rotation);
const [size, center] = sizeCenterForCameraPos(scene.size, unitPos, scene.dimensions.bounds, unitRot, view, factor);
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 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 Down Expand Up @@ -79,7 +79,7 @@ export function toSvg(
point,
view,
factor,
scene.dimensions.material.normal,
scene.dimensions?.material.normal ?? "",
false,
false,
onlyStrokeFill,
Expand Down
7 changes: 6 additions & 1 deletion packages/abstract-visuals-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"rootDir": "src",
"lib": ["dom", "es2022"]
},
"references": [{ "path": "../abstract-image" }, { "path": "../abstract-chart" }, { "path": "../abstract-document" }]
"references": [
{ "path": "../abstract-image" },
{ "path": "../abstract-chart" },
{ "path": "../abstract-document" },
{ "path": "../abstract-3d" }
]
}

0 comments on commit eebde4b

Please sign in to comment.