@snaptrude/plugin-core 0.5.0 → 0.6.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 +52 -0
- package/api-manifest.full.json +2044 -443
- package/api-manifest.json +2051 -394
- package/dist/api/analysis/heatmaps.d.ts +234 -0
- package/dist/api/analysis/heatmaps.d.ts.map +1 -0
- package/dist/api/analysis/illuminance.d.ts +145 -0
- package/dist/api/analysis/illuminance.d.ts.map +1 -0
- package/dist/api/analysis/index.d.ts +44 -0
- package/dist/api/analysis/index.d.ts.map +1 -0
- package/dist/api/analysis/shadows.d.ts +165 -0
- package/dist/api/analysis/shadows.d.ts.map +1 -0
- package/dist/api/analysis/sunlightHours.d.ts +208 -0
- package/dist/api/analysis/sunlightHours.d.ts.map +1 -0
- package/dist/api/analysis/sunpath.d.ts +80 -0
- package/dist/api/analysis/sunpath.d.ts.map +1 -0
- package/dist/api/core/index.d.ts +5 -0
- package/dist/api/core/index.d.ts.map +1 -1
- package/dist/api/core/io/import/index.d.ts +392 -0
- package/dist/api/core/io/import/index.d.ts.map +1 -0
- package/dist/api/core/io/index.d.ts +35 -0
- package/dist/api/core/io/index.d.ts.map +1 -0
- package/dist/api/core/io/job/index.d.ts +139 -0
- package/dist/api/core/io/job/index.d.ts.map +1 -0
- package/dist/api/core/io/query/index.d.ts +74 -0
- package/dist/api/core/io/query/index.d.ts.map +1 -0
- package/dist/api/core/io/terrain/index.d.ts +206 -0
- package/dist/api/core/io/terrain/index.d.ts.map +1 -0
- package/dist/api/core/io/underlay/index.d.ts +286 -0
- package/dist/api/core/io/underlay/index.d.ts.map +1 -0
- package/dist/api/core/layers.d.ts +7 -7
- package/dist/api/design/create/index.d.ts +9 -0
- package/dist/api/design/create/index.d.ts.map +1 -1
- package/dist/api/design/query/spaces.d.ts +3 -3
- package/dist/api/design/selection/index.d.ts +144 -0
- package/dist/api/design/selection/index.d.ts.map +1 -1
- package/dist/api/entity/space.d.ts +2 -2
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/program/site.d.ts +84 -0
- package/dist/api/program/site.d.ts.map +1 -1
- package/dist/handles.d.ts +33 -0
- package/dist/handles.d.ts.map +1 -1
- package/dist/index.cjs +1335 -987
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1278 -983
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/scripts/generate-manifest.test.mjs +26 -4
- package/src/api/analysis/heatmaps.ts +256 -0
- package/src/api/analysis/illuminance.ts +155 -0
- package/src/api/analysis/index.ts +46 -0
- package/src/api/analysis/shadows.ts +183 -0
- package/src/api/analysis/sunlightHours.ts +211 -0
- package/src/api/analysis/sunpath.ts +83 -0
- package/src/api/core/index.ts +5 -0
- package/src/api/core/io/import/index.ts +432 -0
- package/src/api/core/io/index.ts +37 -0
- package/src/api/core/io/job/index.ts +140 -0
- package/src/api/core/io/query/index.ts +71 -0
- package/src/api/core/io/terrain/index.ts +214 -0
- package/src/api/core/io/underlay/index.ts +295 -0
- package/src/api/design/create/index.ts +9 -0
- package/src/api/design/erase/index.ts +1 -1
- package/src/api/design/selection/index.ts +129 -0
- package/src/api/index.ts +5 -0
- package/src/api/program/site.ts +93 -0
- package/src/handles.ts +46 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import * as z from "zod"
|
|
2
|
+
import { PluginApiReturn } from "../../../../types"
|
|
3
|
+
import {
|
|
4
|
+
Vec3Handle,
|
|
5
|
+
UnderlayHandle,
|
|
6
|
+
TerrainHandle,
|
|
7
|
+
ImportJobHandle,
|
|
8
|
+
ComponentHandle,
|
|
9
|
+
} from "../../../../handles"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A file `source` accepted by every importer: an `https://` URL or a `data:`
|
|
13
|
+
* URL (base64). Validated for shape at the boundary — other schemes (`http:`,
|
|
14
|
+
* `blob:`, `file:`) are rejected, since the host page (HTTPS) cannot fetch them.
|
|
15
|
+
*/
|
|
16
|
+
export const ImportSource = z
|
|
17
|
+
.string()
|
|
18
|
+
.min(1)
|
|
19
|
+
.refine((s) => s.startsWith("https://") || s.startsWith("data:"), {
|
|
20
|
+
message: "source must be an https:// URL or a data: URL",
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* File import — bring external files into the Snaptrude **scene**.
|
|
25
|
+
*
|
|
26
|
+
* `core.io.import.*` ingests images, PDFs, CAD drawings, 3D models, and site
|
|
27
|
+
* terrain and commits them to the model as traceable underlays, placed geometry,
|
|
28
|
+
* or topography. It is the scene counterpart to `presentation.import.*` (which
|
|
29
|
+
* drops assets on the Present canvas, not the model).
|
|
30
|
+
*
|
|
31
|
+
* ## The `source` argument
|
|
32
|
+
* Every file importer takes a single `source` **string** — either an `https://`
|
|
33
|
+
* URL or a `data:` URL (base64). A plugin worker cannot hand a browser `File`
|
|
34
|
+
* across the boundary, so the host fetches `source` and rebuilds the `File`
|
|
35
|
+
* itself. Both forms go through the same path.
|
|
36
|
+
*
|
|
37
|
+
* ## Return values
|
|
38
|
+
* - `image` / `pdf` / `cadJson` → an {@linkcode UnderlayHandle} (a placed 2D
|
|
39
|
+
* reference plane; drive it with `core.io.underlay.*`).
|
|
40
|
+
* - `dwg` → an {@linkcode ImportJobHandle} — DWG conversion is a long server job,
|
|
41
|
+
* so `dwg` returns immediately and you poll it with `core.io.job.*`.
|
|
42
|
+
* - `model` → a {@linkcode ComponentHandle} (a placed 3D component).
|
|
43
|
+
* - `terrain` → a {@linkcode TerrainHandle} (the project's single site terrain).
|
|
44
|
+
*
|
|
45
|
+
* Every importer **throws** on failure (bad source, unsupported format, engine
|
|
46
|
+
* error). Accessed via `snaptrude.core.io.import`.
|
|
47
|
+
*/
|
|
48
|
+
export abstract class PluginCoreIoImportApi {
|
|
49
|
+
constructor() {}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Import a raster image as a scene **underlay** — a flat, textured reference
|
|
53
|
+
* plane placed on a storey that you can trace over.
|
|
54
|
+
*
|
|
55
|
+
* Supported formats: PNG, JPG/JPEG, BMP. The image is placed on the target
|
|
56
|
+
* storey's "Image" layer at ~50% opacity by default.
|
|
57
|
+
*
|
|
58
|
+
* The plane is placed at the storey origin (the engine's import placement);
|
|
59
|
+
* there is no placement parameter — calibrate size with
|
|
60
|
+
* {@link PluginCoreIoUnderlayApi.setScale} after import.
|
|
61
|
+
*
|
|
62
|
+
* @param source - The image to import: an `https://` URL or a `data:` URL.
|
|
63
|
+
* @param storey - Target storey number. Defaults to the active storey.
|
|
64
|
+
* @param scale - Initial uniform scale factor applied to the plane. Calibrate
|
|
65
|
+
* precisely afterwards with {@link PluginCoreIoUnderlayApi.setScale}.
|
|
66
|
+
* @param opacity - Plane opacity, `0`..`1` (default ~`0.5`).
|
|
67
|
+
* @param label - A name for the created underlay.
|
|
68
|
+
* @returns the created {@linkcode UnderlayHandle}.
|
|
69
|
+
* @throws if writes are disabled, the source can't be loaded, the format is
|
|
70
|
+
* unsupported, or the engine fails to place the plane.
|
|
71
|
+
*
|
|
72
|
+
* @examplePrompt Import this floor plan image onto the ground floor to trace over
|
|
73
|
+
* @examplePrompt Drop this survey PNG in as a reference underlay at 30% opacity
|
|
74
|
+
* @examplePrompt Add a site plan image on storey 2
|
|
75
|
+
* @examplePrompt Bring in a sketch to trace, faded to half opacity
|
|
76
|
+
*
|
|
77
|
+
* # Example
|
|
78
|
+
* ```ts
|
|
79
|
+
* // Place a floor plan on storey 1, then calibrate it to a real-world size.
|
|
80
|
+
* const plan = await snaptrude.core.io.import.image(
|
|
81
|
+
* "https://example.com/floorplan.png",
|
|
82
|
+
* 1, // storey
|
|
83
|
+
* undefined, // scale
|
|
84
|
+
* 0.4, // opacity
|
|
85
|
+
* "Ground floor plan",
|
|
86
|
+
* )
|
|
87
|
+
* // Make the plan's longest side exactly 40 project-units:
|
|
88
|
+
* await snaptrude.core.io.underlay.setScale(plan, { planSize: 40 })
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
public abstract image(
|
|
92
|
+
source: string,
|
|
93
|
+
storey?: number,
|
|
94
|
+
scale?: number,
|
|
95
|
+
opacity?: number,
|
|
96
|
+
label?: string,
|
|
97
|
+
): PluginApiReturn<UnderlayHandle>
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Import one page of a PDF as a scene **underlay** (a traceable reference plane).
|
|
101
|
+
*
|
|
102
|
+
* One PDF per storey, one page per call. To bring in several pages, call once
|
|
103
|
+
* per page onto different storeys.
|
|
104
|
+
*
|
|
105
|
+
* @param source - The PDF to import: an `https://` URL or a `data:` URL.
|
|
106
|
+
* @param storey - Target storey number. Defaults to the active storey.
|
|
107
|
+
* @param page - 1-based page number to import (multi-page PDFs). Default `1`.
|
|
108
|
+
* @param scale - A drawing-scale **label** that sizes the page in real-world
|
|
109
|
+
* units, matching the project's unit mode: metric `"1:10"`..`"1:1000"` (e.g.
|
|
110
|
+
* `"1:100"`) or imperial `` `1/8" = 1'` `` / `` `1" = 10'` ``. Must be a valid
|
|
111
|
+
* label for the current unit mode (invalid → throws). Defaults to `"1:100"`
|
|
112
|
+
* in metric projects and `` `1" = 1'` `` in imperial projects. Re-calibrate
|
|
113
|
+
* afterwards with {@link PluginCoreIoUnderlayApi.setScale}.
|
|
114
|
+
* @param opacity - Plane opacity, `0`..`1` (default ~`0.5`).
|
|
115
|
+
* @returns the created {@linkcode UnderlayHandle}.
|
|
116
|
+
* @throws if writes are disabled, the source can't be loaded, the storey
|
|
117
|
+
* already has a PDF, the page is out of range, the scale label is invalid for
|
|
118
|
+
* the unit mode, or the engine fails.
|
|
119
|
+
*
|
|
120
|
+
* @examplePrompt Import page 1 of this PDF floor plan onto storey 1
|
|
121
|
+
* @examplePrompt Bring in the second page of this PDF as an underlay at 1:50
|
|
122
|
+
* @examplePrompt Add this PDF plan to the ground floor to trace over
|
|
123
|
+
* @examplePrompt Place page 3 of the drawing set on storey 3
|
|
124
|
+
*
|
|
125
|
+
* # Example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const sheet = await snaptrude.core.io.import.pdf(
|
|
128
|
+
* "https://example.com/plans.pdf",
|
|
129
|
+
* 1, // storey
|
|
130
|
+
* 2, // page
|
|
131
|
+
* "1:100", // drawing scale
|
|
132
|
+
* )
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
public abstract pdf(
|
|
136
|
+
source: string,
|
|
137
|
+
storey?: number,
|
|
138
|
+
page?: number,
|
|
139
|
+
scale?: string,
|
|
140
|
+
opacity?: number,
|
|
141
|
+
): PluginApiReturn<UnderlayHandle>
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Import a **DWG** CAD drawing as a scene underlay. `.dwg` only (no DXF).
|
|
145
|
+
*
|
|
146
|
+
* DWG conversion runs on a server and can take minutes, so this **starts a job
|
|
147
|
+
* and returns immediately** with an {@linkcode ImportJobHandle}. One CAD
|
|
148
|
+
* import runs at a time: starting a second while one is in flight throws —
|
|
149
|
+
* poll the first job to completion first. Poll it with
|
|
150
|
+
* {@link PluginCoreIoJobApi.isComplete} / {@link PluginCoreIoJobApi.getStatus}, then call
|
|
151
|
+
* {@link PluginCoreIoJobApi.getResult} to get the placed {@linkcode UnderlayHandle}.
|
|
152
|
+
* For CAD you already have parsed as JSON, use {@link PluginCoreIoImportApi.cadJson}
|
|
153
|
+
* (synchronous, no server round-trip).
|
|
154
|
+
*
|
|
155
|
+
* All CAD layers are imported (there is no layer filter).
|
|
156
|
+
*
|
|
157
|
+
* @param source - The `.dwg` file: an `https://` URL or a `data:` URL.
|
|
158
|
+
* @param storey - Target storey number. Defaults to the active storey.
|
|
159
|
+
* @returns an {@linkcode ImportJobHandle} to poll via `core.io.job.*`.
|
|
160
|
+
* @throws if writes are disabled or the upload cannot be started. (Conversion
|
|
161
|
+
* failures surface later via {@link PluginCoreIoJobApi.getError}.)
|
|
162
|
+
*
|
|
163
|
+
* @examplePrompt Import this DWG floor plan onto storey 1
|
|
164
|
+
* @examplePrompt Bring in a CAD drawing as an underlay and tell me when it's ready
|
|
165
|
+
* @examplePrompt Start importing this CAD file onto the ground floor
|
|
166
|
+
*
|
|
167
|
+
* # Example
|
|
168
|
+
* ```ts
|
|
169
|
+
* const job = await snaptrude.core.io.import.dwg("https://example.com/plan.dwg", 1)
|
|
170
|
+
* // Poll until the server-side conversion finishes — always with a timeout
|
|
171
|
+
* // (a UI-cancelled import stays "processing" forever).
|
|
172
|
+
* const deadline = Date.now() + 5 * 60_000
|
|
173
|
+
* while (!(await snaptrude.core.io.job.isComplete(job))) {
|
|
174
|
+
* if (Date.now() > deadline) throw new Error("DWG import timed out")
|
|
175
|
+
* await new Promise((r) => setTimeout(r, 2000))
|
|
176
|
+
* }
|
|
177
|
+
* // The DWG lands as a CAD underlay. CAD scaling isn't supported; manage it
|
|
178
|
+
* // (list / fade / delete) via core.io.underlay.*.
|
|
179
|
+
* const cad = await snaptrude.core.io.job.getResult(job)
|
|
180
|
+
* if (cad) console.log("DWG imported as CAD underlay:", cad)
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
public abstract dwg(source: string, storey?: number): PluginApiReturn<ImportJobHandle>
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Sketch a CAD underlay from **already-parsed CAD JSON** — synchronous, with no
|
|
187
|
+
* server round-trip. Use this when you hold parsed CAD data (e.g. produced by
|
|
188
|
+
* your own converter); use {@link PluginCoreIoImportApi.dwg} for raw `.dwg`
|
|
189
|
+
* files.
|
|
190
|
+
*
|
|
191
|
+
* All layers in the JSON are sketched (there is no layer filter), at the
|
|
192
|
+
* drawing's own coordinates.
|
|
193
|
+
*
|
|
194
|
+
* @param cad - The parsed CAD data: `{ unit, geometry: [...] }` describing the
|
|
195
|
+
* drawing's lines/arcs/layers.
|
|
196
|
+
* @param storey - Target storey number. Defaults to the active storey.
|
|
197
|
+
* @returns the created {@linkcode UnderlayHandle}.
|
|
198
|
+
* @throws if writes are disabled, the JSON yields no drawable geometry, or the
|
|
199
|
+
* drawing is out of bounds.
|
|
200
|
+
*
|
|
201
|
+
* @examplePrompt Sketch this parsed CAD JSON onto the active storey
|
|
202
|
+
* @examplePrompt Draw these CAD curves as an underlay on storey 2
|
|
203
|
+
* @examplePrompt Create a CAD sketch from this geometry data
|
|
204
|
+
* @examplePrompt Import my converted CAD JSON onto the ground floor
|
|
205
|
+
*
|
|
206
|
+
* # Example
|
|
207
|
+
* ```ts
|
|
208
|
+
* const cad = await snaptrude.core.io.import.cadJson(
|
|
209
|
+
* { unit: "mm", geometry: [{ type: "line", layer: "WALLS", ... }] },
|
|
210
|
+
* 1,
|
|
211
|
+
* )
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
public abstract cadJson(cad: CadJsonInput, storey?: number): PluginApiReturn<UnderlayHandle>
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Import a **3D model** file and place it in the scene as a component.
|
|
218
|
+
*
|
|
219
|
+
* Supported formats: SketchUp (`.skp`), FBX (`.fbx`), OBJ (`.obj`), 3DS
|
|
220
|
+
* (`.3ds`), and zipped bundles (`.zip`). The file is converted on the server,
|
|
221
|
+
* then placed. `.glb`/`.gltf`/`.ifc`/`.stl` and Rhino/Revit are not supported.
|
|
222
|
+
*
|
|
223
|
+
* The model is placed at its source dimensions (interpreted in the file's own
|
|
224
|
+
* units); there is no import-time scale override.
|
|
225
|
+
*
|
|
226
|
+
* Unlike `dwg`, this call **waits for the server conversion**: a large model
|
|
227
|
+
* may exceed the 60-second call cap and reject at the API boundary while the
|
|
228
|
+
* import still completes in the background (the model then appears without a
|
|
229
|
+
* handle being returned — re-query the scene to find it). Keep sources small.
|
|
230
|
+
*
|
|
231
|
+
* @param source - The model file: an `https://` URL or a `data:` URL.
|
|
232
|
+
* @param storey - Target storey number. Defaults to the active storey.
|
|
233
|
+
* @param format - The file's format. Inferred from `source` when omitted.
|
|
234
|
+
* @param position - Where to place the model. Defaults to the storey origin.
|
|
235
|
+
* @param label - A name for the placed component.
|
|
236
|
+
* @returns the placed {@linkcode ComponentHandle}.
|
|
237
|
+
* @throws if writes are disabled, the source can't be loaded, the format is
|
|
238
|
+
* unsupported, conversion/placement fails, or the converted model cannot be
|
|
239
|
+
* found in the library after upload.
|
|
240
|
+
*
|
|
241
|
+
* @examplePrompt Import this SketchUp model onto storey 1
|
|
242
|
+
* @examplePrompt Bring in this OBJ file and place it at the origin
|
|
243
|
+
* @examplePrompt Add this 3D model to the ground floor
|
|
244
|
+
*
|
|
245
|
+
* # Example
|
|
246
|
+
* ```ts
|
|
247
|
+
* const model = await snaptrude.core.io.import.model(
|
|
248
|
+
* "https://example.com/tree.skp",
|
|
249
|
+
* 1, // storey
|
|
250
|
+
* "skp",
|
|
251
|
+
* )
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
public abstract model(
|
|
255
|
+
source: string,
|
|
256
|
+
storey?: number,
|
|
257
|
+
format?: ModelFormat,
|
|
258
|
+
position?: Vec3Handle,
|
|
259
|
+
label?: string,
|
|
260
|
+
): PluginApiReturn<ComponentHandle>
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Import **site terrain** for a location — Mapbox topography (elevation +
|
|
264
|
+
* satellite/streets imagery, optional neighborhood buildings and parcels).
|
|
265
|
+
*
|
|
266
|
+
* One terrain per project (a singleton). `width`/`length` describe the
|
|
267
|
+
* real-world extent of the area to load **in metres** (regardless of the
|
|
268
|
+
* project's unit mode); the host converts them to the right map zoom
|
|
269
|
+
* internally — you do not pass a zoom level.
|
|
270
|
+
*
|
|
271
|
+
* @param lat - Site latitude (degrees), `-90`..`90`.
|
|
272
|
+
* @param lng - Site longitude (degrees), `-180`..`180`.
|
|
273
|
+
* @param width - East–west extent of the area to load, in metres.
|
|
274
|
+
* @param length - North–south extent of the area to load, in metres.
|
|
275
|
+
* @param elevation - Include DEM elevation (a real terrain surface). Default `true`.
|
|
276
|
+
* @param satellite - Drape satellite imagery. Default `true`.
|
|
277
|
+
* @param neighborhood - Include surrounding context buildings. Default `false`.
|
|
278
|
+
* @param parcels - Include site parcel boundaries. Default `false`.
|
|
279
|
+
* @returns the created {@linkcode TerrainHandle}.
|
|
280
|
+
* @throws if writes are disabled, a terrain already exists, or the map/mesh
|
|
281
|
+
* generation fails.
|
|
282
|
+
*
|
|
283
|
+
* @examplePrompt Import the site terrain for this location, about 500m across
|
|
284
|
+
* @examplePrompt Load the topography at 40.7128, -74.0060 for a 300 by 300 meter site
|
|
285
|
+
* @examplePrompt Bring in satellite terrain for the site with the surrounding buildings
|
|
286
|
+
* @examplePrompt Add site elevation for a 1km by 1km area at these coordinates
|
|
287
|
+
*
|
|
288
|
+
* # Example
|
|
289
|
+
* ```ts
|
|
290
|
+
* // 300m × 300m site with elevation + satellite imagery.
|
|
291
|
+
* const terrain = await snaptrude.core.io.import.terrain(
|
|
292
|
+
* 40.7128, // lat
|
|
293
|
+
* -74.006, // lng
|
|
294
|
+
* 300, // width (metres)
|
|
295
|
+
* 300, // length (metres)
|
|
296
|
+
* true, // elevation
|
|
297
|
+
* true, // satellite
|
|
298
|
+
* )
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
public abstract terrain(
|
|
302
|
+
lat: number,
|
|
303
|
+
lng: number,
|
|
304
|
+
width: number,
|
|
305
|
+
length: number,
|
|
306
|
+
elevation?: boolean,
|
|
307
|
+
satellite?: boolean,
|
|
308
|
+
neighborhood?: boolean,
|
|
309
|
+
parcels?: boolean,
|
|
310
|
+
): PluginApiReturn<TerrainHandle>
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Supported 3D model import formats. `.glb`/`.gltf`/`.ifc`/`.stl` and Rhino/Revit
|
|
315
|
+
* are intentionally excluded (no in-app import path).
|
|
316
|
+
*/
|
|
317
|
+
export const ModelFormat = z.enum(["skp", "fbx", "obj", "3ds", "zip"])
|
|
318
|
+
export type ModelFormat = z.infer<typeof ModelFormat>
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Parsed CAD JSON accepted by {@link PluginCoreIoImportApi.cadJson}. `unit` sets
|
|
322
|
+
* the drawing's length unit; `geometry` is the array of CAD entities (lines,
|
|
323
|
+
* polylines, arcs, circles), each tagged with its CAD `layer`. Additional fields
|
|
324
|
+
* are passed through untouched.
|
|
325
|
+
*/
|
|
326
|
+
export const CadJsonInput = z
|
|
327
|
+
.object({
|
|
328
|
+
unit: z.string().optional(),
|
|
329
|
+
geometry: z.array(z.record(z.string(), z.unknown())).optional(),
|
|
330
|
+
})
|
|
331
|
+
.passthrough()
|
|
332
|
+
export type CadJsonInput = z.infer<typeof CadJsonInput>
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Arguments for {@link PluginCoreIoImportApi.image}.
|
|
336
|
+
*
|
|
337
|
+
* | Property | Type | Description |
|
|
338
|
+
* |---|---|---|
|
|
339
|
+
* | `source` | `string` | Image `https://` URL or `data:` URL (png/jpg/jpeg/bmp) |
|
|
340
|
+
* | `storey` | `number`? | Target storey (default: active) |
|
|
341
|
+
* | `scale` | `number`? | Initial uniform scale |
|
|
342
|
+
* | `opacity` | `number`? | `0`..`1` (default ~`0.5`) |
|
|
343
|
+
* | `label` | `string`? | Name for the underlay |
|
|
344
|
+
*/
|
|
345
|
+
export const PluginImportImageArgs = z.object({
|
|
346
|
+
source: ImportSource,
|
|
347
|
+
storey: z.number().int().optional(),
|
|
348
|
+
scale: z.number().positive().optional(),
|
|
349
|
+
opacity: z.number().min(0).max(1).optional(),
|
|
350
|
+
label: z.string().optional(),
|
|
351
|
+
})
|
|
352
|
+
export type PluginImportImageArgs = z.infer<typeof PluginImportImageArgs>
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Arguments for {@link PluginCoreIoImportApi.pdf}.
|
|
356
|
+
*
|
|
357
|
+
* | Property | Type | Description |
|
|
358
|
+
* |---|---|---|
|
|
359
|
+
* | `source` | `string` | PDF `https://` URL or `data:` URL |
|
|
360
|
+
* | `storey` | `number`? | Target storey (default: active) |
|
|
361
|
+
* | `page` | `number`? | 1-based page (default `1`) |
|
|
362
|
+
* | `scale` | `string`? | Drawing-scale label, e.g. `"1:100"` |
|
|
363
|
+
* | `opacity` | `number`? | `0`..`1` (default ~`0.5`) |
|
|
364
|
+
*/
|
|
365
|
+
export const PluginImportPdfArgs = z.object({
|
|
366
|
+
source: ImportSource,
|
|
367
|
+
storey: z.number().int().optional(),
|
|
368
|
+
page: z.number().int().positive().optional(),
|
|
369
|
+
scale: z.string().optional(),
|
|
370
|
+
opacity: z.number().min(0).max(1).optional(),
|
|
371
|
+
})
|
|
372
|
+
export type PluginImportPdfArgs = z.infer<typeof PluginImportPdfArgs>
|
|
373
|
+
|
|
374
|
+
/** Arguments for {@link PluginCoreIoImportApi.dwg}. */
|
|
375
|
+
export const PluginImportDwgArgs = z.object({
|
|
376
|
+
source: ImportSource,
|
|
377
|
+
storey: z.number().int().optional(),
|
|
378
|
+
})
|
|
379
|
+
export type PluginImportDwgArgs = z.infer<typeof PluginImportDwgArgs>
|
|
380
|
+
|
|
381
|
+
/** Arguments for {@link PluginCoreIoImportApi.cadJson}. */
|
|
382
|
+
export const PluginImportCadJsonArgs = z.object({
|
|
383
|
+
cad: CadJsonInput,
|
|
384
|
+
storey: z.number().int().optional(),
|
|
385
|
+
})
|
|
386
|
+
export type PluginImportCadJsonArgs = z.infer<typeof PluginImportCadJsonArgs>
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Arguments for {@link PluginCoreIoImportApi.model}.
|
|
390
|
+
*
|
|
391
|
+
* | Property | Type | Description |
|
|
392
|
+
* |---|---|---|
|
|
393
|
+
* | `source` | `string` | Model `https://` URL or `data:` URL |
|
|
394
|
+
* | `storey` | `number`? | Target storey (default: active) |
|
|
395
|
+
* | `format` | {@link ModelFormat}? | File format (inferred when omitted) |
|
|
396
|
+
* | `position` | {@link Vec3Handle}? | Placement (default: storey origin) |
|
|
397
|
+
* | `label` | `string`? | Name for the component |
|
|
398
|
+
*/
|
|
399
|
+
export const PluginImportModelArgs = z.object({
|
|
400
|
+
source: ImportSource,
|
|
401
|
+
storey: z.number().int().optional(),
|
|
402
|
+
format: ModelFormat.optional(),
|
|
403
|
+
position: Vec3Handle.optional(),
|
|
404
|
+
label: z.string().optional(),
|
|
405
|
+
})
|
|
406
|
+
export type PluginImportModelArgs = z.infer<typeof PluginImportModelArgs>
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Arguments for {@link PluginCoreIoImportApi.terrain}.
|
|
410
|
+
*
|
|
411
|
+
* | Property | Type | Description |
|
|
412
|
+
* |---|---|---|
|
|
413
|
+
* | `lat` | `number` | Latitude (degrees), `-90`..`90` |
|
|
414
|
+
* | `lng` | `number` | Longitude (degrees), `-180`..`180` |
|
|
415
|
+
* | `width` | `number` | East–west extent, metres |
|
|
416
|
+
* | `length` | `number` | North–south extent, metres |
|
|
417
|
+
* | `elevation` | `boolean`? | Include DEM elevation (default `true`) |
|
|
418
|
+
* | `satellite` | `boolean`? | Drape satellite imagery (default `true`) |
|
|
419
|
+
* | `neighborhood` | `boolean`? | Include context buildings (default `false`) |
|
|
420
|
+
* | `parcels` | `boolean`? | Include parcel boundaries (default `false`) |
|
|
421
|
+
*/
|
|
422
|
+
export const PluginImportTerrainArgs = z.object({
|
|
423
|
+
lat: z.number().min(-90).max(90),
|
|
424
|
+
lng: z.number().min(-180).max(180),
|
|
425
|
+
width: z.number().positive().finite(),
|
|
426
|
+
length: z.number().positive().finite(),
|
|
427
|
+
elevation: z.boolean().optional(),
|
|
428
|
+
satellite: z.boolean().optional(),
|
|
429
|
+
neighborhood: z.boolean().optional(),
|
|
430
|
+
parcels: z.boolean().optional(),
|
|
431
|
+
})
|
|
432
|
+
export type PluginImportTerrainArgs = z.infer<typeof PluginImportTerrainArgs>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PluginCoreIoImportApi } from "./import"
|
|
2
|
+
import { PluginCoreIoJobApi } from "./job"
|
|
3
|
+
import { PluginCoreIoUnderlayApi } from "./underlay"
|
|
4
|
+
import { PluginCoreIoTerrainApi } from "./terrain"
|
|
5
|
+
import { PluginCoreIoQueryApi } from "./query"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* I/O — bring external files into the project and manage what was imported.
|
|
9
|
+
*
|
|
10
|
+
* - {@linkcode PluginCoreIoApi.import} — import images, PDFs, CAD, 3D models, terrain
|
|
11
|
+
* - {@linkcode PluginCoreIoApi.query} — read source metadata before importing (pdf pages, cad layers)
|
|
12
|
+
* - {@linkcode PluginCoreIoApi.job} — poll long-running async imports (e.g. DWG)
|
|
13
|
+
* - {@linkcode PluginCoreIoApi.underlay} — inspect/scale/opacity/delete placed underlays
|
|
14
|
+
* - {@linkcode PluginCoreIoApi.terrain} — inspect/edit the site terrain (datum, layers, delete)
|
|
15
|
+
*
|
|
16
|
+
* Accessed via `snaptrude.core.io`.
|
|
17
|
+
*/
|
|
18
|
+
export abstract class PluginCoreIoApi {
|
|
19
|
+
/** Import external files into the scene. See {@linkcode PluginCoreIoImportApi}. */
|
|
20
|
+
public abstract import: PluginCoreIoImportApi
|
|
21
|
+
/** Read source metadata before import. See {@linkcode PluginCoreIoQueryApi}. */
|
|
22
|
+
public abstract query: PluginCoreIoQueryApi
|
|
23
|
+
/** Poll long-running import jobs. See {@linkcode PluginCoreIoJobApi}. */
|
|
24
|
+
public abstract job: PluginCoreIoJobApi
|
|
25
|
+
/** Inspect and edit placed underlays. See {@linkcode PluginCoreIoUnderlayApi}. */
|
|
26
|
+
public abstract underlay: PluginCoreIoUnderlayApi
|
|
27
|
+
/** Inspect and manage the site terrain. See {@linkcode PluginCoreIoTerrainApi}. */
|
|
28
|
+
public abstract terrain: PluginCoreIoTerrainApi
|
|
29
|
+
|
|
30
|
+
constructor() {}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export * from "./import"
|
|
34
|
+
export * from "./job"
|
|
35
|
+
export * from "./underlay"
|
|
36
|
+
export * from "./terrain"
|
|
37
|
+
export * from "./query"
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as z from "zod"
|
|
2
|
+
import { PluginApiReturn } from "../../../../types"
|
|
3
|
+
import { ImportJobHandle, UnderlayHandle } from "../../../../handles"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Import jobs — poll a long-running asynchronous import.
|
|
7
|
+
*
|
|
8
|
+
* Some imports run on a server and take a while (today: `core.io.import.dwg`,
|
|
9
|
+
* whose DWG → Snaptrude conversion can take minutes). Those importers return an
|
|
10
|
+
* {@linkcode ImportJobHandle} immediately instead of blocking; you drive the job
|
|
11
|
+
* to completion here:
|
|
12
|
+
*
|
|
13
|
+
* 1. poll {@link PluginCoreIoJobApi.isComplete} (or read {@link PluginCoreIoJobApi.getStatus}),
|
|
14
|
+
* 2. once complete, call {@link PluginCoreIoJobApi.getResult} for the placed handle,
|
|
15
|
+
* 3. or read {@link PluginCoreIoJobApi.getError} if it failed.
|
|
16
|
+
*
|
|
17
|
+
* **Always poll with a timeout.** If the import is cancelled from the app UI
|
|
18
|
+
* (or the tab reloads mid-conversion), the job never reaches a terminal state
|
|
19
|
+
* and `getStatus` keeps returning `"processing"` — an unbounded poll loop would
|
|
20
|
+
* spin forever. Give up after a few minutes and surface that to the user.
|
|
21
|
+
*
|
|
22
|
+
* Accessed via `snaptrude.core.io.job`.
|
|
23
|
+
*/
|
|
24
|
+
export abstract class PluginCoreIoJobApi {
|
|
25
|
+
constructor() {}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Read a job's current status: `"pending"` (queued), `"processing"` (running),
|
|
29
|
+
* `"complete"` (result ready), or `"failed"`.
|
|
30
|
+
*
|
|
31
|
+
* Limitation: a job cancelled from the app UI never turns `"failed"` — it
|
|
32
|
+
* stays `"processing"` indefinitely. Bound your poll loop with a timeout.
|
|
33
|
+
*
|
|
34
|
+
* @param job - The import job to inspect.
|
|
35
|
+
* @returns the {@linkcode ImportJobStatus}.
|
|
36
|
+
* @throws {@link HandleInvalidError} if the job handle is unknown.
|
|
37
|
+
*
|
|
38
|
+
* @examplePrompt What's the status of my DWG import?
|
|
39
|
+
* @examplePrompt Is the CAD import still processing?
|
|
40
|
+
* @examplePrompt Check where the import job is up to
|
|
41
|
+
* @examplePrompt Did the import job fail?
|
|
42
|
+
*
|
|
43
|
+
* # Example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const job = await snaptrude.core.io.import.dwg(url, 1)
|
|
46
|
+
* console.log(await snaptrude.core.io.job.getStatus(job)) // "processing"
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
public abstract getStatus(job: ImportJobHandle): PluginApiReturn<ImportJobStatus>
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether the job has finished successfully (status is `"complete"` and a
|
|
53
|
+
* result is ready). Returns `false` while pending/processing and on failure.
|
|
54
|
+
*
|
|
55
|
+
* @param job - The import job to inspect.
|
|
56
|
+
* @throws {@link HandleInvalidError} if the job handle is unknown.
|
|
57
|
+
*
|
|
58
|
+
* @examplePrompt Is the DWG import done yet?
|
|
59
|
+
* @examplePrompt Has the CAD import finished?
|
|
60
|
+
* @examplePrompt Tell me when the import job completes
|
|
61
|
+
* @examplePrompt Is my import ready?
|
|
62
|
+
*
|
|
63
|
+
* # Example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const job = await snaptrude.core.io.import.dwg(url, 1)
|
|
66
|
+
* const deadline = Date.now() + 5 * 60_000 // cap the poll — see getStatus limitation
|
|
67
|
+
* while (!(await snaptrude.core.io.job.isComplete(job))) {
|
|
68
|
+
* if (Date.now() > deadline) throw new Error("DWG import timed out")
|
|
69
|
+
* await new Promise((r) => setTimeout(r, 2000))
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
public abstract isComplete(job: ImportJobHandle): PluginApiReturn<boolean>
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The imported result once the job is complete — the placed
|
|
77
|
+
* {@linkcode UnderlayHandle}. Returns `null` while the job is still
|
|
78
|
+
* pending/processing or if it failed (check {@link PluginCoreIoJobApi.getError}).
|
|
79
|
+
*
|
|
80
|
+
* @param job - The completed import job.
|
|
81
|
+
* @throws {@link HandleInvalidError} if the job handle is unknown.
|
|
82
|
+
*
|
|
83
|
+
* @examplePrompt Get the underlay from my finished DWG import
|
|
84
|
+
* @examplePrompt Give me the result of the CAD import job
|
|
85
|
+
* @examplePrompt Fetch the imported CAD sketch once it's ready
|
|
86
|
+
* @examplePrompt Return the handle for the completed import
|
|
87
|
+
*
|
|
88
|
+
* # Example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const job = await snaptrude.core.io.import.dwg(url, 1)
|
|
91
|
+
* const deadline = Date.now() + 5 * 60_000
|
|
92
|
+
* while (!(await snaptrude.core.io.job.isComplete(job))) {
|
|
93
|
+
* if (Date.now() > deadline) throw new Error("DWG import timed out")
|
|
94
|
+
* await new Promise((r) => setTimeout(r, 2000))
|
|
95
|
+
* }
|
|
96
|
+
* // DWG results are CAD underlays (CAD scaling isn't supported); manage them
|
|
97
|
+
* // via core.io.underlay.* (list / setOpacity / delete).
|
|
98
|
+
* const cad = await snaptrude.core.io.job.getResult(job)
|
|
99
|
+
* if (cad) console.log("import complete:", cad)
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
public abstract getResult(job: ImportJobHandle): PluginApiReturn<UnderlayHandle | null>
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The failure message if the job's status is `"failed"`; otherwise `null`.
|
|
106
|
+
*
|
|
107
|
+
* @param job - The import job to inspect.
|
|
108
|
+
* @throws {@link HandleInvalidError} if the job handle is unknown.
|
|
109
|
+
*
|
|
110
|
+
* @examplePrompt Why did my DWG import fail?
|
|
111
|
+
* @examplePrompt What went wrong with the CAD import?
|
|
112
|
+
* @examplePrompt Show the error from the failed import job
|
|
113
|
+
* @examplePrompt Did the import error out, and why?
|
|
114
|
+
*
|
|
115
|
+
* # Example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const job = await snaptrude.core.io.import.dwg(url, 1)
|
|
118
|
+
* if ((await snaptrude.core.io.job.getStatus(job)) === "failed") {
|
|
119
|
+
* console.error(await snaptrude.core.io.job.getError(job))
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
public abstract getError(job: ImportJobHandle): PluginApiReturn<string | null>
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Lifecycle status of an asynchronous import job. */
|
|
127
|
+
export const ImportJobStatus = z.enum(["pending", "processing", "complete", "failed"])
|
|
128
|
+
export type ImportJobStatus = z.infer<typeof ImportJobStatus>
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Arguments for the `core.io.job.*` readers.
|
|
132
|
+
*
|
|
133
|
+
* | Property | Type | Description |
|
|
134
|
+
* |---|---|---|
|
|
135
|
+
* | `job` | {@link ImportJobHandle} | The import job to inspect |
|
|
136
|
+
*/
|
|
137
|
+
export const PluginImportJobArgs = z.object({
|
|
138
|
+
job: ImportJobHandle,
|
|
139
|
+
})
|
|
140
|
+
export type PluginImportJobArgs = z.infer<typeof PluginImportJobArgs>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as z from "zod"
|
|
2
|
+
import { PluginApiReturn } from "../../../../types"
|
|
3
|
+
import { CadJsonInput } from "../import"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Import queries — read metadata about a source **before** importing it.
|
|
7
|
+
*
|
|
8
|
+
* These reads let a plugin discover a source's shape before importing it:
|
|
9
|
+
* how many pages a PDF has (for `import.pdf`'s `page`), and which CAD layers a
|
|
10
|
+
* drawing defines (imports always bring in every layer — there is no filter —
|
|
11
|
+
* but the names tell you what the drawing contains).
|
|
12
|
+
*
|
|
13
|
+
* Accessed via `snaptrude.core.io.query`.
|
|
14
|
+
*/
|
|
15
|
+
export abstract class PluginCoreIoQueryApi {
|
|
16
|
+
constructor() {}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Count the pages of a PDF without importing it. `null` if the source can't be
|
|
20
|
+
* read as a PDF.
|
|
21
|
+
*
|
|
22
|
+
* @param source - The PDF: an `https://` URL or a `data:` URL.
|
|
23
|
+
* @returns the page count, or `null`.
|
|
24
|
+
*
|
|
25
|
+
* @examplePrompt How many pages does this PDF have?
|
|
26
|
+
* @examplePrompt Count the pages in the drawing set before importing
|
|
27
|
+
* @examplePrompt Get the PDF page count
|
|
28
|
+
* @examplePrompt Is this a multi-page PDF, and how many?
|
|
29
|
+
*
|
|
30
|
+
* # Example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const pages = await snaptrude.core.io.query.getPdfPageCount(url)
|
|
33
|
+
* for (let p = 1; p <= (pages ?? 0); p++) {
|
|
34
|
+
* await snaptrude.core.io.import.pdf(url, p, p) // one page per storey
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
public abstract getPdfPageCount(source: string): PluginApiReturn<number | null>
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* List the distinct CAD layer names tagged on a parsed CAD JSON's entities.
|
|
42
|
+
* Read-only inspection: imports always bring in **every** layer (there is no
|
|
43
|
+
* layer filter on {@link core.io.import.dwg} / {@link core.io.import.cadJson}) —
|
|
44
|
+
* use the names to decide whether to import at all, or what to tell the user.
|
|
45
|
+
*
|
|
46
|
+
* @param cad - Parsed CAD JSON (same shape `import.cadJson` accepts).
|
|
47
|
+
* @returns the layer names (empty array if none).
|
|
48
|
+
*
|
|
49
|
+
* @examplePrompt What CAD layers are in this drawing?
|
|
50
|
+
* @examplePrompt List the layers before importing the CAD
|
|
51
|
+
* @examplePrompt Show the DWG layer names so I can pick which to import
|
|
52
|
+
* @examplePrompt Enumerate the CAD JSON layers
|
|
53
|
+
*
|
|
54
|
+
* # Example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const layers = await snaptrude.core.io.query.listCadLayers(cad)
|
|
57
|
+
* if (layers.some((l) => l.toUpperCase().includes("WALL"))) {
|
|
58
|
+
* await snaptrude.core.io.import.cadJson(cad, 1) // all layers import together
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
public abstract listCadLayers(cad: CadJsonInput): PluginApiReturn<string[]>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Arguments for {@link PluginCoreIoQueryApi.getPdfPageCount}. */
|
|
66
|
+
export const PluginQueryPdfPageCountArgs = z.object({ source: z.string().min(1) })
|
|
67
|
+
export type PluginQueryPdfPageCountArgs = z.infer<typeof PluginQueryPdfPageCountArgs>
|
|
68
|
+
|
|
69
|
+
/** Arguments for {@link PluginCoreIoQueryApi.listCadLayers}. */
|
|
70
|
+
export const PluginQueryCadLayersArgs = z.object({ cad: CadJsonInput })
|
|
71
|
+
export type PluginQueryCadLayersArgs = z.infer<typeof PluginQueryCadLayersArgs>
|