feat(tabletop): author rotation and tilt angles in degrees
Convert bgm rotation and tilt values to radians only at the three.js boundary, so the format's angles are authored in degrees.
This commit is contained in:
@@ -9,7 +9,7 @@ import type { Package } from '@tts/bgm';
|
||||
import { useStacking } from './stacking.js';
|
||||
import type { Placement } from './state.js';
|
||||
import { PartView } from './partView.js';
|
||||
import { MM_TO_WORLD } from './part.js';
|
||||
import { MM_TO_WORLD, DEG_TO_RAD } from './part.js';
|
||||
|
||||
export function PartPlacement({ pkg, placement }: { pkg: Package; placement: Placement }) {
|
||||
const { route, candidate, piece, index, stackSize } = placement;
|
||||
@@ -22,15 +22,16 @@ export function PartPlacement({ pkg, placement }: { pkg: Package; placement: Pla
|
||||
// Route anchors and stacking offsets are in mm; convert to world units so
|
||||
// parts land on the (world-scaled) surface. `z` raises the part along the
|
||||
// surface normal (world +Y); `tilt` fans it about its local Y (long) axis.
|
||||
// Angles are authored in degrees; three.js expects radians.
|
||||
const anchorX = ((candidate?.x ?? route.x ?? 0) + x) * MM_TO_WORLD;
|
||||
const anchorY = ((candidate?.y ?? route.y ?? 0) + y) * MM_TO_WORLD;
|
||||
const anchorZ = z * MM_TO_WORLD;
|
||||
const anchorRotation = (candidate?.rotation ?? route.rotation ?? 0) + rotation;
|
||||
const anchorRotation = ((candidate?.rotation ?? route.rotation ?? 0) + rotation) * DEG_TO_RAD;
|
||||
|
||||
return (
|
||||
<group position={[anchorX, anchorZ, anchorY]} rotation={[0, anchorRotation, 0]}>
|
||||
{/* The part mesh extrudes along +Z; lay it flat so its face points up. */}
|
||||
<group rotation={[-Math.PI / 2, 0, tilt]}>
|
||||
<group rotation={[-Math.PI / 2, 0, tilt * DEG_TO_RAD]}>
|
||||
<PartView part={part} baseUrl={part.baseUrl} />
|
||||
</group>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user