@aiquants/plant-scene 0.1.0 → 0.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0 (2026-11-28)
4
+
5
+ Site markers: the host stands markers on points of the site from its own data, and they are picked, selected and
6
+ focused like the models' objects.
7
+
8
+ ### Added
9
+
10
+ - **`markers`** on `PlantSceneCanvas` (`SiteMarker`: `id`, `label`, `position`, `color`): each marker is a pole from
11
+ the ground and a head above the roofs around its point, with a name tag beside the head that turns to the camera,
12
+ keeps its size on the screen and is drawn over the models; its text is black or white, whichever contrasts more with
13
+ the marker's colour. A new array draws the markers again without loading the models again, and the markers hide while
14
+ a detailed building is shown alone. Nothing is fetched for them.
15
+ - **`markerPosition(pointMm, originMm)`**: a marker's place from a point of the site drawing (mm) and the drawing's point
16
+ the site model's origin stands on, in the frame `detailPlacement` places detailed buildings in.
17
+ - **`checkedMarkers`**: refuses, with a `RangeError` while rendering, an empty or shared id, a blank label, a point that
18
+ is not finite and a colour that is not `#rrggbb`. A marker with the id of an object of the models is reported through
19
+ `onFailure`.
20
+ - **`MarkerObject`** (`kind: "marker"`, `id`, `label`) among the `SceneObject`s: `onPick` returns it, `display.selection`
21
+ selects it (`focus` turns the camera to it), and `sceneObjectLabel` and `objectSummary` label it.
22
+ - **The `markers` display option** (`印`), on by default and kept with the other options; `offeredOptions` offers it
23
+ when `hasMarkers` is true.
24
+ - **The test hook `data-marker-positions`**: every frame drawn writes, as JSON, where a tap picks each marker in sight
25
+ (CSS pixels from the canvas's top left corner).
26
+
27
+ ### Changed
28
+
29
+ - `PlantSceneCanvasProps.markers` and `OptionSubjects.hasMarkers` are required: pass `[]` and `false` for no markers,
30
+ which draw, pick and offer options as 0.1.0 did (the canvas only carries `data-marker-positions="[]"` too).
31
+ `DisplayOptions` has `markers`, and code that switches over `SceneObject.kind` needs a `"marker"` case.
32
+
3
33
  ## 0.1.0 (2026-11-09)
4
34
 
5
35
  The first release: a React 3D view of a plant site drawn with Babylon.js, and the rules a page around it lists the
package/README.md CHANGED
@@ -7,14 +7,14 @@ Babylon.js で描く工場の構内の 3D の表示 (React) と、周りの画
7
7
 
8
8
  ## Overview / 概要
9
9
 
10
- - **The view**: `PlantSceneCanvas` draws the site's buildings and tanks as boxes first, then lays the site drawing's lines and text and the detailed buildings' models over them as they arrive. A click picks a building, a tank or a piece of equipment; a detailed building can be shown alone, up to one of its floors.
11
- - **表示**: `PlantSceneCanvas` はまず構内の建屋とタンクを箱で描き、届き次第、構内の図面の線と字と詳しい建屋の模型を重ねる。押すと建屋・タンク・機器を選べ、詳しい建屋は 1 つだけ、ある階までを見せられる。
10
+ - **The view**: `PlantSceneCanvas` draws the site's buildings and tanks as boxes first, then lays the site drawing's lines and text and the detailed buildings' models over them as they arrive, and stands the host's markers on points of the site. A click picks a building, a tank, a piece of equipment or a marker; a detailed building can be shown alone, up to one of its floors.
11
+ - **表示**: `PlantSceneCanvas` はまず構内の建屋とタンクを箱で描き、届き次第、構内の図面の線と字と詳しい建屋の模型を重ね、使い手の印を構内の点に立てる。押すと建屋・タンク・機器・印を選べ、詳しい建屋は 1 つだけ、ある階までを見せられる。
12
12
  - **Babylon.js loads late**: the canvas loads the scene module with a dynamic `import()` when it mounts, so the page's entry chunk and the server render never carry Babylon.js.
13
13
  - **Babylon.js は後から読む**: キャンバスは置かれたときに場面のモジュールを動的な `import()` で読むので、画面の入口の塊にもサーバの描画にも Babylon.js は載らない。
14
14
  - **The rules around it**: the list of buildings with their floors and equipment, the summary of a selected object, the drawings an object asks for, the display options a manifest offers, and the search folding.
15
15
  - **周りの規則**: 建屋とその階・機器の一覧、選んだ物体の要約、物体が求める図面、目録が出す表示オプション、検索の語のそろえ方。
16
- - **What the host keeps**: the route that serves the models, the manifest of detailed buildings, the colours of its theme, the key the display options are kept under, and the page's own panels.
17
- - **使い手が持つもの**: 模型を配る口、詳しい建屋の目録、テーマの色、表示オプションを残す鍵、画面の欄。
16
+ - **What the host keeps**: the route that serves the models, the manifest of detailed buildings, the points and labels of its markers, the colours of its theme, the key the display options are kept under, and the page's own panels.
17
+ - **使い手が持つもの**: 模型を配る口、詳しい建屋の目録、印の点と名札、テーマの色、表示オプションを残す鍵、画面の欄。
18
18
 
19
19
  The labels the package returns and shows (the display options, the legend, the object summaries and the canvas's accessible name) are Japanese.
20
20
  パッケージが返し見せる名 (表示オプション・凡例・物体の要約・キャンバスの名) は日本語。
@@ -48,12 +48,12 @@ The package is ES modules only (`import`), as Babylon.js 9 is. React 19.2 is the
48
48
  ## Usage / 使い方
49
49
 
50
50
  ```tsx
51
- import { detailPlacement, type DetailModel, PlantSceneCanvas, type ScenePaint, type SceneSelection, useDisplayOptions, useViewInsets } from "@aiquants/plant-scene"
51
+ import { detailPlacement, type DetailModel, markerPosition, PlantSceneCanvas, type ScenePaint, type SceneSelection, type SiteMarker, useDisplayOptions, useViewInsets } from "@aiquants/plant-scene"
52
52
  import { useMemo, useState } from "react"
53
53
 
54
54
  const PAINT: ScenePaint = { sky: "#f1f5f9", ground: "#e2e8f0", ink: "#0f172a", floor: "#ffffff" }
55
55
 
56
- export const PlantView = ({ manifest }: { manifest: YourManifest }) => {
56
+ export const PlantView = ({ manifest, points }: { manifest: YourManifest; points: readonly YourPoint[] }) => {
57
57
  const [options] = useDisplayOptions("<your-app>:plant-scene:display-options")
58
58
  const [view, setView] = useState<HTMLDivElement | null>(null)
59
59
  const [card, setCard] = useState<HTMLDivElement | null>(null)
@@ -64,6 +64,10 @@ export const PlantView = ({ manifest }: { manifest: YourManifest }) => {
64
64
  () => manifest.details.map((detail) => ({ key: detail.key, glbUrl: `/your-asset-route/${detail.glb}`, buildingId: detail.buildingId, placement: detailPlacement(detail, manifest.originMm), floors: detail.floors })),
65
65
  [manifest],
66
66
  )
67
+ const markers = useMemo<SiteMarker[]>(
68
+ () => points.map((point) => ({ id: `point-${point.id}`, label: point.name, position: markerPosition(point.positionMm, manifest.originMm), color: "#1d4ed8" })),
69
+ [points, manifest],
70
+ )
67
71
 
68
72
  return (
69
73
  <div ref={setView} style={{ position: "relative", height: "100dvh", background: PAINT.sky }}>
@@ -72,6 +76,7 @@ export const PlantView = ({ manifest }: { manifest: YourManifest }) => {
72
76
  linesUrl="/your-asset-route/site.lines.glb"
73
77
  details={details}
74
78
  heights={manifest.heights}
79
+ markers={markers}
75
80
  display={{ isolated: null, floor: null, selection }}
76
81
  options={options}
77
82
  insets={insets}
@@ -86,8 +91,8 @@ export const PlantView = ({ manifest }: { manifest: YourManifest }) => {
86
91
  }
87
92
  ```
88
93
 
89
- The canvas fills its nearest positioned ancestor, which gives it its size; it lays itself out with its own `style` and needs no stylesheet. Pass stable arrays (`details`, `heights`): the view lives as long as the two URLs and these arrays, compared by identity, and a new one closes the view and loads the models again.
90
- キャンバスはいちばん近い位置指定の祖先いっぱいに広がり、その祖先が大きさを与える。自分の `style` で自分を置くので、スタイルシートは要らない。`details`・`heights` は変わらない配列を渡すこと。表示は 2 つの URL とこれらの配列 (同一性で比べる) と同じだけ生き、新しいものなら表示を閉じて模型を読み直す。
94
+ The canvas fills its nearest positioned ancestor, which gives it its size; it lays itself out with its own `style` and needs no stylesheet. Pass stable arrays (`details`, `heights`): the view lives as long as the two URLs and these arrays, compared by identity, and a new one closes the view and loads the models again. A new `markers` array draws the markers again and keeps the models, so the markers may come after the host's data has loaded; pass a memoized one all the same, as each new array makes the markers' meshes again.
95
+ キャンバスはいちばん近い位置指定の祖先いっぱいに広がり、その祖先が大きさを与える。自分の `style` で自分を置くので、スタイルシートは要らない。`details`・`heights` は変わらない配列を渡すこと。表示は 2 つの URL とこれらの配列 (同一性で比べる) と同じだけ生き、新しいものなら表示を閉じて模型を読み直す。新しい `markers` の配列は印だけを描き直し、模型は読み直さないので、印は使い手のデータを読んだ後に渡してよい。それでも新しい配列のたびに印の網を作り直すので、変わらない配列を渡すこと。
91
96
 
92
97
  ### `PlantSceneCanvas` props / 引数
93
98
 
@@ -97,39 +102,64 @@ The canvas fills its nearest positioned ancestor, which gives it its size; it la
97
102
  | `linesUrl` | `string` | GLB of the site drawing's lines and text. 構内の図面の線と字の GLB。 |
98
103
  | `details` | `readonly DetailModel[]` | The detailed buildings' models: `key`, `glbUrl`, `buildingId` (the site building it replaces), `placement` (`detailPlacement`) and `floors`. 詳しい建屋の模型。 |
99
104
  | `heights` | `readonly BuildingHeight[]` | Heights of the site buildings whose height is known (`buildingId`, `buildingName`, `heightMm`). 高さの分かる構内の建屋の高さ。 |
100
- | `display` | `SceneDisplay` | What the view shows: `isolated` (a detailed building's key shown alone, or `null`), `floor` (the floor it is shown up to, or `null`) and `selection` (`{ id, focus }` or `null`; `focus` turns the camera to it). 表示が見せるもの。 |
105
+ | `markers` | `readonly SiteMarker[]` | The markers on points of the site: `id` (no building's, tank's or piece of equipment's id), `label` (not blank), `position` (`markerPosition`) and `color` (`#rrggbb`); `[]` for none. 構内の点に立てる印。 |
106
+ | `display` | `SceneDisplay` | What the view shows: `isolated` (a detailed building's key shown alone, or `null`), `floor` (the floor it is shown up to, or `null`) and `selection` (`{ id, focus }` or `null`, `id` an object's or a marker's; `focus` turns the camera to it). 表示が見せるもの。 |
101
107
  | `options` | `DisplayOptions` | How the view draws (`useDisplayOptions`). 描き方。 |
102
108
  | `insets` | `ViewInsets` | The parts of the canvas's height the panels hide (`useViewInsets`): each side 0 or more, the two less than 1. 欄が隠す高さの部分。 |
103
109
  | `paint` | `ScenePaint` | The colours of the sky, the ground, the drawings' ink and the floors, each `#rrggbb`. 空・地面・墨・床の色。 |
104
- | `onPick` | `(object: SceneObject \| null) => void` | The object a click hit, or `null`. 押して当たった物体。 |
110
+ | `onPick` | `(object: SceneObject \| null) => void` | The object or marker (`kind: "marker"`) a click hit, or `null`. 押して当たった物体か印。 |
105
111
  | `onLoad` | `(models: LoadedModels) => void` | The objects and the legend each time more models have loaded (`complete` once everything has). 読み進めるたびの物体と凡例。 |
106
- | `onFailure` | `(error: Error) => void` | Babylon.js or a model could not be loaded, or a model breaks the contract below. 読めなかったときや模型が約束を破るとき。 |
112
+ | `onFailure` | `(error: Error) => void` | Babylon.js or a model could not be loaded, a model breaks the contract below, or a marker has the id of an object of the models. 読めなかったとき、模型が約束を破るとき、印が模型の物体の ID を持つとき。 |
107
113
 
108
- A colour that is not `#rrggbb` (`checkedPaint`) or insets that leave no height in sight (`checkedInsets`) make the canvas throw a `RangeError` while rendering, before a view opens or is painted; an error boundary of the host catches it.
109
- `#rrggbb` でない色や、見える高さを残さない余白は、描く中で `RangeError` になる (表示を開く前・塗る前)。使い手のエラーの境界が受ける。
114
+ A colour that is not `#rrggbb` (`checkedPaint`), insets that leave no height in sight (`checkedInsets`) or markers `checkedMarkers` refuses make the canvas throw a `RangeError` while rendering, before a view opens or is painted; an error boundary of the host catches it.
115
+ `#rrggbb` でない色、見える高さを残さない余白、`checkedMarkers` が退ける印は、描く中で `RangeError` になる (表示を開く前・塗る前)。使い手のエラーの境界が受ける。
110
116
 
111
117
  ### The rest of the API / ほかの API
112
118
 
113
119
  | Name | What it does |
114
120
  | --- | --- |
115
121
  | `useDisplayOptions(storageKey)` | The display options kept under the host's key in `localStorage`, and the function that keeps new ones. Every reader of the same key, in this tab and the others, follows a change; the server render gets `DEFAULT_DISPLAY_OPTIONS`. An empty key throws a `RangeError`. 使い手の鍵で残す表示オプションと、それを変える関数。 |
116
- | `offeredOptions({ hasDetails, hasHeights })` | The options worth offering for a manifest, with their labels, in the page's order. 目録に意味のあるオプション。 |
122
+ | `offeredOptions({ hasDetails, hasHeights, hasMarkers })` | The options worth offering for a manifest and the host's markers, with their labels, in the page's order (`印` only with markers). 目録と使い手の印に意味のあるオプション。 |
117
123
  | `DEFAULT_DISPLAY_OPTIONS` | Every option on. 全てのオプションが入った状態。 |
118
124
  | `useViewInsets(view, panels)` | How much of the view the panels laid over it hide, measured again whenever the view or a panel changes size. Pass a memoized `panels` array. 重ねた欄が隠す部分。 |
119
125
  | `detailPlacement(detail, originMm)` | Where a detailed building's model goes on the site model, from its turn (`rotationDeg`) and shift (`offsetMm`) on the site drawing and the drawing's point the site model's origin stands on. 詳しい建屋の模型の置き方。 |
126
+ | `markerPosition(pointMm, originMm)` | Where a site marker stands on the site model, from its point on the site drawing (mm) and the drawing's point the site model's origin stands on, in the frame `detailPlacement` places in. A coordinate that is not finite throws a `RangeError`. 構内の印の立つ所。 |
120
127
  | `listedBuildings(objects, details, filter, only)` | The page's list: the named buildings and the detailed ones, with their floors (highest first) and equipment, narrowed by words. 画面の一覧。 |
121
128
  | `objectSummary(object, details, objects)` | A selected object's title, what it is, and its detailed building. 選んだ物体の要約。 |
122
129
  | `detailOfObject(object, details)` | The detailed building a building or a piece of equipment belongs to, or `null`. 物体が属する詳しい建屋。 |
123
130
  | `buildingRequestOf(object, details)` | The site building and the words an object asks the drawings for, or `null`. 物体が図面に求める建屋と語。 |
124
- | `sceneObjectLabel(object)` | An object's label. 物体の名札。 |
131
+ | `sceneObjectLabel(object)` | An object's label (a marker's is its `label`). 物体の名札 (印は名札の字)。 |
125
132
  | `foldForSearch(text)` / `searchTerms(query)` | The search folding (NFKC, then lower case) and a query split into folded words at any white space. Fold the host's own matches the same way. 検索の語のそろえ方。 |
126
133
  | `checkedPaint(paint)` | Returns the paint when every colour is `#rrggbb`, or throws a `RangeError` naming the first wrong one. 色を確かめる。 |
134
+ | `checkedMarkers(markers)` | Returns the markers when each has an id of its own that is not empty, a label that is not blank, a finite point and a `#rrggbb` colour, or throws a `RangeError` naming the first wrong one. 印を確かめる。 |
127
135
 
128
136
  `detailOfObject`, `objectSummary` and `listedBuildings` take the host's own manifest entries (any type with the fields of `SceneDetail`: `key`, `buildingId`, `buildingName`, `rotationDeg`, `offsetMm`, `floors`) and hand them back in the host's type.
129
137
  `detailOfObject`・`objectSummary`・`listedBuildings` は使い手の目録の項目 (`SceneDetail` の項目を持つ型) を受け、使い手の型のまま返す。
130
138
 
131
139
  ---
132
140
 
141
+ ## Site markers / 構内の印
142
+
143
+ A marker stands on a point the host's data knows and the models do not: a switchboard room, a meter, a camera, a muster point.
144
+ 構内の点のうち、模型に無く使い手のデータにある所 (配電室・計器・カメラ・集合場所など) に立てる印。
145
+
146
+ - **Where**: `markerPosition(pointMm, originMm)` turns a point of the site drawing (mm) into the site model's frame, the one `detailPlacement` places detailed buildings in, so a manifest with a new `originMm` needs no change to the host's points.
147
+ - **置き場所**: `markerPosition(pointMm, originMm)` が構内の図面の点 (mm) を、`detailPlacement` が詳しい建屋を置くのと同じ構内の模型の座標系へ移す。目録の `originMm` が替わっても、使い手の点は直さずに済む。
148
+ - **How it draws**: a pole from the ground and a head in the marker's `color`, the head 4 m above the highest roof within 10 m of the point and at least 6 m above the ground, so a marker inside a building shows its head above the roof. The head, the pole and the name tag keep their sizes on the screen, and the head and the tag are drawn over the models, so no building hides them.
149
+ - **描き方**: 地面からの柱と頭を印の `color` で描き、頭は点から 10 m の内のいちばん高い屋根の 4 m 上、地面から少なくとも 6 m に立つ (建屋の中の点の印も、屋根の上に頭を見せる)。頭・柱・名札は画面の上の大きさを保ち、頭と名札は模型の上に描くので、どの建屋にも隠れない。
150
+ - **Name tag**: beside the head and turned to the camera, in the marker's colour, with the `label` in black or white, whichever contrasts more with it: at least 4.58 : 1 on any colour, in bold 19 px, which is large text, of which WCAG's AAA asks 4.5 : 1.
151
+ - **名札**: 頭の横で視点へ向き、印の色の地に `label` を黒と白のうちその色とのコントラストの高い方で書く。どの色の上でも少なくとも 4.58 : 1 で、太字の 19 px は WCAG の AAA が 4.5 : 1 を求める大きな字。
152
+ - **Picking and selection**: a tap on a head or a name tag picks the marker before the models, and `onPick` returns `{ kind: "marker", id, label }`. `display.selection` with a marker's `id` makes it glow, and `focus` turns the camera to it.
153
+ - **押しと選択**: 頭か名札を押すと、模型より先にその印が選ばれ、`onPick` は `{ kind: "marker", id, label }` を返す。`display.selection` に印の `id` を渡すと光り、`focus` が真なら視点がその印へ向く。
154
+ - **When it shows**: while the whole site is shown (never while `display.isolated` names a detailed building) and the `markers` display option (`印`) is on. `offeredOptions` offers that option only with `hasMarkers`, and `useDisplayOptions` keeps it with the others.
155
+ - **見せる間**: 構内の全体を見せる間 (`display.isolated` が詳しい建屋を名指す間は見せない) で、表示オプション `markers` (`印`) が入の間。`offeredOptions` はこのオプションを `hasMarkers` のときだけ出し、`useDisplayOptions` がほかのオプションと共に残す。
156
+ - **Ids**: the host chooses ids no building, tank or piece of equipment has. A marker with the id of an object of the models is reported through `onFailure`, when the markers come or when the model that holds the object loads.
157
+ - **ID**: 建屋・タンク・機器の ID と重ならない ID を使い手が決める。模型の物体と同じ ID の印は、印が来たとき、またはその物体を持つ模型を読んだときに `onFailure` で知らせる。
158
+ - **No markers**: with `markers={[]}` and `hasMarkers: false`, nothing of the markers is drawn or offered, a tap reaches the models alone, and `data-marker-positions` reads `[]`.
159
+ - **印が無いとき**: `markers={[]}` と `hasMarkers: false` なら、印は描かず表示オプションにも出さず、押しは模型だけに届き、`data-marker-positions` は `[]`。
160
+
161
+ ---
162
+
133
163
  ## The models / 模型の約束
134
164
 
135
165
  The view reads what each mesh is from its glTF `extras`:
@@ -152,8 +182,8 @@ An unknown role, a building, tank or piece of equipment missing a field, a part
152
182
 
153
183
  ## Network / 通信
154
184
 
155
- The view fetches the GLB URLs it is given and nothing else. Babylon.js fetches a decoder from its own CDN only for a model compressed with Draco, meshopt or KTX2 / Basis textures, so build the models without those compressions (or point Babylon.js's decoder URLs at the host before the canvas mounts).
156
- 表示は渡された GLB の URL だけを読む。Babylon.js は Draco・meshopt・KTX2 / Basis で縮めた模型のときだけ自身の CDN から復号器を読むので、模型はそれらで縮めずに作ること (またはキャンバスを置く前に Babylon.js の復号器の URL を使い手へ向けること)。
185
+ The view fetches the GLB URLs it is given and nothing else; the markers fetch nothing (their name tags are drawn on a canvas in the browser's own `sans-serif` font). Babylon.js fetches a decoder from its own CDN only for a model compressed with Draco, meshopt or KTX2 / Basis textures, so build the models without those compressions (or point Babylon.js's decoder URLs at the host before the canvas mounts).
186
+ 表示は渡された GLB の URL だけを読み、印は何も読まない (名札はブラウザ自身の `sans-serif` の字体でキャンバスに描く)。Babylon.js は Draco・meshopt・KTX2 / Basis で縮めた模型のときだけ自身の CDN から復号器を読むので、模型はそれらで縮めずに作ること (またはキャンバスを置く前に Babylon.js の復号器の URL を使い手へ向けること)。
157
187
 
158
188
  ---
159
189
 
@@ -173,6 +203,8 @@ The view fetches the GLB URLs it is given and nothing else. Babylon.js fetches a
173
203
  - The canvas is `data-testid="plant-scene-canvas"`.
174
204
  - Every frame drawn writes the camera into the canvas's `data-camera-pose`: alpha, beta, radius and the target's x, y and z, split by spaces.
175
205
  - キャンバスは `data-testid="plant-scene-canvas"`。描くコマごとに視点をキャンバスの `data-camera-pose` へ書く (alpha・beta・radius・注視点の x・y・z を空白で分ける)。
206
+ - Every frame drawn writes the markers in sight into the canvas's `data-marker-positions` as JSON, in the order of `markers`: `[{ "id": "point-7", "x": 412.5, "y": 233.25 }]`, where a tap at x, y (CSS pixels from the canvas's top left corner) picks that marker. A marker hidden (a building shown alone, the option off), behind the camera, outside the canvas or covered there by a nearer marker is left out; a page's panel laid over the canvas may still cover a listed point.
207
+ - 描くコマごとに、見えている印をキャンバスの `data-marker-positions` へ JSON で `markers` の順に書く (`[{ "id": "point-7", "x": 412.5, "y": 233.25 }]`。キャンバスの左上の角から CSS の px で x・y の所を押すと、その印が選ばれる)。隠した印 (建屋を 1 つだけ見せる間・オプションを切った間)・視点の後ろの印・キャンバスの外の印・そこを手前の印が覆う印は書かない。画面の欄がキャンバスに重なれば、書いた点を覆うこともある。
176
208
 
177
209
  ---
178
210
 
@@ -0,0 +1,4 @@
1
+ var E=/^#[0-9a-f]{6}$/iu,h=e=>typeof e=="string"&&E.test(e),O=["sky","ground","ink","floor"],B=e=>{for(let t of O){let n=e[t];if(!h(n))throw new RangeError(`the scene's ${t} colour must be #rrggbb, not ${JSON.stringify(n)}`)}return e},T=e=>{let t=new Set;for(let{id:n,label:r,position:o,color:i}of e){let s=JSON.stringify(n);if(typeof n!="string"||n==="")throw new RangeError(`a site marker's id must be a string that is not empty, not ${s}`);if(t.has(n))throw new RangeError(`two site markers share the id ${s}`);if(t.add(n),typeof r!="string"||r.trim()==="")throw new RangeError(`site marker ${s} needs a label that is not blank, not ${JSON.stringify(r)}`);if(!(Number.isFinite(o.x)&&Number.isFinite(o.z)))throw new RangeError(`site marker ${s} must stand at a finite point, not x ${o.x}, z ${o.z}`);if(!h(i))throw new RangeError(`site marker ${s}'s colour must be #rrggbb, not ${JSON.stringify(i)}`)}return e};var k={top:0,bottom:0},$=.15,N=1e-4,j=e=>{for(let t of[e.top,e.bottom])if(!Number.isFinite(t)||t<0)throw new RangeError(`view insets must be finite and not negative: top ${e.top}, bottom ${e.bottom}`);if(e.top+e.bottom>=1)throw new RangeError(`view insets must leave some height in sight: top ${e.top}, bottom ${e.bottom}`);return e},L=(e,t)=>{let n=e.bottom-e.top,r=e.right-e.left;if(!(Number.isFinite(n)&&Number.isFinite(r)&&n>0&&r>0))return k;let o=(e.top+e.bottom)/2,i=0,s=0;for(let l of t){let a={left:Math.max(l.left,e.left),top:Math.max(l.top,e.top),right:Math.min(l.right,e.right),bottom:Math.min(l.bottom,e.bottom)};a.left<a.right&&a.top<a.bottom&&((a.top+a.bottom)/2<o?i=Math.max(i,a.bottom-e.top):s=Math.max(s,e.bottom-a.top))}let d={top:i/n,bottom:s/n};return d.top+d.bottom<1?d:k},V=(e,t,n)=>{if(!Number.isFinite(n)||n<0)throw new RangeError(`elapsed seconds must be finite and not negative: ${n}`);let r=1-Math.exp(-n/$),o=(i,s)=>{let d=i+(s-i)*r;return Math.abs(s-d)<N?s:d};return{top:o(e.top,t.top),bottom:o(e.bottom,t.bottom)}},X=(e,t)=>{let n=1-t.top-t.bottom,r=t.bottom-t.top,o=e.m;for(let i=0;i<4;i+=1){let s=i*4;e.setRowFromFloats(i,o[s]*n,o[s+1]*n+o[s+3]*r,o[s+2],o[s+3])}};var S=(e,t)=>({x:-(e[0]-t[0])/1e3,z:-(e[1]-t[1])/1e3}),K=(e,t)=>{let{x:n,z:r}=S(e.offsetMm,t);return{rotationY:-e.rotationDeg*Math.PI/180,position:[n,0,r]}},v=(e,t)=>{if(![e[0],e[1],t[0],t[1]].every(n=>Number.isFinite(n)))throw new RangeError(`a site marker's point and the site's origin must be finite: point [${e.join(", ")}], origin [${t.join(", ")}]`);return S(e,t)},Z=(e,t,n,r)=>{let o=d=>{let l=e.find(a=>a.name===d);if(l===void 0)throw new Error(`floor ${d} is not one of the building's floors (${e.map(a=>a.name).join(", ")})`);return l.levelMm},i=o(n);if(t===null)return"shown";let s=o(t);return i>s?"hidden":i<s&&(r==="lines"||r==="text")?"faint":"shown"},Y=({alone:e,open:t,envelope:n,near:r})=>e||t&&!n?"hidden":t?"envelope":r?"see-through":"solid";var w=(e,t)=>Math.hypot(Math.max(0,e.minX-t.maxX,t.minX-e.maxX),Math.max(0,e.minZ-t.maxZ,t.minZ-e.maxZ)),J=(e,t)=>{let n=Math.hypot(e.maxX-e.minX,e.maxZ-e.minZ)*1;return t.filter(r=>w(e,r.footprint)<=n).map(r=>r.id)},G=({alone:e,markers:t})=>!e&&t;var Q=(e,t,n)=>{let r={minX:e.x,maxX:e.x,minZ:e.z,maxZ:e.z},o=n+6;for(let i of t)w(r,i.footprint)<=10&&(o=Math.max(o,i.top+4));return o};var f=e=>e.normalize("NFKC").toLowerCase(),M=e=>f(e).split(/\s+/u).filter(t=>t!=="");import{z as u}from"zod";var q=["building","tank","lines","text","slab","plate","equipment"],I=u.object({gltf:u.object({extras:u.record(u.string(),u.unknown())})}),P=u.object({sceneRole:u.enum(q),floorName:u.string().min(1).optional()}),D=u.object({buildingId:u.string().min(1),buildingCode:u.string(),buildingName:u.string()}),_=u.object({tankId:u.string().min(1)}),F=u.object({equipmentId:u.string().min(1),equipmentName:u.string().min(1),equipmentTag:u.string(),floorName:u.string().min(1),drawingQuery:u.string().min(1)}),R=e=>{let t=I.safeParse(e);return t.success?t.data.gltf.extras:null},A=(e,t)=>`${e}/${t}`,ne=e=>{let t=R(e);if(t===null||!("sceneRole"in t))return null;let n=P.parse(t);return{role:n.sceneRole,floor:n.floorName===void 0?null:n.floorName}},re=(e,t)=>{let n=R(e);if(n===null)return null;if("buildingId"in n){let r=D.parse(n);return{kind:"building",id:r.buildingId,code:r.buildingCode,name:r.buildingName}}if("tankId"in n)return{kind:"tank",id:_.parse(n).tankId};if("equipmentId"in n){let r=F.parse(n);if(t===null)throw new Error(`equipment ${r.equipmentId} is in the site's model, outside every detailed building`);return{kind:"equipment",id:A(t,r.equipmentId),detailKey:t,name:r.equipmentName,tag:r.equipmentTag,floor:r.floorName,query:r.drawingQuery}}return null},oe=(e,t)=>{for(let n=e;n!==null;n=n.parent){let r=t(n.metadata);if(r!==null)return r}return null},g=e=>{switch(e.kind){case"marker":return e.label;case"tank":return`\u30BF\u30F3\u30AF (${e.id})`;case"equipment":return e.tag===""?`${e.name} (${e.floor})`:`${e.name} (${e.tag}\u30FB${e.floor})`;case"building":return e.name===""?`\u540D\u524D\u306E\u7121\u3044\u5EFA\u5C4B (${e.id})`:e.code===""?e.name:`${e.name} (${e.code})`}},b=(e,t)=>{let n=t.find(r=>r.key===e.detailKey);if(n===void 0)throw new Error(`equipment ${e.id} belongs to detailed building ${e.detailKey}, which the manifest does not have`);return n},ie=(e,t)=>{switch(e.kind){case"equipment":return{building:b(e,t).buildingName,query:e.query};case"building":return e.name===""?null:{building:e.name,query:""};case"tank":case"marker":return null}},ae=(e,t,n,r)=>{let o=M(n),i=l=>{let a=f(l);return o.every(p=>a.includes(p))},s=e.filter(l=>l.kind==="equipment"),d=[];for(let l of e){if(l.kind!=="building")continue;let a=t.find(c=>c.buildingId===l.id);if(a===void 0&&l.name===""||r!==null&&a?.key!==r)continue;let p=i(`${l.name}
2
+ ${l.code}`),x=a===void 0?[]:[...a.floors].sort((c,m)=>m.levelMm-c.levelMm).map(c=>({floor:c,equipment:s.filter(m=>m.detailKey===a.key&&m.floor===c.name&&(p||i(`${m.name}
3
+ ${m.tag}
4
+ ${m.floor}`))).sort((m,y)=>m.name.localeCompare(y.name,"ja")||m.id.localeCompare(y.id))})).filter(c=>p||c.equipment.length>0);(p||x.length>0)&&d.push({building:l,detail:a===void 0?null:a,floors:x})}return d.sort((l,a)=>l.building.name.localeCompare(a.building.name,"ja")||l.building.id.localeCompare(a.building.id))},C=(e,t)=>{switch(e.kind){case"equipment":return b(e,t);case"building":{let n=t.find(r=>r.buildingId===e.id);return n===void 0?null:n}case"tank":case"marker":return null}},se=(e,t,n)=>{switch(e.kind){case"building":{let r=C(e,t);if(r===null)return{title:g(e),meta:"\u5EFA\u5C4B",detail:r};let o=n.filter(i=>i.kind==="equipment"&&i.detailKey===r.key).length;return{title:g(e),meta:`\u5EFA\u5C4B\u30FB\u8A73\u3057\u3044\u6A21\u578B\u3042\u308A (${r.floors.length} \u968E\u30FB\u6A5F\u5668 ${o})`,detail:r}}case"tank":return{title:g(e),meta:"\u30BF\u30F3\u30AF",detail:null};case"marker":return{title:g(e),meta:"\u5370",detail:null};case"equipment":{let r=b(e,t),o=e.tag===""?"":`\u30FB\u8A2D\u5099\u30BF\u30B0 ${e.tag}`;return{title:e.name,meta:`\u6A5F\u5668\u30FB${r.buildingName}\u306E ${e.floor}${o}`,detail:r}}}},le=e=>({kind:"marker",id:e.id,label:e.label}),ue=(e,t)=>{let n=new Map(t.map(r=>[r.id,r.kind]));for(let{id:r}of e){let o=n.get(r);if(o!==void 0)throw new RangeError(`site marker ${JSON.stringify(r)} has the id of an object of the models (${o})`)}return e};export{h as a,B as b,T as c,k as d,j as e,L as f,V as g,X as h,K as i,v as j,Z as k,Y as l,J as m,G as n,Q as o,f as p,M as q,ne as r,re as s,oe as t,g as u,ie as v,ae as w,C as x,se as y,le as z,ue as A};
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ declare const displayOptionsSchema: z.ZodObject<{
7
7
  fadeLines: z.ZodCatch<z.ZodBoolean>;
8
8
  envelope: z.ZodCatch<z.ZodBoolean>;
9
9
  realHeights: z.ZodCatch<z.ZodBoolean>;
10
+ markers: z.ZodCatch<z.ZodBoolean>;
10
11
  }, "strip", z.ZodTypeAny, {
11
12
  shadows: boolean;
12
13
  shading: boolean;
@@ -14,6 +15,7 @@ declare const displayOptionsSchema: z.ZodObject<{
14
15
  fadeLines: boolean;
15
16
  envelope: boolean;
16
17
  realHeights: boolean;
18
+ markers: boolean;
17
19
  }, {
18
20
  shadows?: unknown;
19
21
  shading?: unknown;
@@ -21,6 +23,7 @@ declare const displayOptionsSchema: z.ZodObject<{
21
23
  fadeLines?: unknown;
22
24
  envelope?: unknown;
23
25
  realHeights?: unknown;
26
+ markers?: unknown;
24
27
  }>;
25
28
  type DisplayOptions = z.infer<typeof displayOptionsSchema>;
26
29
  type DisplayOptionKey = keyof DisplayOptions;
@@ -28,12 +31,13 @@ declare const DEFAULT_DISPLAY_OPTIONS: DisplayOptions;
28
31
  type OptionSubjects = {
29
32
  hasDetails: boolean;
30
33
  hasHeights: boolean;
34
+ hasMarkers: boolean;
31
35
  };
32
36
  type OfferedOption = {
33
37
  key: DisplayOptionKey;
34
38
  label: string;
35
39
  };
36
- declare const offeredOptions: ({ hasDetails, hasHeights }: OptionSubjects) => OfferedOption[];
40
+ declare const offeredOptions: ({ hasDetails, hasHeights, hasMarkers }: OptionSubjects) => OfferedOption[];
37
41
  declare const useDisplayOptions: (storageKey: string) => [
38
42
  DisplayOptions,
39
43
  (options: DisplayOptions) => void
@@ -65,6 +69,17 @@ type ScenePaint = {
65
69
  readonly floor: string;
66
70
  };
67
71
  declare const checkedPaint: (paint: ScenePaint) => ScenePaint;
72
+ type MarkerPosition = {
73
+ readonly x: number;
74
+ readonly z: number;
75
+ };
76
+ type SiteMarker = {
77
+ readonly id: string;
78
+ readonly label: string;
79
+ readonly position: MarkerPosition;
80
+ readonly color: string;
81
+ };
82
+ declare const checkedMarkers: (markers: readonly SiteMarker[]) => readonly SiteMarker[];
68
83
  type BuildingObject = {
69
84
  kind: "building";
70
85
  id: string;
@@ -84,7 +99,12 @@ type EquipmentObject = {
84
99
  floor: string;
85
100
  query: string;
86
101
  };
87
- type SceneObject = BuildingObject | TankObject | EquipmentObject;
102
+ type MarkerObject = {
103
+ kind: "marker";
104
+ id: string;
105
+ label: string;
106
+ };
107
+ type SceneObject = BuildingObject | TankObject | EquipmentObject | MarkerObject;
88
108
  type SceneSelection = {
89
109
  id: string;
90
110
  focus: boolean;
@@ -124,6 +144,13 @@ declare const detailPlacement: (detail: Pick<SceneDetail, "rotationDeg" | "offse
124
144
  number,
125
145
  number
126
146
  ]) => DetailPlacement;
147
+ declare const markerPosition: (pointMm: readonly [
148
+ number,
149
+ number
150
+ ], originMm: readonly [
151
+ number,
152
+ number
153
+ ]) => MarkerPosition;
127
154
  type ViewInsets = {
128
155
  top: number;
129
156
  bottom: number;
@@ -154,6 +181,7 @@ type PlantSceneCanvasProps = {
154
181
  linesUrl: string;
155
182
  details: readonly DetailModel[];
156
183
  heights: readonly BuildingHeight[];
184
+ markers: readonly SiteMarker[];
157
185
  display: SceneDisplay;
158
186
  options: DisplayOptions;
159
187
  insets: ViewInsets;
@@ -162,8 +190,8 @@ type PlantSceneCanvasProps = {
162
190
  onLoad: (models: LoadedModels) => void;
163
191
  onFailure: (error: Error) => void;
164
192
  };
165
- declare const PlantSceneCanvas: ({ massingUrl, linesUrl, details, heights, display, options, insets, paint, onPick, onLoad, onFailure }: PlantSceneCanvasProps) => react.JSX.Element;
193
+ declare const PlantSceneCanvas: ({ massingUrl, linesUrl, details, heights, markers, display, options, insets, paint, onPick, onLoad, onFailure }: PlantSceneCanvasProps) => react.JSX.Element;
166
194
  declare const foldForSearch: (text: string) => string;
167
195
  declare const searchTerms: (query: string) => string[];
168
196
  declare const useViewInsets: (view: Element | null, panels: readonly (Element | null)[]) => ViewInsets;
169
- export { type BuildingHeight, type BuildingObject, type BuildingRequest, DEFAULT_DISPLAY_OPTIONS, type DetailModel, type DetailPlacement, type DisplayOptionKey, type DisplayOptions, type EquipmentObject, type LegendEntry, type ListedBuilding, type ListedFloor, type LoadedModels, type ObjectSummary, type OfferedOption, type OptionSubjects, type PlantFloor, PlantSceneCanvas, type PlantSceneCanvasProps, type SceneDetail, type SceneDisplay, type SceneObject, type ScenePaint, type SceneSelection, type TankObject, type ViewInsets, buildingRequestOf, checkedPaint, detailOfObject, detailPlacement, foldForSearch, listedBuildings, objectSummary, offeredOptions, sceneObjectLabel, searchTerms, useDisplayOptions, useViewInsets };
197
+ export { type BuildingHeight, type BuildingObject, type BuildingRequest, DEFAULT_DISPLAY_OPTIONS, type DetailModel, type DetailPlacement, type DisplayOptionKey, type DisplayOptions, type EquipmentObject, type LegendEntry, type ListedBuilding, type ListedFloor, type LoadedModels, type MarkerObject, type MarkerPosition, type ObjectSummary, type OfferedOption, type OptionSubjects, type PlantFloor, PlantSceneCanvas, type PlantSceneCanvasProps, type SceneDetail, type SceneDisplay, type SceneObject, type ScenePaint, type SceneSelection, type SiteMarker, type TankObject, type ViewInsets, buildingRequestOf, checkedMarkers, checkedPaint, detailOfObject, detailPlacement, foldForSearch, listedBuildings, markerPosition, objectSummary, offeredOptions, sceneObjectLabel, searchTerms, useDisplayOptions, useViewInsets };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as g,b as w,c as B,d as H,g as X,k as Z,l as $,p as K,q as ee,r as te,s as ne,t as oe}from"./chunk-IDQ6FMAI.js";import{useCallback as M,useSyncExternalStore as se}from"react";import{z as F}from"zod";var c=F.boolean().catch(!0),re=F.object({shadows:c,shading:c,edges:c,fadeLines:c,envelope:c,realHeights:c}),f={shadows:!0,shading:!0,edges:!0,fadeLines:!0,envelope:!0,realHeights:!0},ie=({hasDetails:e,hasHeights:t})=>[{key:"shadows",label:"\u5F71"},{key:"shading",label:"\u9670\u5F71\u3092\u5F37\u3081\u308B"},{key:"edges",label:"\u8F2A\u90ED\u7DDA"},{key:"fadeLines",label:"\u9060\u304F\u306E\u7DDA\u3092\u8584\u304F"},...e?[{key:"envelope",label:"\u8A73\u3057\u3044\u5EFA\u5C4B\u306E\u5916\u58C1"}]:[],...t?[{key:"realHeights",label:"\u5B9F\u969B\u306E\u9AD8\u3055"}]:[]],pe=e=>{if(e===null)return f;try{let t=re.safeParse(JSON.parse(e));return t.success?t.data:f}catch(t){if(t instanceof SyntaxError)return f;throw t}},h=new Set,le=e=>(h.add(e),window.addEventListener("storage",e),()=>{h.delete(e),window.removeEventListener("storage",e)}),A=new Map,ae=e=>{let t=window.localStorage.getItem(e),n=A.get(e);if(n!==void 0&&n.text===t)return n.options;let o=pe(t);return A.set(e,{text:t,options:o}),o},ce=()=>f,de=(e,t)=>{window.localStorage.setItem(e,JSON.stringify(t));for(let n of h)n()},ue=e=>{if(e==="")throw new RangeError("useDisplayOptions needs a storage key");let t=M(()=>ae(e),[e]),n=M(o=>de(e,o),[e]);return[se(le,t,ce),n]};import{useEffect as O,useEffectEvent as p,useRef as D}from"react";import{jsx as Oe}from"react/jsx-runtime";var ye={position:"absolute",top:0,right:0,bottom:0,left:0,display:"block",width:"100%",height:"100%",touchAction:"none",outlineStyle:"none"},fe=({massingUrl:e,linesUrl:t,details:n,heights:o,display:r,options:l,insets:a,paint:s,onPick:d,onLoad:_,onFailure:q})=>{let P=D(null),u=D(null),b=D(null),z=p(d),Y=p(_),J=p(q),U=p(()=>r),G=p(()=>s),Q=p(()=>a),W=p(()=>l),{isolated:v,floor:x,selection:k}=r,{top:E,bottom:L}=B(a),{sky:I,ground:j,ink:V,floor:R}=g(s);return O(()=>{let C=P.current;if(C===null)return;let m=!1,T=()=>{};return(async()=>{let{openPlantSceneView:y}=await import("./plantScene-7IMBSUGH.js");if(m)return;let S=y(C,G(),W(),i=>z(i));u.current=S,T=S.close,S.inset(Q()),await S.load({massingUrl:e,linesUrl:t},n,o,i=>{m||(b.current=i,i.show(U()),Y({objects:i.objects,legend:i.legend,complete:i.complete}))})})().catch(y=>{m||J(y instanceof Error?y:new Error(String(y)))}),()=>{m=!0,u.current=null,b.current=null,T()}},[e,t,n,o]),O(()=>{u.current?.paint({sky:I,ground:j,ink:V,floor:R})},[I,j,V,R]),O(()=>{u.current?.inset({top:E,bottom:L})},[E,L]),O(()=>{u.current?.options(l)},[l]),O(()=>{b.current?.show({isolated:v,floor:x,selection:k})},[v,x,k]),Oe("canvas",{ref:P,"data-testid":"plant-scene-canvas",style:ye,"aria-label":"\u5DE5\u5834\u306E 3D \u6A21\u578B"})};import{useEffect as me,useState as Se}from"react";var N=e=>{let{left:t,top:n,right:o,bottom:r}=e.getBoundingClientRect();return{left:t,top:n,right:o,bottom:r}},be=(e,t)=>{let[n,o]=Se(w);return me(()=>{if(e===null){o(w);return}let r=t.filter(s=>s!==null),l=()=>{let s=H(N(e),r.map(N));o(d=>d.top===s.top&&d.bottom===s.bottom?d:s)},a=new ResizeObserver(l);a.observe(e);for(let s of r)a.observe(s);return l(),()=>a.disconnect()},[e,t]),n};export{f as DEFAULT_DISPLAY_OPTIONS,fe as PlantSceneCanvas,ee as buildingRequestOf,g as checkedPaint,ne as detailOfObject,X as detailPlacement,Z as foldForSearch,te as listedBuildings,oe as objectSummary,ie as offeredOptions,K as sceneObjectLabel,$ as searchTerms,ue as useDisplayOptions,be as useViewInsets};
1
+ import{b as w,c as k,d as h,e as H,f as A,i as ee,j as te,p as ne,q as oe,u as se,v as re,w as ie,x as ae,y as le}from"./chunk-SL5ZL75K.js";import{useCallback as F,useSyncExternalStore as pe}from"react";import{z as _}from"zod";var p=_.boolean().catch(!0),ce=_.object({shadows:p,shading:p,edges:p,fadeLines:p,envelope:p,realHeights:p,markers:p}),S={shadows:!0,shading:!0,edges:!0,fadeLines:!0,envelope:!0,realHeights:!0,markers:!0},ye=({hasDetails:e,hasHeights:t,hasMarkers:n})=>[{key:"shadows",label:"\u5F71"},{key:"shading",label:"\u9670\u5F71\u3092\u5F37\u3081\u308B"},{key:"edges",label:"\u8F2A\u90ED\u7DDA"},{key:"fadeLines",label:"\u9060\u304F\u306E\u7DDA\u3092\u8584\u304F"},...e?[{key:"envelope",label:"\u8A73\u3057\u3044\u5EFA\u5C4B\u306E\u5916\u58C1"}]:[],...t?[{key:"realHeights",label:"\u5B9F\u969B\u306E\u9AD8\u3055"}]:[],...n?[{key:"markers",label:"\u5370"}]:[]],ue=e=>{if(e===null)return S;try{let t=ce.safeParse(JSON.parse(e));return t.success?t.data:S}catch(t){if(t instanceof SyntaxError)return S;throw t}},D=new Set,de=e=>(D.add(e),window.addEventListener("storage",e),()=>{D.delete(e),window.removeEventListener("storage",e)}),N=new Map,fe=e=>{let t=window.localStorage.getItem(e),n=N.get(e);if(n!==void 0&&n.text===t)return n.options;let o=ue(t);return N.set(e,{text:t,options:o}),o},Oe=()=>S,me=(e,t)=>{window.localStorage.setItem(e,JSON.stringify(t));for(let n of D)n()},Se=e=>{if(e==="")throw new RangeError("useDisplayOptions needs a storage key");let t=F(()=>fe(e),[e]),n=F(o=>me(e,o),[e]);return[pe(de,t,Oe),n]};import{useEffect as d,useEffectEvent as i,useRef as P}from"react";import{jsx as we}from"react/jsx-runtime";var be={position:"absolute",top:0,right:0,bottom:0,left:0,display:"block",width:"100%",height:"100%",touchAction:"none",outlineStyle:"none"},q=e=>e instanceof Error?e:new Error(String(e)),ge=({massingUrl:e,linesUrl:t,details:n,heights:o,markers:r,display:f,options:a,insets:s,paint:c,onPick:Y,onLoad:J,onFailure:U})=>{let v=P(null),y=P(null),b=P(null),G=i(Y),Q=i(J),x=i(U),W=i(()=>f),X=i(()=>c),Z=i(()=>s),$=i(()=>a),K=i(()=>r),{isolated:E,floor:L,selection:j}=f,{top:I,bottom:M}=H(s),{sky:V,ground:R,ink:C,floor:T}=w(c);return k(r),d(()=>{let O=v.current;if(O===null)return;let u=!1,B=()=>{};return(async()=>{let{openPlantSceneView:g}=await import("./plantScene-W6XPMVO7.js");if(u)return;let m=g(O,X(),$(),l=>G(l));y.current=m,B=m.close,m.inset(Z()),m.markers(K()),await m.load({massingUrl:e,linesUrl:t},n,o,l=>{u||(b.current=l,l.show(W()),Q({objects:l.objects,legend:l.legend,complete:l.complete}))})})().catch(g=>{u||x(q(g))}),()=>{u=!0,y.current=null,b.current=null,B()}},[e,t,n,o]),d(()=>{y.current?.paint({sky:V,ground:R,ink:C,floor:T})},[V,R,C,T]),d(()=>{y.current?.inset({top:I,bottom:M})},[I,M]),d(()=>{y.current?.options(a)},[a]),d(()=>{let O=y.current;if(O!==null)try{O.markers(r)}catch(u){x(q(u))}},[r]),d(()=>{b.current?.show({isolated:E,floor:L,selection:j})},[E,L,j]),we("canvas",{ref:v,"data-testid":"plant-scene-canvas",style:be,"aria-label":"\u5DE5\u5834\u306E 3D \u6A21\u578B"})};import{useEffect as ke,useState as he}from"react";var z=e=>{let{left:t,top:n,right:o,bottom:r}=e.getBoundingClientRect();return{left:t,top:n,right:o,bottom:r}},De=(e,t)=>{let[n,o]=he(h);return ke(()=>{if(e===null){o(h);return}let r=t.filter(s=>s!==null),f=()=>{let s=A(z(e),r.map(z));o(c=>c.top===s.top&&c.bottom===s.bottom?c:s)},a=new ResizeObserver(f);a.observe(e);for(let s of r)a.observe(s);return f(),()=>a.disconnect()},[e,t]),n};export{S as DEFAULT_DISPLAY_OPTIONS,ge as PlantSceneCanvas,re as buildingRequestOf,k as checkedMarkers,w as checkedPaint,ae as detailOfObject,ee as detailPlacement,ne as foldForSearch,ie as listedBuildings,te as markerPosition,le as objectSummary,ye as offeredOptions,se as sceneObjectLabel,oe as searchTerms,Se as useDisplayOptions,De as useViewInsets};
@@ -0,0 +1 @@
1
+ import{A as de,a as rt,b as ke,c as st,d as it,e as at,g as lt,h as ct,k as dt,l as ut,m as mt,n as pt,o as ht,r as Ae,s as Re,t as ne,z as ft}from"./chunk-SL5ZL75K.js";import"@babylonjs/core/Animations/animatable.js";import"@babylonjs/core/Culling/ray.js";import"@babylonjs/core/Rendering/edgesRenderer.js";import"@babylonjs/loaders/glTF/index.js";import{Animation as $}from"@babylonjs/core/Animations/animation.js";import{ArcRotateCamera as wn}from"@babylonjs/core/Cameras/arcRotateCamera.js";import{ArcRotateCameraPointersInput as Pn}from"@babylonjs/core/Cameras/Inputs/arcRotateCameraPointersInput.js";import{Engine as In}from"@babylonjs/core/Engines/engine.js";import{PointerEventTypes as En}from"@babylonjs/core/Events/pointerEvents.js";import{HighlightLayer as On}from"@babylonjs/core/Layers/highlightLayer.js";import{DirectionalLight as kn}from"@babylonjs/core/Lights/directionalLight.js";import{HemisphericLight as jt}from"@babylonjs/core/Lights/hemisphericLight.js";import{ShadowGenerator as An}from"@babylonjs/core/Lights/Shadows/shadowGenerator.js";import{ImportMeshAsync as De}from"@babylonjs/core/Loading/sceneLoader.js";import{Material as $t}from"@babylonjs/core/Materials/material.js";import{StandardMaterial as me}from"@babylonjs/core/Materials/standardMaterial.js";import{DynamicTexture as Rn}from"@babylonjs/core/Materials/Textures/dynamicTexture.js";import{RenderTargetTexture as Tn}from"@babylonjs/core/Materials/Textures/renderTargetTexture.js";import{Color3 as k,Color4 as Gt}from"@babylonjs/core/Maths/math.color.js";import{Matrix as _n,Vector3 as P}from"@babylonjs/core/Maths/math.vector.js";import{CreateCylinder as Nn}from"@babylonjs/core/Meshes/Builders/cylinderBuilder.js";import{CreateGround as Ln}from"@babylonjs/core/Meshes/Builders/groundBuilder.js";import{CreatePlane as Dn}from"@babylonjs/core/Meshes/Builders/planeBuilder.js";import{CreateSphere as Cn}from"@babylonjs/core/Meshes/Builders/sphereBuilder.js";import{Mesh as vn}from"@babylonjs/core/Meshes/mesh.js";import{TransformNode as Fe}from"@babylonjs/core/Meshes/transformNode.js";import{Scene as Fn}from"@babylonjs/core/scene.js";var _e=1e3,Mt=2,ue=[-.5,-1,.35],sn=-ue[1]/Math.hypot(...ue),an={sky:.55,skyGround:[.3,.3,.34],sun:1},ln={sky:.75,skyGround:[.45,.45,.5],sun:.6},yt=e=>e?an:ln,cn=.85,St=(e,n,r,l)=>{let c=n/2/cn/(Math.tan(r/2)*l);return Number.isFinite(c)?Math.max(e,c):e},wt=e=>1-e*sn,dn=.35,un=1,mn=.7,Pt=(e,n)=>{let r=n*dn,l=n*un;return mn*Math.min(1,Math.max(0,(e-r)/(l-r)))},pn=1,hn=50,It=(e,n)=>2*hn*pn*e/n,Et=(e,n,r)=>{let l=r/(n-e);return{scaleY:l,offsetY:e-e*l}},Ot=(e,n)=>e===null?n:e/_e,kt=(e,n,r)=>{if(n!==null)return n/_e;let l=e.at(-1),c=e.at(-2);return l===void 0||c===void 0?r:(l.levelMm*2-c.levelMm)/_e},Te=3,At=()=>{let e=Te,n=[];return{invalidate:()=>{e=Te},shouldDraw:(r,l)=>{let c=r.length!==n.length||r.some((i,I)=>i!==n[I]);return n=r,(c||l)&&(e=Te),e>0},drawn:r=>{r&&(e=Math.max(0,e-1))}}},fn=[6,12],gt=8,Rt=(e,n)=>fn.flatMap(r=>Array.from({length:gt},(l,c)=>{let i=c/gt*2*Math.PI;return{x:e+r*Math.cos(i),y:n+r*Math.sin(i)}})),gn=Math.PI/4,Tt=e=>Math.min(e,gn),_t=(e,n,r,l)=>r/(2*e*Math.tan(n/2))/(1-l),Nt=4,Lt=(e,n,r,l)=>{let c=(r-e.y)/n.y;return c>0&&c<=l?{x:e.x+n.x*c,y:r,z:e.z+n.z*c}:null},Dt=(e,n,r,l,c)=>{let i=e.x+n.x-r.x-l.x,I=e.z+n.z-r.z-l.z,d=Math.min(1,c/Math.hypot(i,I));return{x:l.x+i*d,y:e.y,z:l.z+I*d}},Ct=(e,n,r)=>2*e*Math.tan(n/2)/r,vt=(e,n,r,l)=>{let c=n.x*e[0]+n.y*e[4]+n.z*e[8]+e[12],i=n.x*e[1]+n.y*e[5]+n.z*e[9]+e[13],I=n.x*e[3]+n.y*e[7]+n.z*e[11]+e[15];if(!(I>0))return null;let d=c/I,p=i/I;return Math.abs(d)>1||Math.abs(p)>1?null:{x:(d+1)/2*r,y:(1-p)/2*l}},bt=e=>{if(!rt(e))throw new RangeError(`a colour must be #rrggbb, not ${JSON.stringify(e)}`);let[n,r,l]=[1,3,5].map(c=>{let i=Number.parseInt(e.slice(c,c+2),16)/255;return i<=.04045?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*r+.0722*l},xt=(e,n)=>{let[r,l]=[bt(e),bt(n)].sort((c,i)=>i-c);return(r+.05)/(l+.05)},bn=["#000000","#ffffff"],Ft=e=>{let[n,r]=bn;return xt(e,n)>=xt(e,r)?n:r},Ne=16,Le=3,xn=19,Mn=28,yn=8,Sn=4,Ht=e=>`bold ${Math.round(xn*e)}px sans-serif`,Bt=(e,n)=>{let r=Math.ceil(e+2*yn*n),l=Math.round(Mn*n),c=r/n;return{textureWidth:r,textureHeight:l,widthPx:c,heightPx:l/n,offsetPx:Ne/2+Sn+c/2}};var Hn=[1,.78,.18],Bn=2.7,jn=4,Wt=1.1,Gn=3,Wn=5,zn=1.3,Vn=2,Ce=30,Xn=.05,Un=1.3,$n=.35,Yn=.25,Zn=.25,Kn=.22,qn=.005,Jn=.05,Qn=2048,eo=.45,to=3e-4,no=2,oo=.95,ro=[.12,.16,.22,.55],zt=new Set(["building","tank","slab","equipment"]),so=new Set(["building","tank","equipment"]),io=e=>{let n=e.material;return n!==null&&"albedoColor"in n&&n.albedoColor instanceof k?n.albedoColor.toGammaSpace().toHexString():null},oe=(e,n,r)=>{e.setEnabled(n!=="hidden"),e.visibility=n==="faint"?Zn:1,e.isPickable=r&&n==="shown"},Vt=(e,n,r)=>{e.material=n,e.setEnabled(!0),e.visibility=r,e.isPickable=!1},ao=e=>{let n=e.clone(`${e.name}-see-through`);if(n===null)throw new Error(`the site model's material ${e.name} cannot be copied`);return n.transparencyMode=$t.MATERIAL_ALPHABLEND,n.backFaceCulling=!0,n},Xt=e=>e.flatMap(n=>{let r=ne(n,Ae);return r===null?[]:[{mesh:n,part:r,detail:null,object:ne(n,l=>Re(l,null))}]}),re=e=>e.detail===null&&(e.part.role==="building"||e.part.role==="tank"),Ut=e=>({min:e.reduce((n,r)=>P.Minimize(n,r.min),new P(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)),max:e.reduce((n,r)=>P.Maximize(n,r.max),new P(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY))}),ve=1,lo=e=>{e.setRenderingAutoClearDepthStencil(ve,!0,!0,!1);let n=[],r=!1,l=new Map,c=P.Zero(),i=d=>{let p=`marker-${d.id}`,h=new me(`${p}-paint`,e);h.disableLighting=!0,h.emissiveColor=k.FromHexString(d.color);let x=1/e.getEngine().getHardwareScalingLevel(),M=Ht(x),_=new Rn(`${p}-tag`,{width:1,height:1},e,!1),z=_.getContext();z.font=M;let C=Bt(z.measureText(d.label).width,x);_.scaleTo(C.textureWidth,C.textureHeight),_.drawText(d.label,null,null,M,Ft(d.color),d.color,!0,!0);let L=new me(`${p}-board`,e);L.disableLighting=!0,L.emissiveTexture=_;let G=new Fe(p,e),A=Nn(`${p}-pole`,{height:1,diameter:1,tessellation:12},e),R=Cn(`${p}-head`,{diameter:1,segments:12},e),D=Dn(`${p}-tag`,{width:C.widthPx,height:C.heightPx},e);D.bakeTransformIntoVertices(_n.Translation(C.offsetPx,0,0)),D.billboardMode=Fe.BILLBOARDMODE_ALL,D.material=L,A.material=h,R.material=h,A.isPickable=!1,R.renderingGroupId=ve,D.renderingGroupId=ve;for(let Y of[A,R,D])Y.parent=G;G.setEnabled(r);let X={object:ft(d),position:d.position,root:G,pole:A,head:R,tag:D,headPoint:P.Zero(),paint:h,board:L,texture:_};return l.set(R,X),l.set(D,X),X},I=(d,p)=>{if(!r||n.length===0)return null;let{pickedMesh:h}=e.pick(d,p,M=>l.has(M)&&M.isEnabled()&&M.isPickable),x=h===null?void 0:l.get(h);return x===void 0?null:x.object};return{draw:d=>{for(let p of n)p.root.dispose(),p.paint.dispose(),p.board.dispose(),p.texture.dispose();l.clear(),n=d.map(i)},place:(d,p)=>{for(let h of n){let x=ht(h.position,p,d)-d;h.root.position.copyFromFloats(h.position.x,d,h.position.z),h.pole.position.y=x/2,h.pole.scaling.y=x,h.head.position.y=x,h.tag.position.y=x,h.headPoint.copyFromFloats(h.position.x,d+x,h.position.z)}},show:d=>{r=d;for(let p of n)p.root.setEnabled(d)},scale:(d,p,h,x)=>{if(r)for(let M of n){P.TransformCoordinatesToRef(M.headPoint,d,c);let _=Ct(Math.max(c.z,x),p,h);M.head.scaling.setAll(Ne*_),M.tag.scaling.setAll(_),M.pole.scaling.x=Le*_,M.pole.scaling.z=Le*_}},meshesOf:d=>{let p=n.find(h=>h.object.id===d);return p===void 0?[]:[p.pole,p.head]},at:I,positions:(d,p,h)=>r?n.flatMap(x=>{let M=vt(d.m,x.headPoint,p,h);return M===null||I(M.x,M.y)?.id!==x.object.id?[]:[{id:x.object.id,x:M.x,y:M.y}]}):[]}},Vo=(e,n,r,l)=>{ke(n);let c=new In(e,!0,{stencil:!0,preserveDrawingBuffer:!1,limitDeviceRatio:Mt},!0),i=new Fn(c),I=At(),d=o=>{let s=new me(o,i);return s.disableLighting=!0,s},p=o=>{let s=new me(o,i);return s.specularColor=k.Black(),s},h=p("ground"),x=d("ink-lines");x.fillMode=$t.LineListDrawMode;let M=d("ink-text");M.backFaceCulling=!1;let _=p("floor-slab"),z=d("floor-plate");z.alpha=$n,z.backFaceCulling=!1;let C=new jt("sky",P.Up(),i),L=new kn("sun",new P(...ue),i),G=new jt("ground-fill",P.Up(),i);G.groundColor=k.Black(),G.specular=k.Black();let A=Ln("ground",{width:1,height:1},i);A.material=h,A.isPickable=!1,A.receiveShadows=!0,C.excludedMeshes=[A],G.includedOnlyMeshes=[A];let R=new An(Qn,L);R.usePercentageCloserFiltering=!0,R.setDarkness(eo),R.bias=to,R.transparencyShadow=!0;let D=R.getShadowMap();if(D===null)throw new Error("the sun's shadow generator has no shadow map");D.refreshRate=Tn.REFRESHRATE_RENDER_ONCE;let X=new k,Y=new k,Yt=new Gt(...ro),pe=0,v=r,Z=it,K=!1,se=!0,he=()=>{},q=()=>{K=!1,I.invalidate()},He=()=>{k.LerpToRef(X,Y,pe,x.emissiveColor),M.emissiveColor.copyFrom(x.emissiveColor)},Be=o=>{let{sky:s,ground:f,ink:g,floor:S}=ke(o);i.clearColor=Gt.FromColor3(k.FromHexString(s),1),Y.copyFrom(k.FromHexString(f)),h.diffuseColor.copyFrom(Y),X.copyFrom(k.FromHexString(g)),He(),_.diffuseColor=k.FromHexString(S),z.emissiveColor=k.FromHexString(S),q()};Be(n);let T=[],je=new Map,fe=new Map,Ge=new Map,ge=new Map,We=new Map,ze=new Map,be=null,xe={isolated:null,floor:null,selection:null},Me=new On("selection",i),Zt=new k(...Hn),W=lo(i),ye=!1,ie=[],Kt=o=>T.filter(s=>s.object?.id===o&&s.part.role!=="lines"&&s.part.role!=="text"&&!(s.detail===null&&ge.has(o))).map(s=>s.mesh),J=()=>[...new Map(T.flatMap(o=>o.object===null?[]:[[o.object.id,o.object]])).values()],Ve=()=>{if(!ye)return;let o=T.filter(re).map(({mesh:s})=>{s.computeWorldMatrix(!0);let{minimumWorld:f,maximumWorld:g}=s.getBoundingInfo().boundingBox;return{footprint:{minX:f.x,maxX:g.x,minZ:f.z,maxZ:g.z},top:g.y}});W.place(A.position.y,o)},qt=(o,s,f,g)=>{let S=o.object!==null&&zt.has(o.part.role),E=je.get(o.mesh);if(E===void 0){oe(o.mesh,s?"hidden":"shown",S);return}let m=g?.has(String(o.mesh.uniqueId))===!0;m?R.removeShadowCaster(o.mesh,!1):R.addShadowCaster(o.mesh,!1);let F=f!==void 0&&o.object?.id===f.buildingId;switch(ut({alone:s,open:F,envelope:v.envelope,near:m})){case"hidden":oe(o.mesh,"hidden",S);break;case"envelope":Vt(o.mesh,E.seeThrough,Kn);break;case"see-through":Vt(o.mesh,E.seeThrough,Yn);break;case"solid":o.mesh.material=E.solid,oe(o.mesh,"shown",S);break}},Se=o=>{xe=o;let s=be===null||o.isolated===null?null:be.find(m=>m.key===o.isolated);if(s===void 0)throw new Error(`no detailed building ${o.isolated} to show alone`);let f=o.selection===null?void 0:ze.get(o.selection.id),g=s===null?f:s,S=s===null&&f!==void 0?We.get(f.key):void 0;for(let m of T){if(m.detail===null){qt(m,s!==null,g,S);continue}let F=m.object!==null&&zt.has(m.part.role);if(m.detail.key!==g?.key){oe(m.mesh,"hidden",F);continue}let H=m.part.floor;if(H===null)throw new Error(`a ${m.part.role} of detailed building ${m.detail.key} names no floor`);oe(m.mesh,s===null?"shown":dt(m.detail.floors,o.floor,H,m.part.role),F)}W.show(pt({alone:s!==null,markers:v.markers})),Me.removeAllMeshes();let E=o.selection===null?[]:[...Kt(o.selection.id),...W.meshesOf(o.selection.id)].filter(m=>m.isEnabled());for(let m of E)m instanceof vn&&Me.addMesh(m,Zt);return{isolated:s,selectedMeshes:E}},Jt=o=>{v.edges&&o.edgesRenderer===null&&(o.enableEdgesRendering(oo,!0),o.edgesColor=Yt),o.edgesRenderer!==null&&(o.edgesRenderer.isEnabled=v.edges)},Qt=({mesh:o,object:s})=>{if(s?.kind!=="building")return;let{minimum:f,maximum:g}=o.getBoundingInfo().boundingBox,S=g.y-f.y,E=v.realHeights?Ge.get(s.id)??null:null,m=ge.get(s.id),F=m===void 0?Ot(E,S):kt(m.floors,E,S),{scaleY:H,offsetY:N}=Et(f.y,g.y,F);o.scaling.y=H,o.position.y=N},ae=()=>{let o=yt(v.shading);C.intensity=o.sky,C.groundColor=new k(...o.skyGround),L.intensity=o.sun,G.intensity=wt(o.sun),L.shadowEnabled=v.shadows;for(let s of T)re(s)&&(Jt(s.mesh),Qt(s));Ve(),Se(xe),se=!0,q()};ae();let Xe=o=>{let{min:s,max:f}=Ut(o),g=P.Center(s,f),S=Math.max(f.x-s.x,f.z-s.z)*Un;A.scaling=new P(S,1,S),A.position=new P(g.x,s.y-Xn,g.z);let E=S*no;L.position=g.subtract(L.direction.normalizeToNew().scale(E)),L.shadowMinZ=1,L.shadowMaxZ=E*2},en=o=>{let s=new Map;for(let{mesh:f}of o.filter(re)){let g=f.material;if(g===null)throw new Error(`the site model's box ${f.name} has no material`);let S=s.get(g)??ao(g);s.set(g,S),je.set(f,{solid:g,seeThrough:S})}},Ue=o=>{for(let{mesh:s,part:f}of o)so.has(f.role)&&R.addShadowCaster(s,!1);for(let s of o)s.mesh.receiveShadows=re(s)||s.part.role==="slab"},$e=new ResizeObserver(()=>{c.resize(),I.invalidate(),he()});$e.observe(e);let Ye=()=>I.invalidate();document.addEventListener("visibilitychange",Ye),c.onContextRestoredObservable.add(q);let U=new AbortController;return{load:async(o,s,f,g)=>{let S=await De(o.massingUrl,i,{pluginExtension:".glb"});if(i.isDisposed)return;T.push(...Xt(S.meshes)),de(ie,J()),en(T);let E=new Map(T.flatMap(t=>t.object?.kind==="building"?[[t.object.id,t.object]]:[]));for(let{buildingId:t,heightMm:u}of f){if(!E.has(t))throw new Error(`the height table names site building ${t}, which the site model does not have`);Ge.set(t,u)}Ue(T);let m=S.meshes[0].getHierarchyBoundingVectors(!0),F=P.Center(m.min,m.max),H=Math.max(m.max.x-m.min.x,m.max.z-m.min.z);Xe([m]),ye=!0,W.draw(ie);let N=Z,a=new wn("camera",Math.PI/2,Math.PI/3.2,H*Wt,F.clone(),i),we=(t,u)=>St(t,u,a.fov,e.clientWidth/e.clientHeight),Pe=()=>we(H*Wt,H);a.radius=Pe(),a.lowerRadiusLimit=Vn,a.upperBetaLimit=Math.PI/2.05,a.wheelDeltaPercentage=.02,a.attachControl(e,!0);let le=a.inputs.attached.pointers;le instanceof Pn&&(le.useNaturalPinchZoom=!0,le.multiTouchPanAndZoom=!1,le.multiTouchPanning=!1);let Q=new Map,ee=null,Ze=()=>{let[t,u]=[...Q.values()],{origin:b,direction:y}=i.createPickingRay((t.x+u.x)/2,(t.y+u.y)/2,null,a);return Lt(b,y,A.position.y,a.radius*Nt)},Ke=t=>{t.pointerType==="touch"&&(Q.set(t.pointerId,{x:t.offsetX,y:t.offsetY}),t.type==="pointerdown"&&Q.size===2&&(ee=Ze()))},qe=t=>{Q.delete(t.pointerId)};e.addEventListener("pointerdown",Ke,{signal:U.signal}),e.addEventListener("pointermove",Ke,{signal:U.signal}),e.addEventListener("pointerup",qe,{signal:U.signal}),e.addEventListener("pointercancel",qe,{signal:U.signal}),e.addEventListener("touchend",t=>t.preventDefault(),{passive:!1,signal:U.signal});let tn=()=>{if(Q.size!==2){ee=null;return}let t=Ze();if(t===null)return;if(ee===null){ee=t;return}let{x:u,y:b,z:y}=Dt(a.target,ee,t,F,H);a.target.copyFromFloats(u,b,y)};a.onProjectionMatrixChangedObservable.add(()=>ct(a.getProjectionMatrix(),N)),i.onBeforeRenderObservable.add(()=>{a.minZ=Math.max(Jn,a.radius*qn);let t=lt(N,Z,c.getDeltaTime()/1e3);(t.top!==N.top||t.bottom!==N.bottom)&&(N=t,a.getProjectionMatrix(!0));let u=v.fadeLines?Pt(a.radius,H):0;if(u!==pe&&(pe=u,He()),v.edges){let b=It(a.radius,e.clientHeight);for(let y of T)y.mesh.edgesWidth=b}W.scale(a.getViewMatrix(),a.fov,e.clientHeight*(1-N.top-N.bottom),a.minZ)});let Ie=(t,u,b)=>{$.CreateAndStartAnimation("move-target",a,"target",60,Ce,a.target.clone(),t,$.ANIMATIONLOOPMODE_CONSTANT),$.CreateAndStartAnimation("move-radius",a,"radius",60,Ce,a.radius,u,$.ANIMATIONLOOPMODE_CONSTANT),b!==null&&$.CreateAndStartAnimation("move-beta",a,"beta",60,Ce,a.beta,b,$.ANIMATIONLOOPMODE_CONSTANT)},Je=null,Qe=null,et=t=>{let{isolated:u,selectedMeshes:b}=Se(t),y=t.selection,O=u===null?null:u.key;if(O!==Je)if(O===null)Ie(F,Pe(),null);else{let w=fe.get(O);if(w!==void 0){let{min:B,max:j}=w.getHierarchyBoundingVectors(!0),V=P.Distance(B,j);Ie(P.Center(B,j),we(V*zn,V),null)}}else if(y!==null&&y!==Qe&&y.focus&&b.length>0){let{min:w,max:B}=Ut(b.map(V=>V.getHierarchyBoundingVectors(!0))),j=P.Distance(w,B);Ie(P.Center(w,B),we(Math.max(j*Gn,Wn),j),Tt(a.beta))}Je=O,Qe=y,se=!0,q()},nn=(t,u)=>{let b=W.at(i.pointerX,i.pointerY);if(b!==null)return b;let y=t===null?void 0:T.find(O=>O.mesh===t);if(y!==void 0||!u)return y===void 0?null:y.object;for(let{x:O,y:w}of Rt(i.pointerX,i.pointerY)){let B=W.at(O,w);if(B!==null)return B;let{pickedMesh:j}=i.pick(O,w),V=j===null?void 0:T.find(rn=>rn.mesh===j);if(V!==void 0)return V.object}return null};i.onPointerObservable.add(t=>{if(t.type!==En.POINTERTAP)return;let u="pointerType"in t.event&&t.event.pointerType==="touch";l(nn(t.pickInfo?.hit===!0?t.pickInfo.pickedMesh:null,u))});let Ee=[],Oe=(t,u)=>{if(u===void 0)return;let b=io(u.mesh);if(b===null)throw new Error(`the site model's box ${u.mesh.name} (${t}) has no PBR base colour`);Ee.push({label:t,color:b})},ce=T.filter(re);Oe("\u540D\u524D\u306E\u3042\u308B\u5EFA\u5C4B",ce.find(t=>t.object?.kind==="building"&&t.object.name!=="")),Oe("\u540D\u524D\u306E\u7121\u3044\u5EFA\u5C4B",ce.find(t=>t.object?.kind==="building"&&t.object.name==="")),Oe("\u30BF\u30F3\u30AF",ce.find(t=>t.part.role==="tank")),ae(),he=()=>i.render(!1),c.runRenderLoop(()=>{a.panningSensibility=_t(a.radius,a.fov,e.clientHeight*(1-N.top-N.bottom),a.panningInertia),a.upperRadiusLimit=Pe()*Bn,a.maxZ=a.upperRadiusLimit*jn,a.update(),tn();let t=N.top!==Z.top||N.bottom!==Z.bottom,u=[a.alpha,a.beta,a.radius,a.target.x,a.target.y,a.target.z];I.shouldDraw(u,t||i.animatables.length>0)&&(e.dataset.cameraPose=u.join(" "),K=K||i.isReady(),K&&se&&(se=!1,D.resetRefreshCounter()),he(),e.dataset.markerPositions=JSON.stringify(W.positions(i.getTransformMatrix(),e.clientWidth,e.clientHeight)),I.drawn(K))}),g({objects:J(),legend:Ee,complete:!1,show:et});let[tt,...nt]=await Promise.all([De(o.linesUrl,i,{pluginExtension:".glb"}),...s.map(t=>De(t.glbUrl,i,{pluginExtension:".glb"}))]);if(i.isDisposed)return;let te=Xt(tt.meshes);s.forEach((t,u)=>{let b=E.get(t.buildingId);if(b===void 0)throw new Error(`detailed building ${t.key} replaces site building ${t.buildingId}, which the site model does not have`);let y=new Fe(`detail-${t.key}`,i);y.rotation.y=t.placement.rotationY,y.position=new P(...t.placement.position),nt[u].meshes[0].parent=y,fe.set(t.key,y),ge.set(t.buildingId,t);for(let O of nt[u].meshes){let w=ne(O,Ae);if(w===null)continue;if(w.floor===null)throw new Error(`a ${w.role} of detailed building ${t.key} names no floor`);let B=w.role==="slab"||w.role==="plate"?b:ne(O,j=>Re(j,t.key));te.push({mesh:O,part:w,detail:t,object:B})}});for(let t of te)switch(t.part.role){case"lines":t.mesh.material=x;break;case"text":t.mesh.material=M;break;case"slab":t.mesh.material=_,C.excludedMeshes.push(t.mesh),G.includedOnlyMeshes.push(t.mesh);break;case"plate":t.mesh.material=z;break;default:break}T.push(...te),de(ie,J()),Ue(te);let ot=[...fe.values()].map(t=>t.getHierarchyBoundingVectors(!0));Xe([m,tt.meshes[0].getHierarchyBoundingVectors(!0),...ot]);let on=t=>{let{minimumWorld:u,maximumWorld:b}=t.getBoundingInfo().boundingBox;return{minX:u.x,maxX:b.x,minZ:u.z,maxZ:b.z}};s.forEach((t,u)=>{let{min:b,max:y}=ot[u],O=ce.filter(w=>w.object?.id!==t.buildingId).map(w=>({id:String(w.mesh.uniqueId),footprint:on(w.mesh)}));We.set(t.key,new Set(mt({minX:b.x,maxX:y.x,minZ:b.z,maxZ:y.z},O)))});for(let t of te)t.detail!==null&&t.object!==null&&ze.set(t.object.id,t.detail);be=s,ae(),g({objects:J(),legend:Ee,complete:!0,show:et})},paint:Be,inset:o=>{Z=at(o)},options:o=>{v=o,ae()},markers:o=>{de(st(o),J()),ie=o,Me.removeAllMeshes(),ye&&(W.draw(o),Ve()),Se(xe),q()},close:()=>{$e.disconnect(),document.removeEventListener("visibilitychange",Ye),U.abort(),c.stopRenderLoop(),i.dispose(),c.dispose()}}};export{Vo as openPlantSceneView};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aiquants/plant-scene",
3
- "version": "0.1.0",
4
- "description": "React 3D view of a plant site drawn with Babylon.js: site massing and drawing lines from GLB, detailed buildings by floor, an orbit camera moved by fingers, picking and display options.",
3
+ "version": "0.2.0",
4
+ "description": "React 3D view of a plant site drawn with Babylon.js: site massing and drawing lines from GLB, detailed buildings by floor, site markers with name tags, an orbit camera moved by fingers, picking and display options.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "types": "./dist/index.d.ts",
@@ -1,4 +0,0 @@
1
- var w=/^#[0-9a-f]{6}$/iu,O=["sky","ground","ink","floor"],B=e=>{for(let t of O){let n=e[t];if(typeof n!="string"||!w.test(n))throw new RangeError(`the scene's ${t} colour must be #rrggbb, not ${JSON.stringify(n)}`)}return e};var h={top:0,bottom:0},q=.15,D=1e-4,T=e=>{for(let t of[e.top,e.bottom])if(!Number.isFinite(t)||t<0)throw new RangeError(`view insets must be finite and not negative: top ${e.top}, bottom ${e.bottom}`);if(e.top+e.bottom>=1)throw new RangeError(`view insets must leave some height in sight: top ${e.top}, bottom ${e.bottom}`);return e},V=(e,t)=>{let n=e.bottom-e.top,o=e.right-e.left;if(!(Number.isFinite(n)&&Number.isFinite(o)&&n>0&&o>0))return h;let s=(e.top+e.bottom)/2,l=0,u=0;for(let i of t){let r={left:Math.max(i.left,e.left),top:Math.max(i.top,e.top),right:Math.min(i.right,e.right),bottom:Math.min(i.bottom,e.bottom)};r.left<r.right&&r.top<r.bottom&&((r.top+r.bottom)/2<s?l=Math.max(l,r.bottom-e.top):u=Math.max(u,e.bottom-r.top))}let m={top:l/n,bottom:u/n};return m.top+m.bottom<1?m:h},L=(e,t,n)=>{if(!Number.isFinite(n)||n<0)throw new RangeError(`elapsed seconds must be finite and not negative: ${n}`);let o=1-Math.exp(-n/q),s=(l,u)=>{let m=l+(u-l)*o;return Math.abs(u-m)<D?u:m};return{top:s(e.top,t.top),bottom:s(e.bottom,t.bottom)}},X=(e,t)=>{let n=1-t.top-t.bottom,o=t.bottom-t.top,s=e.m;for(let l=0;l<4;l+=1){let u=l*4;e.setRowFromFloats(l,s[u]*n,s[u+1]*n+s[u+3]*o,s[u+2],s[u+3])}};var v=(e,t)=>({rotationY:-e.rotationDeg*Math.PI/180,position:[-(e.offsetMm[0]-t[0])/1e3,0,-(e.offsetMm[1]-t[1])/1e3]}),j=(e,t,n,o)=>{let s=m=>{let i=e.find(r=>r.name===m);if(i===void 0)throw new Error(`floor ${m} is not one of the building's floors (${e.map(r=>r.name).join(", ")})`);return i.levelMm},l=s(n);if(t===null)return"shown";let u=s(t);return l>u?"hidden":l<u&&(o==="lines"||o==="text")?"faint":"shown"},Z=({alone:e,open:t,envelope:n,near:o})=>e||t&&!n?"hidden":t?"envelope":o?"see-through":"solid";var E=(e,t)=>Math.hypot(Math.max(0,e.minX-t.maxX,t.minX-e.maxX),Math.max(0,e.minZ-t.maxZ,t.minZ-e.maxZ)),Y=(e,t)=>{let n=Math.hypot(e.maxX-e.minX,e.maxZ-e.minZ)*1;return t.filter(o=>E(e,o.footprint)<=n).map(o=>o.id)};var g=e=>e.normalize("NFKC").toLowerCase(),S=e=>g(e).split(/\s+/u).filter(t=>t!=="");import{z as a}from"zod";var M=["building","tank","lines","text","slab","plate","equipment"],$=a.object({gltf:a.object({extras:a.record(a.string(),a.unknown())})}),I=a.object({sceneRole:a.enum(M),floorName:a.string().min(1).optional()}),R=a.object({buildingId:a.string().min(1),buildingCode:a.string(),buildingName:a.string()}),N=a.object({tankId:a.string().min(1)}),P=a.object({equipmentId:a.string().min(1),equipmentName:a.string().min(1),equipmentTag:a.string(),floorName:a.string().min(1),drawingQuery:a.string().min(1)}),k=e=>{let t=$.safeParse(e);return t.success?t.data.gltf.extras:null},F=(e,t)=>`${e}/${t}`,G=e=>{let t=k(e);if(t===null||!("sceneRole"in t))return null;let n=I.parse(t);return{role:n.sceneRole,floor:n.floorName===void 0?null:n.floorName}},J=(e,t)=>{let n=k(e);if(n===null)return null;if("buildingId"in n){let o=R.parse(n);return{kind:"building",id:o.buildingId,code:o.buildingCode,name:o.buildingName}}if("tankId"in n)return{kind:"tank",id:N.parse(n).tankId};if("equipmentId"in n){let o=P.parse(n);if(t===null)throw new Error(`equipment ${o.equipmentId} is in the site's model, outside every detailed building`);return{kind:"equipment",id:F(t,o.equipmentId),detailKey:t,name:o.equipmentName,tag:o.equipmentTag,floor:o.floorName,query:o.drawingQuery}}return null},U=(e,t)=>{for(let n=e;n!==null;n=n.parent){let o=t(n.metadata);if(o!==null)return o}return null},f=e=>{switch(e.kind){case"tank":return`\u30BF\u30F3\u30AF (${e.id})`;case"equipment":return e.tag===""?`${e.name} (${e.floor})`:`${e.name} (${e.tag}\u30FB${e.floor})`;case"building":return e.name===""?`\u540D\u524D\u306E\u7121\u3044\u5EFA\u5C4B (${e.id})`:e.code===""?e.name:`${e.name} (${e.code})`}},b=(e,t)=>{let n=t.find(o=>o.key===e.detailKey);if(n===void 0)throw new Error(`equipment ${e.id} belongs to detailed building ${e.detailKey}, which the manifest does not have`);return n},W=(e,t)=>{switch(e.kind){case"equipment":return{building:b(e,t).buildingName,query:e.query};case"building":return e.name===""?null:{building:e.name,query:""};case"tank":return null}},ee=(e,t,n,o)=>{let s=S(n),l=i=>{let r=g(i);return s.every(p=>r.includes(p))},u=e.filter(i=>i.kind==="equipment"),m=[];for(let i of e){if(i.kind!=="building")continue;let r=t.find(c=>c.buildingId===i.id);if(r===void 0&&i.name===""||o!==null&&r?.key!==o)continue;let p=l(`${i.name}
2
- ${i.code}`),x=r===void 0?[]:[...r.floors].sort((c,d)=>d.levelMm-c.levelMm).map(c=>({floor:c,equipment:u.filter(d=>d.detailKey===r.key&&d.floor===c.name&&(p||l(`${d.name}
3
- ${d.tag}
4
- ${d.floor}`))).sort((d,y)=>d.name.localeCompare(y.name,"ja")||d.id.localeCompare(y.id))})).filter(c=>p||c.equipment.length>0);(p||x.length>0)&&m.push({building:i,detail:r===void 0?null:r,floors:x})}return m.sort((i,r)=>i.building.name.localeCompare(r.building.name,"ja")||i.building.id.localeCompare(r.building.id))},_=(e,t)=>{switch(e.kind){case"equipment":return b(e,t);case"building":{let n=t.find(o=>o.buildingId===e.id);return n===void 0?null:n}case"tank":return null}},te=(e,t,n)=>{switch(e.kind){case"building":{let o=_(e,t);if(o===null)return{title:f(e),meta:"\u5EFA\u5C4B",detail:o};let s=n.filter(l=>l.kind==="equipment"&&l.detailKey===o.key).length;return{title:f(e),meta:`\u5EFA\u5C4B\u30FB\u8A73\u3057\u3044\u6A21\u578B\u3042\u308A (${o.floors.length} \u968E\u30FB\u6A5F\u5668 ${s})`,detail:o}}case"tank":return{title:f(e),meta:"\u30BF\u30F3\u30AF",detail:null};case"equipment":{let o=b(e,t),s=e.tag===""?"":`\u30FB\u8A2D\u5099\u30BF\u30B0 ${e.tag}`;return{title:e.name,meta:`\u6A5F\u5668\u30FB${o.buildingName}\u306E ${e.floor}${s}`,detail:o}}}};export{B as a,h as b,T as c,V as d,L as e,X as f,v as g,j as h,Z as i,Y as j,g as k,S as l,G as m,J as n,U as o,f as p,W as q,ee as r,_ as s,te as t};
@@ -1 +0,0 @@
1
- import{a as he,b as Xe,c as $e,e as Ze,f as qe,h as Ke,i as Je,j as Qe,m as fe,n as ge,o as W}from"./chunk-IDQ6FMAI.js";import"@babylonjs/core/Animations/animatable.js";import"@babylonjs/core/Culling/ray.js";import"@babylonjs/core/Rendering/edgesRenderer.js";import"@babylonjs/loaders/glTF/index.js";import{Animation as C}from"@babylonjs/core/Animations/animation.js";import{ArcRotateCamera as $n}from"@babylonjs/core/Cameras/arcRotateCamera.js";import{ArcRotateCameraPointersInput as Zn}from"@babylonjs/core/Cameras/Inputs/arcRotateCameraPointersInput.js";import{Engine as qn}from"@babylonjs/core/Engines/engine.js";import{PointerEventTypes as Kn}from"@babylonjs/core/Events/pointerEvents.js";import{HighlightLayer as Jn}from"@babylonjs/core/Layers/highlightLayer.js";import{DirectionalLight as Qn}from"@babylonjs/core/Lights/directionalLight.js";import{HemisphericLight as bn}from"@babylonjs/core/Lights/hemisphericLight.js";import{ShadowGenerator as et}from"@babylonjs/core/Lights/Shadows/shadowGenerator.js";import{ImportMeshAsync as Me}from"@babylonjs/core/Loading/sceneLoader.js";import{Material as On}from"@babylonjs/core/Materials/material.js";import{StandardMaterial as Mn}from"@babylonjs/core/Materials/standardMaterial.js";import{RenderTargetTexture as nt}from"@babylonjs/core/Materials/Textures/renderTargetTexture.js";import{Color3 as I,Color4 as yn}from"@babylonjs/core/Maths/math.color.js";import{Vector3 as y}from"@babylonjs/core/Maths/math.vector.js";import{CreateGround as tt}from"@babylonjs/core/Meshes/Builders/groundBuilder.js";import{Mesh as ot}from"@babylonjs/core/Meshes/mesh.js";import{TransformNode as rt}from"@babylonjs/core/Meshes/transformNode.js";import{Scene as st}from"@babylonjs/core/scene.js";var Q=[-.5,-1,.35],vn=-Q[1]/Math.hypot(...Q),Fn={sky:.55,skyGround:[.3,.3,.34],sun:1},Bn={sky:.75,skyGround:[.45,.45,.5],sun:.6},nn=n=>n?Fn:Bn,Hn=.85,tn=(n,o,i,u)=>{let m=o/2/Hn/(Math.tan(i/2)*u);return Number.isFinite(m)?Math.max(n,m):n},on=n=>1-n*vn,jn=.35,Gn=1,Wn=.7,rn=(n,o)=>{let i=o*jn,u=o*Gn;return Wn*Math.min(1,Math.max(0,(n-i)/(u-i)))},zn=1,Vn=50,sn=(n,o)=>2*Vn*zn*n/o,ln=(n,o,i)=>{let u=i/(o-n);return{scaleY:u,offsetY:n-n*u}},an=(n,o)=>n===null?o:n/1e3,cn=(n,o,i)=>{if(o!==null)return o/1e3;let u=n.at(-1),m=n.at(-2);return u===void 0||m===void 0?i:(u.levelMm*2-m.levelMm)/1e3},be=3,dn=()=>{let n=be,o=[];return{invalidate:()=>{n=be},shouldDraw:(i,u)=>{let m=i.length!==o.length||i.some((c,w)=>c!==o[w]);return o=i,(m||u)&&(n=be),n>0},drawn:i=>{i&&(n=Math.max(0,n-1))}}},Un=[6,12],en=8,un=(n,o)=>Un.flatMap(i=>Array.from({length:en},(u,m)=>{let c=m/en*2*Math.PI;return{x:n+i*Math.cos(c),y:o+i*Math.sin(c)}})),Yn=Math.PI/4,mn=n=>Math.min(n,Yn),pn=(n,o,i,u)=>i/(2*n*Math.tan(o/2))/(1-u),hn=4,fn=(n,o,i,u)=>{let m=(i-n.y)/o.y;return m>0&&m<=u?{x:n.x+o.x*m,y:i,z:n.z+o.z*m}:null},gn=(n,o,i,u,m)=>{let c=n.x+o.x-i.x-u.x,w=n.z+o.z-i.z-u.z,L=Math.min(1,m/Math.hypot(c,w));return{x:u.x+c*L,y:n.y,z:u.z+w*L}};var it=[1,.78,.18],lt=2.7,at=4,In=1.1,ct=3,dt=5,ut=1.3,mt=2,ye=30,pt=.05,ht=1.3,ft=.35,gt=.25,bt=.25,Mt=.22,yt=.005,It=.05,St=2048,Et=.45,xt=3e-4,wt=2,Ot=.95,Pt=[.12,.16,.22,.55],Sn=new Set(["building","tank","slab","equipment"]),_t=new Set(["building","tank","equipment"]),At=n=>{let o=n.material;return o!==null&&"albedoColor"in o&&o.albedoColor instanceof I?o.albedoColor.toGammaSpace().toHexString():null},z=(n,o,i)=>{n.setEnabled(o!=="hidden"),n.visibility=o==="faint"?bt:1,n.isPickable=i&&o==="shown"},En=(n,o,i)=>{n.material=o,n.setEnabled(!0),n.visibility=i,n.isPickable=!1},Rt=n=>{let o=n.clone(`${n.name}-see-through`);if(o===null)throw new Error(`the site model's material ${n.name} cannot be copied`);return o.transparencyMode=On.MATERIAL_ALPHABLEND,o.backFaceCulling=!0,o},xn=n=>n.flatMap(o=>{let i=W(o,fe);return i===null?[]:[{mesh:o,part:i,detail:null,object:W(o,u=>ge(u,null))}]}),ee=n=>n.detail===null&&(n.part.role==="building"||n.part.role==="tank"),wn=n=>({min:n.reduce((o,i)=>y.Minimize(o,i.min),new y(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)),max:n.reduce((o,i)=>y.Maximize(o,i.max),new y(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY))}),so=(n,o,i,u)=>{he(o);let m=new qn(n,!0,{stencil:!0,preserveDrawingBuffer:!1,limitDeviceRatio:2},!0),c=new st(m),w=dn(),L=t=>{let r=new Mn(t,c);return r.disableLighting=!0,r},Ie=t=>{let r=new Mn(t,c);return r.specularColor=I.Black(),r},Se=Ie("ground"),V=L("ink-lines");V.fillMode=On.LineListDrawMode;let ne=L("ink-text");ne.backFaceCulling=!1;let Ee=Ie("floor-slab"),U=L("floor-plate");U.alpha=ft,U.backFaceCulling=!1;let Y=new bn("sky",y.Up(),c),D=new Qn("sun",new y(...Q),c),v=new bn("ground-fill",y.Up(),c);v.groundColor=I.Black(),v.specular=I.Black();let T=tt("ground",{width:1,height:1},c);T.material=Se,T.isPickable=!1,T.receiveShadows=!0,Y.excludedMeshes=[T],v.includedOnlyMeshes=[T];let N=new et(St,D);N.usePercentageCloserFiltering=!0,N.setDarkness(Et),N.bias=xt,N.transparencyShadow=!0;let te=N.getShadowMap();if(te===null)throw new Error("the sun's shadow generator has no shadow map");te.refreshRate=nt.REFRESHRATE_RENDER_ONCE;let xe=new I,oe=new I,Pn=new yn(...Pt),re=0,A=i,F=Xe,B=!1,X=!0,se=()=>{},$=()=>{B=!1,w.invalidate()},we=()=>{I.LerpToRef(xe,oe,re,V.emissiveColor),ne.emissiveColor.copyFrom(V.emissiveColor)},Oe=t=>{let{sky:r,ground:p,ink:h,floor:g}=he(t);c.clearColor=yn.FromColor3(I.FromHexString(r),1),oe.copyFrom(I.FromHexString(p)),Se.diffuseColor.copyFrom(oe),xe.copyFrom(I.FromHexString(h)),we(),Ee.diffuseColor=I.FromHexString(g),U.emissiveColor=I.FromHexString(g),$()};Oe(o);let S=[],Pe=new Map,ie=new Map,_e=new Map,le=new Map,Ae=new Map,Re=new Map,ae=null,Te={isolated:null,floor:null,selection:null},Ne=new Jn("selection",c),_n=new I(...it),An=t=>S.filter(r=>r.object?.id===t&&r.part.role!=="lines"&&r.part.role!=="text"&&!(r.detail===null&&le.has(t))).map(r=>r.mesh),Rn=(t,r,p,h)=>{let g=t.object!==null&&Sn.has(t.part.role),M=Pe.get(t.mesh);if(M===void 0){z(t.mesh,r?"hidden":"shown",g);return}let a=h?.has(String(t.mesh.uniqueId))===!0;a?N.removeShadowCaster(t.mesh,!1):N.addShadowCaster(t.mesh,!1);let O=p!==void 0&&t.object?.id===p.buildingId;switch(Je({alone:r,open:O,envelope:A.envelope,near:a})){case"hidden":z(t.mesh,"hidden",g);break;case"envelope":En(t.mesh,M.seeThrough,Mt);break;case"see-through":En(t.mesh,M.seeThrough,gt);break;case"solid":t.mesh.material=M.solid,z(t.mesh,"shown",g);break}},De=t=>{Te=t;let r=ae===null||t.isolated===null?null:ae.find(a=>a.key===t.isolated);if(r===void 0)throw new Error(`no detailed building ${t.isolated} to show alone`);let p=t.selection===null?void 0:Re.get(t.selection.id),h=r===null?p:r,g=r===null&&p!==void 0?Ae.get(p.key):void 0;for(let a of S){if(a.detail===null){Rn(a,r!==null,h,g);continue}let O=a.object!==null&&Sn.has(a.part.role);if(a.detail.key!==h?.key){z(a.mesh,"hidden",O);continue}let P=a.part.floor;if(P===null)throw new Error(`a ${a.part.role} of detailed building ${a.detail.key} names no floor`);z(a.mesh,r===null?"shown":Ke(a.detail.floors,t.floor,P,a.part.role),O)}Ne.removeAllMeshes();let M=t.selection===null?[]:An(t.selection.id).filter(a=>a.isEnabled());for(let a of M)a instanceof ot&&Ne.addMesh(a,_n);return{isolated:r,selectedMeshes:M}},Tn=t=>{A.edges&&t.edgesRenderer===null&&(t.enableEdgesRendering(Ot,!0),t.edgesColor=Pn),t.edgesRenderer!==null&&(t.edgesRenderer.isEnabled=A.edges)},Nn=({mesh:t,object:r})=>{if(r?.kind!=="building")return;let{minimum:p,maximum:h}=t.getBoundingInfo().boundingBox,g=h.y-p.y,M=A.realHeights?_e.get(r.id)??null:null,a=le.get(r.id),O=a===void 0?an(M,g):cn(a.floors,M,g),{scaleY:P,offsetY:x}=ln(p.y,h.y,O);t.scaling.y=P,t.position.y=x},Z=()=>{let t=nn(A.shading);Y.intensity=t.sky,Y.groundColor=new I(...t.skyGround),D.intensity=t.sun,v.intensity=on(t.sun),D.shadowEnabled=A.shadows;for(let r of S)ee(r)&&(Tn(r.mesh),Nn(r));De(Te),X=!0,$()};Z();let Le=t=>{let{min:r,max:p}=wn(t),h=y.Center(r,p),g=Math.max(p.x-r.x,p.z-r.z)*ht;T.scaling=new y(g,1,g),T.position=new y(h.x,r.y-pt,h.z);let M=g*wt;D.position=h.subtract(D.direction.normalizeToNew().scale(M)),D.shadowMinZ=1,D.shadowMaxZ=M*2},Dn=t=>{let r=new Map;for(let{mesh:p}of t.filter(ee)){let h=p.material;if(h===null)throw new Error(`the site model's box ${p.name} has no material`);let g=r.get(h)??Rt(h);r.set(h,g),Pe.set(p,{solid:h,seeThrough:g})}},ke=t=>{for(let{mesh:r,part:p}of t)_t.has(p.role)&&N.addShadowCaster(r,!1);for(let r of t)r.mesh.receiveShadows=ee(r)||r.part.role==="slab"},Ce=new ResizeObserver(()=>{m.resize(),w.invalidate(),se()});Ce.observe(n);let ve=()=>w.invalidate();document.addEventListener("visibilitychange",ve),m.onContextRestoredObservable.add($);let k=new AbortController;return{load:async(t,r,p,h)=>{let g=await Me(t.massingUrl,c,{pluginExtension:".glb"});if(c.isDisposed)return;S.push(...xn(g.meshes)),Dn(S);let M=new Map(S.flatMap(e=>e.object?.kind==="building"?[[e.object.id,e.object]]:[]));for(let{buildingId:e,heightMm:l}of p){if(!M.has(e))throw new Error(`the height table names site building ${e}, which the site model does not have`);_e.set(e,l)}ke(S);let a=g.meshes[0].getHierarchyBoundingVectors(!0),O=y.Center(a.min,a.max),P=Math.max(a.max.x-a.min.x,a.max.z-a.min.z);Le([a]);let x=F,s=new $n("camera",Math.PI/2,Math.PI/3.2,P*In,O.clone(),c),ce=(e,l)=>tn(e,l,s.fov,n.clientWidth/n.clientHeight),de=()=>ce(P*In,P);s.radius=de(),s.lowerRadiusLimit=mt,s.upperBetaLimit=Math.PI/2.05,s.wheelDeltaPercentage=.02,s.attachControl(n,!0);let q=s.inputs.attached.pointers;q instanceof Zn&&(q.useNaturalPinchZoom=!0,q.multiTouchPanAndZoom=!1,q.multiTouchPanning=!1);let H=new Map,j=null,Fe=()=>{let[e,l]=[...H.values()],{origin:d,direction:f}=c.createPickingRay((e.x+l.x)/2,(e.y+l.y)/2,null,s);return fn(d,f,T.position.y,s.radius*hn)},Be=e=>{e.pointerType==="touch"&&(H.set(e.pointerId,{x:e.offsetX,y:e.offsetY}),e.type==="pointerdown"&&H.size===2&&(j=Fe()))},He=e=>{H.delete(e.pointerId)};n.addEventListener("pointerdown",Be,{signal:k.signal}),n.addEventListener("pointermove",Be,{signal:k.signal}),n.addEventListener("pointerup",He,{signal:k.signal}),n.addEventListener("pointercancel",He,{signal:k.signal}),n.addEventListener("touchend",e=>e.preventDefault(),{passive:!1,signal:k.signal});let Ln=()=>{if(H.size!==2){j=null;return}let e=Fe();if(e===null)return;if(j===null){j=e;return}let{x:l,y:d,z:f}=gn(s.target,j,e,O,P);s.target.copyFromFloats(l,d,f)};s.onProjectionMatrixChangedObservable.add(()=>qe(s.getProjectionMatrix(),x)),c.onBeforeRenderObservable.add(()=>{s.minZ=Math.max(It,s.radius*yt);let e=Ze(x,F,m.getDeltaTime()/1e3);(e.top!==x.top||e.bottom!==x.bottom)&&(x=e,s.getProjectionMatrix(!0));let l=A.fadeLines?rn(s.radius,P):0;if(l!==re&&(re=l,we()),A.edges){let d=sn(s.radius,n.clientHeight);for(let f of S)f.mesh.edgesWidth=d}});let ue=(e,l,d)=>{C.CreateAndStartAnimation("move-target",s,"target",60,ye,s.target.clone(),e,C.ANIMATIONLOOPMODE_CONSTANT),C.CreateAndStartAnimation("move-radius",s,"radius",60,ye,s.radius,l,C.ANIMATIONLOOPMODE_CONSTANT),d!==null&&C.CreateAndStartAnimation("move-beta",s,"beta",60,ye,s.beta,d,C.ANIMATIONLOOPMODE_CONSTANT)},je=null,Ge=null,We=e=>{let{isolated:l,selectedMeshes:d}=De(e),f=e.selection,E=l===null?null:l.key;if(E!==je)if(E===null)ue(O,de(),null);else{let b=ie.get(E);if(b!==void 0){let{min:_,max:R}=b.getHierarchyBoundingVectors(!0),J=y.Distance(_,R);ue(y.Center(_,R),ce(J*ut,J),null)}}else if(f!==null&&f!==Ge&&f.focus&&d.length>0){let{min:b,max:_}=wn(d.map(J=>J.getHierarchyBoundingVectors(!0))),R=y.Distance(b,_);ue(y.Center(b,_),ce(Math.max(R*ct,dt),R),mn(s.beta))}je=E,Ge=f,X=!0,$()},kn=(e,l)=>{let d=e===null?void 0:S.find(f=>f.mesh===e);if(d!==void 0||!l)return d;for(let{x:f,y:E}of un(c.pointerX,c.pointerY)){let{pickedMesh:b}=c.pick(f,E),_=b===null?void 0:S.find(R=>R.mesh===b);if(_!==void 0)return _}};c.onPointerObservable.add(e=>{if(e.type!==Kn.POINTERTAP)return;let l="pointerType"in e.event&&e.event.pointerType==="touch",d=kn(e.pickInfo?.hit===!0?e.pickInfo.pickedMesh:null,l);u(d===void 0?null:d.object)});let ze=()=>[...new Map(S.flatMap(e=>e.object===null?[]:[[e.object.id,e.object]])).values()],me=[],pe=(e,l)=>{if(l===void 0)return;let d=At(l.mesh);if(d===null)throw new Error(`the site model's box ${l.mesh.name} (${e}) has no PBR base colour`);me.push({label:e,color:d})},K=S.filter(ee);pe("\u540D\u524D\u306E\u3042\u308B\u5EFA\u5C4B",K.find(e=>e.object?.kind==="building"&&e.object.name!=="")),pe("\u540D\u524D\u306E\u7121\u3044\u5EFA\u5C4B",K.find(e=>e.object?.kind==="building"&&e.object.name==="")),pe("\u30BF\u30F3\u30AF",K.find(e=>e.part.role==="tank")),Z(),se=()=>c.render(!1),m.runRenderLoop(()=>{s.panningSensibility=pn(s.radius,s.fov,n.clientHeight*(1-x.top-x.bottom),s.panningInertia),s.upperRadiusLimit=de()*lt,s.maxZ=s.upperRadiusLimit*at,s.update(),Ln();let e=x.top!==F.top||x.bottom!==F.bottom,l=[s.alpha,s.beta,s.radius,s.target.x,s.target.y,s.target.z];w.shouldDraw(l,e||c.animatables.length>0)&&(n.dataset.cameraPose=l.join(" "),B=B||c.isReady(),B&&X&&(X=!1,te.resetRefreshCounter()),se(),w.drawn(B))}),h({objects:ze(),legend:me,complete:!1,show:We});let[Ve,...Ue]=await Promise.all([Me(t.linesUrl,c,{pluginExtension:".glb"}),...r.map(e=>Me(e.glbUrl,c,{pluginExtension:".glb"}))]);if(c.isDisposed)return;let G=xn(Ve.meshes);r.forEach((e,l)=>{let d=M.get(e.buildingId);if(d===void 0)throw new Error(`detailed building ${e.key} replaces site building ${e.buildingId}, which the site model does not have`);let f=new rt(`detail-${e.key}`,c);f.rotation.y=e.placement.rotationY,f.position=new y(...e.placement.position),Ue[l].meshes[0].parent=f,ie.set(e.key,f),le.set(e.buildingId,e);for(let E of Ue[l].meshes){let b=W(E,fe);if(b===null)continue;if(b.floor===null)throw new Error(`a ${b.role} of detailed building ${e.key} names no floor`);let _=b.role==="slab"||b.role==="plate"?d:W(E,R=>ge(R,e.key));G.push({mesh:E,part:b,detail:e,object:_})}});for(let e of G)switch(e.part.role){case"lines":e.mesh.material=V;break;case"text":e.mesh.material=ne;break;case"slab":e.mesh.material=Ee,Y.excludedMeshes.push(e.mesh),v.includedOnlyMeshes.push(e.mesh);break;case"plate":e.mesh.material=U;break;default:break}S.push(...G),ke(G);let Ye=[...ie.values()].map(e=>e.getHierarchyBoundingVectors(!0));Le([a,Ve.meshes[0].getHierarchyBoundingVectors(!0),...Ye]);let Cn=e=>{let{minimumWorld:l,maximumWorld:d}=e.getBoundingInfo().boundingBox;return{minX:l.x,maxX:d.x,minZ:l.z,maxZ:d.z}};r.forEach((e,l)=>{let{min:d,max:f}=Ye[l],E=K.filter(b=>b.object?.id!==e.buildingId).map(b=>({id:String(b.mesh.uniqueId),footprint:Cn(b.mesh)}));Ae.set(e.key,new Set(Qe({minX:d.x,maxX:f.x,minZ:d.z,maxZ:f.z},E)))});for(let e of G)e.detail!==null&&e.object!==null&&Re.set(e.object.id,e.detail);ae=r,Z(),h({objects:ze(),legend:me,complete:!0,show:We})},paint:Oe,inset:t=>{F=$e(t)},options:t=>{A=t,Z()},close:()=>{Ce.disconnect(),document.removeEventListener("visibilitychange",ve),k.abort(),m.stopRenderLoop(),c.dispose(),m.dispose()}}};export{so as openPlantSceneView};