@file-viewer/renderer-3d 3.2.1 → 3.3.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/GEO3D.md +43 -3
- package/README.en.md +39 -3
- package/README.md +39 -3
- package/README.zh-CN.md +43 -0
- package/dist/geo3d-workers/manifest.json +2 -2
- package/dist/geo3dCrs.d.ts +4 -0
- package/dist/geo3dCrs.js +33 -1
- package/dist/geo3dLasCrs.d.ts +7 -0
- package/dist/geo3dLasCrs.js +96 -0
- package/dist/geo3dPointFactories.js +6 -6
- package/dist/geo3dRasterFactories.js +1 -1
- package/dist/geo3dRuntime.d.ts +1 -0
- package/dist/geo3dRuntime.js +16 -4
- package/package.json +7 -4
package/GEO3D.md
CHANGED
|
@@ -35,7 +35,7 @@ glTF resources and textures remain relative to the dataset.
|
|
|
35
35
|
Giro3D is an optional peer, matching the IFC specialist entry:
|
|
36
36
|
|
|
37
37
|
```sh
|
|
38
|
-
npm install @file-viewer/renderer-3d @giro3d/giro3d@2.0.
|
|
38
|
+
npm install @file-viewer/renderer-3d @giro3d/giro3d@2.0.5
|
|
39
39
|
# Only required when 3TZ archives are enabled:
|
|
40
40
|
npm install jszip@3.10.2
|
|
41
41
|
|
|
@@ -51,7 +51,7 @@ npm install --save-dev @types/three@0.185.0
|
|
|
51
51
|
|
|
52
52
|
The NodeNext and Bundler consumer checks keep `strict: true` and
|
|
53
53
|
`skipLibCheck: false`, and exercise the real Giro3D classes and format-narrowed
|
|
54
|
-
hooks. Giro3D 2.0.
|
|
54
|
+
hooks. Giro3D 2.0.5 requires the Three 0.180 runtime; the renderer retains its own
|
|
55
55
|
Three 0.186 dependency. Three type host 0.186 adds a `dispose` event that conflicts
|
|
56
56
|
with Giro3D's published `LayerNodeEventMap` and `TileMeshEventMap` declarations.
|
|
57
57
|
That upstream combination is not supported by the strict optional-entry check.
|
|
@@ -82,6 +82,31 @@ with static decoder scripts under a nested custom asset path.
|
|
|
82
82
|
|
|
83
83
|
## Usage
|
|
84
84
|
|
|
85
|
+
Raw LAS/LAZ with unresolved CRS metadata is rejected by default. Citation text
|
|
86
|
+
is descriptive and is never converted into a guessed EPSG code. When the data
|
|
87
|
+
owner has verified the source CRS, configure it explicitly without rewriting
|
|
88
|
+
the original file:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const renderer = createGeo3dRenderer({
|
|
92
|
+
assetBaseUrl: '/file-viewer/vendor/geo3d/',
|
|
93
|
+
giro3d: {
|
|
94
|
+
sources: { las: { sourceCrs: 'EPSG:32632' } },
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Use the dataset's verified CRS, rather than the example code above. For a CRS
|
|
100
|
+
without a built-in definition, pass `{ id, definition }` as `sourceCrs`, with an
|
|
101
|
+
offline WKT or PROJ definition, or register it through `crsDefinitions`.
|
|
102
|
+
This fallback applies only to unresolved raw LAS/LAZ. A conflicting GeoKey or
|
|
103
|
+
decoded WKT CRS is rejected; a resolved file definition remains authoritative.
|
|
104
|
+
Resolvable authority definitions, including built-in UTM codes, are preferred
|
|
105
|
+
before registering any same-ID definition supplied with this fallback.
|
|
106
|
+
IDs must match exactly, including when equivalent definitions use different
|
|
107
|
+
names. `giro3d.instance.crs` must also match the source CRS: this point-cloud
|
|
108
|
+
path does not reproject coordinates. No EPSG-registry network request is made.
|
|
109
|
+
|
|
85
110
|
```ts
|
|
86
111
|
import { modelRenderer } from '@file-viewer/renderer-3d'
|
|
87
112
|
import { createGeo3dRenderer } from '@file-viewer/renderer-3d/geo3d'
|
|
@@ -271,7 +296,7 @@ cases run against both workspace output and physical installed tarballs.
|
|
|
271
296
|
|
|
272
297
|
### Pinned engine maintenance boundary
|
|
273
298
|
|
|
274
|
-
The ownership adapters deliberately depend on reviewed Giro3D 2.0.
|
|
299
|
+
The ownership adapters deliberately depend on reviewed Giro3D 2.0.5 source.
|
|
275
300
|
Besides source-local pool injection, the PointCloud subclass overrides the
|
|
276
301
|
engine's internal loading method to link node and viewer cancellation. Source
|
|
277
302
|
initialization uses protected readiness fields. These are not an assertion of
|
|
@@ -308,9 +333,24 @@ Remote COPC uses strict byte ranges: HTTP 206, exposed and matching
|
|
|
308
333
|
COPC uses `File.slice()`. Plain LAS/LAZ uses the derived Giro3D `LASSource` with a
|
|
309
334
|
bounded whole-file read controlled by `maxLasBytes`; it is not progressive.
|
|
310
335
|
|
|
336
|
+
COPC initialization still reads the hierarchy metadata before the first point
|
|
337
|
+
frame. Adjacent declared hierarchy pages share a request, with merged spans
|
|
338
|
+
limited to 512 KiB and at most eight group reads per source. Gaps are not
|
|
339
|
+
prefetched; an isolated larger page retains its original range. Point payloads
|
|
340
|
+
remain selected by the engine's LOD. This does not guarantee a fixed startup
|
|
341
|
+
time on high-latency data origins. Point clouds without a Color attribute can
|
|
342
|
+
select Intensity or Z through the public post-load hook and set the attribute
|
|
343
|
+
color-map bounds to the data range.
|
|
344
|
+
|
|
311
345
|
The point-cloud scene CRS must match the dataset CRS. An incompatible scene is
|
|
312
346
|
rejected before application hooks; no runtime point-cloud reprojection is
|
|
313
347
|
performed. Reproject the dataset beforehand when a different scene is required.
|
|
348
|
+
LAS/LAZ GeoKeyDirectory CRS codes are read as well as WKT. A projected EPSG
|
|
349
|
+
code takes precedence over its underlying geographic CRS. Supply unregistered
|
|
350
|
+
CRS definitions through `crsDefinitions` for offline use. A declared CRS with
|
|
351
|
+
only citation text or an unsupported/user-defined GeoKey fails explicitly;
|
|
352
|
+
citation names are not guessed into EPSG codes or silently assigned the scene
|
|
353
|
+
CRS. Add authoritative WKT/EPSG metadata to such a dataset before loading it.
|
|
314
354
|
|
|
315
355
|
### GeoTIFF / COG versus ordinary TIFF
|
|
316
356
|
|
package/README.en.md
CHANGED
|
@@ -1,7 +1,43 @@
|
|
|
1
1
|
# @file-viewer/renderer-3d
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/3d/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/3d/README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Standalone 3D model renderer for Flyfish File Viewer. It uses Three.js, OrbitControls, and lazy format-specific loaders for GLB / GLTF, OBJ, STL, PLY, FBX, DAE, 3DS, 3MF, AMF, USD, KMZ, PCD, VRML, XYZ, VTK, and related files. STEP / STP, IGES / IGS, and BREP use a local OCCT worker for real geometry decoding and rendering.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import FileViewer from '@file-viewer/vue3'
|
|
11
|
+
import { modelRenderer } from '@file-viewer/renderer-3d'
|
|
12
|
+
|
|
13
|
+
const options = {
|
|
14
|
+
rendererMode: 'replace',
|
|
15
|
+
renderers: modelRenderer,
|
|
16
|
+
model: {
|
|
17
|
+
workerUrl: '/viewer-assets/wasm/model/occt-worker.js',
|
|
18
|
+
runtimeUrl: '/viewer-assets/wasm/model/occt-import-js.js',
|
|
19
|
+
wasmUrl: '/viewer-assets/wasm/model/occt-import-js.wasm',
|
|
20
|
+
workerTimeoutMs: 120_000,
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`modelRenderer` can be combined with CAD and other renderer packages, or consumed through `@file-viewer/preset-all`. Full packages and `@file-viewer/vite-plugin` prepare the default offline assets. A renderer-only integration must self-host the OCCT worker, runtime, WASM, and both license notices.
|
|
26
|
+
|
|
27
|
+
Specialist capabilities stay opt-in through separate subpath entries: `@file-viewer/renderer-3d/ifc` for IFC and `@file-viewer/renderer-3d/geo3d` for LAS / LAZ / COPC / GeoTIFF / COG / CityJSON / 3D Tiles / 3TZ. Neither sub-entry is imported by the ordinary model renderer or added implicitly to Full presets. See `IFC.md` and `GEO3D.md` for installation, self-hosted runtime assets, and configuration.
|
|
28
|
+
|
|
29
|
+
Default paths:
|
|
30
|
+
|
|
31
|
+
- `wasm/model/occt-worker.js`
|
|
32
|
+
- `wasm/model/occt-import-js.js`
|
|
33
|
+
- `wasm/model/occt-import-js.wasm`
|
|
34
|
+
|
|
35
|
+
For subpath deployments or a dedicated asset origin, provide final URLs through `options.model.workerUrl`, `runtimeUrl`, and `wasmUrl`. There is no runtime CDN fallback. A strict CSP must allow that origin in `worker-src`, `script-src`, and `connect-src`; some browsers also require `script-src 'wasm-unsafe-eval'`.
|
|
36
|
+
|
|
37
|
+
## Boundaries
|
|
38
|
+
|
|
39
|
+
- STEP / STP, IGES / IGS, and BREP are tessellated by `occt-import-js` / OpenCascade in a worker. Assembly hierarchy, instances, normals, and face colors are preserved when the Three.js scene is built.
|
|
40
|
+
- General models support WebGL orbit controls, fit-to-view, grid, axes, wireframe, and auto-rotate. External textures or binary resources referenced by `gltf`, `dae`, and `fbx` continue to resolve against the original file URL directory.
|
|
41
|
+
- Unified global zoom: the renderer registers the standard zoom provider, so the outer toolbar's zoom in, zoom out, reset, and fit actions control the camera. Wheel, trackpad, and pinch zoom also update the shared zoom state.
|
|
42
|
+
- IFC is available through the explicit `@file-viewer/renderer-3d/ifc` specialist entry. Streaming COPC / 3D Tiles are available through the explicit `@file-viewer/renderer-3d/geo3d` entry. 3DM still needs a dedicated `rhino3dm` renderer.
|
|
43
|
+
- `@file-viewer/core` does not bundle Three.js or a geometry kernel. Install this renderer, the matching preset, or a full package when model preview is required.
|
package/README.md
CHANGED
|
@@ -1,7 +1,43 @@
|
|
|
1
1
|
# @file-viewer/renderer-3d
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/3d/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/3d/README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Standalone 3D model renderer for Flyfish File Viewer. It uses Three.js, OrbitControls, and lazy format-specific loaders for GLB / GLTF, OBJ, STL, PLY, FBX, DAE, 3DS, 3MF, AMF, USD, KMZ, PCD, VRML, XYZ, VTK, and related files. STEP / STP, IGES / IGS, and BREP use a local OCCT worker for real geometry decoding and rendering.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import FileViewer from '@file-viewer/vue3'
|
|
11
|
+
import { modelRenderer } from '@file-viewer/renderer-3d'
|
|
12
|
+
|
|
13
|
+
const options = {
|
|
14
|
+
rendererMode: 'replace',
|
|
15
|
+
renderers: modelRenderer,
|
|
16
|
+
model: {
|
|
17
|
+
workerUrl: '/viewer-assets/wasm/model/occt-worker.js',
|
|
18
|
+
runtimeUrl: '/viewer-assets/wasm/model/occt-import-js.js',
|
|
19
|
+
wasmUrl: '/viewer-assets/wasm/model/occt-import-js.wasm',
|
|
20
|
+
workerTimeoutMs: 120_000,
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`modelRenderer` can be combined with CAD and other renderer packages, or consumed through `@file-viewer/preset-all`. Full packages and `@file-viewer/vite-plugin` prepare the default offline assets. A renderer-only integration must self-host the OCCT worker, runtime, WASM, and both license notices.
|
|
26
|
+
|
|
27
|
+
Specialist capabilities stay opt-in through separate subpath entries: `@file-viewer/renderer-3d/ifc` for IFC and `@file-viewer/renderer-3d/geo3d` for LAS / LAZ / COPC / GeoTIFF / COG / CityJSON / 3D Tiles / 3TZ. Neither sub-entry is imported by the ordinary model renderer or added implicitly to Full presets. See `IFC.md` and `GEO3D.md` for installation, self-hosted runtime assets, and configuration.
|
|
28
|
+
|
|
29
|
+
Default paths:
|
|
30
|
+
|
|
31
|
+
- `wasm/model/occt-worker.js`
|
|
32
|
+
- `wasm/model/occt-import-js.js`
|
|
33
|
+
- `wasm/model/occt-import-js.wasm`
|
|
34
|
+
|
|
35
|
+
For subpath deployments or a dedicated asset origin, provide final URLs through `options.model.workerUrl`, `runtimeUrl`, and `wasmUrl`. There is no runtime CDN fallback. A strict CSP must allow that origin in `worker-src`, `script-src`, and `connect-src`; some browsers also require `script-src 'wasm-unsafe-eval'`.
|
|
36
|
+
|
|
37
|
+
## Boundaries
|
|
38
|
+
|
|
39
|
+
- STEP / STP, IGES / IGS, and BREP are tessellated by `occt-import-js` / OpenCascade in a worker. Assembly hierarchy, instances, normals, and face colors are preserved when the Three.js scene is built.
|
|
40
|
+
- General models support WebGL orbit controls, fit-to-view, grid, axes, wireframe, and auto-rotate. External textures or binary resources referenced by `gltf`, `dae`, and `fbx` continue to resolve against the original file URL directory.
|
|
41
|
+
- Unified global zoom: the renderer registers the standard zoom provider, so the outer toolbar's zoom in, zoom out, reset, and fit actions control the camera. Wheel, trackpad, and pinch zoom also update the shared zoom state.
|
|
42
|
+
- IFC is available through the explicit `@file-viewer/renderer-3d/ifc` specialist entry. Streaming COPC / 3D Tiles are available through the explicit `@file-viewer/renderer-3d/geo3d` entry. 3DM still needs a dedicated `rhino3dm` renderer.
|
|
43
|
+
- `@file-viewer/core` does not bundle Three.js or a geometry kernel. Install this renderer, the matching preset, or a full package when model preview is required.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @file-viewer/renderer-3d
|
|
2
|
+
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/3d/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/3d/README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Flyfish File Viewer 的独立 3D 模型 renderer。它使用 Three.js、OrbitControls 和按格式异步加载的 loader,在浏览器内预览 GLB / GLTF、OBJ、STL、PLY、FBX、DAE、3DS、3MF、AMF、USD、KMZ、PCD、VRML、XYZ、VTK 等模型;STEP / STP、IGES / IGS 和 BREP 则通过本地 OCCT Worker 完成真实几何解析和渲染。
|
|
6
|
+
|
|
7
|
+
## 用法
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import FileViewer from '@file-viewer/vue3'
|
|
11
|
+
import { modelRenderer } from '@file-viewer/renderer-3d'
|
|
12
|
+
|
|
13
|
+
const options = {
|
|
14
|
+
rendererMode: 'replace',
|
|
15
|
+
renderers: modelRenderer,
|
|
16
|
+
model: {
|
|
17
|
+
workerUrl: '/viewer-assets/wasm/model/occt-worker.js',
|
|
18
|
+
runtimeUrl: '/viewer-assets/wasm/model/occt-import-js.js',
|
|
19
|
+
wasmUrl: '/viewer-assets/wasm/model/occt-import-js.wasm',
|
|
20
|
+
workerTimeoutMs: 120_000,
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
也可以把 `modelRenderer` 与 CAD 等 renderer 组合,或直接使用已经聚合它的 `@file-viewer/preset-all`。full 包和 `@file-viewer/vite-plugin` 会准备默认离线资产;只安装 renderer 时,需要自行托管 OCCT Worker、runtime、WASM 和两个许可证文件。
|
|
26
|
+
|
|
27
|
+
专用能力继续通过显式子路径按需安装:IFC 使用 `@file-viewer/renderer-3d/ifc`,LAS / LAZ / COPC / GeoTIFF / COG / CityJSON / 3D Tiles / 3TZ 使用 `@file-viewer/renderer-3d/geo3d`。普通 3D 入口不会导入这两个子入口,Full preset 也不会隐式加入它们。安装、自托管运行时资源和配置分别见 `IFC.md` 与 `GEO3D.md`。
|
|
28
|
+
|
|
29
|
+
默认路径为:
|
|
30
|
+
|
|
31
|
+
- `wasm/model/occt-worker.js`
|
|
32
|
+
- `wasm/model/occt-import-js.js`
|
|
33
|
+
- `wasm/model/occt-import-js.wasm`
|
|
34
|
+
|
|
35
|
+
部署在子路径或独立资产域名时,通过 `options.model.workerUrl`、`runtimeUrl`、`wasmUrl` 传入最终 URL。不要使用运行时 CDN 回退。严格 CSP 需要在 `worker-src`、`script-src` 和 `connect-src` 中允许对应来源;部分浏览器还需要 `script-src 'wasm-unsafe-eval'`。
|
|
36
|
+
|
|
37
|
+
## 能力边界
|
|
38
|
+
|
|
39
|
+
- STEP / STP、IGES / IGS、BREP:在 Worker 中使用 `occt-import-js` / OpenCascade 三角化,保留装配层级、实例、法线和面颜色,再构建 Three.js 场景。
|
|
40
|
+
- 通用模型:支持 WebGL 轨道控制、适配视图、网格、坐标轴、线框和自动旋转。`gltf` / `dae` / `fbx` 的外部贴图或二进制资源继续以原始 `url` 目录为基准加载。
|
|
41
|
+
- 全局统一缩放:renderer 注册标准缩放 provider,因此外层工具栏的放大、缩小、比例重置和适配视图会直接控制相机;滚轮、触控板和捏合缩放也会同步更新全局比例状态。
|
|
42
|
+
- IFC 可通过显式的 `@file-viewer/renderer-3d/ifc` 专用入口启用;LAS / LAZ / COPC / GeoTIFF / COG / CityJSON / 3D Tiles / 3TZ 可通过 `@file-viewer/renderer-3d/geo3d` 启用。3DM 仍需专门的 `rhino3dm` renderer。
|
|
43
|
+
- `@file-viewer/core` 不内置 Three.js 或几何内核。需要模型预览时请显式安装本包、相应 preset,或 full 包。
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"PointCloudSource": "882f470513f76ce024fe2284d73e7c235530654655894c5efc8e67a81d087552",
|
|
9
9
|
"worker": "cd2fb4cf51d66175b21dcdc70229a6f256c83b923e5ed5cd6445a65cf8bf130b"
|
|
10
10
|
},
|
|
11
|
-
"adapterSha256": "
|
|
11
|
+
"adapterSha256": "d932517849f1328660db4f7289f30051245ecc6b65c4f6dab76d2116ce33105d",
|
|
12
12
|
"workerSha256": "831459fc9f82443bd0f3d2c12a8d7b1a1f0308c55f09a53cc3759034a02fec0b",
|
|
13
13
|
"packages": [
|
|
14
14
|
{
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"geotiffPool": "6b8cdc6a98f9f443dbb5ddfb516a7ce01ae40ca776ba6a1e9cc2a9667a148ae3",
|
|
92
92
|
"geotiffWorker": "4453d3dca492eedca5e4d78d66e1153569f0af5d0d2bd178f7bab400b1d581e8"
|
|
93
93
|
},
|
|
94
|
-
"factorySha256": "
|
|
94
|
+
"factorySha256": "7f6b4b16aec23c90319b90c8e445dbae3635bed0d36d35f4ad90440a957bbad8",
|
|
95
95
|
"files": {
|
|
96
96
|
"geotiff-worker.js": "7857b60dc9a4e2b915eda04a7b5697a0322464ccedbd4568d5ce3f280b284f36",
|
|
97
97
|
"texture-worker.js": "5d6131d4f184845deb75284b7903e29b8d5394f73f9abe6d88406efee56200a5"
|
package/dist/geo3dCrs.d.ts
CHANGED
|
@@ -5,4 +5,8 @@ export type Geo3dCrsInput = `EPSG:${number}` | {
|
|
|
5
5
|
definition: string;
|
|
6
6
|
};
|
|
7
7
|
export declare function resolveGeo3dCrs(input?: Geo3dCrsInput | string, fallback?: CoordinateSystem): Promise<CoordinateSystem>;
|
|
8
|
+
export declare function resolveLasSourceCrs(native: CoordinateSystem | undefined, inspected: {
|
|
9
|
+
crs?: string;
|
|
10
|
+
hasCrsMetadata: boolean;
|
|
11
|
+
}, input?: Geo3dCrsInput): Promise<CoordinateSystem | undefined>;
|
|
8
12
|
export {};
|
package/dist/geo3dCrs.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
class UnknownGeo3dCrsError extends Error {
|
|
2
|
+
}
|
|
1
3
|
export async function resolveGeo3dCrs(input, fallback) {
|
|
2
4
|
const { default: CRS } = await import('@giro3d/giro3d/core/geographic/CoordinateSystem.js');
|
|
3
5
|
if (!input)
|
|
@@ -14,5 +16,35 @@ export async function resolveGeo3dCrs(input, fallback) {
|
|
|
14
16
|
if (match && Number(match[2]) >= 1 && Number(match[2]) <= 60) {
|
|
15
17
|
return CRS.register(input, `+proj=utm +zone=${Number(match[2])}${match[1] === '327' ? ' +south' : ''} +datum=WGS84 +units=m +no_defs`, { throwIfFailedToRegisterWithProj: true });
|
|
16
18
|
}
|
|
17
|
-
throw new
|
|
19
|
+
throw new UnknownGeo3dCrsError(`Unknown Geo3D CRS ${input}. Register its offline definition with crsDefinitions; coordinates are not silently relabelled.`);
|
|
20
|
+
}
|
|
21
|
+
export async function resolveLasSourceCrs(native, inspected, input) {
|
|
22
|
+
const known = native && !native.isUnknown() ? native : undefined;
|
|
23
|
+
if (input !== undefined) {
|
|
24
|
+
const id = typeof input === 'string' ? input : input?.id;
|
|
25
|
+
if (typeof id !== 'string' || !id.trim())
|
|
26
|
+
throw new Error('Invalid explicit LAS source CRS.');
|
|
27
|
+
if ((known && known.id !== id) || (inspected.crs && inspected.crs !== id))
|
|
28
|
+
throw new Error('Explicit LAS source CRS conflicts with dataset CRS metadata; it is a fallback, not an override.');
|
|
29
|
+
if (known)
|
|
30
|
+
return known;
|
|
31
|
+
try {
|
|
32
|
+
return await resolveGeo3dCrs(inspected.crs ?? id);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (!(error instanceof UnknownGeo3dCrsError))
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
const explicit = await resolveGeo3dCrs(input);
|
|
39
|
+
if (explicit.isUnknown())
|
|
40
|
+
throw new Error('Explicit LAS source CRS must have a resolvable definition.');
|
|
41
|
+
return explicit;
|
|
42
|
+
}
|
|
43
|
+
if (known)
|
|
44
|
+
return known;
|
|
45
|
+
if (inspected.crs)
|
|
46
|
+
return resolveGeo3dCrs(inspected.crs);
|
|
47
|
+
if (inspected.hasCrsMetadata)
|
|
48
|
+
throw new Error('LAS CRS metadata cannot be resolved. Add an authoritative EPSG GeoKey or WKT definition before loading, or explicitly configure giro3d.sources.las.sourceCrs from a verified source; coordinates are not silently relabelled.');
|
|
49
|
+
return native;
|
|
18
50
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Geo3dRangeGetter } from './geo3dInspect.js';
|
|
2
|
+
export interface LasCrsInspection {
|
|
3
|
+
crs?: string;
|
|
4
|
+
hasCrsMetadata: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function parseLasGeoKeys(bytes: Uint8Array): string | undefined;
|
|
7
|
+
export declare function inspectLasCrsRangeSource(getter: Geo3dRangeGetter): Promise<LasCrsInspection>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const text = (bytes) => new TextDecoder().decode(bytes).replace(/\0/g, '').trim();
|
|
2
|
+
const view = (bytes) => new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
3
|
+
export function parseLasGeoKeys(bytes) {
|
|
4
|
+
const data = view(bytes);
|
|
5
|
+
if (bytes.length < 8 || bytes.length % 2 || data.getUint16(0, true) !== 1
|
|
6
|
+
|| data.getUint16(2, true) !== 1 || data.getUint16(4, true) > 1)
|
|
7
|
+
throw new Error('Invalid LAS GeoKeyDirectory header.');
|
|
8
|
+
const count = data.getUint16(6, true);
|
|
9
|
+
if (8 + count * 8 > bytes.length)
|
|
10
|
+
throw new Error('Truncated LAS GeoKeyDirectory.');
|
|
11
|
+
const keys = new Map();
|
|
12
|
+
for (let i = 0; i < count; i++) {
|
|
13
|
+
const offset = 8 + i * 8;
|
|
14
|
+
const key = data.getUint16(offset, true);
|
|
15
|
+
if (![1024, 2048, 3072].includes(key))
|
|
16
|
+
continue;
|
|
17
|
+
if (data.getUint16(offset + 2, true) !== 0 || data.getUint16(offset + 4, true) !== 1)
|
|
18
|
+
throw new Error('Unsupported LAS GeoKey CRS value encoding.');
|
|
19
|
+
const value = data.getUint16(offset + 6, true);
|
|
20
|
+
if (keys.has(key) && keys.get(key) !== value)
|
|
21
|
+
throw new Error('Conflicting LAS GeoKey CRS values.');
|
|
22
|
+
keys.set(key, value);
|
|
23
|
+
}
|
|
24
|
+
const model = keys.get(1024);
|
|
25
|
+
const code = model === 1 || keys.has(3072) ? keys.get(3072)
|
|
26
|
+
: model === undefined || model === 2 || model === 3 ? keys.get(2048) : undefined;
|
|
27
|
+
return code && code < 32767 ? `EPSG:${code}` : undefined;
|
|
28
|
+
}
|
|
29
|
+
export async function inspectLasCrsRangeSource(getter) {
|
|
30
|
+
let budget = 4 * 1024 * 1024;
|
|
31
|
+
const exact = async (begin, end) => {
|
|
32
|
+
budget -= end - begin;
|
|
33
|
+
if (budget < 0)
|
|
34
|
+
throw new Error('LAS CRS metadata exceeds the inspection budget.');
|
|
35
|
+
const bytes = await getter(begin, end);
|
|
36
|
+
if (bytes.byteLength !== end - begin)
|
|
37
|
+
throw new Error('Truncated LAS CRS metadata.');
|
|
38
|
+
return bytes;
|
|
39
|
+
};
|
|
40
|
+
const header = await exact(0, 227);
|
|
41
|
+
if (text(header.subarray(0, 4)) !== 'LASF' || header[24] !== 1 || header[25] > 4)
|
|
42
|
+
throw new Error('Invalid LAS header while reading CRS metadata.');
|
|
43
|
+
const data = view(header);
|
|
44
|
+
let offset = data.getUint16(94, true);
|
|
45
|
+
const end = data.getUint32(96, true);
|
|
46
|
+
const count = data.getUint32(100, true);
|
|
47
|
+
if (offset < 227 || end < offset || count > 4096)
|
|
48
|
+
throw new Error('Invalid LAS VLR metadata bounds.');
|
|
49
|
+
let crs;
|
|
50
|
+
let hasCrsMetadata = false;
|
|
51
|
+
const inspectPayload = async (userId, id, begin, end) => {
|
|
52
|
+
if (userId !== 'LASF_Projection' || ![2112, 34735, 34736, 34737].includes(id) || end === begin)
|
|
53
|
+
return;
|
|
54
|
+
const payload = await exact(begin, end);
|
|
55
|
+
hasCrsMetadata ||= id === 34735 || id === 34736 || !!text(payload);
|
|
56
|
+
if (id === 34735) {
|
|
57
|
+
const candidate = parseLasGeoKeys(payload);
|
|
58
|
+
if (crs && candidate && crs !== candidate)
|
|
59
|
+
throw new Error('Conflicting LAS GeoKey CRS directories.');
|
|
60
|
+
crs = candidate ?? crs;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
for (let i = 0; i < count; i++) {
|
|
64
|
+
if (offset + 54 > end)
|
|
65
|
+
throw new Error('LAS VLR header exceeds the point-data offset.');
|
|
66
|
+
const vlr = await exact(offset, offset + 54);
|
|
67
|
+
const fields = view(vlr);
|
|
68
|
+
const length = fields.getUint16(20, true);
|
|
69
|
+
const next = offset + 54 + length;
|
|
70
|
+
if (next > end)
|
|
71
|
+
throw new Error('LAS VLR payload exceeds the point-data offset.');
|
|
72
|
+
const id = fields.getUint16(18, true);
|
|
73
|
+
await inspectPayload(text(vlr.subarray(2, 18)), id, offset + 54, next);
|
|
74
|
+
offset = next;
|
|
75
|
+
}
|
|
76
|
+
if (header[25] === 4) {
|
|
77
|
+
if (data.getUint16(94, true) < 375)
|
|
78
|
+
throw new Error('Invalid LAS 1.4 header length.');
|
|
79
|
+
const extended = view(await exact(227, 375));
|
|
80
|
+
offset = Number(extended.getBigUint64(8, true));
|
|
81
|
+
const evlrCount = extended.getUint32(16, true);
|
|
82
|
+
if (evlrCount > 4096 || (evlrCount && (!Number.isSafeInteger(offset) || offset < end)))
|
|
83
|
+
throw new Error('Invalid LAS EVLR metadata bounds.');
|
|
84
|
+
for (let i = 0; i < evlrCount; i++) {
|
|
85
|
+
const evlr = await exact(offset, offset + 60);
|
|
86
|
+
const fields = view(evlr);
|
|
87
|
+
const length = Number(fields.getBigUint64(20, true));
|
|
88
|
+
const next = offset + 60 + length;
|
|
89
|
+
if (!Number.isSafeInteger(length) || !Number.isSafeInteger(next))
|
|
90
|
+
throw new Error('Invalid LAS EVLR payload length.');
|
|
91
|
+
await inspectPayload(text(evlr.subarray(2, 18)), fields.getUint16(18, true), offset + 60, next);
|
|
92
|
+
offset = next;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { crs, hasCrsMetadata };
|
|
96
|
+
}
|