Skip to content

Commit

Permalink
added wall end caps
Browse files Browse the repository at this point in the history
  • Loading branch information
Steedie committed Oct 22, 2024
1 parent 5565c53 commit 423c40f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions src/CalcWallModels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useGLTF } from "@react-three/drei";
import wall_mediumGLTF from "./assets/walls/wall_medium2.glb?url";
import wall_largeGLTF from "./assets/walls/wall_large2.glb?url";
import wall_cornerMediumGLTF from "./assets/walls/wall_cornerMedium2.glb?url";
import wall_endCapGLTF from "./assets/walls/wall_endCap2.glb?url";

interface CalcWallModelsProps {
lines: THREE.Vector3[][];
Expand All @@ -19,6 +20,7 @@ const CalcWallModels: React.FC<CalcWallModelsProps> = ({
const { scene: wallMedium } = useGLTF(wall_mediumGLTF);
const { scene: wallLarge } = useGLTF(wall_largeGLTF);
const { scene: wallCornerMedium } = useGLTF(wall_cornerMediumGLTF);
const { scene: wallEndCap } = useGLTF(wall_endCapGLTF);
const groupRef = useRef<THREE.Group>(null);
let models: { name: string; position: THREE.Vector3; rotation: number }[] =
[];
Expand All @@ -37,6 +39,48 @@ const CalcWallModels: React.FC<CalcWallModelsProps> = ({
models = [];

lines.forEach((line) => {
if (line.length < 2) return;

const start = new THREE.Vector3(...line[0]);
const end = new THREE.Vector3(...line[line.length - 1]);

// Determine if the start end cap is on a diagonal wall
const isStartDiagonal =
Math.abs(line[1].x - line[0].x) === Math.abs(line[1].y - line[0].y);

// Place end cap at the start
const startRotation = Math.atan2(
line[1].y - line[0].y,
line[1].x - line[0].x
);

placeWall(
wallEndCap,
start,
startRotation,
"wallEndCap",
Math.PI / (isStartDiagonal ? 1.33333 : 2)
);

// Determine if the end end cap is on a diagonal wall
const isEndDiagonal =
Math.abs(line[line.length - 1].x - line[line.length - 2].x) ===
Math.abs(line[line.length - 1].y - line[line.length - 2].y);

// Place end cap at the end
const endRotation = Math.atan2(
line[line.length - 1].y - line[line.length - 2].y,
line[line.length - 1].x - line[line.length - 2].x
);

placeWall(
wallEndCap,
end,
endRotation + Math.PI,
"wallEndCap",
Math.PI / (isEndDiagonal ? 4 : 2)
);

for (let i = 0; i < line.length - 1; i++) {
const start = new THREE.Vector3(...line[i]);
const end = new THREE.Vector3(...line[i + 1]);
Expand Down Expand Up @@ -102,16 +146,21 @@ const CalcWallModels: React.FC<CalcWallModelsProps> = ({
wall: THREE.Object3D,
position: THREE.Vector3,
rotation: number,
name: string
name: string,
rotationOffset: number = 0
) => {
const wallClone = wall.clone();
wallClone.position.copy(position);
wallClone.rotation.z = rotation;
wallClone.rotation.z = rotation + rotationOffset;
wallClone.scale.set(10, 10, 10); // 10x scale
if (groupRef.current) {
groupRef.current.add(wallClone);
}
models.push({ name, position: position.clone(), rotation });
models.push({
name,
position: position.clone(),
rotation: rotation + rotationOffset,
});
};

return <group ref={groupRef} />;
Expand Down
Binary file added src/assets/walls/wall_endCap2.glb
Binary file not shown.

0 comments on commit 423c40f

Please sign in to comment.