From 6c60b173f7ccbecf23bca6262c42b473d7d83102 Mon Sep 17 00:00:00 2001 From: John Rees Date: Sun, 17 May 2020 12:23:29 +0100 Subject: [PATCH] start using outline on hangar --- src/building/NewBuilding.tsx | 64 +++++++++++++++++++++++++++++++---- src/building/crossSections.ts | 22 ++++++------ src/hangar/shared.ts | 2 +- src/shared/materials.ts | 8 ++--- 4 files changed, 74 insertions(+), 22 deletions(-) diff --git a/src/building/NewBuilding.tsx b/src/building/NewBuilding.tsx index 1c4e16b..8cb569d 100644 --- a/src/building/NewBuilding.tsx +++ b/src/building/NewBuilding.tsx @@ -1,8 +1,12 @@ -import { identity, times } from "ramda"; -import React from "react"; +import { flatten, identity, times } from "ramda"; +import React, { useMemo } from "react"; import { + BufferAttribute, + BufferGeometry, DoubleSide, + LineBasicMaterial, LineDashedMaterial, + LinePieces, LineSegments, MeshStandardMaterial, } from "three"; @@ -32,16 +36,61 @@ const linesMaterial = new LineDashedMaterial({ clipShadows: true, }); +const hangarLineMaterial = new LineBasicMaterial({ + color: "#53ADF9", + linewidth: 2, +}); + const Module: React.FC = ({ type, position, end = false }) => { const { geometry, edgesGeometry, endEdgesGeometry, endGeometry, + width: widthMM, + height: heightMM, } = crossSections[type]; + const geo = useMemo(() => { + const width = widthMM / 1000; + const height = heightMM / 1000; + const vertices = []; + vertices.push([0, 0, 0]); + vertices.push([0, height, 0]); + vertices.push([0, 0, 1.2]); + vertices.push([0, height, 1.2]); + + vertices.push([width, 0, 0]); + vertices.push([width, height, 0]); + vertices.push([width, 0, 1.2]); + vertices.push([width, height, 1.2]); + + vertices.push([0, height, 0]); + vertices.push([width, height, 0]); + + vertices.push([0, height, 1.2]); + vertices.push([width, height, 1.2]); + + vertices.push([0, height, 0]); + vertices.push([0, height, 1.2]); + + vertices.push([width, height, 0]); + vertices.push([width, height, 1.2]); + + const g = new BufferGeometry(); + g.setAttribute( + "position", + new BufferAttribute(new Float32Array(flatten(vertices)), 3) + ); + return g; + }, [geometry]); + return ( + dashed && e?.computeLineDistances()} + /> = React.memo(({ hangar }) => { // }); return ( + // k.startsWith(type) && (k.startsWith(type) || k.startsWith("D1") || k.startsWith("E1")) && - v.width === Math.round(wx * 1000) + v.clipWidth === Math.round(wx * 1000) ); }) .map(([k]) => k); @@ -92,12 +142,12 @@ const NewBuilding: React.FC<{ hangar: Hangar }> = React.memo(({ hangar }) => { {times(identity, rows).map((_r) => { return ( <> - + /> */} {times(identity, cols).map((_z) => { count += 1; return ( @@ -108,12 +158,12 @@ const NewBuilding: React.FC<{ hangar: Hangar }> = React.memo(({ hangar }) => { /> ); })} - + /> */} ); })} diff --git a/src/building/crossSections.ts b/src/building/crossSections.ts index 1c3e7ca..9920b28 100644 --- a/src/building/crossSections.ts +++ b/src/building/crossSections.ts @@ -76,18 +76,22 @@ const crossSections = Object.entries(variants).reduce( for (let i = 1; i <= numVariants; i++) { let shape = shapes[type[0]]; - let h = 9000; - if (type.startsWith("D")) h = 4600; - else if (type.startsWith("E")) h = 3600; + const { minX, maxX, minY, maxY } = bounds(shape); + + let width = Math.abs(maxX - minX); + let height = Math.abs(maxY - minY); + + if (type.startsWith("D")) height = 4600; + else if (type.startsWith("E")) height = 3600; const box: Point[] = [ [boxCoords[i][0], 0], - [boxCoords[i][0], h], - [boxCoords[i][1], h], + [boxCoords[i][0], height], + [boxCoords[i][1], height], [boxCoords[i][1], 0], ]; - if (h === 9000) shape = intersection([shape], [box])[0]; + if (height > 8000) shape = intersection([shape], [box])[0]; const holes = offset(-FRAME_WIDTH)([shape]); @@ -96,10 +100,6 @@ const crossSections = Object.entries(variants).reduce( [box] ); - const { minX, maxX, minY, maxY } = bounds(shape); - const width = Math.abs(maxX - minX); - const height = Math.abs(maxY - minY); - const [gOutline, ...gHoles] = points.map((pts) => pts.map(([x, y]) => [x / 1000, y / 1000]) ); @@ -107,6 +107,8 @@ const crossSections = Object.entries(variants).reduce( const gShape = pointsToThreeShape(gOutline, gHoles); const position = [-width / 2000, 0, -grid("m").z / 2]; + width = boxCoords[i][1] - boxCoords[i][0]; + const geometry = new ExtrudeBufferGeometry(gShape, extrudeSettings); const edgesGeometry = new EdgesGeometry(geometry); diff --git a/src/hangar/shared.ts b/src/hangar/shared.ts index a9ed872..e9e39e3 100644 --- a/src/hangar/shared.ts +++ b/src/hangar/shared.ts @@ -3,7 +3,7 @@ import grid from "../shared/grid"; export const { x: gridX, z: gridZ } = grid("m"); -export const gridY = 2.5; +export const gridY = 8.7; // Pre-calculate the rotation Eulers for box faces diff --git a/src/shared/materials.ts b/src/shared/materials.ts index 909f754..cc50968 100644 --- a/src/shared/materials.ts +++ b/src/shared/materials.ts @@ -8,15 +8,15 @@ export const wallGhostMaterial = new MeshPhongMaterial({ }); export const wallMaterial = new MeshPhongMaterial({ - color: "#666", - opacity: 0.8, + color: "#53ADF9", + opacity: 0.03, transparent: true, side: DoubleSide, }); export const wallMaterialHover = new MeshPhongMaterial({ - color: "#F2BB05", - opacity: 0.8, + color: "#53ADF9", + opacity: 0.6, transparent: true, side: DoubleSide, });