@vim3d/geojson 0.5.0 → 0.7.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/README.md +14 -0
- package/esm/scene.js +20 -18
- package/package.json +2 -2
- package/scene.d.ts +10 -3
- package/scene.js +19 -17
package/README.md
CHANGED
|
@@ -63,3 +63,17 @@ comes out of `maxPositions: 5000` with all 41 polygons kept.
|
|
|
63
63
|
width and beveled past that, or when a short segment would make the strip
|
|
64
64
|
fold. A line that ends where it starts joins up.
|
|
65
65
|
- `simplifyLine`, `simplifyRing`, `countPositions`, `bbox`, `eachPosition`.
|
|
66
|
+
|
|
67
|
+
### Drape points, curves, and ribbons
|
|
68
|
+
|
|
69
|
+
Pass `{ drape: { heightfield, spacing, offset, onMissing } }` to
|
|
70
|
+
`toScenePoints`, `toSceneCurves`, or `toSceneRibbons`. Build
|
|
71
|
+
`heightfield` with `new Heightfield(grid)` from `@vim3d/core`; the grid
|
|
72
|
+
must already be in the projected scene frame used by the GeoJSON
|
|
73
|
+
conversion. Draping replaces projected Y (including input altitudes)
|
|
74
|
+
with the sampled Y plus `offset` (default 0). `spacing` is the maximum
|
|
75
|
+
horizontal step in metres and defaults to the smaller grid spacing.
|
|
76
|
+
It inserts additional samples at terrain triangle boundaries and keeps
|
|
77
|
+
the feature's properties and ID. Missing terrain throws by default; use
|
|
78
|
+
`onMissing: 'omit'` to omit the affected point, curve or ribbon without
|
|
79
|
+
bridging holes. Only ribbon edges conform; `toSceneFills` does not drape.
|
package/esm/scene.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { geodeticToScene } from '@vim3d/core';
|
|
1
|
+
import { drapeFeature, geodeticToScene, ribbonMesh } from '@vim3d/core';
|
|
2
2
|
import earcut from 'earcut';
|
|
3
3
|
function eachFeature(input, emit) {
|
|
4
4
|
if (input.type === 'FeatureCollection')
|
|
@@ -56,7 +56,10 @@ export function toSceneCurves(input, origin, options = {}) {
|
|
|
56
56
|
const [first, last] = [vertices[0], vertices[vertices.length - 1]];
|
|
57
57
|
if (closed && first.some((v, i) => v !== last[i]))
|
|
58
58
|
vertices.push(first);
|
|
59
|
-
|
|
59
|
+
const { drape } = options;
|
|
60
|
+
const sampled = drape ? drapeFeature(drape.heightfield, { kind: 'curve', vertices }, drape)?.vertices : vertices;
|
|
61
|
+
if (sampled)
|
|
62
|
+
curves.push({ geometry: { primitive: 'curve', args: [], vertices: sampled }, properties, id, closed });
|
|
60
63
|
}));
|
|
61
64
|
return curves;
|
|
62
65
|
}
|
|
@@ -69,8 +72,12 @@ export function toScenePoints(input, origin, options = {}) {
|
|
|
69
72
|
const project = projector(origin, options);
|
|
70
73
|
eachFeature(input, (geometry, properties, id) => eachGeometry(geometry, child => {
|
|
71
74
|
const positions = child.type === 'Point' ? [child.coordinates] : child.type === 'MultiPoint' ? child.coordinates : [];
|
|
72
|
-
for (const position of project(positions))
|
|
73
|
-
|
|
75
|
+
for (const position of project(positions)) {
|
|
76
|
+
const { drape } = options;
|
|
77
|
+
const sampled = drape ? drapeFeature(drape.heightfield, { kind: 'point', position }, drape)?.position : position;
|
|
78
|
+
if (sampled)
|
|
79
|
+
points.push({ position: sampled, properties, id });
|
|
80
|
+
}
|
|
74
81
|
}));
|
|
75
82
|
return points;
|
|
76
83
|
}
|
|
@@ -145,7 +152,7 @@ function ribbon(line, width) {
|
|
|
145
152
|
lengths.push(length);
|
|
146
153
|
}
|
|
147
154
|
const sections = [];
|
|
148
|
-
const section = ([x, y, z], [nx, nz], scale) => sections.push([x, y, z, nx * scale, nz * scale]);
|
|
155
|
+
const section = ([x, y, z], [nx, nz], scale) => sections.push([[x + nx * scale, y, z + nz * scale], [x - nx * scale, y, z - nz * scale]]);
|
|
149
156
|
points.forEach((point, i) => {
|
|
150
157
|
const before = closed ? (i + count - 1) % count : i - 1;
|
|
151
158
|
const after = i < segments ? i : -1;
|
|
@@ -166,16 +173,7 @@ function ribbon(line, width) {
|
|
|
166
173
|
});
|
|
167
174
|
if (closed)
|
|
168
175
|
sections.push(sections[0]);
|
|
169
|
-
|
|
170
|
-
const indices = [];
|
|
171
|
-
sections.forEach(([x, y, z, ox, oz], i) => {
|
|
172
|
-
positions.push(x + ox, y, z + oz, x - ox, y, z - oz);
|
|
173
|
-
if (i > 0) {
|
|
174
|
-
const k = 2 * (i - 1);
|
|
175
|
-
indices.push(k, k + 1, k + 2, k + 1, k + 3, k + 2);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
return mesh(positions, indices);
|
|
176
|
+
return sections;
|
|
179
177
|
}
|
|
180
178
|
/**
|
|
181
179
|
* Every line (not polygon rings) as a flat, upward-facing strip of the given
|
|
@@ -192,9 +190,13 @@ export function toSceneRibbons(input, origin, options = {}) {
|
|
|
192
190
|
eachGeometry(geometry, child => {
|
|
193
191
|
const parts = child.type === 'LineString' ? [child.coordinates] : child.type === 'MultiLineString' ? child.coordinates : [];
|
|
194
192
|
for (const part of parts) {
|
|
195
|
-
const
|
|
196
|
-
if (
|
|
197
|
-
|
|
193
|
+
const sections = ribbon(project(part), width);
|
|
194
|
+
if (!sections)
|
|
195
|
+
continue;
|
|
196
|
+
const { drape } = options;
|
|
197
|
+
const sampled = drape ? drapeFeature(drape.heightfield, { kind: 'ribbon', sections }, drape)?.sections : sections;
|
|
198
|
+
if (sampled)
|
|
199
|
+
meshes.push({ geometry: ribbonMesh(sampled), properties, id });
|
|
198
200
|
}
|
|
199
201
|
});
|
|
200
202
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vim3d/geojson",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Fetch GeoJSON at load time and resample it for Vim3D scenes.",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/pyramation/vim3d/tree/master/js/packages/geojson",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@constructive-io/fetch": "^1.2.2",
|
|
25
25
|
"earcut": "^2.2.4",
|
|
26
|
-
"@vim3d/core": "^0.
|
|
26
|
+
"@vim3d/core": "^0.11.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/earcut": "^2.1.4",
|
package/scene.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type GeometrySnapshot, type GeoOrigin, type Vec3 } from '@vim3d/core';
|
|
1
|
+
import { type DrapeOptions, type GeometrySnapshot, type GeoOrigin, type Heightfield, type Vec3 } from '@vim3d/core';
|
|
2
2
|
import type { GeoJSON, Properties } from './types.js';
|
|
3
3
|
export interface SceneCurve {
|
|
4
4
|
/** A curve geometry @vim3d/threejs draws as a line. */
|
|
@@ -7,10 +7,16 @@ export interface SceneCurve {
|
|
|
7
7
|
readonly id?: string | number;
|
|
8
8
|
readonly closed: boolean;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
interface ProjectionOptions {
|
|
11
11
|
/** Elevation in metres for positions without one; defaults to the origin's. */
|
|
12
12
|
elevation?: number;
|
|
13
13
|
}
|
|
14
|
+
export interface SceneCurveOptions extends ProjectionOptions {
|
|
15
|
+
/** Drape projected XZ positions; replaces their Y with sampled terrain plus offset. */
|
|
16
|
+
drape?: DrapeOptions & {
|
|
17
|
+
readonly heightfield: Heightfield;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
14
20
|
export interface ScenePoint {
|
|
15
21
|
readonly position: Vec3;
|
|
16
22
|
readonly properties: Properties;
|
|
@@ -51,7 +57,7 @@ export declare function toScenePoints(input: GeoJSON, origin: GeoOrigin, options
|
|
|
51
57
|
* Every polygon (each part of a `MultiPolygon` on its own) as a flat,
|
|
52
58
|
* upward-facing triangle mesh with its holes cut out.
|
|
53
59
|
*/
|
|
54
|
-
export declare function toSceneFills(input: GeoJSON, origin: GeoOrigin, options?:
|
|
60
|
+
export declare function toSceneFills(input: GeoJSON, origin: GeoOrigin, options?: ProjectionOptions): SceneMesh[];
|
|
55
61
|
/**
|
|
56
62
|
* Every line (not polygon rings) as a flat, upward-facing strip of the given
|
|
57
63
|
* width around its centerline, for streets and paths. Corners are mitered;
|
|
@@ -59,3 +65,4 @@ export declare function toSceneFills(input: GeoJSON, origin: GeoOrigin, options?
|
|
|
59
65
|
* next vertex, are beveled. A line that ends where it starts joins up.
|
|
60
66
|
*/
|
|
61
67
|
export declare function toSceneRibbons(input: GeoJSON, origin: GeoOrigin, options?: SceneRibbonOptions): SceneMesh[];
|
|
68
|
+
export {};
|
package/scene.js
CHANGED
|
@@ -65,7 +65,10 @@ function toSceneCurves(input, origin, options = {}) {
|
|
|
65
65
|
const [first, last] = [vertices[0], vertices[vertices.length - 1]];
|
|
66
66
|
if (closed && first.some((v, i) => v !== last[i]))
|
|
67
67
|
vertices.push(first);
|
|
68
|
-
|
|
68
|
+
const { drape } = options;
|
|
69
|
+
const sampled = drape ? (0, core_1.drapeFeature)(drape.heightfield, { kind: 'curve', vertices }, drape)?.vertices : vertices;
|
|
70
|
+
if (sampled)
|
|
71
|
+
curves.push({ geometry: { primitive: 'curve', args: [], vertices: sampled }, properties, id, closed });
|
|
69
72
|
}));
|
|
70
73
|
return curves;
|
|
71
74
|
}
|
|
@@ -78,8 +81,12 @@ function toScenePoints(input, origin, options = {}) {
|
|
|
78
81
|
const project = projector(origin, options);
|
|
79
82
|
eachFeature(input, (geometry, properties, id) => eachGeometry(geometry, child => {
|
|
80
83
|
const positions = child.type === 'Point' ? [child.coordinates] : child.type === 'MultiPoint' ? child.coordinates : [];
|
|
81
|
-
for (const position of project(positions))
|
|
82
|
-
|
|
84
|
+
for (const position of project(positions)) {
|
|
85
|
+
const { drape } = options;
|
|
86
|
+
const sampled = drape ? (0, core_1.drapeFeature)(drape.heightfield, { kind: 'point', position }, drape)?.position : position;
|
|
87
|
+
if (sampled)
|
|
88
|
+
points.push({ position: sampled, properties, id });
|
|
89
|
+
}
|
|
83
90
|
}));
|
|
84
91
|
return points;
|
|
85
92
|
}
|
|
@@ -154,7 +161,7 @@ function ribbon(line, width) {
|
|
|
154
161
|
lengths.push(length);
|
|
155
162
|
}
|
|
156
163
|
const sections = [];
|
|
157
|
-
const section = ([x, y, z], [nx, nz], scale) => sections.push([x, y, z, nx * scale, nz * scale]);
|
|
164
|
+
const section = ([x, y, z], [nx, nz], scale) => sections.push([[x + nx * scale, y, z + nz * scale], [x - nx * scale, y, z - nz * scale]]);
|
|
158
165
|
points.forEach((point, i) => {
|
|
159
166
|
const before = closed ? (i + count - 1) % count : i - 1;
|
|
160
167
|
const after = i < segments ? i : -1;
|
|
@@ -175,16 +182,7 @@ function ribbon(line, width) {
|
|
|
175
182
|
});
|
|
176
183
|
if (closed)
|
|
177
184
|
sections.push(sections[0]);
|
|
178
|
-
|
|
179
|
-
const indices = [];
|
|
180
|
-
sections.forEach(([x, y, z, ox, oz], i) => {
|
|
181
|
-
positions.push(x + ox, y, z + oz, x - ox, y, z - oz);
|
|
182
|
-
if (i > 0) {
|
|
183
|
-
const k = 2 * (i - 1);
|
|
184
|
-
indices.push(k, k + 1, k + 2, k + 1, k + 3, k + 2);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
return mesh(positions, indices);
|
|
185
|
+
return sections;
|
|
188
186
|
}
|
|
189
187
|
/**
|
|
190
188
|
* Every line (not polygon rings) as a flat, upward-facing strip of the given
|
|
@@ -201,9 +199,13 @@ function toSceneRibbons(input, origin, options = {}) {
|
|
|
201
199
|
eachGeometry(geometry, child => {
|
|
202
200
|
const parts = child.type === 'LineString' ? [child.coordinates] : child.type === 'MultiLineString' ? child.coordinates : [];
|
|
203
201
|
for (const part of parts) {
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
206
|
-
|
|
202
|
+
const sections = ribbon(project(part), width);
|
|
203
|
+
if (!sections)
|
|
204
|
+
continue;
|
|
205
|
+
const { drape } = options;
|
|
206
|
+
const sampled = drape ? (0, core_1.drapeFeature)(drape.heightfield, { kind: 'ribbon', sections }, drape)?.sections : sections;
|
|
207
|
+
if (sampled)
|
|
208
|
+
meshes.push({ geometry: (0, core_1.ribbonMesh)(sampled), properties, id });
|
|
207
209
|
}
|
|
208
210
|
});
|
|
209
211
|
});
|