@mark1russell7/room-view 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/build/anchors-BEnxNnSV.d.ts +75 -0
- package/build/anchors-BEnxNnSV.d.ts.map +1 -0
- package/build/frames-BYMK5ZId.d.ts +39 -0
- package/build/frames-BYMK5ZId.d.ts.map +1 -0
- package/build/index.d.ts +7 -211
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -613
- package/build/index.js.map +1 -1
- package/build/joins-2p01wnr_.d.ts +39 -0
- package/build/joins-2p01wnr_.d.ts.map +1 -0
- package/build/layers-CKx0dcM0.d.ts +143 -0
- package/build/layers-CKx0dcM0.d.ts.map +1 -0
- package/build/layers-bgJ3OTId.js +630 -0
- package/build/layers-bgJ3OTId.js.map +1 -0
- package/build/{level-Cu8vgrwN.js → level-5Nb9rq5L.js} +3 -28
- package/build/level-5Nb9rq5L.js.map +1 -0
- package/build/{loads-C3Nrj3Gd.d.ts → loads-CriZuwcu.d.ts} +4 -73
- package/build/loads-CriZuwcu.d.ts.map +1 -0
- package/build/loads-CtHa4EHo.js +103 -0
- package/build/loads-CtHa4EHo.js.map +1 -0
- package/build/marks.d.ts +29 -0
- package/build/marks.d.ts.map +1 -0
- package/build/marks.js +34 -0
- package/build/marks.js.map +1 -0
- package/build/room-DrXMmX_h.js +29 -0
- package/build/room-DrXMmX_h.js.map +1 -0
- package/build/schema.d.ts +6 -0
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +37 -2
- package/build/schema.js.map +1 -1
- package/build/{loads-Br73kIsQ.js → solids-BKb-izIP.js} +2 -102
- package/build/solids-BKb-izIP.js.map +1 -0
- package/build/three.d.ts +1 -1
- package/build/three.js +2 -1
- package/build/three.js.map +1 -1
- package/package.json +7 -1
- package/build/level-Cu8vgrwN.js.map +0 -1
- package/build/loads-Br73kIsQ.js.map +0 -1
- package/build/loads-C3Nrj3Gd.d.ts.map +0 -1
package/build/three.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"three.js","names":["World"],"sources":["../src/viewer/geometry.ts","../src/viewer/theme.ts","../src/viewer/fade.ts","../src/viewer/markers.ts","../src/viewer/view.ts","../src/viewer/model.ts","../src/viewer/viewer.ts"],"sourcesContent":["import { transformPoint3, type Point3, type Rotation3 } from \"@mark1russell7/layout-contract\";\nimport { BoxGeometry, ExtrudeGeometry, Shape, Vector2, type BufferGeometry } from \"three\";\nimport type { Solid } from \"../solids.ts\";\n\n/**\n * The three.js geometry of a solid, and its place in the room.\n * The origin of the geometry is the center of the solid. Thus three.js puts clear solids in the correct sequence.\n */\nexport interface SolidPlacement {\n /** The geometry, in meters, around its own origin. The caller disposes it. */\n readonly geometry: BufferGeometry;\n /** The position of the origin of the geometry in the room, where the z axis points up. */\n readonly position: Point3;\n /** The rotation of the geometry in the room. */\n readonly rotation: Rotation3;\n}\n\n/** The rotation that changes no direction. */\nconst NO_ROTATION: Rotation3 = { x: 0, y: 0, z: 0, w: 1 };\n\n/**\n * This function gives the three.js geometry of a solid, with its place in the room.\n *\n * A mesh with this geometry, this position and this rotation is in the space of the room: the z axis points up.\n * Put the mesh in a group with the rotation of `TO_Y_UP`. Then three.js shows it with the y axis up.\n */\nexport function solidGeometry(solid: Solid): SolidPlacement {\n const shape = solid.shape;\n if (shape.kind === \"box\") {\n const { box, transform } = shape;\n const center = { x: box.x + box.w / 2, y: box.y + box.h / 2, z: box.z + box.d / 2 };\n return { geometry: new BoxGeometry(box.w, box.h, box.d), position: transformPoint3(transform, center), rotation: transform.rotation };\n }\n let minX = Infinity;\n let maxX = -Infinity;\n let minY = Infinity;\n let maxY = -Infinity;\n for (const [x, y] of shape.ring) {\n minX = Math.min(minX, x);\n maxX = Math.max(maxX, x);\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n }\n const centerX = (minX + maxX) / 2;\n const centerY = (minY + maxY) / 2;\n const outline = new Shape(shape.ring.map(([x, y]) => new Vector2(x - centerX, y - centerY)));\n const geometry = new ExtrudeGeometry(outline, { depth: shape.d, bevelEnabled: false, steps: 1, curveSegments: 1 });\n geometry.translate(0, 0, 0 - shape.d / 2);\n return { geometry, position: { x: centerX, y: centerY, z: shape.z + shape.d / 2 }, rotation: NO_ROTATION };\n}\n","import type { LoadLevel } from \"../loads.ts\";\n\n/**\n * The colors of a viewer. Each color is a CSS hex color, for example `#22364a`.\n * The viewer has no background: the page shows behind the model.\n */\nexport interface ViewerTheme {\n /** The color of the edges of each solid. */\n readonly edge: string;\n /** The color that marks the solids under the pointer and the selected solids. */\n readonly accent: string;\n readonly floor: string;\n readonly wall: string;\n readonly glass: string;\n /** The part of the glass that is not clear, from 0 to 1. */\n readonly glassOpacity: number;\n /** The color of an outlet with no circuit. */\n readonly outlet: string;\n /** The color of the outlets of a circuit at each level of its load. */\n readonly levels: Readonly<Record<LoadLevel, string>>;\n /** The color of the line around the marker of an outlet. It is the color of the page, so a marker is clear on each solid. */\n readonly halo: string;\n /** The color of a placed object whose kind has no color in `objects`. */\n readonly object: string;\n /** The color of the placed objects of each kind. The key is the field `kind` of a placed object. */\n readonly objects: Readonly<Record<string, string>>;\n /** The color of the light from above. */\n readonly sky: string;\n /** The color of the light from below. */\n readonly ground: string;\n}\n\n/** The colors of a model of white card with ink edges, for a light page. */\nexport const LIGHT_THEME: ViewerTheme = {\n edge: \"#22364a\",\n accent: \"#f2b705\",\n floor: \"#dfe5ea\",\n wall: \"#fcfcfb\",\n glass: \"#8fc4e8\",\n glassOpacity: 0.35,\n outlet: \"#55677a\",\n levels: { unknown: \"#55677a\", ok: \"#1f5fa8\", near: \"#d9662f\", over: \"#c62f2f\" },\n halo: \"#ffffff\",\n object: \"#b8c0c8\",\n objects: { desk: \"#c9b596\", sofa: \"#8fa3b5\", rack: \"#3d4954\", computer: \"#5b6d7e\", display: \"#2c3640\" },\n sky: \"#ffffff\",\n ground: \"#b9c3cd\",\n};\n\n/** The colors of a blueprint, for a dark page. */\nexport const DARK_THEME: ViewerTheme = {\n edge: \"#cfe6ff\",\n accent: \"#ffd24a\",\n floor: \"#17395a\",\n wall: \"#1f4a73\",\n glass: \"#9fd0ff\",\n glassOpacity: 0.25,\n outlet: \"#a9bfd4\",\n levels: { unknown: \"#a9bfd4\", ok: \"#6fb3f2\", near: \"#f5a962\", over: \"#f0625f\" },\n halo: \"#0e2740\",\n object: \"#2a5580\",\n objects: { desk: \"#2a5a8a\", sofa: \"#28527c\", rack: \"#16324e\", computer: \"#3a74ad\", display: \"#122a42\" },\n sky: \"#ffffff\",\n ground: \"#7f9bb8\",\n};\n","import { pointInRing, type Point, type Point3, type Ring } from \"@mark1russell7/layout-contract\";\nimport { wallFrames, wallHasOutline, wallPoint, type WallFrame } from \"../frames.ts\";\nimport type { Room } from \"../room.ts\";\nimport { metersPer } from \"../units.ts\";\n\n/** The side of a wall that looks at the room. A wall between two parts of a room has the value `both`. */\nexport type InnerSide = \"left\" | \"right\" | \"both\";\n\n/** A wall, and the side of it that looks at the room. */\nexport interface WallShade {\n readonly frame: WallFrame;\n readonly inner: InnerSide;\n}\n\n/** The distance from a face of a wall to the points that find the floor, in meters. */\nconst PROBE = 0.05;\n\n/** A wall hides the room when it hides a strip of the floor that is deeper than this, in meters. */\nexport const HIDDEN_LIMIT = 0.3;\n\n/** This function gives the distance of a point of the plan across a wall. It is positive to the left of the line of the wall. */\nfunction across(frame: WallFrame, point: Point): number {\n return (point.x - frame.start.x) * frame.left.x + (point.y - frame.start.y) * frame.left.y;\n}\n\n/** This function tells if a floor is next to one face of a wall. `offset` is the distance across of points near that face. */\nfunction hasFloor(frame: WallFrame, offset: number, floors: readonly Ring[]): boolean {\n return [0.25, 0.5, 0.75].some((part) => {\n const point = wallPoint(frame, frame.length * part, offset);\n return floors.some((ring) => pointInRing(point.x, point.y, ring));\n });\n}\n\n/**\n * This function gives each wall that the model makes, with the side that looks at the room.\n *\n * A side looks at the room when a floor is next to it. For a wall with no floor on each side, the side is the side of `center`,\n * a point of the plan in meters. Without a center, such a wall has the value `both`.\n */\nexport function wallShades(room: Room, center?: Point): readonly WallShade[] {\n const scale = metersPer(room.unit);\n const floors = (room.floors ?? []).map((floor): Ring => floor.ring.map(([x, y]) => [x * scale, y * scale] as const));\n return wallFrames(room)\n .filter((frame) => wallHasOutline(frame))\n .map((frame): WallShade => {\n const left = hasFloor(frame, frame.leftOffset + PROBE, floors);\n const right = hasFloor(frame, frame.rightOffset - PROBE, floors);\n if (left !== right) return { frame, inner: left ? \"left\" : \"right\" };\n if (left || center === undefined) return { frame, inner: \"both\" };\n const side = across(frame, center);\n return { frame, inner: side > frame.leftOffset ? \"left\" : side < frame.rightOffset ? \"right\" : \"both\" };\n });\n}\n\n/**\n * This function gives the depth of the strip of the floor that a wall hides from a camera, in meters.\n *\n * `camera` is a point of the room in meters, with the z axis up. A camera above the wall, between its two faces, hides no strip.\n * A camera that is not above the top of the wall hides all of the floor behind the wall, and the depth is `Infinity`.\n */\nexport function hiddenDepth(frame: WallFrame, camera: Point3): number {\n const side = across(frame, camera);\n const gap = side > frame.leftOffset ? side - frame.leftOffset : side < frame.rightOffset ? frame.rightOffset - side : 0;\n if (!(gap > 0)) return 0;\n return camera.z > frame.height ? (frame.height * gap) / (camera.z - frame.height) : Infinity;\n}\n\n/**\n * This function gives the `id` of each wall that hides the room from a camera. A viewer makes these walls almost clear.\n *\n * A wall with one side to the room hides the room when the camera is on its other side.\n * A wall between two parts of a room hides the part behind it from each side.\n * `limit` is the depth of the hidden strip of the floor, in meters, above which a wall hides the room.\n */\nexport function hidingWalls(shades: readonly WallShade[], camera: Point3, limit: number = HIDDEN_LIMIT): ReadonlySet<string> {\n const hiding = new Set<string>();\n for (const { frame, inner } of shades) {\n const side = across(frame, camera);\n const cameraSide = side > frame.leftOffset ? \"left\" : side < frame.rightOffset ? \"right\" : undefined;\n if (cameraSide === undefined || cameraSide === inner) continue;\n if (hiddenDepth(frame, camera) > limit) hiding.add(frame.id);\n }\n return hiding;\n}\n","import type { Point3 } from \"@mark1russell7/layout-contract\";\nimport { CircleGeometry, Group, Mesh, MeshBasicMaterial, RingGeometry, type BufferGeometry } from \"three\";\nimport { LineMaterial } from \"three/addons/lines/LineMaterial.js\";\nimport { LineSegments2 } from \"three/addons/lines/LineSegments2.js\";\nimport { LineSegmentsGeometry } from \"three/addons/lines/LineSegmentsGeometry.js\";\nimport { levelShape, SHAPE_OUTLINES, type LevelShape, type LoadLevel } from \"../loads.ts\";\n\n/**\n * The marker of an outlet: a flat sign that looks at the camera and keeps its size in the picture.\n * The plate of an outlet is too small for a person to find it in a room, so each outlet has a marker.\n */\nexport interface OutletMarker {\n /** The group of the marker, at the center of the plate of the outlet, in the space of the viewer. */\n readonly root: Group;\n /** The line around the sign. The pointer selects the marker by this mesh, because it is the larger mesh. */\n readonly back: Mesh<BufferGeometry, MeshBasicMaterial>;\n /** The sign: its shape and its color tell the level of the circuit of the outlet. */\n readonly front: Mesh<BufferGeometry, MeshBasicMaterial>;\n readonly shape: LevelShape;\n /** The radius of the sign in the picture, in CSS pixels. The viewer changes it. */\n radius: number;\n /** This value is true while a solid is between the camera and the outlet. The viewer changes it. */\n hidden: boolean;\n}\n\n/** A link from an outlet to a placed object that takes its power from the outlet. */\nexport interface PowerLink {\n /** The name of the record of the outlet. */\n readonly outlet: string;\n /** The name of the record of the placed object. */\n readonly object: string;\n /** The level of the circuit of the outlet. */\n readonly level: LoadLevel | undefined;\n readonly line: LineSegments2;\n}\n\n/** The radius of the sign of a marker with no mark, in CSS pixels. */\nexport const MARKER_RADIUS = 7;\n\n/** The width of the line around a sign, as a part of the radius of the disc. */\nconst HALO_WIDTH = 0.36;\n\n/** The three.js objects of a marker and of a link are above the solids in the sequence of the drawing. */\nconst LINK_ORDER = 9;\nconst MARKER_ORDER = 10;\n\n/**\n * This function gives the factor between a sign and the line around it.\n * The line has the same width around each shape, so a shape with a small circle in it gets a larger factor.\n */\nexport function haloScale(shape: LevelShape): number {\n const { radius, sides } = SHAPE_OUTLINES[shape];\n return 1 + HALO_WIDTH / (radius * Math.cos(Math.PI / sides));\n}\n\n/** This function makes the geometry of the outline of a shape, in the plane of x and y, with its center at the origin. */\nfunction outlineGeometry(shape: LevelShape): BufferGeometry {\n const { radius, sides, start } = SHAPE_OUTLINES[shape];\n return new CircleGeometry(radius, sides, start);\n}\n\n/** This function makes the geometry of the sign of a shape. A sign with a hole is a ring, and each other sign is its outline. */\nfunction signGeometry(shape: LevelShape): BufferGeometry {\n const { radius, sides, start, hole } = SHAPE_OUTLINES[shape];\n return hole > 0 ? new RingGeometry(hole, radius, sides, 1, start) : outlineGeometry(shape);\n}\n\n/** This function makes a material that the solids do not hide. */\nfunction overlayMaterial(): MeshBasicMaterial {\n return new MeshBasicMaterial({ transparent: true, depthTest: false, depthWrite: false });\n}\n\n/**\n * This function makes the marker of an outlet at a point of the space of the viewer.\n * The marker has no colors until `paintPart` gives them, and the viewer gives it its size and its turn for each picture.\n */\nexport function makeMarker(at: Point3, level: LoadLevel | undefined): OutletMarker {\n const shape = levelShape(level);\n const root = new Group();\n root.position.set(at.x, at.y, at.z);\n const back = new Mesh(outlineGeometry(shape), overlayMaterial());\n back.scale.setScalar(haloScale(shape));\n const front = new Mesh(signGeometry(shape), overlayMaterial());\n // The line is before the sign in the group. Thus two objects at one distance draw in this sequence.\n back.renderOrder = MARKER_ORDER;\n front.renderOrder = MARKER_ORDER;\n root.add(back, front);\n return { root, back, front, shape, radius: MARKER_RADIUS, hidden: false };\n}\n\n/** This function makes the line of a link between two points of the space of the viewer. The line shows only when the viewer says so. */\nexport function makeLink(outlet: string, object: string, level: LoadLevel | undefined, from: Point3, to: Point3): PowerLink {\n const geometry = new LineSegmentsGeometry().setPositions([from.x, from.y, from.z, to.x, to.y, to.z]);\n const material = new LineMaterial({ linewidth: 2, dashed: true, dashSize: 0.09, gapSize: 0.06, transparent: true, depthTest: false, depthWrite: false });\n const line = new LineSegments2(geometry, material);\n line.computeLineDistances();\n line.renderOrder = LINK_ORDER;\n line.visible = false;\n return { outlet, object, level, line };\n}\n\n/** This function releases the memory of the graphics card that a marker uses. */\nexport function disposeMarker(marker: OutletMarker): void {\n marker.back.geometry.dispose();\n marker.back.material.dispose();\n marker.front.geometry.dispose();\n marker.front.material.dispose();\n marker.root.clear();\n}\n\n/** This function releases the memory of the graphics card that a link uses. */\nexport function disposeLink(link: PowerLink): void {\n link.line.geometry.dispose();\n link.line.material.dispose();\n}\n","import type { Point3 } from \"@mark1russell7/layout-contract\";\n\n/**\n * The direction of a view: where the camera is, as seen from the point that it looks at.\n * The viewer has the y axis up. The x axis is the x axis of the plan, and the negative z axis is the y axis of the plan.\n */\nexport interface ViewAngles {\n /** The angle from the up axis to the camera, in radians. At 0, the camera looks down from above. */\n readonly polar: number;\n /** The angle around the up axis, in radians. At 0, the camera is south of the room and it looks north. */\n readonly azimuth: number;\n}\n\n/** The view of a dollhouse: from the south-east, 38 degrees above the floor. */\nexport const HOME_VIEW: ViewAngles = { polar: (52 * Math.PI) / 180, azimuth: (35 * Math.PI) / 180 };\n\n/** The view of a plan: from above, with north at the top. */\nexport const TOP_VIEW: ViewAngles = { polar: 0, azimuth: 0 };\n\n/** The three axes of a camera, as unit vectors in the space of the viewer. */\nexport interface ViewAxes {\n /** The vector from the point that the camera looks at to the camera. */\n readonly back: Point3;\n /** The vector to the right side of the picture. */\n readonly right: Point3;\n /** The vector to the top of the picture. */\n readonly up: Point3;\n}\n\n/** This function gives a point of the room in the space of the viewer: the z axis of the room becomes the y axis. */\nexport function toViewer(point: Point3): Point3 {\n return { x: point.x, y: point.z, z: 0 - point.y };\n}\n\n/** This function gives a point of the viewer in the space of the room: the y axis of the viewer becomes the z axis. */\nexport function toRoom(point: Point3): Point3 {\n return { x: point.x, y: 0 - point.z, z: point.y };\n}\n\n/** This function gives the axes of the camera of a view. At a polar angle of 0, the top of the picture is north. */\nexport function viewAxes(view: ViewAngles): ViewAxes {\n const sinPolar = Math.sin(view.polar);\n const cosPolar = Math.cos(view.polar);\n const sinAzimuth = Math.sin(view.azimuth);\n const cosAzimuth = Math.cos(view.azimuth);\n return {\n back: { x: sinPolar * sinAzimuth, y: cosPolar, z: sinPolar * cosAzimuth },\n right: { x: cosAzimuth, y: 0, z: 0 - sinAzimuth },\n up: { x: 0 - cosPolar * sinAzimuth, y: sinPolar, z: 0 - cosPolar * cosAzimuth },\n };\n}\n\n/** This function gives the dot product of the vector from `origin` to `point` with `axis`. */\nfunction along(point: Point3, origin: Point3, axis: Point3): number {\n return (point.x - origin.x) * axis.x + (point.y - origin.y) * axis.y + (point.z - origin.z) * axis.z;\n}\n\n/**\n * This function gives the smallest distance from `target` at which a camera shows each point.\n *\n * The camera looks at `target` along the direction of `view`. `fov` is the vertical angle of the picture in degrees,\n * and `aspect` is the width of the picture divided by its height. The points and the target are in the space of the viewer.\n * The function gives 0 for no points, and for an angle or an aspect that makes no picture.\n */\nexport function fitDistance(points: readonly Point3[], target: Point3, view: ViewAngles, fov: number, aspect: number): number {\n const tanUp = Math.tan((fov * Math.PI) / 360);\n const tanRight = tanUp * aspect;\n if (!(tanUp > 0) || !(tanRight > 0) || !Number.isFinite(tanRight)) return 0;\n const axes = viewAxes(view);\n let distance = 0;\n for (const point of points) {\n const depth = along(point, target, axes.back);\n const needed = Math.max(Math.abs(along(point, target, axes.right)) / tanRight, Math.abs(along(point, target, axes.up)) / tanUp);\n distance = Math.max(distance, depth + needed);\n }\n return distance;\n}\n\n/** This function gives the position of a camera at a distance from `target`, in the direction of `view`. */\nexport function cameraPosition(target: Point3, view: ViewAngles, distance: number): Point3 {\n const { back } = viewAxes(view);\n return { x: target.x + back.x * distance, y: target.y + back.y * distance, z: target.z + back.z * distance };\n}\n\n/** This function gives the angles of the view from `target` to a camera, and the distance between them. A camera at the target gives the angles 0. */\nexport function viewOf(camera: Point3, target: Point3): ViewAngles & { readonly distance: number } {\n const x = camera.x - target.x;\n const y = camera.y - target.y;\n const z = camera.z - target.z;\n const distance = Math.hypot(x, y, z);\n if (!(distance > 0)) return { polar: 0, azimuth: 0, distance: 0 };\n return { polar: Math.acos(Math.min(Math.max(y / distance, -1), 1)), azimuth: Math.atan2(x, z), distance };\n}\n\n/** This function gives the angle between two azimuths along the shortest way, from −π to π. */\nexport function turnBetween(from: number, to: number): number {\n const full = 2 * Math.PI;\n const turn = (((to - from) % full) + full) % full;\n return turn > Math.PI ? turn - full : turn;\n}\n","import type { Point3 } from \"@mark1russell7/layout-contract\";\nimport { Color, EdgesGeometry, Group, Mesh, MeshLambertMaterial, type BufferGeometry, type Material } from \"three\";\nimport { LineMaterial } from \"three/addons/lines/LineMaterial.js\";\nimport { LineSegments2 } from \"three/addons/lines/LineSegments2.js\";\nimport { LineSegmentsGeometry } from \"three/addons/lines/LineSegmentsGeometry.js\";\nimport { outletLevels, type LoadLevel, type LoadOptions } from \"../loads.ts\";\nimport type { Scene } from \"../room.ts\";\nimport { boundsOfSolids, sceneSolids, solidCorners, TO_Y_UP, type Solid, type SolidKind, type SolidOptions } from \"../solids.ts\";\nimport { metersPer } from \"../units.ts\";\nimport { wallShades, type WallShade } from \"./fade.ts\";\nimport { solidGeometry } from \"./geometry.ts\";\nimport { disposeLink, disposeMarker, makeLink, makeMarker, MARKER_RADIUS, type OutletMarker, type PowerLink } from \"./markers.ts\";\nimport type { ViewerTheme } from \"./theme.ts\";\nimport { toViewer } from \"./view.ts\";\n\n/** The mark of a part: 0 for no mark, 1 for a part under the pointer, 2 for a selected part. */\nexport type PartMark = 0 | 1 | 2;\n\n/** One solid of the model as three.js objects. */\nexport interface ModelPart {\n readonly solid: Solid;\n /** The name of the record of the solid: its kind and its source. Each part of one wall has the same name. */\n readonly record: string;\n /** The `id` of the wall that the part fades with: the wall itself, the wall of a window or the wall of an outlet. */\n readonly wall: string | undefined;\n /** The name of the record of the object that this object is in or on. */\n readonly holder: string | undefined;\n /** This value is true for an object with other objects in it. Such an object shows as a clear box. */\n readonly holds: boolean;\n /** The level of the circuit of an outlet. An outlet with no circuit has no level, and so has each other part. */\n readonly level: LoadLevel | undefined;\n /** The marker of an outlet. */\n readonly marker: OutletMarker | undefined;\n readonly mesh: Mesh<BufferGeometry, MeshLambertMaterial>;\n readonly lines: LineSegments2;\n /** The fade of the part, from 0 for a solid part to 1 for a part that hides the room. The viewer changes it. */\n fade: number;\n}\n\n/** The model of a scene as three.js objects. */\nexport interface RoomModel {\n /** The group of each part. It has the rotation from the room to the space of the viewer. */\n readonly group: Group;\n /** The group of the markers and the links, in the space of the viewer. The solids do not hide them. */\n readonly overlay: Group;\n readonly parts: readonly ModelPart[];\n /** The link from each outlet to each placed object that takes its power from the outlet. */\n readonly links: readonly PowerLink[];\n /** Each corner of each solid, in the space of the viewer. */\n readonly corners: readonly Point3[];\n /** The center of the model, in the space of the viewer. */\n readonly center: Point3;\n /** The walls of the room, each with the side that looks at the room. */\n readonly shades: readonly WallShade[];\n}\n\n/** This function gives the name of a record of a kind. */\nexport function recordName(kind: SolidKind, source: string): string {\n return `${kind}:${source}`;\n}\n\n/** The width of the edges of each kind of solid, in CSS pixels. */\nconst EDGE_WIDTH: Readonly<Record<SolidKind, number>> = { floor: 1.25, wall: 1.25, glass: 1, outlet: 1, object: 1.25 };\n\n/** The part of a clear box of objects that is not clear. */\nconst HOLDER_OPACITY = 0.14;\n\n/** A part with an opacity above this value writes its depth, as a solid part does. */\nconst SOLID_OPACITY = 0.999;\n\n/** This function gives the `id` of each placed object that has an object in its box. */\nfunction holders(scene: Scene): ReadonlySet<string> {\n const scale = metersPer(scene.room.unit);\n const objects = new Map((scene.objects ?? []).map((object) => [object.id, object] as const));\n const found = new Set<string>();\n for (const object of scene.objects ?? []) {\n const parent = object.parent === undefined ? undefined : objects.get(object.parent);\n if (parent === undefined) continue;\n const x = object.at[0] * scale;\n const y = object.at[1] * scale;\n const z = ((object.lift ?? 0) + object.size[2] / 2) * scale;\n const [w, h, d] = [parent.size[0] * scale, parent.size[1] * scale, parent.size[2] * scale];\n if (Math.abs(x) < w / 2 && Math.abs(y) < h / 2 && z > 0 && z < d) found.add(parent.id);\n }\n return found;\n}\n\n/**\n * This function makes the three.js objects of a scene: one mesh with its edges for each solid.\n * Each outlet has a marker, and each placed object with an outlet has a link to it.\n * The parts have no colors until `paintPart` gives them. The caller disposes the model with `disposeModel`.\n */\nexport function buildModel(scene: Scene, options: SolidOptions = {}, loads: LoadOptions = {}): RoomModel {\n const solids = sceneSolids(scene, options);\n const levels = outletLevels(scene, loads);\n const wallOfOpening = new Map((scene.room.openings ?? []).map((opening) => [opening.id, opening.wall] as const));\n const wallOfOutlet = new Map((scene.room.outlets ?? []).map((outlet) => [outlet.id, outlet.wall] as const));\n const parentOf = new Map((scene.objects ?? []).map((object) => [object.id, object.parent] as const));\n const holding = holders(scene);\n const group = new Group();\n const overlay = new Group();\n const centers = new Map<string, Point3>();\n group.quaternion.set(TO_Y_UP.rotation.x, TO_Y_UP.rotation.y, TO_Y_UP.rotation.z, TO_Y_UP.rotation.w);\n const parts = solids.map((solid): ModelPart => {\n const { geometry, position, rotation } = solidGeometry(solid);\n const mesh = new Mesh(geometry, new MeshLambertMaterial({ polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 }));\n mesh.position.set(position.x, position.y, position.z);\n mesh.quaternion.set(rotation.x, rotation.y, rotation.z, rotation.w);\n const edges = new EdgesGeometry(geometry, 30);\n const lines = new LineSegments2(new LineSegmentsGeometry().fromEdgesGeometry(edges), new LineMaterial({ linewidth: EDGE_WIDTH[solid.kind] }));\n edges.dispose();\n mesh.add(lines);\n group.add(mesh);\n const parent = solid.kind === \"object\" ? parentOf.get(solid.source) : undefined;\n const record = recordName(solid.kind, solid.source);\n const center = toViewer(centerOf(solid));\n centers.set(record, center);\n const level = solid.kind === \"outlet\" ? levels.get(solid.source) : undefined;\n const marker = solid.kind === \"outlet\" ? makeMarker(center, level) : undefined;\n if (marker !== undefined) overlay.add(marker.root);\n return {\n solid,\n record,\n wall: solid.kind === \"wall\" ? solid.source : solid.kind === \"glass\" ? wallOfOpening.get(solid.source) : solid.kind === \"outlet\" ? wallOfOutlet.get(solid.source) : undefined,\n holder: parent === undefined ? undefined : recordName(\"object\", parent),\n holds: solid.kind === \"object\" && holding.has(solid.source),\n level,\n marker,\n mesh,\n lines,\n fade: 0,\n };\n });\n const links: PowerLink[] = [];\n for (const object of scene.objects ?? []) {\n if (object.outlet === undefined) continue;\n const outlet = recordName(\"outlet\", object.outlet);\n const user = recordName(\"object\", object.id);\n const from = centers.get(outlet);\n const to = centers.get(user);\n if (from === undefined || to === undefined) continue;\n const link = makeLink(outlet, user, levels.get(object.outlet), from, to);\n overlay.add(link.line);\n links.push(link);\n }\n const bounds = boundsOfSolids(solids);\n const middle = bounds === undefined ? { x: 0, y: 0, z: 0 } : { x: bounds.x + bounds.w / 2, y: bounds.y + bounds.h / 2, z: bounds.z + bounds.d / 2 };\n return {\n group,\n overlay,\n parts,\n links,\n corners: solids.flatMap((solid) => solidCorners(solid).map((corner) => toViewer(corner))),\n center: toViewer(middle),\n shades: wallShades(scene.room, bounds === undefined ? undefined : middle),\n };\n}\n\n/** This function gives the center of a solid, in the frame of the room: the mean of its corners. */\nfunction centerOf(solid: Solid): Point3 {\n const corners = solidCorners(solid);\n const sum = corners.reduce((total, corner) => ({ x: total.x + corner.x, y: total.y + corner.y, z: total.z + corner.z }), { x: 0, y: 0, z: 0 });\n const count = Math.max(corners.length, 1);\n return { x: sum.x / count, y: sum.y / count, z: sum.z / count };\n}\n\n/** This function sets the opacity of a material. A material that is not solid does not write its depth. */\nfunction setOpacity(material: Material, opacity: number): void {\n const clear = opacity < SOLID_OPACITY;\n if (material.transparent !== clear) {\n material.transparent = clear;\n material.depthWrite = !clear;\n material.needsUpdate = true;\n }\n material.opacity = opacity;\n}\n\n/** This function gives the color of a part in a theme, before a mark. */\nfunction baseColor(part: ModelPart, scene: Scene, theme: ViewerTheme): string {\n const kind = part.solid.kind;\n if (kind === \"outlet\") return part.level === undefined ? theme.outlet : theme.levels[part.level];\n if (kind !== \"object\") return theme[kind];\n const object = (scene.objects ?? []).find((candidate) => candidate.id === part.solid.source);\n return (object === undefined ? undefined : theme.objects[object.kind]) ?? theme.object;\n}\n\n/**\n * This function gives a part its colors: the colors of the theme, the fade of the part and its mark.\n * A marked part has some of the color `accent` of the theme, and a selected part has wide edges.\n * An outlet has the color of the level of its circuit, and its marker has the same color.\n */\nexport function paintPart(part: ModelPart, scene: Scene, theme: ViewerTheme, mark: PartMark): void {\n const kind = part.solid.kind;\n const fill = part.mesh.material;\n const ink = part.lines.material;\n const color = baseColor(part, scene, theme);\n fill.color.set(color);\n if (mark !== 0) fill.color.lerp(new Color(theme.accent), mark === 2 ? 0.55 : 0.3);\n ink.color.set(theme.edge);\n ink.linewidth = EDGE_WIDTH[kind] * (mark === 2 ? 2 : 1);\n const still = 1 - part.fade;\n let opacity = kind === \"glass\" ? theme.glassOpacity : part.holds ? (mark === 0 ? HOLDER_OPACITY : 0.45) : 1;\n let edge = 1;\n if (kind === \"wall\") {\n opacity *= 0.08 + 0.92 * still;\n edge = 0.3 + 0.7 * still;\n } else if (kind === \"glass\" || kind === \"outlet\") {\n opacity *= 0.35 + 0.65 * still;\n edge = 0.35 + 0.65 * still;\n }\n setOpacity(fill, opacity);\n setOpacity(ink, edge);\n if (part.marker !== undefined) paintMarker(part.marker, color, theme, mark, still);\n}\n\n/** The part of a marker that is not clear while a solid hides its outlet. */\nconst HIDDEN_MARKER = 0.45;\n\n/** This function gives a marker its colors and its size. `still` is 1 for a marker on a solid wall and 0 on a clear wall. */\nfunction paintMarker(marker: OutletMarker, color: string, theme: ViewerTheme, mark: PartMark, still: number): void {\n marker.front.material.color.set(color);\n marker.back.material.color.set(mark === 0 ? theme.halo : theme.accent);\n // A marker with a mark is always solid, so that a person finds the outlet behind a wall or a machine.\n const opacity = mark === 0 ? (0.35 + 0.65 * still) * (marker.hidden ? HIDDEN_MARKER : 1) : 1;\n marker.front.material.opacity = opacity;\n marker.back.material.opacity = opacity;\n marker.radius = MARKER_RADIUS * (mark === 2 ? 1.3 : mark === 1 ? 1.15 : 1);\n}\n\n/** This function gives a link the color of the level of its circuit, and shows it or hides it. */\nexport function paintLink(link: PowerLink, theme: ViewerTheme, visible: boolean): void {\n link.line.material.color.set(link.level === undefined ? theme.outlet : theme.levels[link.level]);\n link.line.visible = visible;\n}\n\n/** This function releases the memory of the graphics card that a model uses. */\nexport function disposeModel(model: RoomModel): void {\n for (const part of model.parts) {\n part.mesh.geometry.dispose();\n part.mesh.material.dispose();\n part.lines.geometry.dispose();\n part.lines.material.dispose();\n if (part.marker !== undefined) disposeMarker(part.marker);\n }\n for (const link of model.links) disposeLink(link);\n model.group.clear();\n model.overlay.clear();\n}\n","import type { Point3 } from \"@mark1russell7/layout-contract\";\nimport { DirectionalLight, HemisphereLight, PerspectiveCamera, Raycaster, Scene as World, Vector2, Vector3, WebGLRenderer, type Object3D } from \"three\";\nimport { OrbitControls } from \"three/addons/controls/OrbitControls.js\";\nimport type { LoadOptions } from \"../loads.ts\";\nimport type { Scene } from \"../room.ts\";\nimport type { SolidKind, SolidOptions } from \"../solids.ts\";\nimport { hidingWalls } from \"./fade.ts\";\nimport { buildModel, disposeModel, paintLink, paintPart, recordName, type ModelPart, type PartMark, type RoomModel } from \"./model.ts\";\nimport { LIGHT_THEME, type ViewerTheme } from \"./theme.ts\";\nimport { cameraPosition, fitDistance, HOME_VIEW, TOP_VIEW, toRoom, turnBetween, viewOf, type ViewAngles } from \"./view.ts\";\n\n/** A record of a scene that the viewer shows: a floor, a wall, a window, an outlet or a placed object. */\nexport interface ViewerRecord {\n /** The kind of the solids of the record. A window has the kind `glass`. */\n readonly kind: SolidKind;\n /** The `id` of the record in the scene. */\n readonly source: string;\n}\n\n/** The solid under the pointer, with its record. */\nexport interface ViewerPick extends ViewerRecord {\n /** The `id` of the solid. A wall with openings has more than one solid. */\n readonly solid: string;\n}\n\n/** The name of a view: `home` looks into the room from a corner above it, and `top` shows the plan. */\nexport type ViewName = \"home\" | \"top\";\n\n/** The options of a viewer. */\nexport interface RoomViewerOptions {\n readonly scene: Scene;\n /** The colors. The default is `LIGHT_THEME`. */\n readonly theme?: ViewerTheme | undefined;\n /** The options of the model. */\n readonly solids?: SolidOptions | undefined;\n /** The options of the levels of the circuits. */\n readonly loads?: LoadOptions | undefined;\n /** The name of the picture for a screen reader. */\n readonly label?: string | undefined;\n /** The viewer starts this function when the pointer goes to a different record, or to no record. */\n readonly onHover?: ((pick: ViewerPick | undefined) => void) | undefined;\n /** The viewer starts this function when a person selects a record with the pointer, or selects no record. */\n readonly onSelect?: ((pick: ViewerPick | undefined) => void) | undefined;\n}\n\n/** A viewer of one scene in a page. */\nexport interface RoomViewer {\n /** The canvas of the viewer. It is in the container. */\n readonly canvas: HTMLCanvasElement;\n /** This function shows a different scene. The view stays if a person moved it. */\n setScene(scene: Scene): void;\n /** This function changes the colors. */\n setTheme(theme: ViewerTheme): void;\n /** This function moves the camera to a view that shows all of the model. */\n setView(view: ViewName): void;\n /** This function marks records, as the pointer does. An empty list removes the marks. */\n highlight(records: readonly ViewerRecord[]): void;\n /** This function selects one record, or no record. It does not start `onSelect`. */\n select(record: ViewerRecord | undefined): void;\n /** This function removes the canvas and releases the memory of the graphics card. */\n dispose(): void;\n}\n\n/** The vertical angle of the picture, in degrees. A small angle gives the look of a drawing. */\nconst FIELD_OF_VIEW = 32;\n\n/** The space around the model in a view that shows all of it, as a factor of the distance. */\nconst MARGIN = 1.06;\n\n/** The time of the move between two views, in milliseconds. */\nconst MOVE_TIME = 380;\n\n/** The time in which a wall goes most of the way to clear or to solid, in seconds. */\nconst FADE_TIME = 0.11;\n\n/** A pointer that moves less than this distance between down and up is a click, in CSS pixels. */\nconst CLICK_DISTANCE = 4;\n\n/** The angle of one step of an arrow key, in radians. */\nconst KEY_TURN = Math.PI / 24;\n\n/** The smallest polar angle. At 0, the azimuth of a camera has no meaning. */\nconst SMALLEST_POLAR = 0.0005;\n\n/** The largest polar angle: the camera stays above the floor. */\nconst LARGEST_POLAR = Math.PI / 2 - 0.05;\n\n/** A solid hides a marker when it is this distance or more before the outlet, in meters. */\nconst SIGHT_MARGIN = 0.06;\n\n/** A place of the camera: the point that it looks at, the angles and the distance. */\ninterface Place extends ViewAngles {\n readonly target: Point3;\n readonly distance: number;\n}\n\n/** A move of the camera from one place to a different place. */\ninterface Move {\n readonly from: Place;\n readonly to: Place;\n readonly start: number;\n}\n\n/** This function tells if the person asks for less motion. */\nfunction lessMotion(): boolean {\n return typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\n\n/**\n * This function makes a viewer of a scene in a container of a page. The viewer fills the container, so give the container a size.\n *\n * A person turns the model with a drag, and moves nearer with the wheel after a click in the picture.\n * The walls between the camera and the room become almost clear. A click selects the record of a solid.\n * Each outlet has a marker with the color and the shape of the level of its circuit. A marker keeps its size in the picture.\n * A marked outlet or object shows a line from the outlet to each object that takes its power from it.\n * With the keyboard, the arrow keys turn the model, `+` and `-` change the distance, `Home` shows the first view and `T` shows the plan.\n *\n * The function gives `undefined` when the browser has no WebGL 2. It does not throw, and it writes no error to the console.\n */\nexport function createRoomViewer(container: HTMLElement, options: RoomViewerOptions): RoomViewer | undefined {\n const canvas = container.ownerDocument.createElement(\"canvas\");\n const context = canvas.getContext(\"webgl2\", { alpha: true, antialias: true, depth: true, stencil: false, premultipliedAlpha: true, powerPreference: \"default\" });\n if (context === null) return undefined;\n let renderer: WebGLRenderer;\n try {\n renderer = new WebGLRenderer({ canvas, context, alpha: true, antialias: true });\n } catch {\n return undefined;\n }\n renderer.setClearColor(0x000000, 0);\n\n canvas.style.display = \"block\";\n canvas.style.width = \"100%\";\n canvas.style.height = \"100%\";\n canvas.style.cursor = \"grab\";\n canvas.tabIndex = 0;\n canvas.setAttribute(\"role\", \"application\");\n canvas.setAttribute(\"aria-label\", options.label ?? \"3D model of the room\");\n container.append(canvas);\n\n const world = new World();\n const sky = new HemisphereLight(\"#ffffff\", \"#ffffff\", 2.2);\n const sun = new DirectionalLight(\"#ffffff\", 1.5);\n sun.position.set(-10, 24, 15);\n world.add(sky, sun);\n const camera = new PerspectiveCamera(FIELD_OF_VIEW, 1, 0.05, 1000);\n\n let scene = options.scene;\n let theme = options.theme ?? LIGHT_THEME;\n let model: RoomModel = buildModel(scene, options.solids, options.loads);\n world.add(model.group, model.overlay);\n\n let hovered: string | undefined;\n let selected: string | undefined;\n let marked: ReadonlySet<string> = new Set();\n let hiding: ReadonlySet<string> = new Set();\n let view: ViewName = \"home\";\n let move: Move | undefined;\n /** This value is true after a person moved the view. Then a new size of the container does not move the camera. */\n let moved = false;\n /** The height of the picture, in CSS pixels. */\n let viewHeight = 1;\n let frame = 0;\n let lastTime = 0;\n let disposed = false;\n\n const invalidate = (): void => {\n if (frame === 0 && !disposed) frame = requestAnimationFrame(tick);\n };\n\n const controls = new OrbitControls(camera, canvas);\n controls.enableDamping = !lessMotion();\n controls.dampingFactor = 0.14;\n controls.maxPolarAngle = LARGEST_POLAR;\n controls.rotateSpeed = 0.9;\n controls.screenSpacePanning = true;\n // The wheel moves the page until a person uses the picture. Thus the picture does not stop a person who reads down the page.\n controls.enableZoom = false;\n\n const markOfRecord = (record: string): PartMark => (record === selected ? 2 : record === hovered || marked.has(record) ? 1 : 0);\n const markOf = (part: ModelPart): PartMark => markOfRecord(part.record);\n const paintAll = (): void => {\n for (const part of model.parts) paintPart(part, scene, theme, markOf(part));\n // A link shows while its outlet or its object has a mark.\n for (const link of model.links) paintLink(link, theme, markOfRecord(link.outlet) !== 0 || markOfRecord(link.object) !== 0);\n invalidate();\n };\n const pickOf = (part: ModelPart): ViewerPick => ({ solid: part.solid.id, kind: part.solid.kind, source: part.solid.source });\n\n const place = (to: Place): void => {\n const polar = Math.min(Math.max(to.polar, SMALLEST_POLAR), LARGEST_POLAR);\n const distance = Math.min(Math.max(to.distance, controls.minDistance), controls.maxDistance);\n const eye = cameraPosition(to.target, { polar, azimuth: to.azimuth }, distance);\n controls.target.set(to.target.x, to.target.y, to.target.z);\n camera.position.set(eye.x, eye.y, eye.z);\n camera.lookAt(controls.target);\n };\n const placeNow = (): Place => {\n const target = { x: controls.target.x, y: controls.target.y, z: controls.target.z };\n return { target, ...viewOf(camera.position, target) };\n };\n const fit = (name: ViewName): Place => {\n const angles = name === \"top\" ? TOP_VIEW : HOME_VIEW;\n const distance = fitDistance(model.corners, model.center, angles, FIELD_OF_VIEW, camera.aspect) * MARGIN;\n return { target: model.center, ...angles, distance: distance > 0 ? distance : 10 };\n };\n /** This function sets the nearest and the farthest distance of the camera from the size of the model. */\n const setLimits = (): void => {\n const far = Math.max(fit(\"home\").distance, fit(\"top\").distance);\n controls.minDistance = 0.4;\n controls.maxDistance = far * 3;\n camera.far = far * 8 + 100;\n camera.updateProjectionMatrix();\n };\n /**\n * This function stops the turn that continues after a drag. The camera stays where it is.\n * Without it, the camera continues to turn after a move to a view, and the view is not exact.\n */\n const stopDrift = (): void => {\n if (!controls.enableDamping) return;\n const now = placeNow();\n // With no damping, an update of the controls uses all of the turn that remains. The camera then goes back.\n controls.enableDamping = false;\n controls.update();\n controls.enableDamping = true;\n place(now);\n };\n const goTo = (name: ViewName, animate: boolean): void => {\n view = name;\n moved = false;\n stopDrift();\n const to = fit(name);\n if (animate && !lessMotion()) {\n move = { from: placeNow(), to, start: performance.now() };\n } else {\n move = undefined;\n place(to);\n }\n invalidate();\n };\n\n /** This function sets the size of the picture from the size of the container. It gives false for a container with no size. */\n const setSize = (): boolean => {\n const width = container.clientWidth;\n const height = container.clientHeight;\n if (width === 0 || height === 0) return false;\n viewHeight = height;\n renderer.setPixelRatio(Math.min(globalThis.devicePixelRatio, 2));\n renderer.setSize(width, height, false);\n camera.aspect = width / height;\n camera.updateProjectionMatrix();\n return true;\n };\n\n /** This function moves the camera one step of a move between two views. It gives true while the move continues. */\n const stepMove = (now: number): boolean => {\n if (move === undefined) return false;\n const { from, to } = move;\n const part = Math.min(Math.max((now - move.start) / MOVE_TIME, 0), 1);\n const eased = part < 0.5 ? 4 * part * part * part : 1 - (-2 * part + 2) ** 3 / 2;\n const between = (a: number, b: number): number => a + (b - a) * eased;\n place({\n target: { x: between(from.target.x, to.target.x), y: between(from.target.y, to.target.y), z: between(from.target.z, to.target.z) },\n polar: between(from.polar, to.polar),\n azimuth: from.azimuth + turnBetween(from.azimuth, to.azimuth) * eased,\n distance: between(from.distance, to.distance),\n });\n if (part >= 1) move = undefined;\n return true;\n };\n\n /**\n * This function moves the fade of each wall one step to its goal: clear for a wall that hides the room, solid for the others.\n * `seconds` is the time since the last picture, and 0 sets each goal immediately. It gives true while a wall changes.\n */\n const stepFade = (seconds: number): boolean => {\n hiding = hidingWalls(model.shades, toRoom(camera.position));\n const rate = seconds > 0 ? 1 - Math.exp(0 - seconds / FADE_TIME) : 1;\n let active = false;\n for (const part of model.parts) {\n if (part.wall === undefined) continue;\n const goal = hiding.has(part.wall) ? 1 : 0;\n if (part.fade === goal) continue;\n const next = part.fade + (goal - part.fade) * rate;\n part.fade = Math.abs(goal - next) < 0.01 ? goal : next;\n paintPart(part, scene, theme, markOf(part));\n active = active || part.fade !== goal;\n }\n return active;\n };\n\n const sight = new Raycaster();\n const forward = new Vector3();\n const offset = new Vector3();\n /**\n * This function turns each marker to the camera and gives it its size in the picture.\n * It also finds each marker with a solid between the camera and its outlet: such a marker is less clear.\n */\n const stepOverlay = (): void => {\n const perPixel = (2 * Math.tan((FIELD_OF_VIEW * Math.PI) / 360)) / viewHeight;\n camera.getWorldDirection(forward);\n model.group.updateMatrixWorld();\n // Glass, a clear wall and a clear box of objects hide nothing.\n const blockers = model.parts\n .filter((part) => {\n const kind = part.solid.kind;\n return kind === \"floor\" || (kind === \"wall\" && !hiding.has(part.solid.source)) || (kind === \"object\" && !part.holds);\n })\n .map((part) => part.mesh);\n for (const part of model.parts) {\n const marker = part.marker;\n if (marker === undefined) continue;\n offset.subVectors(marker.root.position, camera.position);\n const distance = offset.length();\n marker.root.quaternion.copy(camera.quaternion);\n marker.root.scale.setScalar(Math.max(offset.dot(forward), 0.01) * perPixel * marker.radius);\n sight.set(camera.position, offset.divideScalar(Math.max(distance, 1e-9)));\n sight.far = distance - SIGHT_MARGIN;\n const hidden = sight.far > 0 && sight.intersectObjects(blockers, false).length > 0;\n if (hidden === marker.hidden) continue;\n marker.hidden = hidden;\n paintPart(part, scene, theme, markOf(part));\n }\n };\n\n function tick(now: number): void {\n frame = 0;\n if (disposed) return;\n const seconds = lastTime === 0 ? 1 / 60 : Math.min((now - lastTime) / 1000, 0.1);\n let active = stepMove(now);\n active = controls.update() || active;\n active = stepFade(lessMotion() ? 0 : seconds) || active;\n stepOverlay();\n renderer.render(world, camera);\n lastTime = active ? now : 0;\n if (active) invalidate();\n }\n\n const raycaster = new Raycaster();\n const pointer = new Vector2();\n /**\n * This function gives the part under a pointer. A wall that hides the room is clear, and the pointer goes through it.\n * The marker of an outlet is above each solid in the picture, so the pointer selects a marker first.\n */\n const partAt = (event: PointerEvent): ModelPart | undefined => {\n const box = canvas.getBoundingClientRect();\n if (box.width === 0 || box.height === 0) return undefined;\n pointer.set(((event.clientX - box.left) / box.width) * 2 - 1, 1 - ((event.clientY - box.top) / box.height) * 2);\n raycaster.setFromCamera(pointer, camera);\n const bySign = new Map<Object3D, ModelPart>();\n for (const part of model.parts) if (part.marker !== undefined) bySign.set(part.marker.back, part);\n const sign = raycaster.intersectObjects([...bySign.keys()], false)[0];\n if (sign !== undefined) return bySign.get(sign.object);\n const open = model.parts.filter((part) => part.wall === undefined || !hiding.has(part.wall));\n const byMesh = new Map<Object3D, ModelPart>(open.map((part) => [part.mesh, part]));\n const hits = raycaster.intersectObjects(\n open.map((part) => part.mesh),\n false,\n );\n const first = hits[0] === undefined ? undefined : byMesh.get(hits[0].object);\n if (first === undefined || !first.holds) return first;\n // A clear box of objects: the pointer selects an object in the box before the box.\n for (const hit of hits) {\n const part = byMesh.get(hit.object);\n if (part !== undefined && part.holder === first.record) return part;\n }\n return first;\n };\n\n const setHover = (part: ModelPart | undefined): void => {\n const record = part?.record;\n if (record === hovered) return;\n hovered = record;\n canvas.style.cursor = record === undefined ? \"grab\" : \"pointer\";\n paintAll();\n options.onHover?.(part === undefined ? undefined : pickOf(part));\n };\n\n const listeners = new AbortController();\n const signal = listeners.signal;\n let down: { readonly id: number; readonly x: number; readonly y: number } | undefined;\n const setInUse = (inUse: boolean): void => {\n controls.enableZoom = inUse;\n };\n canvas.addEventListener(\n \"pointerdown\",\n (event) => {\n setInUse(true);\n canvas.focus({ preventScroll: true });\n down = { id: event.pointerId, x: event.clientX, y: event.clientY };\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointermove\",\n (event) => {\n if (event.buttons === 0 && event.pointerType !== \"touch\") setHover(partAt(event));\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointerup\",\n (event) => {\n const start = down;\n down = undefined;\n if (start === undefined || start.id !== event.pointerId) return;\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) > CLICK_DISTANCE) return;\n const part = partAt(event);\n selected = part?.record;\n paintAll();\n options.onSelect?.(part === undefined ? undefined : pickOf(part));\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointercancel\",\n () => {\n down = undefined;\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointerleave\",\n (event) => {\n setHover(undefined);\n if (event.pointerType === \"mouse\") setInUse(false);\n },\n { signal },\n );\n canvas.addEventListener(\"blur\", () => setInUse(false), { signal });\n canvas.addEventListener(\n \"keydown\",\n (event) => {\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n const now = placeNow();\n let to: Place | undefined;\n if (event.key === \"ArrowLeft\") to = { ...now, azimuth: now.azimuth - KEY_TURN };\n else if (event.key === \"ArrowRight\") to = { ...now, azimuth: now.azimuth + KEY_TURN };\n else if (event.key === \"ArrowUp\") to = { ...now, polar: now.polar - KEY_TURN };\n else if (event.key === \"ArrowDown\") to = { ...now, polar: now.polar + KEY_TURN };\n else if (event.key === \"+\" || event.key === \"=\") to = { ...now, distance: now.distance * 0.85 };\n else if (event.key === \"-\" || event.key === \"_\") to = { ...now, distance: now.distance / 0.85 };\n else if (event.key === \"Home\" || event.key === \"0\") goTo(\"home\", true);\n else if (event.key === \"t\" || event.key === \"T\") goTo(\"top\", true);\n else return;\n event.preventDefault();\n setInUse(true);\n if (to === undefined) return;\n moved = true;\n move = undefined;\n place(to);\n invalidate();\n },\n { signal },\n );\n canvas.addEventListener(\"webglcontextlost\", (event) => event.preventDefault(), { signal });\n canvas.addEventListener(\"webglcontextrestored\", invalidate, { signal });\n\n controls.addEventListener(\"start\", () => {\n moved = true;\n move = undefined;\n canvas.style.cursor = \"grabbing\";\n invalidate();\n });\n controls.addEventListener(\"end\", () => {\n canvas.style.cursor = hovered === undefined ? \"grab\" : \"pointer\";\n });\n controls.addEventListener(\"change\", invalidate);\n\n const applyTheme = (): void => {\n sky.color.set(theme.sky);\n sky.groundColor.set(theme.ground);\n paintAll();\n };\n\n const observer = new ResizeObserver(() => {\n if (disposed || !setSize()) return;\n setLimits();\n if (!moved) goTo(view, false);\n invalidate();\n });\n\n setSize();\n setLimits();\n goTo(\"home\", false);\n stepFade(0);\n applyTheme();\n observer.observe(container);\n\n return {\n canvas,\n setScene(next: Scene): void {\n world.remove(model.group, model.overlay);\n disposeModel(model);\n scene = next;\n model = buildModel(scene, options.solids, options.loads);\n world.add(model.group, model.overlay);\n hovered = undefined;\n if (selected !== undefined && !model.parts.some((part) => part.record === selected)) selected = undefined;\n setLimits();\n if (!moved) goTo(view, false);\n stepFade(0);\n paintAll();\n },\n setTheme(next: ViewerTheme): void {\n theme = next;\n applyTheme();\n },\n setView(name: ViewName): void {\n goTo(name, true);\n },\n highlight(records: readonly ViewerRecord[]): void {\n marked = new Set(records.map((record) => recordName(record.kind, record.source)));\n paintAll();\n },\n select(record: ViewerRecord | undefined): void {\n selected = record === undefined ? undefined : recordName(record.kind, record.source);\n paintAll();\n },\n dispose(): void {\n if (disposed) return;\n disposed = true;\n cancelAnimationFrame(frame);\n observer.disconnect();\n listeners.abort();\n controls.dispose();\n world.remove(model.group, model.overlay);\n disposeModel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GAChF,SAAS;EACX;EACA,OAAO,QAAwC;GAC7C,WAAW,WAAW,KAAA,IAAY,KAAA,IAAY,WAAW,OAAO,MAAM,OAAO,MAAM;GACnF,SAAS;EACX;EACA,UAAgB;GACd,IAAI,UAAU;GACd,WAAW;GACX,qBAAqB,KAAK;GAC1B,SAAS,WAAW;GACpB,UAAU,MAAM;GAChB,SAAS,QAAQ;GACjB,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO;GACvC,aAAa,KAAK;GAClB,SAAS,QAAQ;GACjB,OAAO,OAAO;EAChB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"three.js","names":["World"],"sources":["../src/viewer/geometry.ts","../src/viewer/theme.ts","../src/viewer/fade.ts","../src/viewer/markers.ts","../src/viewer/view.ts","../src/viewer/model.ts","../src/viewer/viewer.ts"],"sourcesContent":["import { transformPoint3, type Point3, type Rotation3 } from \"@mark1russell7/layout-contract\";\nimport { BoxGeometry, ExtrudeGeometry, Shape, Vector2, type BufferGeometry } from \"three\";\nimport type { Solid } from \"../solids.ts\";\n\n/**\n * The three.js geometry of a solid, and its place in the room.\n * The origin of the geometry is the center of the solid. Thus three.js puts clear solids in the correct sequence.\n */\nexport interface SolidPlacement {\n /** The geometry, in meters, around its own origin. The caller disposes it. */\n readonly geometry: BufferGeometry;\n /** The position of the origin of the geometry in the room, where the z axis points up. */\n readonly position: Point3;\n /** The rotation of the geometry in the room. */\n readonly rotation: Rotation3;\n}\n\n/** The rotation that changes no direction. */\nconst NO_ROTATION: Rotation3 = { x: 0, y: 0, z: 0, w: 1 };\n\n/**\n * This function gives the three.js geometry of a solid, with its place in the room.\n *\n * A mesh with this geometry, this position and this rotation is in the space of the room: the z axis points up.\n * Put the mesh in a group with the rotation of `TO_Y_UP`. Then three.js shows it with the y axis up.\n */\nexport function solidGeometry(solid: Solid): SolidPlacement {\n const shape = solid.shape;\n if (shape.kind === \"box\") {\n const { box, transform } = shape;\n const center = { x: box.x + box.w / 2, y: box.y + box.h / 2, z: box.z + box.d / 2 };\n return { geometry: new BoxGeometry(box.w, box.h, box.d), position: transformPoint3(transform, center), rotation: transform.rotation };\n }\n let minX = Infinity;\n let maxX = -Infinity;\n let minY = Infinity;\n let maxY = -Infinity;\n for (const [x, y] of shape.ring) {\n minX = Math.min(minX, x);\n maxX = Math.max(maxX, x);\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n }\n const centerX = (minX + maxX) / 2;\n const centerY = (minY + maxY) / 2;\n const outline = new Shape(shape.ring.map(([x, y]) => new Vector2(x - centerX, y - centerY)));\n const geometry = new ExtrudeGeometry(outline, { depth: shape.d, bevelEnabled: false, steps: 1, curveSegments: 1 });\n geometry.translate(0, 0, 0 - shape.d / 2);\n return { geometry, position: { x: centerX, y: centerY, z: shape.z + shape.d / 2 }, rotation: NO_ROTATION };\n}\n","import type { LoadLevel } from \"../loads.ts\";\n\n/**\n * The colors of a viewer. Each color is a CSS hex color, for example `#22364a`.\n * The viewer has no background: the page shows behind the model.\n */\nexport interface ViewerTheme {\n /** The color of the edges of each solid. */\n readonly edge: string;\n /** The color that marks the solids under the pointer and the selected solids. */\n readonly accent: string;\n readonly floor: string;\n readonly wall: string;\n readonly glass: string;\n /** The part of the glass that is not clear, from 0 to 1. */\n readonly glassOpacity: number;\n /** The color of an outlet with no circuit. */\n readonly outlet: string;\n /** The color of the outlets of a circuit at each level of its load. */\n readonly levels: Readonly<Record<LoadLevel, string>>;\n /** The color of the line around the marker of an outlet. It is the color of the page, so a marker is clear on each solid. */\n readonly halo: string;\n /** The color of a placed object whose kind has no color in `objects`. */\n readonly object: string;\n /** The color of the placed objects of each kind. The key is the field `kind` of a placed object. */\n readonly objects: Readonly<Record<string, string>>;\n /** The color of the light from above. */\n readonly sky: string;\n /** The color of the light from below. */\n readonly ground: string;\n}\n\n/** The colors of a model of white card with ink edges, for a light page. */\nexport const LIGHT_THEME: ViewerTheme = {\n edge: \"#22364a\",\n accent: \"#f2b705\",\n floor: \"#dfe5ea\",\n wall: \"#fcfcfb\",\n glass: \"#8fc4e8\",\n glassOpacity: 0.35,\n outlet: \"#55677a\",\n levels: { unknown: \"#55677a\", ok: \"#1f5fa8\", near: \"#d9662f\", over: \"#c62f2f\" },\n halo: \"#ffffff\",\n object: \"#b8c0c8\",\n objects: { desk: \"#c9b596\", sofa: \"#8fa3b5\", rack: \"#3d4954\", computer: \"#5b6d7e\", display: \"#2c3640\" },\n sky: \"#ffffff\",\n ground: \"#b9c3cd\",\n};\n\n/** The colors of a blueprint, for a dark page. */\nexport const DARK_THEME: ViewerTheme = {\n edge: \"#cfe6ff\",\n accent: \"#ffd24a\",\n floor: \"#17395a\",\n wall: \"#1f4a73\",\n glass: \"#9fd0ff\",\n glassOpacity: 0.25,\n outlet: \"#a9bfd4\",\n levels: { unknown: \"#a9bfd4\", ok: \"#6fb3f2\", near: \"#f5a962\", over: \"#f0625f\" },\n halo: \"#0e2740\",\n object: \"#2a5580\",\n objects: { desk: \"#2a5a8a\", sofa: \"#28527c\", rack: \"#16324e\", computer: \"#3a74ad\", display: \"#122a42\" },\n sky: \"#ffffff\",\n ground: \"#7f9bb8\",\n};\n","import { pointInRing, type Point, type Point3, type Ring } from \"@mark1russell7/layout-contract\";\nimport { wallFrames, wallHasOutline, wallPoint, type WallFrame } from \"../frames.ts\";\nimport type { Room } from \"../room.ts\";\nimport { metersPer } from \"../units.ts\";\n\n/** The side of a wall that looks at the room. A wall between two parts of a room has the value `both`. */\nexport type InnerSide = \"left\" | \"right\" | \"both\";\n\n/** A wall, and the side of it that looks at the room. */\nexport interface WallShade {\n readonly frame: WallFrame;\n readonly inner: InnerSide;\n}\n\n/** The distance from a face of a wall to the points that find the floor, in meters. */\nconst PROBE = 0.05;\n\n/** A wall hides the room when it hides a strip of the floor that is deeper than this, in meters. */\nexport const HIDDEN_LIMIT = 0.3;\n\n/** This function gives the distance of a point of the plan across a wall. It is positive to the left of the line of the wall. */\nfunction across(frame: WallFrame, point: Point): number {\n return (point.x - frame.start.x) * frame.left.x + (point.y - frame.start.y) * frame.left.y;\n}\n\n/** This function tells if a floor is next to one face of a wall. `offset` is the distance across of points near that face. */\nfunction hasFloor(frame: WallFrame, offset: number, floors: readonly Ring[]): boolean {\n return [0.25, 0.5, 0.75].some((part) => {\n const point = wallPoint(frame, frame.length * part, offset);\n return floors.some((ring) => pointInRing(point.x, point.y, ring));\n });\n}\n\n/**\n * This function gives each wall that the model makes, with the side that looks at the room.\n *\n * A side looks at the room when a floor is next to it. For a wall with no floor on each side, the side is the side of `center`,\n * a point of the plan in meters. Without a center, such a wall has the value `both`.\n */\nexport function wallShades(room: Room, center?: Point): readonly WallShade[] {\n const scale = metersPer(room.unit);\n const floors = (room.floors ?? []).map((floor): Ring => floor.ring.map(([x, y]) => [x * scale, y * scale] as const));\n return wallFrames(room)\n .filter((frame) => wallHasOutline(frame))\n .map((frame): WallShade => {\n const left = hasFloor(frame, frame.leftOffset + PROBE, floors);\n const right = hasFloor(frame, frame.rightOffset - PROBE, floors);\n if (left !== right) return { frame, inner: left ? \"left\" : \"right\" };\n if (left || center === undefined) return { frame, inner: \"both\" };\n const side = across(frame, center);\n return { frame, inner: side > frame.leftOffset ? \"left\" : side < frame.rightOffset ? \"right\" : \"both\" };\n });\n}\n\n/**\n * This function gives the depth of the strip of the floor that a wall hides from a camera, in meters.\n *\n * `camera` is a point of the room in meters, with the z axis up. A camera above the wall, between its two faces, hides no strip.\n * A camera that is not above the top of the wall hides all of the floor behind the wall, and the depth is `Infinity`.\n */\nexport function hiddenDepth(frame: WallFrame, camera: Point3): number {\n const side = across(frame, camera);\n const gap = side > frame.leftOffset ? side - frame.leftOffset : side < frame.rightOffset ? frame.rightOffset - side : 0;\n if (!(gap > 0)) return 0;\n return camera.z > frame.height ? (frame.height * gap) / (camera.z - frame.height) : Infinity;\n}\n\n/**\n * This function gives the `id` of each wall that hides the room from a camera. A viewer makes these walls almost clear.\n *\n * A wall with one side to the room hides the room when the camera is on its other side.\n * A wall between two parts of a room hides the part behind it from each side.\n * `limit` is the depth of the hidden strip of the floor, in meters, above which a wall hides the room.\n */\nexport function hidingWalls(shades: readonly WallShade[], camera: Point3, limit: number = HIDDEN_LIMIT): ReadonlySet<string> {\n const hiding = new Set<string>();\n for (const { frame, inner } of shades) {\n const side = across(frame, camera);\n const cameraSide = side > frame.leftOffset ? \"left\" : side < frame.rightOffset ? \"right\" : undefined;\n if (cameraSide === undefined || cameraSide === inner) continue;\n if (hiddenDepth(frame, camera) > limit) hiding.add(frame.id);\n }\n return hiding;\n}\n","import type { Point3 } from \"@mark1russell7/layout-contract\";\nimport { CircleGeometry, Group, Mesh, MeshBasicMaterial, RingGeometry, type BufferGeometry } from \"three\";\nimport { LineMaterial } from \"three/addons/lines/LineMaterial.js\";\nimport { LineSegments2 } from \"three/addons/lines/LineSegments2.js\";\nimport { LineSegmentsGeometry } from \"three/addons/lines/LineSegmentsGeometry.js\";\nimport { levelShape, SHAPE_OUTLINES, type LevelShape, type LoadLevel } from \"../loads.ts\";\n\n/**\n * The marker of an outlet: a flat sign that looks at the camera and keeps its size in the picture.\n * The plate of an outlet is too small for a person to find it in a room, so each outlet has a marker.\n */\nexport interface OutletMarker {\n /** The group of the marker, at the center of the plate of the outlet, in the space of the viewer. */\n readonly root: Group;\n /** The line around the sign. The pointer selects the marker by this mesh, because it is the larger mesh. */\n readonly back: Mesh<BufferGeometry, MeshBasicMaterial>;\n /** The sign: its shape and its color tell the level of the circuit of the outlet. */\n readonly front: Mesh<BufferGeometry, MeshBasicMaterial>;\n readonly shape: LevelShape;\n /** The radius of the sign in the picture, in CSS pixels. The viewer changes it. */\n radius: number;\n /** This value is true while a solid is between the camera and the outlet. The viewer changes it. */\n hidden: boolean;\n}\n\n/** A link from an outlet to a placed object that takes its power from the outlet. */\nexport interface PowerLink {\n /** The name of the record of the outlet. */\n readonly outlet: string;\n /** The name of the record of the placed object. */\n readonly object: string;\n /** The level of the circuit of the outlet. */\n readonly level: LoadLevel | undefined;\n readonly line: LineSegments2;\n}\n\n/** The radius of the sign of a marker with no mark, in CSS pixels. */\nexport const MARKER_RADIUS = 7;\n\n/** The width of the line around a sign, as a part of the radius of the disc. */\nconst HALO_WIDTH = 0.36;\n\n/** The three.js objects of a marker and of a link are above the solids in the sequence of the drawing. */\nconst LINK_ORDER = 9;\nconst MARKER_ORDER = 10;\n\n/**\n * This function gives the factor between a sign and the line around it.\n * The line has the same width around each shape, so a shape with a small circle in it gets a larger factor.\n */\nexport function haloScale(shape: LevelShape): number {\n const { radius, sides } = SHAPE_OUTLINES[shape];\n return 1 + HALO_WIDTH / (radius * Math.cos(Math.PI / sides));\n}\n\n/** This function makes the geometry of the outline of a shape, in the plane of x and y, with its center at the origin. */\nfunction outlineGeometry(shape: LevelShape): BufferGeometry {\n const { radius, sides, start } = SHAPE_OUTLINES[shape];\n return new CircleGeometry(radius, sides, start);\n}\n\n/** This function makes the geometry of the sign of a shape. A sign with a hole is a ring, and each other sign is its outline. */\nfunction signGeometry(shape: LevelShape): BufferGeometry {\n const { radius, sides, start, hole } = SHAPE_OUTLINES[shape];\n return hole > 0 ? new RingGeometry(hole, radius, sides, 1, start) : outlineGeometry(shape);\n}\n\n/** This function makes a material that the solids do not hide. */\nfunction overlayMaterial(): MeshBasicMaterial {\n return new MeshBasicMaterial({ transparent: true, depthTest: false, depthWrite: false });\n}\n\n/**\n * This function makes the marker of an outlet at a point of the space of the viewer.\n * The marker has no colors until `paintPart` gives them, and the viewer gives it its size and its turn for each picture.\n */\nexport function makeMarker(at: Point3, level: LoadLevel | undefined): OutletMarker {\n const shape = levelShape(level);\n const root = new Group();\n root.position.set(at.x, at.y, at.z);\n const back = new Mesh(outlineGeometry(shape), overlayMaterial());\n back.scale.setScalar(haloScale(shape));\n const front = new Mesh(signGeometry(shape), overlayMaterial());\n // The line is before the sign in the group. Thus two objects at one distance draw in this sequence.\n back.renderOrder = MARKER_ORDER;\n front.renderOrder = MARKER_ORDER;\n root.add(back, front);\n return { root, back, front, shape, radius: MARKER_RADIUS, hidden: false };\n}\n\n/** This function makes the line of a link between two points of the space of the viewer. The line shows only when the viewer says so. */\nexport function makeLink(outlet: string, object: string, level: LoadLevel | undefined, from: Point3, to: Point3): PowerLink {\n const geometry = new LineSegmentsGeometry().setPositions([from.x, from.y, from.z, to.x, to.y, to.z]);\n const material = new LineMaterial({ linewidth: 2, dashed: true, dashSize: 0.09, gapSize: 0.06, transparent: true, depthTest: false, depthWrite: false });\n const line = new LineSegments2(geometry, material);\n line.computeLineDistances();\n line.renderOrder = LINK_ORDER;\n line.visible = false;\n return { outlet, object, level, line };\n}\n\n/** This function releases the memory of the graphics card that a marker uses. */\nexport function disposeMarker(marker: OutletMarker): void {\n marker.back.geometry.dispose();\n marker.back.material.dispose();\n marker.front.geometry.dispose();\n marker.front.material.dispose();\n marker.root.clear();\n}\n\n/** This function releases the memory of the graphics card that a link uses. */\nexport function disposeLink(link: PowerLink): void {\n link.line.geometry.dispose();\n link.line.material.dispose();\n}\n","import type { Point3 } from \"@mark1russell7/layout-contract\";\n\n/**\n * The direction of a view: where the camera is, as seen from the point that it looks at.\n * The viewer has the y axis up. The x axis is the x axis of the plan, and the negative z axis is the y axis of the plan.\n */\nexport interface ViewAngles {\n /** The angle from the up axis to the camera, in radians. At 0, the camera looks down from above. */\n readonly polar: number;\n /** The angle around the up axis, in radians. At 0, the camera is south of the room and it looks north. */\n readonly azimuth: number;\n}\n\n/** The view of a dollhouse: from the south-east, 38 degrees above the floor. */\nexport const HOME_VIEW: ViewAngles = { polar: (52 * Math.PI) / 180, azimuth: (35 * Math.PI) / 180 };\n\n/** The view of a plan: from above, with north at the top. */\nexport const TOP_VIEW: ViewAngles = { polar: 0, azimuth: 0 };\n\n/** The three axes of a camera, as unit vectors in the space of the viewer. */\nexport interface ViewAxes {\n /** The vector from the point that the camera looks at to the camera. */\n readonly back: Point3;\n /** The vector to the right side of the picture. */\n readonly right: Point3;\n /** The vector to the top of the picture. */\n readonly up: Point3;\n}\n\n/** This function gives a point of the room in the space of the viewer: the z axis of the room becomes the y axis. */\nexport function toViewer(point: Point3): Point3 {\n return { x: point.x, y: point.z, z: 0 - point.y };\n}\n\n/** This function gives a point of the viewer in the space of the room: the y axis of the viewer becomes the z axis. */\nexport function toRoom(point: Point3): Point3 {\n return { x: point.x, y: 0 - point.z, z: point.y };\n}\n\n/** This function gives the axes of the camera of a view. At a polar angle of 0, the top of the picture is north. */\nexport function viewAxes(view: ViewAngles): ViewAxes {\n const sinPolar = Math.sin(view.polar);\n const cosPolar = Math.cos(view.polar);\n const sinAzimuth = Math.sin(view.azimuth);\n const cosAzimuth = Math.cos(view.azimuth);\n return {\n back: { x: sinPolar * sinAzimuth, y: cosPolar, z: sinPolar * cosAzimuth },\n right: { x: cosAzimuth, y: 0, z: 0 - sinAzimuth },\n up: { x: 0 - cosPolar * sinAzimuth, y: sinPolar, z: 0 - cosPolar * cosAzimuth },\n };\n}\n\n/** This function gives the dot product of the vector from `origin` to `point` with `axis`. */\nfunction along(point: Point3, origin: Point3, axis: Point3): number {\n return (point.x - origin.x) * axis.x + (point.y - origin.y) * axis.y + (point.z - origin.z) * axis.z;\n}\n\n/**\n * This function gives the smallest distance from `target` at which a camera shows each point.\n *\n * The camera looks at `target` along the direction of `view`. `fov` is the vertical angle of the picture in degrees,\n * and `aspect` is the width of the picture divided by its height. The points and the target are in the space of the viewer.\n * The function gives 0 for no points, and for an angle or an aspect that makes no picture.\n */\nexport function fitDistance(points: readonly Point3[], target: Point3, view: ViewAngles, fov: number, aspect: number): number {\n const tanUp = Math.tan((fov * Math.PI) / 360);\n const tanRight = tanUp * aspect;\n if (!(tanUp > 0) || !(tanRight > 0) || !Number.isFinite(tanRight)) return 0;\n const axes = viewAxes(view);\n let distance = 0;\n for (const point of points) {\n const depth = along(point, target, axes.back);\n const needed = Math.max(Math.abs(along(point, target, axes.right)) / tanRight, Math.abs(along(point, target, axes.up)) / tanUp);\n distance = Math.max(distance, depth + needed);\n }\n return distance;\n}\n\n/** This function gives the position of a camera at a distance from `target`, in the direction of `view`. */\nexport function cameraPosition(target: Point3, view: ViewAngles, distance: number): Point3 {\n const { back } = viewAxes(view);\n return { x: target.x + back.x * distance, y: target.y + back.y * distance, z: target.z + back.z * distance };\n}\n\n/** This function gives the angles of the view from `target` to a camera, and the distance between them. A camera at the target gives the angles 0. */\nexport function viewOf(camera: Point3, target: Point3): ViewAngles & { readonly distance: number } {\n const x = camera.x - target.x;\n const y = camera.y - target.y;\n const z = camera.z - target.z;\n const distance = Math.hypot(x, y, z);\n if (!(distance > 0)) return { polar: 0, azimuth: 0, distance: 0 };\n return { polar: Math.acos(Math.min(Math.max(y / distance, -1), 1)), azimuth: Math.atan2(x, z), distance };\n}\n\n/** This function gives the angle between two azimuths along the shortest way, from −π to π. */\nexport function turnBetween(from: number, to: number): number {\n const full = 2 * Math.PI;\n const turn = (((to - from) % full) + full) % full;\n return turn > Math.PI ? turn - full : turn;\n}\n","import type { Point3 } from \"@mark1russell7/layout-contract\";\nimport { Color, EdgesGeometry, Group, Mesh, MeshLambertMaterial, type BufferGeometry, type Material } from \"three\";\nimport { LineMaterial } from \"three/addons/lines/LineMaterial.js\";\nimport { LineSegments2 } from \"three/addons/lines/LineSegments2.js\";\nimport { LineSegmentsGeometry } from \"three/addons/lines/LineSegmentsGeometry.js\";\nimport { outletLevels, type LoadLevel, type LoadOptions } from \"../loads.ts\";\nimport type { Scene } from \"../room.ts\";\nimport { boundsOfSolids, sceneSolids, solidCorners, TO_Y_UP, type Solid, type SolidKind, type SolidOptions } from \"../solids.ts\";\nimport { metersPer } from \"../units.ts\";\nimport { wallShades, type WallShade } from \"./fade.ts\";\nimport { solidGeometry } from \"./geometry.ts\";\nimport { disposeLink, disposeMarker, makeLink, makeMarker, MARKER_RADIUS, type OutletMarker, type PowerLink } from \"./markers.ts\";\nimport type { ViewerTheme } from \"./theme.ts\";\nimport { toViewer } from \"./view.ts\";\n\n/** The mark of a part: 0 for no mark, 1 for a part under the pointer, 2 for a selected part. */\nexport type PartMark = 0 | 1 | 2;\n\n/** One solid of the model as three.js objects. */\nexport interface ModelPart {\n readonly solid: Solid;\n /** The name of the record of the solid: its kind and its source. Each part of one wall has the same name. */\n readonly record: string;\n /** The `id` of the wall that the part fades with: the wall itself, the wall of a window or the wall of an outlet. */\n readonly wall: string | undefined;\n /** The name of the record of the object that this object is in or on. */\n readonly holder: string | undefined;\n /** This value is true for an object with other objects in it. Such an object shows as a clear box. */\n readonly holds: boolean;\n /** The level of the circuit of an outlet. An outlet with no circuit has no level, and so has each other part. */\n readonly level: LoadLevel | undefined;\n /** The marker of an outlet. */\n readonly marker: OutletMarker | undefined;\n readonly mesh: Mesh<BufferGeometry, MeshLambertMaterial>;\n readonly lines: LineSegments2;\n /** The fade of the part, from 0 for a solid part to 1 for a part that hides the room. The viewer changes it. */\n fade: number;\n}\n\n/** The model of a scene as three.js objects. */\nexport interface RoomModel {\n /** The group of each part. It has the rotation from the room to the space of the viewer. */\n readonly group: Group;\n /** The group of the markers and the links, in the space of the viewer. The solids do not hide them. */\n readonly overlay: Group;\n readonly parts: readonly ModelPart[];\n /** The link from each outlet to each placed object that takes its power from the outlet. */\n readonly links: readonly PowerLink[];\n /** Each corner of each solid, in the space of the viewer. */\n readonly corners: readonly Point3[];\n /** The center of the model, in the space of the viewer. */\n readonly center: Point3;\n /** The walls of the room, each with the side that looks at the room. */\n readonly shades: readonly WallShade[];\n}\n\n/** This function gives the name of a record of a kind. */\nexport function recordName(kind: SolidKind, source: string): string {\n return `${kind}:${source}`;\n}\n\n/** The width of the edges of each kind of solid, in CSS pixels. */\nconst EDGE_WIDTH: Readonly<Record<SolidKind, number>> = { floor: 1.25, wall: 1.25, glass: 1, outlet: 1, object: 1.25 };\n\n/** The part of a clear box of objects that is not clear. */\nconst HOLDER_OPACITY = 0.14;\n\n/** A part with an opacity above this value writes its depth, as a solid part does. */\nconst SOLID_OPACITY = 0.999;\n\n/** This function gives the `id` of each placed object that has an object in its box. */\nfunction holders(scene: Scene): ReadonlySet<string> {\n const scale = metersPer(scene.room.unit);\n const objects = new Map((scene.objects ?? []).map((object) => [object.id, object] as const));\n const found = new Set<string>();\n for (const object of scene.objects ?? []) {\n const parent = object.parent === undefined ? undefined : objects.get(object.parent);\n if (parent === undefined) continue;\n const x = object.at[0] * scale;\n const y = object.at[1] * scale;\n const z = ((object.lift ?? 0) + object.size[2] / 2) * scale;\n const [w, h, d] = [parent.size[0] * scale, parent.size[1] * scale, parent.size[2] * scale];\n if (Math.abs(x) < w / 2 && Math.abs(y) < h / 2 && z > 0 && z < d) found.add(parent.id);\n }\n return found;\n}\n\n/**\n * This function makes the three.js objects of a scene: one mesh with its edges for each solid.\n * Each outlet has a marker, and each placed object with an outlet has a link to it.\n * The parts have no colors until `paintPart` gives them. The caller disposes the model with `disposeModel`.\n */\nexport function buildModel(scene: Scene, options: SolidOptions = {}, loads: LoadOptions = {}): RoomModel {\n const solids = sceneSolids(scene, options);\n const levels = outletLevels(scene, loads);\n const wallOfOpening = new Map((scene.room.openings ?? []).map((opening) => [opening.id, opening.wall] as const));\n const wallOfOutlet = new Map((scene.room.outlets ?? []).map((outlet) => [outlet.id, outlet.wall] as const));\n const parentOf = new Map((scene.objects ?? []).map((object) => [object.id, object.parent] as const));\n const holding = holders(scene);\n const group = new Group();\n const overlay = new Group();\n const centers = new Map<string, Point3>();\n group.quaternion.set(TO_Y_UP.rotation.x, TO_Y_UP.rotation.y, TO_Y_UP.rotation.z, TO_Y_UP.rotation.w);\n const parts = solids.map((solid): ModelPart => {\n const { geometry, position, rotation } = solidGeometry(solid);\n const mesh = new Mesh(geometry, new MeshLambertMaterial({ polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 }));\n mesh.position.set(position.x, position.y, position.z);\n mesh.quaternion.set(rotation.x, rotation.y, rotation.z, rotation.w);\n const edges = new EdgesGeometry(geometry, 30);\n const lines = new LineSegments2(new LineSegmentsGeometry().fromEdgesGeometry(edges), new LineMaterial({ linewidth: EDGE_WIDTH[solid.kind] }));\n edges.dispose();\n mesh.add(lines);\n group.add(mesh);\n const parent = solid.kind === \"object\" ? parentOf.get(solid.source) : undefined;\n const record = recordName(solid.kind, solid.source);\n const center = toViewer(centerOf(solid));\n centers.set(record, center);\n const level = solid.kind === \"outlet\" ? levels.get(solid.source) : undefined;\n const marker = solid.kind === \"outlet\" ? makeMarker(center, level) : undefined;\n if (marker !== undefined) overlay.add(marker.root);\n return {\n solid,\n record,\n wall: solid.kind === \"wall\" ? solid.source : solid.kind === \"glass\" ? wallOfOpening.get(solid.source) : solid.kind === \"outlet\" ? wallOfOutlet.get(solid.source) : undefined,\n holder: parent === undefined ? undefined : recordName(\"object\", parent),\n holds: solid.kind === \"object\" && holding.has(solid.source),\n level,\n marker,\n mesh,\n lines,\n fade: 0,\n };\n });\n const links: PowerLink[] = [];\n for (const object of scene.objects ?? []) {\n if (object.outlet === undefined) continue;\n const outlet = recordName(\"outlet\", object.outlet);\n const user = recordName(\"object\", object.id);\n const from = centers.get(outlet);\n const to = centers.get(user);\n if (from === undefined || to === undefined) continue;\n const link = makeLink(outlet, user, levels.get(object.outlet), from, to);\n overlay.add(link.line);\n links.push(link);\n }\n const bounds = boundsOfSolids(solids);\n const middle = bounds === undefined ? { x: 0, y: 0, z: 0 } : { x: bounds.x + bounds.w / 2, y: bounds.y + bounds.h / 2, z: bounds.z + bounds.d / 2 };\n return {\n group,\n overlay,\n parts,\n links,\n corners: solids.flatMap((solid) => solidCorners(solid).map((corner) => toViewer(corner))),\n center: toViewer(middle),\n shades: wallShades(scene.room, bounds === undefined ? undefined : middle),\n };\n}\n\n/** This function gives the center of a solid, in the frame of the room: the mean of its corners. */\nfunction centerOf(solid: Solid): Point3 {\n const corners = solidCorners(solid);\n const sum = corners.reduce((total, corner) => ({ x: total.x + corner.x, y: total.y + corner.y, z: total.z + corner.z }), { x: 0, y: 0, z: 0 });\n const count = Math.max(corners.length, 1);\n return { x: sum.x / count, y: sum.y / count, z: sum.z / count };\n}\n\n/** This function sets the opacity of a material. A material that is not solid does not write its depth. */\nfunction setOpacity(material: Material, opacity: number): void {\n const clear = opacity < SOLID_OPACITY;\n if (material.transparent !== clear) {\n material.transparent = clear;\n material.depthWrite = !clear;\n material.needsUpdate = true;\n }\n material.opacity = opacity;\n}\n\n/** This function gives the color of a part in a theme, before a mark. */\nfunction baseColor(part: ModelPart, scene: Scene, theme: ViewerTheme): string {\n const kind = part.solid.kind;\n if (kind === \"outlet\") return part.level === undefined ? theme.outlet : theme.levels[part.level];\n if (kind !== \"object\") return theme[kind];\n const object = (scene.objects ?? []).find((candidate) => candidate.id === part.solid.source);\n return (object === undefined ? undefined : theme.objects[object.kind]) ?? theme.object;\n}\n\n/**\n * This function gives a part its colors: the colors of the theme, the fade of the part and its mark.\n * A marked part has some of the color `accent` of the theme, and a selected part has wide edges.\n * An outlet has the color of the level of its circuit, and its marker has the same color.\n */\nexport function paintPart(part: ModelPart, scene: Scene, theme: ViewerTheme, mark: PartMark): void {\n const kind = part.solid.kind;\n const fill = part.mesh.material;\n const ink = part.lines.material;\n const color = baseColor(part, scene, theme);\n fill.color.set(color);\n if (mark !== 0) fill.color.lerp(new Color(theme.accent), mark === 2 ? 0.55 : 0.3);\n ink.color.set(theme.edge);\n ink.linewidth = EDGE_WIDTH[kind] * (mark === 2 ? 2 : 1);\n const still = 1 - part.fade;\n let opacity = kind === \"glass\" ? theme.glassOpacity : part.holds ? (mark === 0 ? HOLDER_OPACITY : 0.45) : 1;\n let edge = 1;\n if (kind === \"wall\") {\n opacity *= 0.08 + 0.92 * still;\n edge = 0.3 + 0.7 * still;\n } else if (kind === \"glass\" || kind === \"outlet\") {\n opacity *= 0.35 + 0.65 * still;\n edge = 0.35 + 0.65 * still;\n }\n setOpacity(fill, opacity);\n setOpacity(ink, edge);\n if (part.marker !== undefined) paintMarker(part.marker, color, theme, mark, still);\n}\n\n/** The part of a marker that is not clear while a solid hides its outlet. */\nconst HIDDEN_MARKER = 0.45;\n\n/** This function gives a marker its colors and its size. `still` is 1 for a marker on a solid wall and 0 on a clear wall. */\nfunction paintMarker(marker: OutletMarker, color: string, theme: ViewerTheme, mark: PartMark, still: number): void {\n marker.front.material.color.set(color);\n marker.back.material.color.set(mark === 0 ? theme.halo : theme.accent);\n // A marker with a mark is always solid, so that a person finds the outlet behind a wall or a machine.\n const opacity = mark === 0 ? (0.35 + 0.65 * still) * (marker.hidden ? HIDDEN_MARKER : 1) : 1;\n marker.front.material.opacity = opacity;\n marker.back.material.opacity = opacity;\n marker.radius = MARKER_RADIUS * (mark === 2 ? 1.3 : mark === 1 ? 1.15 : 1);\n}\n\n/** This function gives a link the color of the level of its circuit, and shows it or hides it. */\nexport function paintLink(link: PowerLink, theme: ViewerTheme, visible: boolean): void {\n link.line.material.color.set(link.level === undefined ? theme.outlet : theme.levels[link.level]);\n link.line.visible = visible;\n}\n\n/** This function releases the memory of the graphics card that a model uses. */\nexport function disposeModel(model: RoomModel): void {\n for (const part of model.parts) {\n part.mesh.geometry.dispose();\n part.mesh.material.dispose();\n part.lines.geometry.dispose();\n part.lines.material.dispose();\n if (part.marker !== undefined) disposeMarker(part.marker);\n }\n for (const link of model.links) disposeLink(link);\n model.group.clear();\n model.overlay.clear();\n}\n","import type { Point3 } from \"@mark1russell7/layout-contract\";\nimport { DirectionalLight, HemisphereLight, PerspectiveCamera, Raycaster, Scene as World, Vector2, Vector3, WebGLRenderer, type Object3D } from \"three\";\nimport { OrbitControls } from \"three/addons/controls/OrbitControls.js\";\nimport type { LoadOptions } from \"../loads.ts\";\nimport type { Scene } from \"../room.ts\";\nimport type { SolidKind, SolidOptions } from \"../solids.ts\";\nimport { hidingWalls } from \"./fade.ts\";\nimport { buildModel, disposeModel, paintLink, paintPart, recordName, type ModelPart, type PartMark, type RoomModel } from \"./model.ts\";\nimport { LIGHT_THEME, type ViewerTheme } from \"./theme.ts\";\nimport { cameraPosition, fitDistance, HOME_VIEW, TOP_VIEW, toRoom, turnBetween, viewOf, type ViewAngles } from \"./view.ts\";\n\n/** A record of a scene that the viewer shows: a floor, a wall, a window, an outlet or a placed object. */\nexport interface ViewerRecord {\n /** The kind of the solids of the record. A window has the kind `glass`. */\n readonly kind: SolidKind;\n /** The `id` of the record in the scene. */\n readonly source: string;\n}\n\n/** The solid under the pointer, with its record. */\nexport interface ViewerPick extends ViewerRecord {\n /** The `id` of the solid. A wall with openings has more than one solid. */\n readonly solid: string;\n}\n\n/** The name of a view: `home` looks into the room from a corner above it, and `top` shows the plan. */\nexport type ViewName = \"home\" | \"top\";\n\n/** The options of a viewer. */\nexport interface RoomViewerOptions {\n readonly scene: Scene;\n /** The colors. The default is `LIGHT_THEME`. */\n readonly theme?: ViewerTheme | undefined;\n /** The options of the model. */\n readonly solids?: SolidOptions | undefined;\n /** The options of the levels of the circuits. */\n readonly loads?: LoadOptions | undefined;\n /** The name of the picture for a screen reader. */\n readonly label?: string | undefined;\n /** The viewer starts this function when the pointer goes to a different record, or to no record. */\n readonly onHover?: ((pick: ViewerPick | undefined) => void) | undefined;\n /** The viewer starts this function when a person selects a record with the pointer, or selects no record. */\n readonly onSelect?: ((pick: ViewerPick | undefined) => void) | undefined;\n}\n\n/** A viewer of one scene in a page. */\nexport interface RoomViewer {\n /** The canvas of the viewer. It is in the container. */\n readonly canvas: HTMLCanvasElement;\n /** This function shows a different scene. The view stays if a person moved it. */\n setScene(scene: Scene): void;\n /** This function changes the colors. */\n setTheme(theme: ViewerTheme): void;\n /** This function moves the camera to a view that shows all of the model. */\n setView(view: ViewName): void;\n /** This function marks records, as the pointer does. An empty list removes the marks. */\n highlight(records: readonly ViewerRecord[]): void;\n /** This function selects one record, or no record. It does not start `onSelect`. */\n select(record: ViewerRecord | undefined): void;\n /** This function removes the canvas and releases the memory of the graphics card. */\n dispose(): void;\n}\n\n/** The vertical angle of the picture, in degrees. A small angle gives the look of a drawing. */\nconst FIELD_OF_VIEW = 32;\n\n/** The space around the model in a view that shows all of it, as a factor of the distance. */\nconst MARGIN = 1.06;\n\n/** The time of the move between two views, in milliseconds. */\nconst MOVE_TIME = 380;\n\n/** The time in which a wall goes most of the way to clear or to solid, in seconds. */\nconst FADE_TIME = 0.11;\n\n/** A pointer that moves less than this distance between down and up is a click, in CSS pixels. */\nconst CLICK_DISTANCE = 4;\n\n/** The angle of one step of an arrow key, in radians. */\nconst KEY_TURN = Math.PI / 24;\n\n/** The smallest polar angle. At 0, the azimuth of a camera has no meaning. */\nconst SMALLEST_POLAR = 0.0005;\n\n/** The largest polar angle: the camera stays above the floor. */\nconst LARGEST_POLAR = Math.PI / 2 - 0.05;\n\n/** A solid hides a marker when it is this distance or more before the outlet, in meters. */\nconst SIGHT_MARGIN = 0.06;\n\n/** A place of the camera: the point that it looks at, the angles and the distance. */\ninterface Place extends ViewAngles {\n readonly target: Point3;\n readonly distance: number;\n}\n\n/** A move of the camera from one place to a different place. */\ninterface Move {\n readonly from: Place;\n readonly to: Place;\n readonly start: number;\n}\n\n/** This function tells if the person asks for less motion. */\nfunction lessMotion(): boolean {\n return typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\n\n/**\n * This function makes a viewer of a scene in a container of a page. The viewer fills the container, so give the container a size.\n *\n * A person turns the model with a drag, and moves nearer with the wheel after a click in the picture.\n * The walls between the camera and the room become almost clear. A click selects the record of a solid.\n * Each outlet has a marker with the color and the shape of the level of its circuit. A marker keeps its size in the picture.\n * A marked outlet or object shows a line from the outlet to each object that takes its power from it.\n * With the keyboard, the arrow keys turn the model, `+` and `-` change the distance, `Home` shows the first view and `T` shows the plan.\n *\n * The function gives `undefined` when the browser has no WebGL 2. It does not throw, and it writes no error to the console.\n */\nexport function createRoomViewer(container: HTMLElement, options: RoomViewerOptions): RoomViewer | undefined {\n const canvas = container.ownerDocument.createElement(\"canvas\");\n const context = canvas.getContext(\"webgl2\", { alpha: true, antialias: true, depth: true, stencil: false, premultipliedAlpha: true, powerPreference: \"default\" });\n if (context === null) return undefined;\n let renderer: WebGLRenderer;\n try {\n renderer = new WebGLRenderer({ canvas, context, alpha: true, antialias: true });\n } catch {\n return undefined;\n }\n renderer.setClearColor(0x000000, 0);\n\n canvas.style.display = \"block\";\n canvas.style.width = \"100%\";\n canvas.style.height = \"100%\";\n canvas.style.cursor = \"grab\";\n canvas.tabIndex = 0;\n canvas.setAttribute(\"role\", \"application\");\n canvas.setAttribute(\"aria-label\", options.label ?? \"3D model of the room\");\n container.append(canvas);\n\n const world = new World();\n const sky = new HemisphereLight(\"#ffffff\", \"#ffffff\", 2.2);\n const sun = new DirectionalLight(\"#ffffff\", 1.5);\n sun.position.set(-10, 24, 15);\n world.add(sky, sun);\n const camera = new PerspectiveCamera(FIELD_OF_VIEW, 1, 0.05, 1000);\n\n let scene = options.scene;\n let theme = options.theme ?? LIGHT_THEME;\n let model: RoomModel = buildModel(scene, options.solids, options.loads);\n world.add(model.group, model.overlay);\n\n let hovered: string | undefined;\n let selected: string | undefined;\n let marked: ReadonlySet<string> = new Set();\n let hiding: ReadonlySet<string> = new Set();\n let view: ViewName = \"home\";\n let move: Move | undefined;\n /** This value is true after a person moved the view. Then a new size of the container does not move the camera. */\n let moved = false;\n /** The height of the picture, in CSS pixels. */\n let viewHeight = 1;\n let frame = 0;\n let lastTime = 0;\n let disposed = false;\n\n const invalidate = (): void => {\n if (frame === 0 && !disposed) frame = requestAnimationFrame(tick);\n };\n\n const controls = new OrbitControls(camera, canvas);\n controls.enableDamping = !lessMotion();\n controls.dampingFactor = 0.14;\n controls.maxPolarAngle = LARGEST_POLAR;\n controls.rotateSpeed = 0.9;\n controls.screenSpacePanning = true;\n // The wheel moves the page until a person uses the picture. Thus the picture does not stop a person who reads down the page.\n controls.enableZoom = false;\n\n const markOfRecord = (record: string): PartMark => (record === selected ? 2 : record === hovered || marked.has(record) ? 1 : 0);\n const markOf = (part: ModelPart): PartMark => markOfRecord(part.record);\n const paintAll = (): void => {\n for (const part of model.parts) paintPart(part, scene, theme, markOf(part));\n // A link shows while its outlet or its object has a mark.\n for (const link of model.links) paintLink(link, theme, markOfRecord(link.outlet) !== 0 || markOfRecord(link.object) !== 0);\n invalidate();\n };\n const pickOf = (part: ModelPart): ViewerPick => ({ solid: part.solid.id, kind: part.solid.kind, source: part.solid.source });\n\n const place = (to: Place): void => {\n const polar = Math.min(Math.max(to.polar, SMALLEST_POLAR), LARGEST_POLAR);\n const distance = Math.min(Math.max(to.distance, controls.minDistance), controls.maxDistance);\n const eye = cameraPosition(to.target, { polar, azimuth: to.azimuth }, distance);\n controls.target.set(to.target.x, to.target.y, to.target.z);\n camera.position.set(eye.x, eye.y, eye.z);\n camera.lookAt(controls.target);\n };\n const placeNow = (): Place => {\n const target = { x: controls.target.x, y: controls.target.y, z: controls.target.z };\n return { target, ...viewOf(camera.position, target) };\n };\n const fit = (name: ViewName): Place => {\n const angles = name === \"top\" ? TOP_VIEW : HOME_VIEW;\n const distance = fitDistance(model.corners, model.center, angles, FIELD_OF_VIEW, camera.aspect) * MARGIN;\n return { target: model.center, ...angles, distance: distance > 0 ? distance : 10 };\n };\n /** This function sets the nearest and the farthest distance of the camera from the size of the model. */\n const setLimits = (): void => {\n const far = Math.max(fit(\"home\").distance, fit(\"top\").distance);\n controls.minDistance = 0.4;\n controls.maxDistance = far * 3;\n camera.far = far * 8 + 100;\n camera.updateProjectionMatrix();\n };\n /**\n * This function stops the turn that continues after a drag. The camera stays where it is.\n * Without it, the camera continues to turn after a move to a view, and the view is not exact.\n */\n const stopDrift = (): void => {\n if (!controls.enableDamping) return;\n const now = placeNow();\n // With no damping, an update of the controls uses all of the turn that remains. The camera then goes back.\n controls.enableDamping = false;\n controls.update();\n controls.enableDamping = true;\n place(now);\n };\n const goTo = (name: ViewName, animate: boolean): void => {\n view = name;\n moved = false;\n stopDrift();\n const to = fit(name);\n if (animate && !lessMotion()) {\n move = { from: placeNow(), to, start: performance.now() };\n } else {\n move = undefined;\n place(to);\n }\n invalidate();\n };\n\n /** This function sets the size of the picture from the size of the container. It gives false for a container with no size. */\n const setSize = (): boolean => {\n const width = container.clientWidth;\n const height = container.clientHeight;\n if (width === 0 || height === 0) return false;\n viewHeight = height;\n renderer.setPixelRatio(Math.min(globalThis.devicePixelRatio, 2));\n renderer.setSize(width, height, false);\n camera.aspect = width / height;\n camera.updateProjectionMatrix();\n return true;\n };\n\n /** This function moves the camera one step of a move between two views. It gives true while the move continues. */\n const stepMove = (now: number): boolean => {\n if (move === undefined) return false;\n const { from, to } = move;\n const part = Math.min(Math.max((now - move.start) / MOVE_TIME, 0), 1);\n const eased = part < 0.5 ? 4 * part * part * part : 1 - (-2 * part + 2) ** 3 / 2;\n const between = (a: number, b: number): number => a + (b - a) * eased;\n place({\n target: { x: between(from.target.x, to.target.x), y: between(from.target.y, to.target.y), z: between(from.target.z, to.target.z) },\n polar: between(from.polar, to.polar),\n azimuth: from.azimuth + turnBetween(from.azimuth, to.azimuth) * eased,\n distance: between(from.distance, to.distance),\n });\n if (part >= 1) move = undefined;\n return true;\n };\n\n /**\n * This function moves the fade of each wall one step to its goal: clear for a wall that hides the room, solid for the others.\n * `seconds` is the time since the last picture, and 0 sets each goal immediately. It gives true while a wall changes.\n */\n const stepFade = (seconds: number): boolean => {\n hiding = hidingWalls(model.shades, toRoom(camera.position));\n const rate = seconds > 0 ? 1 - Math.exp(0 - seconds / FADE_TIME) : 1;\n let active = false;\n for (const part of model.parts) {\n if (part.wall === undefined) continue;\n const goal = hiding.has(part.wall) ? 1 : 0;\n if (part.fade === goal) continue;\n const next = part.fade + (goal - part.fade) * rate;\n part.fade = Math.abs(goal - next) < 0.01 ? goal : next;\n paintPart(part, scene, theme, markOf(part));\n active = active || part.fade !== goal;\n }\n return active;\n };\n\n const sight = new Raycaster();\n const forward = new Vector3();\n const offset = new Vector3();\n /**\n * This function turns each marker to the camera and gives it its size in the picture.\n * It also finds each marker with a solid between the camera and its outlet: such a marker is less clear.\n */\n const stepOverlay = (): void => {\n const perPixel = (2 * Math.tan((FIELD_OF_VIEW * Math.PI) / 360)) / viewHeight;\n camera.getWorldDirection(forward);\n model.group.updateMatrixWorld();\n // Glass, a clear wall and a clear box of objects hide nothing.\n const blockers = model.parts\n .filter((part) => {\n const kind = part.solid.kind;\n return kind === \"floor\" || (kind === \"wall\" && !hiding.has(part.solid.source)) || (kind === \"object\" && !part.holds);\n })\n .map((part) => part.mesh);\n for (const part of model.parts) {\n const marker = part.marker;\n if (marker === undefined) continue;\n offset.subVectors(marker.root.position, camera.position);\n const distance = offset.length();\n marker.root.quaternion.copy(camera.quaternion);\n marker.root.scale.setScalar(Math.max(offset.dot(forward), 0.01) * perPixel * marker.radius);\n sight.set(camera.position, offset.divideScalar(Math.max(distance, 1e-9)));\n sight.far = distance - SIGHT_MARGIN;\n const hidden = sight.far > 0 && sight.intersectObjects(blockers, false).length > 0;\n if (hidden === marker.hidden) continue;\n marker.hidden = hidden;\n paintPart(part, scene, theme, markOf(part));\n }\n };\n\n function tick(now: number): void {\n frame = 0;\n if (disposed) return;\n const seconds = lastTime === 0 ? 1 / 60 : Math.min((now - lastTime) / 1000, 0.1);\n let active = stepMove(now);\n active = controls.update() || active;\n active = stepFade(lessMotion() ? 0 : seconds) || active;\n stepOverlay();\n renderer.render(world, camera);\n lastTime = active ? now : 0;\n if (active) invalidate();\n }\n\n const raycaster = new Raycaster();\n const pointer = new Vector2();\n /**\n * This function gives the part under a pointer. A wall that hides the room is clear, and the pointer goes through it.\n * The marker of an outlet is above each solid in the picture, so the pointer selects a marker first.\n */\n const partAt = (event: PointerEvent): ModelPart | undefined => {\n const box = canvas.getBoundingClientRect();\n if (box.width === 0 || box.height === 0) return undefined;\n pointer.set(((event.clientX - box.left) / box.width) * 2 - 1, 1 - ((event.clientY - box.top) / box.height) * 2);\n raycaster.setFromCamera(pointer, camera);\n const bySign = new Map<Object3D, ModelPart>();\n for (const part of model.parts) if (part.marker !== undefined) bySign.set(part.marker.back, part);\n const sign = raycaster.intersectObjects([...bySign.keys()], false)[0];\n if (sign !== undefined) return bySign.get(sign.object);\n const open = model.parts.filter((part) => part.wall === undefined || !hiding.has(part.wall));\n const byMesh = new Map<Object3D, ModelPart>(open.map((part) => [part.mesh, part]));\n const hits = raycaster.intersectObjects(\n open.map((part) => part.mesh),\n false,\n );\n const first = hits[0] === undefined ? undefined : byMesh.get(hits[0].object);\n if (first === undefined || !first.holds) return first;\n // A clear box of objects: the pointer selects an object in the box before the box.\n for (const hit of hits) {\n const part = byMesh.get(hit.object);\n if (part !== undefined && part.holder === first.record) return part;\n }\n return first;\n };\n\n const setHover = (part: ModelPart | undefined): void => {\n const record = part?.record;\n if (record === hovered) return;\n hovered = record;\n canvas.style.cursor = record === undefined ? \"grab\" : \"pointer\";\n paintAll();\n options.onHover?.(part === undefined ? undefined : pickOf(part));\n };\n\n const listeners = new AbortController();\n const signal = listeners.signal;\n let down: { readonly id: number; readonly x: number; readonly y: number } | undefined;\n const setInUse = (inUse: boolean): void => {\n controls.enableZoom = inUse;\n };\n canvas.addEventListener(\n \"pointerdown\",\n (event) => {\n setInUse(true);\n canvas.focus({ preventScroll: true });\n down = { id: event.pointerId, x: event.clientX, y: event.clientY };\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointermove\",\n (event) => {\n if (event.buttons === 0 && event.pointerType !== \"touch\") setHover(partAt(event));\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointerup\",\n (event) => {\n const start = down;\n down = undefined;\n if (start === undefined || start.id !== event.pointerId) return;\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) > CLICK_DISTANCE) return;\n const part = partAt(event);\n selected = part?.record;\n paintAll();\n options.onSelect?.(part === undefined ? undefined : pickOf(part));\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointercancel\",\n () => {\n down = undefined;\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointerleave\",\n (event) => {\n setHover(undefined);\n if (event.pointerType === \"mouse\") setInUse(false);\n },\n { signal },\n );\n canvas.addEventListener(\"blur\", () => setInUse(false), { signal });\n canvas.addEventListener(\n \"keydown\",\n (event) => {\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n const now = placeNow();\n let to: Place | undefined;\n if (event.key === \"ArrowLeft\") to = { ...now, azimuth: now.azimuth - KEY_TURN };\n else if (event.key === \"ArrowRight\") to = { ...now, azimuth: now.azimuth + KEY_TURN };\n else if (event.key === \"ArrowUp\") to = { ...now, polar: now.polar - KEY_TURN };\n else if (event.key === \"ArrowDown\") to = { ...now, polar: now.polar + KEY_TURN };\n else if (event.key === \"+\" || event.key === \"=\") to = { ...now, distance: now.distance * 0.85 };\n else if (event.key === \"-\" || event.key === \"_\") to = { ...now, distance: now.distance / 0.85 };\n else if (event.key === \"Home\" || event.key === \"0\") goTo(\"home\", true);\n else if (event.key === \"t\" || event.key === \"T\") goTo(\"top\", true);\n else return;\n event.preventDefault();\n setInUse(true);\n if (to === undefined) return;\n moved = true;\n move = undefined;\n place(to);\n invalidate();\n },\n { signal },\n );\n canvas.addEventListener(\"webglcontextlost\", (event) => event.preventDefault(), { signal });\n canvas.addEventListener(\"webglcontextrestored\", invalidate, { signal });\n\n controls.addEventListener(\"start\", () => {\n moved = true;\n move = undefined;\n canvas.style.cursor = \"grabbing\";\n invalidate();\n });\n controls.addEventListener(\"end\", () => {\n canvas.style.cursor = hovered === undefined ? \"grab\" : \"pointer\";\n });\n controls.addEventListener(\"change\", invalidate);\n\n const applyTheme = (): void => {\n sky.color.set(theme.sky);\n sky.groundColor.set(theme.ground);\n paintAll();\n };\n\n const observer = new ResizeObserver(() => {\n if (disposed || !setSize()) return;\n setLimits();\n if (!moved) goTo(view, false);\n invalidate();\n });\n\n setSize();\n setLimits();\n goTo(\"home\", false);\n stepFade(0);\n applyTheme();\n observer.observe(container);\n\n return {\n canvas,\n setScene(next: Scene): void {\n world.remove(model.group, model.overlay);\n disposeModel(model);\n scene = next;\n model = buildModel(scene, options.solids, options.loads);\n world.add(model.group, model.overlay);\n hovered = undefined;\n if (selected !== undefined && !model.parts.some((part) => part.record === selected)) selected = undefined;\n setLimits();\n if (!moved) goTo(view, false);\n stepFade(0);\n paintAll();\n },\n setTheme(next: ViewerTheme): void {\n theme = next;\n applyTheme();\n },\n setView(name: ViewName): void {\n goTo(name, true);\n },\n highlight(records: readonly ViewerRecord[]): void {\n marked = new Set(records.map((record) => recordName(record.kind, record.source)));\n paintAll();\n },\n select(record: ViewerRecord | undefined): void {\n selected = record === undefined ? undefined : recordName(record.kind, record.source);\n paintAll();\n },\n dispose(): void {\n if (disposed) return;\n disposed = true;\n cancelAnimationFrame(frame);\n observer.disconnect();\n listeners.abort();\n controls.dispose();\n world.remove(model.group, model.overlay);\n disposeModel(model);\n renderer.dispose();\n canvas.remove();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AAkBA,MAAM,cAAyB;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;;;;;;;AAQxD,SAAgB,cAAc,OAA8B;CAC1D,MAAM,QAAQ,MAAM;CACpB,IAAI,MAAM,SAAS,OAAO;EACxB,MAAM,EAAE,KAAK,cAAc;EAC3B,MAAM,SAAS;GAAE,GAAG,IAAI,IAAI,IAAI,IAAI;GAAG,GAAG,IAAI,IAAI,IAAI,IAAI;GAAG,GAAG,IAAI,IAAI,IAAI,IAAI;EAAE;EAClF,OAAO;GAAE,UAAU,IAAI,YAAY,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;GAAG,UAAU,gBAAgB,WAAW,MAAM;GAAG,UAAU,UAAU;EAAS;CACtI;CACA,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CACX,KAAK,MAAM,CAAC,GAAG,MAAM,MAAM,MAAM;EAC/B,OAAO,KAAK,IAAI,MAAM,CAAC;EACvB,OAAO,KAAK,IAAI,MAAM,CAAC;EACvB,OAAO,KAAK,IAAI,MAAM,CAAC;EACvB,OAAO,KAAK,IAAI,MAAM,CAAC;CACzB;CACA,MAAM,WAAW,OAAO,QAAQ;CAChC,MAAM,WAAW,OAAO,QAAQ;CAChC,MAAM,UAAU,IAAI,MAAM,MAAM,KAAK,KAAK,CAAC,GAAG,OAAO,IAAI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,GAAG,WAAW,KAAA;GAChG,UAAU;GACV,IAAI,CAAC,OAAO,KAAK,MAAM,KAAK;GAC5B,SAAS,CAAC;GACV,SAAS;EACX;EACA,SAAS,MAAyB;GAChC,QAAQ;GACR,WAAW;EACb;EACA,QAAQ,MAAsB;GAC5B,KAAK,MAAM,IAAI;EACjB;EACA,UAAU,SAAwC;GAChD,SAAS,IAAI,IAAI,QAAQ,KAAK,WAAW,WAAW,OAAO,MAAM,OAAO,MAAM,CAAC,CAAC;GAChF,SAAS;EACX;EACA,OAAO,QAAwC;GAC7C,WAAW,WAAW,KAAA,IAAY,KAAA,IAAY,WAAW,OAAO,MAAM,OAAO,MAAM;GACnF,SAAS;EACX;EACA,UAAgB;GACd,IAAI,UAAU;GACd,WAAW;GACX,qBAAqB,KAAK;GAC1B,SAAS,WAAW;GACpB,UAAU,MAAM;GAChB,SAAS,QAAQ;GACjB,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO;GACvC,aAAa,KAAK;GAClB,SAAS,QAAQ;GACjB,OAAO,OAAO;EAChB;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/room-view",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"description": "A room as data, and its 3D model from that data: walls with openings, floors, outlets, circuits and placed objects.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -47,6 +47,11 @@
|
|
|
47
47
|
"import": "./build/three.js",
|
|
48
48
|
"default": "./build/three.js"
|
|
49
49
|
},
|
|
50
|
+
"./marks": {
|
|
51
|
+
"types": "./build/marks.d.ts",
|
|
52
|
+
"import": "./build/marks.js",
|
|
53
|
+
"default": "./build/marks.js"
|
|
54
|
+
},
|
|
50
55
|
"./package.json": "./package.json"
|
|
51
56
|
},
|
|
52
57
|
"files": [
|
|
@@ -55,6 +60,7 @@
|
|
|
55
60
|
"dependencies": {
|
|
56
61
|
"@mark1russell7/layout-contract": "^0.10.2",
|
|
57
62
|
"@mark1russell7/quantity": "^0.4.1",
|
|
63
|
+
"@mark1russell7/visuals": "^0.2.2",
|
|
58
64
|
"zod": "^4.6.7"
|
|
59
65
|
},
|
|
60
66
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"level-Cu8vgrwN.js","names":[],"sources":["../src/room.ts","../src/direction.ts","../src/survey.ts","../src/level.ts"],"sourcesContent":["import type { Ring } from \"@mark1russell7/layout-contract\";\nimport type { LengthUnit } from \"./units.ts\";\n\n/** A point of the plan: `[x, y]`. The plan is the view from above, and the z axis points up. */\nexport type PlanPoint = readonly [number, number];\n\n/** The name of the format of a room record. */\nexport const ROOM_SCHEMA = \"room/1\";\n\n/** The name of the format of a scene record. */\nexport const SCENE_SCHEMA = \"scene/1\";\n\n/**\n * This function tells if a text is the name of a layer: a word, a slash and a version, for example `electrical/1`.\n * The word has lowercase letters, digits and hyphens. Thus a layer name has no colon, and `recordName` gives each record one name.\n */\nexport function isLayerName(text: string): boolean {\n return /^[a-z][a-z0-9-]*\\/[0-9]+$/.test(text);\n}\n\n/** These are the sides of the line of a wall that can have the wall. */\nexport const WALL_SIDES: readonly [\"center\", \"left\", \"right\"] = [\"center\", \"left\", \"right\"];\n\n/**\n * The side of the line of a wall that has the wall, for a person who looks from `from` to `to`.\n * With `center`, the line is the middle of the wall. With `left` or `right`, the line is one face of the wall.\n */\nexport type WallSide = (typeof WALL_SIDES)[number];\n\n/** These are the faces of a wall, for a person who looks from `from` to `to`. */\nexport const WALL_FACES: readonly [\"left\", \"right\"] = [\"left\", \"right\"];\n\n/** A face of a wall. */\nexport type WallFace = (typeof WALL_FACES)[number];\n\n/**\n * A wall: a straight line in the plan, with a thickness and a height.\n * A tape measure gives the faces of a wall, so `side` lets the line be a face. Two walls with a common end make a corner.\n */\nexport interface Wall {\n readonly id: string;\n readonly from: PlanPoint;\n readonly to: PlanPoint;\n /** The thickness of the wall. The default is `wallThickness` of the room. */\n readonly thickness?: number | undefined;\n /** The height of the wall. The default is `height` of the room. */\n readonly height?: number | undefined;\n /** The side of the line that has the wall. The default is `center`. */\n readonly side?: WallSide | undefined;\n}\n\n/** These are the kinds of an opening. A window has glass. A door and a gap are empty. */\nexport const OPENING_KINDS: readonly [\"door\", \"window\", \"gap\"] = [\"door\", \"window\", \"gap\"];\n\n/** A kind of opening. */\nexport type OpeningKind = (typeof OPENING_KINDS)[number];\n\n/** An opening: a hole through a wall. */\nexport interface Opening {\n readonly id: string;\n /** The `id` of the wall. */\n readonly wall: string;\n readonly kind: OpeningKind;\n /** The distance along the line of the wall, from `from` to the near edge of the opening. */\n readonly offset: number;\n readonly width: number;\n /** The height of the bottom of the opening above the floor. The default is 0. */\n readonly sill?: number | undefined;\n readonly height: number;\n}\n\n/** A floor: one area of the plan, for example one room of an apartment. The ring is the line where the floor touches the walls. */\nexport interface Floor {\n readonly id: string;\n readonly name?: string | undefined;\n readonly ring: Ring;\n}\n\n/** An outlet: a point on a face of a wall. */\nexport interface Outlet {\n readonly id: string;\n /** The `id` of the wall. */\n readonly wall: string;\n /** The face of the wall that has the outlet. */\n readonly face: WallFace;\n /** The distance along the line of the wall, from `from` to the center of the outlet. */\n readonly offset: number;\n /** The height of the center of the outlet above the floor. */\n readonly height: number;\n /** The `id` of the circuit of the outlet. */\n readonly circuit?: string | undefined;\n}\n\n/** A circuit: it gives power to outlets, and it has a limit. */\nexport interface Circuit {\n readonly id: string;\n readonly name?: string | undefined;\n /** The rating of the breaker of the circuit, in amperes, for example 15. The record keeps it as a fact. The limit does not change with it. */\n readonly breaker?: number | undefined;\n /** The voltage of the circuit, in volts, for example 120. The record keeps it as a fact. The limit does not change with it. */\n readonly voltage?: number | undefined;\n /**\n * The largest continuous load, in watts.\n * For example, a breaker of 15 A at 120 V carries 1800 W, and 80% of that for a continuous load is 1440 W.\n */\n readonly limit: number;\n}\n\n/** A room: the walls, the openings, the floors, the outlets and the circuits of one room or one apartment. */\nexport interface Room {\n readonly schema: typeof ROOM_SCHEMA;\n readonly name?: string | undefined;\n /** The unit of each length of the record. */\n readonly unit: LengthUnit;\n /** The height of each wall that has no height of its own. */\n readonly height: number;\n /** The thickness of each wall that has no thickness of its own. */\n readonly wallThickness: number;\n readonly walls: readonly Wall[];\n readonly openings?: readonly Opening[] | undefined;\n readonly floors?: readonly Floor[] | undefined;\n readonly outlets?: readonly Outlet[] | undefined;\n readonly circuits?: readonly Circuit[] | undefined;\n}\n\n/**\n * A placed object: a box in the room, for example a desk, a rack or a computer.\n * With a `parent`, the position and the turn are relative to that object, whose origin is the center of its bottom.\n */\nexport interface PlacedObject {\n readonly id: string;\n /** The class of the object, for example `desk`, `rack` or `computer`. A viewer gives each class a color. */\n readonly kind: string;\n readonly name?: string | undefined;\n /** The size before the turn: along x, along y, and the height. */\n readonly size: readonly [number, number, number];\n /** The point of the plan below the center of the object. */\n readonly at: PlanPoint;\n /** The height of the bottom of the object above the floor, or above the bottom of its parent. The default is 0. */\n readonly lift?: number | undefined;\n /** The turn about the vertical axis in degrees, counter-clockwise from above. The default is 0. */\n readonly turn?: number | undefined;\n /** The `id` of the object that holds this object. */\n readonly parent?: string | undefined;\n /** The `id` of the outlet that gives power to the object. */\n readonly outlet?: string | undefined;\n}\n\n/** A load on a circuit, in watts. A circuit can have many loads: their sum is the load of the circuit. */\nexport interface CircuitLoad {\n /** The `id` of the circuit. */\n readonly circuit: string;\n readonly watts: number;\n}\n\n/** A scene: one room with its placed objects and the loads of its circuits. Two scenes of one room can be compared. */\nexport interface Scene {\n readonly schema: typeof SCENE_SCHEMA;\n readonly name?: string | undefined;\n readonly room: Room;\n readonly objects?: readonly PlacedObject[] | undefined;\n readonly loads?: readonly CircuitLoad[] | undefined;\n /**\n * The records of each add-on, by the name of its layer, for example `electrical/1`. `isLayerName` tells the form of a name.\n * The core keeps each layer and does not read it. `checkLayers` examines the layers with a list of add-ons.\n */\n readonly layers?: Readonly<Record<string, unknown>> | undefined;\n}\n","import type { PlanPoint } from \"./room.ts\";\n\n/** The turn at a square corner, in degrees. */\nexport const SQUARE = 90;\n\n/** One full turn, in degrees. */\nexport const FULL = 360;\n\n/** An angle with an error below this value is exact for the model, in degrees. The value is larger than the error of a sum of numbers. */\nexport const TURN_NOISE = 1e-9;\n\n/** This function gives the unit vector of a direction in degrees. A direction along an axis gives an exact vector. */\nexport function directionOf(degrees: number): PlanPoint {\n const turn = ((degrees % FULL) + FULL) % FULL;\n if (turn === 0) return [1, 0];\n if (turn === SQUARE) return [0, 1];\n if (turn === 2 * SQUARE) return [-1, 0];\n if (turn === 3 * SQUARE) return [0, -1];\n const angle = (turn * Math.PI) / 180;\n return [Math.cos(angle), Math.sin(angle)];\n}\n\n/** This function turns a vector of the plan by an angle in degrees, counter-clockwise. A turn by 90, 180 or 270 degrees is exact. */\nexport function turned([x, y]: PlanPoint, degrees: number): PlanPoint {\n const [cos, sin] = directionOf(degrees);\n return [x * cos - y * sin, x * sin + y * cos];\n}\n\n/**\n * This function gives the direction of a vector in degrees, from 0 to 360, counter-clockwise from the x axis.\n * A direction near 0, 90, 180 or 270 degrees becomes that value, so a room with square corners keeps exact numbers.\n */\nexport function headingOf([x, y]: PlanPoint): number {\n return squared((Math.atan2(y, x) * 180) / Math.PI);\n}\n\n/** This function gives an angle in degrees from 0 to 360. An angle near 0, 90, 180 or 270 degrees becomes that value. */\nexport function squared(degrees: number): number {\n const turn = ((degrees % FULL) + FULL) % FULL;\n const near = Math.round(turn / SQUARE) * SQUARE;\n return Math.abs(turn - near) < TURN_NOISE ? near % FULL : turn;\n}\n","import { directionOf, FULL, headingOf, SQUARE, TURN_NOISE } from \"./direction.ts\";\nimport { ROOM_SCHEMA, type Circuit, type Opening, type Outlet, type PlacedObject, type PlanPoint, type Room, type Wall } from \"./room.ts\";\nimport { LARGEST_LENGTH, metersPer, unitsPer, type LengthUnit } from \"./units.ts\";\n\n/** The name of the format of a survey record. */\nexport const SURVEY_SCHEMA = \"survey/1\";\n\n/** These are the names of the turns at a square corner. */\nexport const SQUARE_TURNS: readonly [\"left\", \"right\"] = [\"left\", \"right\"];\n\n/**\n * The turn of the person at the end of a side, to the direction of the next side.\n *\n * `left` and `right` are the turns at a square corner: 90 degrees. They are exact.\n * A number is a measured angle in degrees, from -360 to 360, and a turn to the left is positive.\n */\nexport type SurveyTurn = (typeof SQUARE_TURNS)[number] | number;\n\n/** One side of a survey: the inner face of one wall, from a corner to the next corner. */\nexport interface SurveySide {\n /** The `id` of the wall of the side. */\n readonly id: string;\n /** The length of the inner face, from corner to corner. */\n readonly length: number;\n /** The turn at the end of the side. */\n readonly turn: SurveyTurn;\n /** The thickness of the wall. The default is `wallThickness` of the survey. */\n readonly thickness?: number | undefined;\n /** The height of the wall. The default is `height` of the survey. */\n readonly height?: number | undefined;\n}\n\n/** A measured distance between two corners of a survey, for example a diagonal of the room. It examines the walk. */\nexport interface SurveyCheck {\n readonly id: string;\n /** The `id` of a side. The first corner is the corner at the start of that side. */\n readonly from: string;\n /** The `id` of a side. The second corner is the corner at the start of that side. */\n readonly to: string;\n /** The measured distance between the two corners. */\n readonly length: number;\n}\n\n/** An outlet of a survey. It is on the inner face of its wall, so it has no field `face`. */\nexport type SurveyOutlet = Omit<Outlet, \"face\">;\n\n/**\n * An object of a survey: a box that a person measures from a side, for example a desk, a shelf or a rack.\n *\n * The back of the object is parallel to the inner face of the side. The person measures along the face to the near edge of the object,\n * and out from the face to its back. The near edge is the edge that is nearest to the first corner of the side.\n * Thus the record has no coordinate.\n *\n * An object with `on` is on a different object or in it, for example a display on a desk or a computer in a rack.\n * Then the person measures from the near edge and from the back of that object, which is the holder.\n * An object has `wall` or `on`. When it has the two, `on` applies.\n */\nexport interface SurveyObject {\n readonly id: string;\n /** The class of the object, for example `desk`, `rack` or `computer`. A viewer gives each class a color. */\n readonly kind: string;\n readonly name?: string | undefined;\n /** The `id` of the side. */\n readonly wall?: string | undefined;\n /** The `id` of the holder. The first object with the `id` applies. */\n readonly on?: string | undefined;\n /**\n * The distance along the inner face, from the first corner of the side to the near edge of the object.\n * With `on`, this is the distance from the near edge of the holder to the near edge of the object.\n */\n readonly offset: number;\n /** The size of the object along the wall. */\n readonly width: number;\n /** The size of the object out from the wall. */\n readonly depth: number;\n readonly height: number;\n /**\n * The distance from the inner face to the back of the object. With `on`, this is the distance from the back of the holder.\n * The default is 0: the object touches the wall, or its back is level with the back of the holder.\n */\n readonly gap?: number | undefined;\n /**\n * The height of the bottom of the object above the floor. The default is 0.\n * With `on`, this is the height above the bottom of the holder. Then the default is the height of the holder: the object is on its top.\n */\n readonly lift?: number | undefined;\n /** The `id` of the outlet that gives power to the object. */\n readonly outlet?: string | undefined;\n}\n\n/**\n * A survey: the measurements of one room by a person with a tape measure.\n *\n * The person goes around the room along the inner faces of the walls, in one direction.\n * Each side has the length of one face, and the turn at its end. The last turn gives the direction of the first side again.\n * An opening, an outlet and an object name their side in `wall`. Their `offset` starts at the first corner of that side.\n */\nexport interface Survey {\n readonly schema: typeof SURVEY_SCHEMA;\n readonly name?: string | undefined;\n /** The unit of each length of the record. */\n readonly unit: LengthUnit;\n /** The height of each wall that has no height of its own. */\n readonly height: number;\n /** The thickness of each wall that has no thickness of its own. */\n readonly wallThickness: number;\n /** The sides, in the sequence of the walk. */\n readonly sides: readonly SurveySide[];\n /** The place of the first corner in the plan. The default is the origin. */\n readonly start?: PlanPoint | undefined;\n /** The direction of the first side, in degrees counter-clockwise from the x axis. The default is 0. */\n readonly heading?: number | undefined;\n readonly checks?: readonly SurveyCheck[] | undefined;\n readonly openings?: readonly Opening[] | undefined;\n readonly outlets?: readonly SurveyOutlet[] | undefined;\n readonly circuits?: readonly Circuit[] | undefined;\n readonly objects?: readonly SurveyObject[] | undefined;\n}\n\n/** The closure of a survey: the difference between the end of the walk and its start. */\nexport interface SurveyClosure {\n /** The distance from the end of the last side to the first corner, in the unit of the survey. */\n readonly gap: number;\n /** The gap as a part of the length of the walk. A walk with no length has 0. */\n readonly ratio: number;\n /** The sum of the turns minus one full turn in the direction of the walk, in degrees. */\n readonly turn: number;\n /** This value is true when the walk has 3 sides or more, its turns make one full turn, and its gap is in the limit. */\n readonly closed: boolean;\n}\n\n/** The result of one check of a survey. */\nexport interface SurveyCheckResult {\n /** The `id` of the check. */\n readonly id: string;\n /** The measured distance, in the unit of the survey. */\n readonly measured: number;\n /** The distance between the two corners in the room record. A check with a side that the survey does not have gets `undefined`. */\n readonly model: number | undefined;\n /** The measured distance minus the distance in the room record. */\n readonly difference: number | undefined;\n}\n\n/** The result of the expansion of a survey. */\nexport interface SurveyResult {\n /** The room record of the survey. */\n readonly room: Room;\n /** The corner at the start of each side, as the room record has it. */\n readonly corners: readonly PlanPoint[];\n /** The points of the walk before the correction of the gap. The walk has one point more than the survey has sides. */\n readonly walk: readonly PlanPoint[];\n readonly closure: SurveyClosure;\n /** The result of each check, in the sequence of the checks. */\n readonly checks: readonly SurveyCheckResult[];\n /**\n * The placed object of each object of the survey that has a place, in the sequence of the survey.\n * A scene record with the room record and these objects gives the model of the room with its objects.\n */\n readonly objects: readonly PlacedObject[];\n}\n\n/** The default limit of the gap of a closed walk, as a part of the length of the walk. */\nexport const CLOSURE_LIMIT = 0.01;\n\n/** The options of the expansion of a survey. */\nexport interface SurveyOptions {\n /** The largest gap of a closed walk, as a part of the length of the walk. The default is `CLOSURE_LIMIT`. */\n readonly limit?: number | undefined;\n}\n\n/** This function tells if a turn is a measured angle: an angle from -360 degrees to 360 degrees. */\nfunction isMeasured(turn: SurveyTurn): turn is number {\n return typeof turn === \"number\" && Math.abs(turn) <= FULL;\n}\n\n/** This function gives a turn in degrees. A turn that is not a square turn or a measured angle is 0. */\nfunction degreesOf(turn: SurveyTurn): number {\n if (turn === \"left\") return SQUARE;\n if (turn === \"right\") return 0 - SQUARE;\n return isMeasured(turn) ? turn : 0;\n}\n\n/**\n * This function gives a survey in a different unit. Each length of the record changes, and each angle stays.\n * A survey that has the unit already is the result.\n */\nexport function convertSurvey(survey: Survey, unit: LengthUnit): Survey {\n if (survey.unit === unit) return survey;\n const factor = unitsPer(survey.unit, unit);\n const to = (value: number): number => value * factor;\n const start: PlanPoint | undefined = survey.start === undefined ? undefined : [to(survey.start[0]), to(survey.start[1])];\n return {\n ...survey,\n unit,\n height: to(survey.height),\n wallThickness: to(survey.wallThickness),\n sides: survey.sides.map((side) => ({\n ...side,\n length: to(side.length),\n ...(side.thickness === undefined ? {} : { thickness: to(side.thickness) }),\n ...(side.height === undefined ? {} : { height: to(side.height) }),\n })),\n ...(start === undefined ? {} : { start }),\n ...(survey.checks === undefined ? {} : { checks: survey.checks.map((check) => ({ ...check, length: to(check.length) })) }),\n ...(survey.openings === undefined\n ? {}\n : {\n openings: survey.openings.map((opening) => ({\n ...opening,\n offset: to(opening.offset),\n width: to(opening.width),\n ...(opening.sill === undefined ? {} : { sill: to(opening.sill) }),\n height: to(opening.height),\n })),\n }),\n ...(survey.outlets === undefined ? {} : { outlets: survey.outlets.map((outlet) => ({ ...outlet, offset: to(outlet.offset), height: to(outlet.height) })) }),\n ...(survey.objects === undefined\n ? {}\n : {\n objects: survey.objects.map((object) => ({\n ...object,\n offset: to(object.offset),\n width: to(object.width),\n depth: to(object.depth),\n height: to(object.height),\n ...(object.gap === undefined ? {} : { gap: to(object.gap) }),\n ...(object.lift === undefined ? {} : { lift: to(object.lift) }),\n })),\n }),\n };\n}\n\n/**\n * This function makes the room record of a survey.\n *\n * The walk starts at `start` in the direction `heading`. Each side adds its length, and then the person turns.\n * A length that is not a finite number above 0, or is not in the range of the model, counts as 0.\n * A turn that is not a number from -360 to 360 counts as 0. Thus each number of the result is finite.\n *\n * A measured length has an error, so the walk does not end exactly at its start. The function corrects the two errors of a walk:\n *\n * 1. When the sum of the turns has an error below 45 degrees, each measured turn gets an equal part of the error.\n * The turns `left` and `right` are exact, so they do not change. A larger error is a mistake, for example a wrong turn.\n * 2. When the walk is closed, the sides share the gap. Along each axis of the first side, each side changes in proportion to its length along that axis.\n * This is the transit rule of land survey. A side along an axis stays along that axis, so a room with square corners keeps them.\n * Then the last wall ends exactly at the first corner, and the room gets a floor.\n *\n * An opening and an outlet keep their place on a side that changes its length: each `offset` and each `width` changes in the same proportion.\n * Thus an opening that fits in its measured side fits in its wall, and two openings that do not overlap stay apart.\n *\n * An object keeps its size on a side that changes its length. It moves by a part of that change: its place in the free length of the side.\n * Thus an object that touches a corner continues to touch it. The x axis of a placed object goes along its wall,\n * and its y axis points into the room. An object with a holder has the holder as its parent, and its place is relative to the holder.\n *\n * Some objects have no place, and the result does not have them. A side that is not in the survey or has no length gives no place.\n * A holder with no place gives no place. A size that is not a finite number above 0 gives no place.\n * A distance that is not in the range of the model gives no place.\n *\n * A walk that is not closed gets no correction of the gap: its walls follow the walk, and the room has no floor.\n * Thus the record of a survey in progress shows the walls that the person measured.\n *\n * The wall of each side is on the outer side of its line. Thus each `offset` of the survey is a distance along the inner face.\n * `checkRoom` examines the room record.\n */\nexport function expandSurvey(survey: Survey, options: SurveyOptions = {}): SurveyResult {\n const scale = metersPer(survey.unit);\n const inRange = (value: number): boolean => Number.isFinite(value) && Math.abs(value) * scale <= LARGEST_LENGTH;\n const sides = survey.sides;\n const count = sides.length;\n const lengths = sides.map((side) => (side.length > 0 && inRange(side.length) ? side.length : 0));\n const turns = sides.map((side) => degreesOf(side.turn));\n const total = lengths.reduce((sum, length) => sum + length, 0);\n\n const sum = turns.reduce((all, turn) => all + turn, 0);\n const toLeft = sum >= 0;\n const error = sum - (toLeft ? FULL : 0 - FULL);\n const measured = sides.filter((side) => isMeasured(side.turn)).length;\n const corrected = measured > 0 && Math.abs(error) < SQUARE / 2;\n const share = corrected ? error / measured : 0;\n\n // The walk in its own frame: the first corner is the origin, and the first side goes along the x axis.\n let direction = 0;\n const steps = sides.map((side, index): PlanPoint => {\n const [dx, dy] = directionOf(direction);\n direction += turns[index]! - (isMeasured(side.turn) ? share : 0);\n return [dx * lengths[index]!, dy * lengths[index]!];\n });\n const points: PlanPoint[] = [[0, 0]];\n steps.forEach(([dx, dy], index) => {\n const [x, y] = points[index]!;\n points.push([x + dx, y + dy]);\n });\n\n const [gapX, gapY] = points[count]!;\n const gap = Math.hypot(gapX, gapY);\n const ratio = total > 0 ? gap / total : 0;\n const given = options.limit ?? CLOSURE_LIMIT;\n const limit = Number.isFinite(given) && given >= 0 ? given : CLOSURE_LIMIT;\n const closed = count >= 3 && total > 0 && (corrected || Math.abs(error) < TURN_NOISE) && ratio <= limit;\n\n // The transit rule: along each axis, a corner moves against the gap by the part of the movement before it.\n const moveX = steps.reduce((all, [dx]) => all + Math.abs(dx), 0);\n const moveY = steps.reduce((all, [, dy]) => all + Math.abs(dy), 0);\n let beforeX = 0;\n let beforeY = 0;\n const adjusted = steps.map(([dx, dy], index): PlanPoint => {\n const [x, y] = points[index]!;\n const partX = closed && moveX > 0 ? beforeX / moveX : 0;\n const partY = closed && moveY > 0 ? beforeY / moveY : 0;\n beforeX += Math.abs(dx);\n beforeY += Math.abs(dy);\n return [x - partX * gapX, y - partY * gapY];\n });\n\n // The frame of the walk goes to its place in the plan.\n const start: PlanPoint = survey.start !== undefined && inRange(survey.start[0]) && inRange(survey.start[1]) ? survey.start : [0, 0];\n const [cos, sin] = directionOf(survey.heading !== undefined && Number.isFinite(survey.heading) ? survey.heading : 0);\n const place = ([x, y]: PlanPoint): PlanPoint => [start[0] + (x * cos - y * sin), start[1] + (x * sin + y * cos)];\n const walk = points.map(place);\n const corners = adjusted.map(place);\n\n const walls = sides.map((side, index): Wall => {\n const to = closed ? corners[(index + 1) % count]! : walk[index + 1]!;\n return {\n id: side.id,\n from: corners[index]!,\n to,\n side: toLeft ? \"right\" : \"left\",\n ...(side.thickness === undefined ? {} : { thickness: side.thickness }),\n ...(side.height === undefined ? {} : { height: side.height }),\n };\n });\n\n const cornerOf = new Map<string, PlanPoint>();\n sides.forEach((side, index) => {\n if (!cornerOf.has(side.id)) cornerOf.set(side.id, corners[index]!);\n });\n const checks = (survey.checks ?? []).map((check): SurveyCheckResult => {\n const from = cornerOf.get(check.from);\n const to = cornerOf.get(check.to);\n const model = from === undefined || to === undefined ? undefined : Math.hypot(to[0] - from[0], to[1] - from[1]);\n return { id: check.id, measured: check.length, model, difference: model === undefined ? undefined : check.length - model };\n });\n\n // A side that shares the gap changes its length. The length of its wall, as a part of the measured length, is the factor of the side.\n const shared = closed && gap > 0;\n const factorOf = new Map<string, number>();\n sides.forEach((side, index) => {\n if (!shared || factorOf.has(side.id) || !(lengths[index]! > 0)) return;\n const { from, to } = walls[index]!;\n factorOf.set(side.id, Math.hypot(to[0] - from[0], to[1] - from[1]) / lengths[index]!);\n });\n const openings = survey.openings?.map((opening): Opening => {\n const factor = factorOf.get(opening.wall) ?? 1;\n return factor === 1 ? opening : { ...opening, offset: opening.offset * factor, width: opening.width * factor };\n });\n\n const face = toLeft ? \"left\" : \"right\";\n const room: Room = {\n schema: ROOM_SCHEMA,\n ...(survey.name === undefined ? {} : { name: survey.name }),\n unit: survey.unit,\n height: survey.height,\n wallThickness: survey.wallThickness,\n walls,\n // A walk with no shared gap keeps the list of the survey.\n ...(survey.openings === undefined || openings === undefined ? {} : { openings: shared ? openings : survey.openings }),\n // A floor has a counter-clockwise outline.\n ...(closed ? { floors: [{ id: \"floor\", ...(survey.name === undefined ? {} : { name: survey.name }), ring: toLeft ? corners : [...corners].reverse() }] } : {}),\n ...(survey.outlets === undefined ? {} : { outlets: survey.outlets.map((outlet): Outlet => ({ ...outlet, offset: outlet.offset * (factorOf.get(outlet.wall) ?? 1), face })) }),\n ...(survey.circuits === undefined ? {} : { circuits: survey.circuits }),\n };\n\n const sideOf = new Map<string, number>();\n sides.forEach((side, index) => {\n if (!sideOf.has(side.id)) sideOf.set(side.id, index);\n });\n const listed = new Map<string, SurveyObject>();\n for (const object of survey.objects ?? []) if (!listed.has(object.id)) listed.set(object.id, object);\n const places = new Map<SurveyObject, PlacedObject | undefined>();\n const placeOf = (object: SurveyObject): PlacedObject | undefined => {\n if (places.has(object)) return places.get(object);\n // An object in a ring of objects that hold one another finds itself here. Thus it has no place.\n places.set(object, undefined);\n const made = placed(object);\n places.set(object, made);\n return made;\n };\n const placed = (object: SurveyObject): PlacedObject | undefined => {\n const out = object.gap ?? 0;\n if (![object.width, object.depth, object.height].every((size) => size > 0 && inRange(size))) return undefined;\n if (![object.offset, out, object.lift ?? 0].every(inRange)) return undefined;\n const record = {\n id: object.id,\n kind: object.kind,\n ...(object.name === undefined ? {} : { name: object.name }),\n size: [object.width, object.depth, object.height] as const,\n };\n const power = object.outlet === undefined ? {} : { outlet: object.outlet };\n if (object.on !== undefined) {\n const holder = listed.get(object.on);\n if (holder === undefined || placeOf(holder) === undefined) return undefined;\n // The x axis of the holder goes along its side for a walk to the left, and against its side for a walk to the right.\n const x = object.offset + object.width / 2 - holder.width / 2;\n return { ...record, at: [toLeft ? x : 0 - x, out + object.depth / 2 - holder.depth / 2], lift: object.lift ?? holder.height, parent: holder.id, ...power };\n }\n const index = object.wall === undefined ? undefined : sideOf.get(object.wall);\n if (index === undefined) return undefined;\n const { from, to } = walls[index]!;\n const measure = lengths[index]!;\n const line = Math.hypot(to[0] - from[0], to[1] - from[1]);\n if (!(line > 0) || !(measure > 0)) return undefined;\n // The object keeps its size, so it moves by a part of the change of the length of its side.\n // The part is the place of the object in the free length of the side. An object that is longer than its side has no free length,\n // so the part is its place in the full length, as for an opening.\n const free = measure - object.width;\n const part = Math.min(1, Math.max(0, object.offset / (free > 0 ? free : measure)));\n const near = shared ? object.offset + (line - measure) * part : object.offset;\n const along: PlanPoint = [(to[0] - from[0]) / line, (to[1] - from[1]) / line];\n // The room is on the left of each side of a walk to the left, and on the right of each side of a walk to the right.\n const inward: PlanPoint = toLeft ? [0 - along[1], along[0]] : [along[1], 0 - along[0]];\n const a = near + object.width / 2;\n const b = out + object.depth / 2;\n // The y axis of the object is on the left of its x axis, so the x axis of a walk to the right goes against the side.\n const turn = headingOf(toLeft ? along : [0 - along[0], 0 - along[1]]);\n return {\n ...record,\n at: [from[0] + along[0] * a + inward[0] * b, from[1] + along[1] * a + inward[1] * b],\n ...(object.lift === undefined ? {} : { lift: object.lift }),\n ...(turn === 0 ? {} : { turn }),\n ...power,\n };\n };\n const objects = (survey.objects ?? []).flatMap((object) => {\n const made = placeOf(object);\n return made === undefined ? [] : [made];\n });\n return { room, corners, walk, closure: { gap, ratio, turn: error, closed }, checks, objects };\n}\n","import { headingOf, squared, turned } from \"./direction.ts\";\nimport { ROOM_SCHEMA, type Circuit, type Floor, type Opening, type Outlet, type PlacedObject, type PlanPoint, type Room, type Wall } from \"./room.ts\";\nimport { CLOSURE_LIMIT, convertSurvey, expandSurvey, type Survey, type SurveyOptions, type SurveyResult } from \"./survey.ts\";\nimport { LARGEST_LENGTH, metersPer, type LengthUnit } from \"./units.ts\";\n\n/** The name of the format of a level record. */\nexport const LEVEL_SCHEMA = \"level/1\";\n\n/** One room of a level: the survey of the room, with an `id`. */\nexport interface LevelRoom {\n readonly id: string;\n readonly survey: Survey;\n}\n\n/** One end of a connection: an opening of a room of the level. */\nexport interface ConnectionEnd {\n /** The `id` of the room. */\n readonly room: string;\n /** The `id` of the opening in the survey of that room. */\n readonly opening: string;\n}\n\n/**\n * A connection: one hole through the wall between two rooms, for example a door.\n * A person measures the hole in each room, so the survey of each room has it as an opening.\n */\nexport interface LevelConnection {\n readonly id: string;\n readonly from: ConnectionEnd;\n readonly to: ConnectionEnd;\n /**\n * The thickness of the wall at the hole: the distance between the faces of the wall in the two rooms.\n * A person measures it in the frame of a door. The default is the thickness of the wall of `from`.\n */\n readonly thickness?: number | undefined;\n}\n\n/**\n * A level: the rooms of one level of a building, for example the rooms of an apartment.\n *\n * Each room has its own survey, so each room has its own first corner and its own first direction.\n * A connection gives the place of a room: its two openings are one hole, so the two walls are back to back.\n */\nexport interface Level {\n readonly schema: typeof LEVEL_SCHEMA;\n readonly name?: string | undefined;\n /** The unit of each length of the room record of the level. A survey can have a different unit. */\n readonly unit: LengthUnit;\n readonly rooms: readonly LevelRoom[];\n readonly connections?: readonly LevelConnection[] | undefined;\n /** The circuits of the level. A survey can also have circuits. Two circuits with one `id` are one circuit, and the first one stays. */\n readonly circuits?: readonly Circuit[] | undefined;\n}\n\n/**\n * These are the sources of the place of a room.\n *\n * - `first`: the room is the first room of the level. It keeps the `start` and the `heading` of its survey.\n * - `connection`: a connection gives the place.\n * - `apart`: the room has no path of connections to a room before it, so its place is not known.\n */\nexport const ROOM_PLACES: readonly [\"first\", \"connection\", \"apart\"] = [\"first\", \"connection\", \"apart\"];\n\n/** A source of the place of a room. */\nexport type RoomPlace = (typeof ROOM_PLACES)[number];\n\n/** The result of one room of a level. */\nexport interface LevelRoomResult {\n /** The `id` of the room. */\n readonly id: string;\n readonly place: RoomPlace;\n /** The number of the group of the room, from 0. The rooms of one group have a path of connections between them. */\n readonly group: number;\n /** The survey of the room in the unit of the level. Its `start` and its `heading` are the place of the room in the level. */\n readonly survey: Survey;\n /** The expansion of that survey. */\n readonly result: SurveyResult;\n}\n\n/**\n * These are the uses of a connection.\n *\n * - `place`: the connection gives the place of a room.\n * - `check`: its two rooms have a place from other connections, so the connection examines the measurements.\n * - `none`: the connection has a fault, so the level does not use it.\n */\nexport const CONNECTION_USES: readonly [\"place\", \"check\", \"none\"] = [\"place\", \"check\", \"none\"];\n\n/** A use of a connection. */\nexport type ConnectionUse = (typeof CONNECTION_USES)[number];\n\n/**\n * These are the faults of a connection.\n *\n * - `room`: an end names a room that the level does not have.\n * - `opening`: an end names an opening that its room does not have, or the wall of the opening has no length.\n * - `one-room`: the two ends are in one room.\n */\nexport const CONNECTION_FAULTS: readonly [\"room\", \"opening\", \"one-room\"] = [\"room\", \"opening\", \"one-room\"];\n\n/** A fault of a connection. */\nexport type ConnectionFault = (typeof CONNECTION_FAULTS)[number];\n\n/** The result of one connection of a level. A connection with a fault has no numbers. */\nexport interface LevelConnectionResult {\n /** The `id` of the connection. */\n readonly id: string;\n readonly use: ConnectionUse;\n readonly fault?: ConnectionFault | undefined;\n /**\n * The distance between the two openings along the wall and through it, minus the thickness of the wall, in the unit of the level.\n * It is 0 for a connection that gives a place.\n */\n readonly gap: number | undefined;\n /** The gap as a part of the lengths of the walks of the two rooms. */\n readonly ratio: number | undefined;\n /** The angle between the two walls in degrees, from -180 to 180. Two walls that are back to back have 0. */\n readonly turn: number | undefined;\n /** The width of the opening of `to` minus the width of the opening of `from`, in the unit of the level. */\n readonly width: number | undefined;\n /** This value is true when the connection has no fault, its gap is in the limit, and its angle is `CONNECTION_TURN_LIMIT` or less. */\n readonly fits: boolean;\n}\n\n/** The result of the expansion of a level. */\nexport interface LevelResult {\n /**\n * One room record with each room of the level, in the unit of the level.\n * The `id` of a wall, an opening or an outlet is the `id` of its room, then `/`, then its `id` in the survey.\n * Each closed room gives one floor with the `id` and the name of the room.\n */\n readonly room: Room;\n /** The result of each room, in the sequence of the rooms. */\n readonly rooms: readonly LevelRoomResult[];\n /** The result of each connection, in the sequence of the connections. */\n readonly connections: readonly LevelConnectionResult[];\n /**\n * The placed objects of each room, in the sequence of the rooms. The `id` of an object, of its parent and of its outlet\n * has the same form as the `id` of a wall. A scene record with the room record and these objects gives the model of the level.\n */\n readonly objects: readonly PlacedObject[];\n}\n\n/** The options of the expansion of a level. */\nexport interface LevelOptions extends SurveyOptions {\n /** The distance between two groups of rooms, in the unit of the level. The default is 1 m. A value that is not a length of 0 or more gives the default. */\n readonly groupGap?: number | undefined;\n}\n\n/** The largest angle between the two walls of a connection that fits, in degrees. */\nexport const CONNECTION_TURN_LIMIT = 2;\n\n/** A length in meters at this value or less is 0 for the level. */\nconst SMALL = 1e-6;\n\n/** Two unit vectors with a cross product below this value are parallel. */\nconst PARALLEL = 1e-6;\n\n/** The number of steps of the grid of calculated lengths in one unit. The noise of float arithmetic is much smaller than one step. */\nconst GRID = 1e9;\n\n/** The place of a room in the level: the first corner of its walk, and the direction of its first side in degrees. */\ninterface Place {\n readonly start: PlanPoint;\n readonly heading: number;\n}\n\n/** An opening of a room, in the frame of its survey. The first corner is the origin, and the first side goes along the x axis. */\ninterface Hole {\n /** The position of the wall of the opening in the room record. */\n readonly wall: number;\n /** The center of the opening on the inner face of its wall. */\n readonly center: PlanPoint;\n /** The unit vector from the room through the wall. */\n readonly out: PlanPoint;\n readonly width: number;\n /** The thickness of the wall of the opening. */\n readonly thickness: number;\n}\n\n/** A connection with no fault: its two rooms as positions in the list of the rooms, and its two openings. */\ninterface Link {\n readonly from: number;\n readonly to: number;\n readonly fromHole: Hole;\n readonly toHole: Hole;\n /** The thickness of the wall at the hole. */\n readonly depth: number;\n}\n\n/** One wall of a room of the level, at its place. */\ninterface Face {\n readonly room: number;\n readonly wall: number;\n readonly from: PlanPoint;\n readonly to: PlanPoint;\n readonly along: PlanPoint;\n readonly out: PlanPoint;\n readonly length: number;\n readonly thickness: number;\n}\n\n/** This function gives the sum of two vectors of the plan. The second vector has a factor. */\nfunction plus(a: PlanPoint, b: PlanPoint, factor = 1): PlanPoint {\n return [a[0] + b[0] * factor, a[1] + b[1] * factor];\n}\n\n/** This function gives the dot product of two vectors of the plan. */\nfunction dot(a: PlanPoint, b: PlanPoint): number {\n return a[0] * b[0] + a[1] * b[1];\n}\n\n/** This function gives the cross product of two vectors of the plan. */\nfunction cross(a: PlanPoint, b: PlanPoint): number {\n return a[0] * b[1] - a[1] * b[0];\n}\n\n/**\n * This function gives a calculated length on the grid. It removes the noise of float arithmetic,\n * so a place of 0.1 does not become 0.10000000000000009 in a file.\n */\nfunction tidy(value: number): number {\n const steps = Math.round(value * GRID);\n // The sum with 0 changes -0 to 0.\n return Number.isSafeInteger(steps) ? steps / GRID + 0 : value;\n}\n\n/** This function gives a point of the frame of a room as a point of the level. */\nfunction placed(place: Place, point: PlanPoint): PlanPoint {\n return plus(place.start, turned(point, place.heading));\n}\n\n/** This function gives the unit vector along a wall and the unit vector from the room through the wall. A wall with no length has no vectors. */\nfunction vectorsOf(wall: Wall): { readonly along: PlanPoint; readonly out: PlanPoint; readonly length: number } | undefined {\n const dx = wall.to[0] - wall.from[0];\n const dy = wall.to[1] - wall.from[1];\n const length = Math.hypot(dx, dy);\n if (!(length > 0) || !Number.isFinite(length)) return undefined;\n const along: PlanPoint = [dx / length, dy / length];\n // The wall of a survey is on the outer side of its line.\n return { along, out: wall.side === \"left\" ? [0 - along[1], along[0]] : [along[1], 0 - along[0]], length };\n}\n\n/** This function gives an opening of a room in the frame of its survey. `own` is the expansion of the survey with no `start` and no `heading`. */\nfunction holeOf(own: SurveyResult, id: string, inRange: (value: number) => boolean): Hole | undefined {\n const opening = own.room.openings?.find((item) => item.id === id);\n if (opening === undefined || !inRange(opening.offset) || !inRange(opening.width)) return undefined;\n const wall = own.room.walls.findIndex((item) => item.id === opening.wall);\n const record = own.room.walls[wall];\n const vectors = record === undefined ? undefined : vectorsOf(record);\n if (record === undefined || vectors === undefined) return undefined;\n return {\n wall,\n center: plus(record.from, vectors.along, opening.offset + opening.width / 2),\n out: vectors.out,\n width: opening.width,\n thickness: record.thickness ?? own.room.wallThickness,\n };\n}\n\n/**\n * This function gives the place of a room from a connection to a room that has a place.\n * The two walls are back to back, and the centers of the two openings are opposite, at the distance `depth`.\n */\nfunction placeFrom(known: Place, knownHole: Hole, hole: Hole, depth: number): Place {\n const out = turned(knownHole.out, known.heading);\n const heading = squared(headingOf([0 - out[0], 0 - out[1]]) - headingOf(hole.out));\n const center = turned(hole.center, heading);\n const start = plus(plus(placed(known, knownHole.center), out, depth), center, -1);\n return { start: [tidy(start[0]), tidy(start[1])], heading };\n}\n\n/**\n * This function makes one room record from the rooms of a level.\n *\n * The first room keeps the `start` and the `heading` of its survey. The function goes from that room along the connections.\n * A connection to a room with no place gives the place of that room. The two walls are back to back, and the centers of the\n * two openings are opposite. The faces of the two walls are at the distance `thickness`.\n * A connection between two rooms that have a place examines the measurements: its `gap` and its `turn` tell a mistake.\n *\n * A room with no path of connections to a room before it starts a new group. Its place is not known,\n * so its group goes to the right of the groups before it. Thus a drawing of a level in progress shows each room.\n *\n * The survey of a room gives the thickness of each wall. Two rooms have one wall between them, so two walls that are\n * back to back share it. Each wall gets one half of the distance between the two faces.\n * This applies to the two walls of a connection, and to two walls that overlap.\n * A wall that is in part an outer wall gets the same thickness along its full length.\n *\n * `checkRoom` examines the room record. It tells when two rooms overlap.\n */\nexport function expandLevel(level: Level, options: LevelOptions = {}): LevelResult {\n const unit = level.unit;\n const scale = metersPer(unit);\n const inRange = (value: number): boolean => Number.isFinite(value) && Math.abs(value) * scale <= LARGEST_LENGTH;\n const size = (value: number | undefined): number | undefined => (value !== undefined && inRange(value) && value * scale > SMALL ? value : undefined);\n const count = level.rooms.length;\n const surveys = level.rooms.map((room) => convertSurvey(room.survey, unit));\n // Each room in the frame of its survey: the first corner is the origin, and the first side goes along the x axis.\n const owns = surveys.map((survey) => expandSurvey({ ...survey, start: undefined, heading: undefined }, options));\n\n const positionOf = new Map<string, number>();\n level.rooms.forEach((room, index) => {\n if (!positionOf.has(room.id)) positionOf.set(room.id, index);\n });\n\n const connections = level.connections ?? [];\n const faults: (ConnectionFault | undefined)[] = [];\n const links = connections.map((connection, index): Link | undefined => {\n const from = positionOf.get(connection.from.room);\n const to = positionOf.get(connection.to.room);\n if (from === undefined || to === undefined) {\n faults[index] = \"room\";\n return undefined;\n }\n if (from === to) {\n faults[index] = \"one-room\";\n return undefined;\n }\n const fromHole = holeOf(owns[from]!, connection.from.opening, inRange);\n const toHole = holeOf(owns[to]!, connection.to.opening, inRange);\n if (fromHole === undefined || toHole === undefined) {\n faults[index] = \"opening\";\n return undefined;\n }\n return { from, to, fromHole, toHole, depth: size(connection.thickness) ?? size(fromHole.thickness) ?? 0 };\n });\n\n // The place of each room: the function goes from the first room of each group along the connections.\n const places: Place[] = [];\n const sources: RoomPlace[] = [];\n const groups: number[] = [];\n const members: number[][] = [];\n const gives = new Set<number>();\n for (let root = 0; root < count; root++) {\n if (places[root] !== undefined) continue;\n const group = members.length;\n const survey = surveys[root]!;\n const heading = survey.heading !== undefined && Number.isFinite(survey.heading) ? survey.heading : 0;\n const start: PlanPoint = group === 0 && survey.start !== undefined && inRange(survey.start[0]) && inRange(survey.start[1]) ? survey.start : [0, 0];\n places[root] = { start, heading };\n sources[root] = group === 0 ? \"first\" : \"apart\";\n groups[root] = group;\n const queue = [root];\n for (let next = 0; next < queue.length; next++) {\n const known = queue[next]!;\n links.forEach((link, index) => {\n if (link === undefined) return;\n const forward = link.from === known;\n if (!forward && link.to !== known) return;\n const room = forward ? link.to : link.from;\n if (places[room] !== undefined) return;\n places[room] = placeFrom(places[known]!, forward ? link.fromHole : link.toHole, forward ? link.toHole : link.fromHole, link.depth);\n sources[room] = \"connection\";\n groups[room] = group;\n gives.add(index);\n queue.push(room);\n });\n }\n members.push(queue);\n }\n\n // A group with no known place goes to the right of the groups before it. The bottoms of the groups are on one line.\n const givenGap = options.groupGap;\n const groupGap = givenGap !== undefined && inRange(givenGap) && givenGap >= 0 ? givenGap : 1 / scale;\n let right: number | undefined;\n let base = 0;\n for (const [number, group] of members.entries()) {\n let low: PlanPoint | undefined;\n let high: PlanPoint | undefined;\n for (const room of group) {\n const survey = surveys[room]!;\n const margin = Math.max(0, ...[survey.wallThickness, ...survey.sides.map((side) => side.thickness)].map((value) => size(value) ?? 0));\n for (const point of [...owns[room]!.walk, ...owns[room]!.corners]) {\n const [x, y] = placed(places[room]!, point);\n low = low === undefined ? [x - margin, y - margin] : [Math.min(low[0], x - margin), Math.min(low[1], y - margin)];\n high = high === undefined ? [x + margin, y + margin] : [Math.max(high[0], x + margin), Math.max(high[1], y + margin)];\n }\n }\n if (low === undefined || high === undefined) continue;\n if (number === 0 || right === undefined) {\n right = right === undefined ? high[0] : Math.max(right, high[0]);\n if (number === 0) base = low[1];\n continue;\n }\n const move: PlanPoint = [right + groupGap - low[0], base - low[1]];\n for (const room of group) {\n const [x, y] = plus(places[room]!.start, move);\n places[room] = { start: [tidy(x), tidy(y)], heading: places[room]!.heading };\n }\n right = Math.max(right, high[0] + move[0]);\n }\n\n const rooms = level.rooms.map((room, index): LevelRoomResult => {\n const survey: Survey = { ...surveys[index]!, start: places[index]!.start, heading: places[index]!.heading };\n return { id: room.id, place: sources[index]!, group: groups[index]!, survey, result: expandSurvey(survey, options) };\n });\n\n // The measure of each connection, from the places of its two rooms.\n const givenLimit = options.limit ?? CLOSURE_LIMIT;\n const limit = Number.isFinite(givenLimit) && givenLimit >= 0 ? givenLimit : CLOSURE_LIMIT;\n const walkOf = (room: number): number => {\n const walk = owns[room]!.walk;\n return walk.reduce((sum, point, index) => (index === 0 ? 0 : sum + Math.hypot(point[0] - walk[index - 1]![0], point[1] - walk[index - 1]![1])), 0);\n };\n const results = connections.map((connection, index): LevelConnectionResult => {\n const link = links[index];\n if (link === undefined) return { id: connection.id, use: \"none\", fault: faults[index], gap: undefined, ratio: undefined, turn: undefined, width: undefined, fits: false };\n const width = link.toHole.width - link.fromHole.width;\n if (gives.has(index)) return { id: connection.id, use: \"place\", gap: 0, ratio: 0, turn: 0, width, fits: true };\n const from = places[link.from]!;\n const to = places[link.to]!;\n const out = turned(link.fromHole.out, from.heading);\n const back = turned(link.toHole.out, to.heading);\n const target = plus(placed(from, link.fromHole.center), out, link.depth);\n const center = placed(to, link.toHole.center);\n const miss = Math.hypot(center[0] - target[0], center[1] - target[1]);\n const walk = walkOf(link.from) + walkOf(link.to);\n const ratio = walk > 0 ? miss / walk : 0;\n const against: PlanPoint = [0 - out[0], 0 - out[1]];\n // The sum with 0 changes -0 to 0.\n const turn = (Math.atan2(cross(against, back), dot(against, back)) * 180) / Math.PI + 0;\n return { id: connection.id, use: \"check\", gap: miss, ratio, turn, width, fits: ratio <= limit && Math.abs(turn) <= CONNECTION_TURN_LIMIT };\n });\n\n // Each wall at its place. Two walls that are back to back share the wall between their rooms.\n const faces: Face[] = [];\n rooms.forEach(({ result }, room) => {\n result.room.walls.forEach((wall, index) => {\n const vectors = vectorsOf(wall);\n const thickness = size(wall.thickness ?? result.room.wallThickness);\n if (vectors === undefined || thickness === undefined) return;\n faces.push({ room, wall: index, from: wall.from, to: wall.to, along: vectors.along, out: vectors.out, length: vectors.length, thickness });\n });\n });\n const joined = new Set<string>();\n links.forEach((link, index) => {\n if (link === undefined || !results[index]!.fits) return;\n joined.add(`${link.from}:${link.fromHole.wall}:${link.to}:${link.toHole.wall}`);\n joined.add(`${link.to}:${link.toHole.wall}:${link.from}:${link.fromHole.wall}`);\n });\n const shared = new Map<string, number>();\n for (let i = 0; i < faces.length; i++) {\n for (let j = i + 1; j < faces.length; j++) {\n const a = faces[i]!;\n const b = faces[j]!;\n if (a.room === b.room || Math.abs(cross(a.along, b.along)) > PARALLEL || !(dot(a.out, b.out) < 0)) continue;\n const first: PlanPoint = [b.from[0] - a.from[0], b.from[1] - a.from[1]];\n const second: PlanPoint = [b.to[0] - a.from[0], b.to[1] - a.from[1]];\n const between = dot(first, a.out);\n const common = Math.min(a.length, Math.max(dot(first, a.along), dot(second, a.along))) - Math.max(0, Math.min(dot(first, a.along), dot(second, a.along)));\n if (!(between * scale > SMALL) || !(common * scale > SMALL)) continue;\n // The two walls of a connection are one wall. Two other walls are one wall when they overlap.\n if (!joined.has(`${a.room}:${a.wall}:${b.room}:${b.wall}`) && !((a.thickness + b.thickness - between) * scale > SMALL)) continue;\n const half = tidy(between / 2);\n for (const face of [a, b]) {\n const key = `${face.room}:${face.wall}`;\n shared.set(key, Math.min(shared.get(key) ?? Infinity, half));\n }\n }\n }\n\n const first = rooms[0]?.result.room;\n const height = first?.height ?? 1;\n const wallThickness = first?.wallThickness ?? 1;\n const walls: Wall[] = [];\n const openings: Opening[] = [];\n const floors: Floor[] = [];\n const outlets: Outlet[] = [];\n const objects: PlacedObject[] = [];\n const circuits = new Map<string, Circuit>();\n for (const circuit of level.circuits ?? []) if (!circuits.has(circuit.id)) circuits.set(circuit.id, circuit);\n rooms.forEach(({ id, survey, result }, room) => {\n const record = result.room;\n record.walls.forEach((wall, index) => {\n const thickness = shared.get(`${room}:${index}`) ?? wall.thickness ?? (record.wallThickness === wallThickness ? undefined : record.wallThickness);\n const tall = wall.height ?? (record.height === height ? undefined : record.height);\n walls.push({\n id: `${id}/${wall.id}`,\n from: wall.from,\n to: wall.to,\n ...(wall.side === undefined ? {} : { side: wall.side }),\n ...(thickness === undefined ? {} : { thickness }),\n ...(tall === undefined ? {} : { height: tall }),\n });\n });\n for (const opening of record.openings ?? []) openings.push({ ...opening, id: `${id}/${opening.id}`, wall: `${id}/${opening.wall}` });\n for (const floor of record.floors ?? []) floors.push({ id, ...(survey.name === undefined ? {} : { name: survey.name }), ring: floor.ring });\n for (const outlet of record.outlets ?? []) outlets.push({ ...outlet, id: `${id}/${outlet.id}`, wall: `${id}/${outlet.wall}` });\n for (const circuit of record.circuits ?? []) if (!circuits.has(circuit.id)) circuits.set(circuit.id, circuit);\n for (const object of result.objects) {\n objects.push({\n ...object,\n id: `${id}/${object.id}`,\n ...(object.parent === undefined ? {} : { parent: `${id}/${object.parent}` }),\n ...(object.outlet === undefined ? {} : { outlet: `${id}/${object.outlet}` }),\n });\n }\n });\n\n const room: Room = {\n schema: ROOM_SCHEMA,\n ...(level.name === undefined ? {} : { name: level.name }),\n unit,\n height,\n wallThickness,\n walls,\n ...(openings.length === 0 ? {} : { openings }),\n ...(floors.length === 0 ? {} : { floors }),\n ...(outlets.length === 0 ? {} : { outlets }),\n ...(circuits.size === 0 ? {} : { circuits: [...circuits.values()] }),\n };\n return { room, rooms, connections: results, objects };\n}\n"],"mappings":";;;AAOA,MAAa,cAAc;;AAG3B,MAAa,eAAe;;;;;AAM5B,SAAgB,YAAY,MAAuB;CACjD,OAAO,4BAA4B,KAAK,IAAI;AAC9C;;AAGA,MAAa,aAAmD;CAAC;CAAU;CAAQ;AAAO;;AAS1F,MAAa,aAAyC,CAAC,QAAQ,OAAO;;AAsBtE,MAAa,gBAAoD;CAAC;CAAQ;CAAU;AAAK;;ACxCzF,SAAgB,YAAY,SAA4B;CACtD,MAAM,QAAS,UAAA,MAAA,OAAA;CACf,IAAI,SAAS,GAAG,OAA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