@edv4h/usketch-plugin-elevation 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +100 -2
- package/dist/__tests__/helpers.d.ts +6 -0
- package/dist/__tests__/helpers.d.ts.map +1 -0
- package/dist/__tests__/helpers.js +38 -0
- package/dist/__tests__/helpers.js.map +1 -0
- package/dist/brush-cursor-layer.d.ts +15 -0
- package/dist/brush-cursor-layer.d.ts.map +1 -0
- package/dist/brush-cursor-layer.js +47 -0
- package/dist/brush-cursor-layer.js.map +1 -0
- package/dist/elevation-brush.d.ts +99 -0
- package/dist/elevation-brush.d.ts.map +1 -0
- package/dist/elevation-brush.js +230 -0
- package/dist/elevation-brush.js.map +1 -0
- package/dist/elevation-codec.d.ts +10 -0
- package/dist/elevation-codec.d.ts.map +1 -0
- package/dist/elevation-codec.js +47 -0
- package/dist/elevation-codec.js.map +1 -0
- package/dist/elevation-field.d.ts +92 -0
- package/dist/elevation-field.d.ts.map +1 -0
- package/dist/elevation-field.js +123 -0
- package/dist/elevation-field.js.map +1 -0
- package/dist/elevation-layer.d.ts +36 -0
- package/dist/elevation-layer.d.ts.map +1 -0
- package/dist/elevation-layer.js +267 -0
- package/dist/elevation-layer.js.map +1 -0
- package/dist/elevation-mesh-layer.d.ts +18 -0
- package/dist/elevation-mesh-layer.d.ts.map +1 -0
- package/dist/elevation-mesh-layer.js +343 -0
- package/dist/elevation-mesh-layer.js.map +1 -0
- package/dist/elevation-mesh.d.ts +42 -0
- package/dist/elevation-mesh.d.ts.map +1 -0
- package/dist/elevation-mesh.js +118 -0
- package/dist/elevation-mesh.js.map +1 -0
- package/dist/elevation-model.d.ts +43 -0
- package/dist/elevation-model.d.ts.map +1 -0
- package/dist/elevation-model.js +188 -0
- package/dist/elevation-model.js.map +1 -0
- package/dist/elevation-noise.d.ts +13 -0
- package/dist/elevation-noise.d.ts.map +1 -0
- package/dist/elevation-noise.js +69 -0
- package/dist/elevation-noise.js.map +1 -0
- package/dist/elevation-ops.d.ts +66 -0
- package/dist/elevation-ops.d.ts.map +1 -0
- package/dist/elevation-ops.js +208 -0
- package/dist/elevation-ops.js.map +1 -0
- package/dist/elevation-service.d.ts +41 -0
- package/dist/elevation-service.d.ts.map +1 -0
- package/dist/elevation-service.js +27 -0
- package/dist/elevation-service.js.map +1 -0
- package/dist/elevation-shade.d.ts +41 -0
- package/dist/elevation-shade.d.ts.map +1 -0
- package/dist/elevation-shade.js +181 -0
- package/dist/elevation-shade.js.map +1 -0
- package/dist/elevation-shapes.d.ts +4 -0
- package/dist/elevation-shapes.d.ts.map +1 -0
- package/dist/elevation-shapes.js +48 -0
- package/dist/elevation-shapes.js.map +1 -0
- package/dist/elevation-tiles.d.ts +43 -0
- package/dist/elevation-tiles.d.ts.map +1 -0
- package/dist/elevation-tiles.js +77 -0
- package/dist/elevation-tiles.js.map +1 -0
- package/dist/elevation-tool.d.ts +24 -0
- package/dist/elevation-tool.d.ts.map +1 -0
- package/dist/elevation-tool.js +121 -0
- package/dist/elevation-tool.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +139 -0
- package/dist/plugin.js.map +1 -0
- package/dist/reactive-store.d.ts +7 -0
- package/dist/reactive-store.d.ts.map +1 -0
- package/dist/reactive-store.js +32 -0
- package/dist/reactive-store.js.map +1 -0
- package/dist/register-elevation-hud.d.ts +5 -0
- package/dist/register-elevation-hud.d.ts.map +1 -0
- package/dist/register-elevation-hud.js +183 -0
- package/dist/register-elevation-hud.js.map +1 -0
- package/package.json +50 -3
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// A chunk's deltas as text: Int16 values (quarter units), little-endian, base64. Fixed
|
|
2
|
+
// byte order so every client reads the same heights whatever its CPU.
|
|
3
|
+
/** Encode deltas (`Int16Array`, any length) as base64. Pure. */
|
|
4
|
+
export function encodeChunk(values) {
|
|
5
|
+
const bytes = new Uint8Array(values.length * 2);
|
|
6
|
+
const view = new DataView(bytes.buffer);
|
|
7
|
+
for (let i = 0; i < values.length; i++)
|
|
8
|
+
view.setInt16(i * 2, values[i], true);
|
|
9
|
+
let text = "";
|
|
10
|
+
// In slices: `String.fromCharCode(...bytes)` on a large array overflows the stack.
|
|
11
|
+
for (let i = 0; i < bytes.length; i += 0x2000) {
|
|
12
|
+
text += String.fromCharCode(...bytes.subarray(i, i + 0x2000));
|
|
13
|
+
}
|
|
14
|
+
return btoa(text);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Decode `length` deltas. `null` when `data` isn't base64 of exactly `length` values
|
|
18
|
+
* (synced data could be anything): the caller treats that chunk as unedited. Pure.
|
|
19
|
+
*/
|
|
20
|
+
export function decodeChunk(data, length) {
|
|
21
|
+
if (typeof data !== "string")
|
|
22
|
+
return null;
|
|
23
|
+
let text;
|
|
24
|
+
try {
|
|
25
|
+
text = atob(data);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (text.length !== length * 2)
|
|
31
|
+
return null;
|
|
32
|
+
const out = new Int16Array(length);
|
|
33
|
+
for (let i = 0; i < length; i++) {
|
|
34
|
+
const lo = text.charCodeAt(i * 2);
|
|
35
|
+
const hi = text.charCodeAt(i * 2 + 1);
|
|
36
|
+
out[i] = (((hi << 8) | lo) << 16) >> 16;
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/** Whether every delta is 0 (such a chunk is removed rather than stored). Pure. */
|
|
41
|
+
export function isEmptyChunk(values) {
|
|
42
|
+
for (let i = 0; i < values.length; i++)
|
|
43
|
+
if (values[i] !== 0)
|
|
44
|
+
return false;
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=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AE,OAAO,IAAI,CAAC;IAC5C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACjC,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAClC,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACtC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IACzC,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;IAC1E,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ShapeData } from "@edv4h/usketch-shared";
|
|
2
|
+
export declare const FIELD_TYPE = "elevation-field";
|
|
3
|
+
export declare const CHUNK_TYPE = "elevation-chunk";
|
|
4
|
+
/** World units between two samples of a new field. */
|
|
5
|
+
export declare const DEFAULT_SPACING = 16;
|
|
6
|
+
/** Samples along a chunk's side. */
|
|
7
|
+
export declare const DEFAULT_CHUNK = 32;
|
|
8
|
+
/** Highest ground (world units); heights are kept in `0 … MAX_HEIGHT`. */
|
|
9
|
+
export declare const MAX_HEIGHT = 4095.75;
|
|
10
|
+
/** Stored deltas are in quarter units. */
|
|
11
|
+
export declare const DELTA_SCALE = 4;
|
|
12
|
+
/**
|
|
13
|
+
* The id every client gives the field it creates. Fixed, so two clients turning the
|
|
14
|
+
* terrain on at once write the same shape (one field) instead of two fields whose
|
|
15
|
+
* chunk ids (`elev:<field>:…`) differ — the edits on the field that doesn't win would
|
|
16
|
+
* otherwise be lost.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ELEVATION_FIELD_ID = "elevation-field";
|
|
19
|
+
/** Parameters of the infinite terrain, frozen on the field when it is created. */
|
|
20
|
+
export interface ElevationGenParams {
|
|
21
|
+
/** Generator version. */
|
|
22
|
+
v: 1;
|
|
23
|
+
/** Height of the highest peaks, roughly (world units). */
|
|
24
|
+
relief: number;
|
|
25
|
+
/** Size of a mountain (world units): larger is gentler. */
|
|
26
|
+
scale: number;
|
|
27
|
+
/** How much each finer octave adds, `0 … 1` (fbm persistence). */
|
|
28
|
+
roughness: number;
|
|
29
|
+
/** How much ridged noise sharpens the high ground, `0 … 1`. */
|
|
30
|
+
ridges: number;
|
|
31
|
+
/** Octaves layered, `1 … 8`. */
|
|
32
|
+
octaves: number;
|
|
33
|
+
}
|
|
34
|
+
export declare const DEFAULT_GEN: ElevationGenParams;
|
|
35
|
+
/** Water level of a new infinite terrain, as a fraction of its `relief`. */
|
|
36
|
+
export declare const DEFAULT_WATER_RATIO = 0.15;
|
|
37
|
+
export interface ElevationFieldShape extends ShapeData {
|
|
38
|
+
type: typeof FIELD_TYPE;
|
|
39
|
+
spacing: number;
|
|
40
|
+
chunk: number;
|
|
41
|
+
/** Encoding version of the chunks. */
|
|
42
|
+
version: 1;
|
|
43
|
+
/** Seed of the infinite terrain (an integer). Absent = a flat board. */
|
|
44
|
+
seed?: number;
|
|
45
|
+
gen?: ElevationGenParams;
|
|
46
|
+
/** Ground below this height is drawn as water. Absent = no water. */
|
|
47
|
+
waterLevel?: number;
|
|
48
|
+
}
|
|
49
|
+
export interface ElevationChunkShape extends ShapeData {
|
|
50
|
+
type: typeof CHUNK_TYPE;
|
|
51
|
+
/** Id of the field it belongs to. */
|
|
52
|
+
field: string;
|
|
53
|
+
cx: number;
|
|
54
|
+
cy: number;
|
|
55
|
+
/** `chunk²` Int16 deltas (quarter units, row-major, little-endian), base64. */
|
|
56
|
+
data: string;
|
|
57
|
+
}
|
|
58
|
+
/** A field's settings with every value checked (see {@link normalizeField}). */
|
|
59
|
+
export interface ElevationFieldConfig {
|
|
60
|
+
id: string;
|
|
61
|
+
spacing: number;
|
|
62
|
+
chunk: number;
|
|
63
|
+
/** `null` = no generated terrain (the ground is flat under the edits). */
|
|
64
|
+
seed: number | null;
|
|
65
|
+
gen: ElevationGenParams;
|
|
66
|
+
waterLevel: number | null;
|
|
67
|
+
}
|
|
68
|
+
export declare function isElevationField(shape: ShapeData): shape is ElevationFieldShape;
|
|
69
|
+
export declare function isElevationChunk(shape: ShapeData): shape is ElevationChunkShape;
|
|
70
|
+
/** Generator parameters with junk replaced by the defaults and values kept in range. Pure. */
|
|
71
|
+
export declare function normalizeGen(raw: unknown): ElevationGenParams;
|
|
72
|
+
/**
|
|
73
|
+
* A field's settings, checked: synced data could carry anything. A spacing / chunk out
|
|
74
|
+
* of range falls back to the default, a non-integer seed means no generated terrain.
|
|
75
|
+
* The same object for the same shape object. Pure.
|
|
76
|
+
*/
|
|
77
|
+
export declare function normalizeField(shape: ElevationFieldShape): ElevationFieldConfig;
|
|
78
|
+
/** The deterministic id of a field's chunk: two clients editing a new spot write the same key. */
|
|
79
|
+
export declare function chunkShapeId(fieldId: string, cx: number, cy: number): string;
|
|
80
|
+
/** `"cx,cy"`. */
|
|
81
|
+
export declare function chunkKey(cx: number, cy: number): string;
|
|
82
|
+
/** A new field shape (no generated terrain unless `seed` is given). */
|
|
83
|
+
export declare function makeFieldShape(id: string, opts?: {
|
|
84
|
+
spacing?: number;
|
|
85
|
+
chunk?: number;
|
|
86
|
+
seed?: number;
|
|
87
|
+
gen?: ElevationGenParams;
|
|
88
|
+
waterLevel?: number;
|
|
89
|
+
}): ElevationFieldShape;
|
|
90
|
+
/** A chunk shape covering its chunk's world rect. */
|
|
91
|
+
export declare function makeChunkShape(field: ElevationFieldConfig, cx: number, cy: number, data: string): ElevationChunkShape;
|
|
92
|
+
//# sourceMappingURL=elevation-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elevation-field.d.ts","sourceRoot":"","sources":["../src/elevation-field.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,eAAO,MAAM,UAAU,oBAAoB,CAAC;AAC5C,eAAO,MAAM,UAAU,oBAAoB,CAAC;AAE5C,sDAAsD;AACtD,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,oCAAoC;AACpC,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,0EAA0E;AAC1E,eAAO,MAAM,UAAU,UAAU,CAAC;AAClC,0CAA0C;AAC1C,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,oBAAoB,CAAC;AAEpD,kFAAkF;AAClF,MAAM,WAAW,kBAAkB;IAClC,yBAAyB;IACzB,CAAC,EAAE,CAAC,CAAC;IACL,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,WAAW,EAAE,kBAOzB,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,MAAM,WAAW,mBAAoB,SAAQ,SAAS;IACrD,IAAI,EAAE,OAAO,UAAU,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,OAAO,EAAE,CAAC,CAAC;IACX,wEAAwE;IAC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ACV,IAAI,GAAE;IACL,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,kBAAkB,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACf,GACJ,mBAAmB,CAiBrB;AAED,qDAAqD;AACrD,wBAAgB,cAAc,CAC7B,KAAK,EAAE,oBAAoB,EAC3B,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GACV,mBAAmB,CAgBrB"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export const FIELD_TYPE = "elevation-field";
|
|
2
|
+
export const CHUNK_TYPE = "elevation-chunk";
|
|
3
|
+
/** World units between two samples of a new field. */
|
|
4
|
+
export const DEFAULT_SPACING = 16;
|
|
5
|
+
/** Samples along a chunk's side. */
|
|
6
|
+
export const DEFAULT_CHUNK = 32;
|
|
7
|
+
/** Highest ground (world units); heights are kept in `0 … MAX_HEIGHT`. */
|
|
8
|
+
export const MAX_HEIGHT = 4095.75;
|
|
9
|
+
/** Stored deltas are in quarter units. */
|
|
10
|
+
export const DELTA_SCALE = 4;
|
|
11
|
+
/**
|
|
12
|
+
* The id every client gives the field it creates. Fixed, so two clients turning the
|
|
13
|
+
* terrain on at once write the same shape (one field) instead of two fields whose
|
|
14
|
+
* chunk ids (`elev:<field>:…`) differ — the edits on the field that doesn't win would
|
|
15
|
+
* otherwise be lost.
|
|
16
|
+
*/
|
|
17
|
+
export const ELEVATION_FIELD_ID = "elevation-field";
|
|
18
|
+
export const DEFAULT_GEN = {
|
|
19
|
+
v: 1,
|
|
20
|
+
relief: 320,
|
|
21
|
+
scale: 2048,
|
|
22
|
+
roughness: 0.5,
|
|
23
|
+
ridges: 0.3,
|
|
24
|
+
octaves: 5,
|
|
25
|
+
};
|
|
26
|
+
/** Water level of a new infinite terrain, as a fraction of its `relief`. */
|
|
27
|
+
export const DEFAULT_WATER_RATIO = 0.15;
|
|
28
|
+
export function isElevationField(shape) {
|
|
29
|
+
return shape.type === FIELD_TYPE;
|
|
30
|
+
}
|
|
31
|
+
export function isElevationChunk(shape) {
|
|
32
|
+
return shape.type === CHUNK_TYPE;
|
|
33
|
+
}
|
|
34
|
+
const finite = (v) => typeof v === "number" && Number.isFinite(v);
|
|
35
|
+
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
36
|
+
const num = (v, fallback, lo, hi) => finite(v) ? clamp(v, lo, hi) : fallback;
|
|
37
|
+
/** Generator parameters with junk replaced by the defaults and values kept in range. Pure. */
|
|
38
|
+
export function normalizeGen(raw) {
|
|
39
|
+
const g = (raw && typeof raw === "object" ? raw : {});
|
|
40
|
+
return {
|
|
41
|
+
v: 1,
|
|
42
|
+
relief: num(g.relief, DEFAULT_GEN.relief, 0, MAX_HEIGHT),
|
|
43
|
+
scale: num(g.scale, DEFAULT_GEN.scale, 64, 65536),
|
|
44
|
+
roughness: num(g.roughness, DEFAULT_GEN.roughness, 0, 1),
|
|
45
|
+
ridges: num(g.ridges, DEFAULT_GEN.ridges, 0, 1),
|
|
46
|
+
octaves: Math.round(num(g.octaves, DEFAULT_GEN.octaves, 1, 8)),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const configCache = new WeakMap();
|
|
50
|
+
/**
|
|
51
|
+
* A field's settings, checked: synced data could carry anything. A spacing / chunk out
|
|
52
|
+
* of range falls back to the default, a non-integer seed means no generated terrain.
|
|
53
|
+
* The same object for the same shape object. Pure.
|
|
54
|
+
*/
|
|
55
|
+
export function normalizeField(shape) {
|
|
56
|
+
const hit = configCache.get(shape);
|
|
57
|
+
if (hit)
|
|
58
|
+
return hit;
|
|
59
|
+
const spacing = finite(shape.spacing) && shape.spacing >= 1 && shape.spacing <= 1024
|
|
60
|
+
? shape.spacing
|
|
61
|
+
: DEFAULT_SPACING;
|
|
62
|
+
const chunk = Number.isInteger(shape.chunk) && shape.chunk >= 4 && shape.chunk <= 256
|
|
63
|
+
? shape.chunk
|
|
64
|
+
: DEFAULT_CHUNK;
|
|
65
|
+
const seed = Number.isInteger(shape.seed) ? shape.seed : null;
|
|
66
|
+
const config = {
|
|
67
|
+
id: shape.id,
|
|
68
|
+
spacing,
|
|
69
|
+
chunk,
|
|
70
|
+
seed,
|
|
71
|
+
gen: normalizeGen(shape.gen),
|
|
72
|
+
waterLevel: finite(shape.waterLevel) ? clamp(shape.waterLevel, 0, MAX_HEIGHT) : null,
|
|
73
|
+
};
|
|
74
|
+
configCache.set(shape, config);
|
|
75
|
+
return config;
|
|
76
|
+
}
|
|
77
|
+
/** The deterministic id of a field's chunk: two clients editing a new spot write the same key. */
|
|
78
|
+
export function chunkShapeId(fieldId, cx, cy) {
|
|
79
|
+
return `elev:${fieldId}:${cx}:${cy}`;
|
|
80
|
+
}
|
|
81
|
+
/** `"cx,cy"`. */
|
|
82
|
+
export function chunkKey(cx, cy) {
|
|
83
|
+
return `${cx},${cy}`;
|
|
84
|
+
}
|
|
85
|
+
const SUBSTRATE_STYLE = { fill: "transparent", stroke: "transparent", strokeWidth: 0, opacity: 1 };
|
|
86
|
+
/** A new field shape (no generated terrain unless `seed` is given). */
|
|
87
|
+
export function makeFieldShape(id, opts = {}) {
|
|
88
|
+
return {
|
|
89
|
+
id,
|
|
90
|
+
type: FIELD_TYPE,
|
|
91
|
+
x: 0,
|
|
92
|
+
y: 0,
|
|
93
|
+
width: 0,
|
|
94
|
+
height: 0,
|
|
95
|
+
style: { ...SUBSTRATE_STYLE },
|
|
96
|
+
locked: true,
|
|
97
|
+
spacing: opts.spacing ?? DEFAULT_SPACING,
|
|
98
|
+
chunk: opts.chunk ?? DEFAULT_CHUNK,
|
|
99
|
+
version: 1,
|
|
100
|
+
...(opts.seed !== undefined ? { seed: opts.seed } : {}),
|
|
101
|
+
...(opts.gen ? { gen: opts.gen } : {}),
|
|
102
|
+
...(opts.waterLevel !== undefined ? { waterLevel: opts.waterLevel } : {}),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** A chunk shape covering its chunk's world rect. */
|
|
106
|
+
export function makeChunkShape(field, cx, cy, data) {
|
|
107
|
+
const size = field.chunk * field.spacing;
|
|
108
|
+
return {
|
|
109
|
+
id: chunkShapeId(field.id, cx, cy),
|
|
110
|
+
type: CHUNK_TYPE,
|
|
111
|
+
x: cx * size,
|
|
112
|
+
y: cy * size,
|
|
113
|
+
width: size,
|
|
114
|
+
height: size,
|
|
115
|
+
style: { ...SUBSTRATE_STYLE },
|
|
116
|
+
locked: true,
|
|
117
|
+
field: field.id,
|
|
118
|
+
cx,
|
|
119
|
+
cy,
|
|
120
|
+
data,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=elevation-field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elevation-field.js","sourceRoot":"","sources":["../src/elevation-field.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAC5C,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAE5C,sDAAsD;AACtD,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAClC,oCAAoC;AACpC,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAChC,0EAA0E;AAC1E,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC;AAClC,0CAA0C;AAC1C,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAkBpD,MAAM,CAAC,MAAM,WAAW,GAAuB;IAC9C,CAAC,EAAE,CAAC;IACJ,MAAM,EAAE,GAAG;IACX,KAAK,EAAE,IAAI;IACX,SAAS,EAAE,GAAG;IACd,MAAM,EAAE,GAAG;IACX,OAAO,EAAE,CAAC;CACV,CAAC;AAEF,4EAA4E;AAC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AAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzE,CAAC;AACH,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,cAAc,CAC7B,KAA2B,EAC3B,EAAU,EACV,EAAU,EACV,IAAY;IAEZ,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC;IACzC,OAAO;QACN,EAAE,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;QAClC,IAAI,EAAE,UAAU;QAChB,CAAC,EAAE,EAAE,GAAG,IAAI;QACZ,CAAC,EAAE,EAAE,GAAG,IAAI;QACZ,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,EAAE,GAAG,eAAe,EAAE;QAC7B,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,KAAK,CAAC,EAAE;QACf,EAAE;QACF,EAAE;QACF,IAAI;KACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type BoardStore } from "@edv4h/usketch-shared";
|
|
2
|
+
import { type ElevationModel } from "./elevation-model.js";
|
|
3
|
+
import { type ElevationDisplay } from "./elevation-shade.js";
|
|
4
|
+
import type { ReactiveStore } from "./reactive-store.js";
|
|
5
|
+
export declare const GROUND_LAYER_ID = "usketch-elevation:ground";
|
|
6
|
+
/** Queue `job` under `key` (a later job for the same key replaces it). Returns a cancel. */
|
|
7
|
+
export declare function queueDraw(key: object, job: () => void): () => void;
|
|
8
|
+
/**
|
|
9
|
+
* A key that changes exactly when the deltas a tile reads change: the chunks under the
|
|
10
|
+
* tile and the ring of samples around it (its edge slopes). At level 0 a ring chunk counts
|
|
11
|
+
* by the strip the tile reads; at coarser levels by its array.
|
|
12
|
+
*/
|
|
13
|
+
export declare function tileRevision(model: ElevationModel, level: number, tx: number, ty: number): string;
|
|
14
|
+
/**
|
|
15
|
+
* Bitmap size of a tile a brush stroke is changing: drawn every frame while the stroke
|
|
16
|
+
* lasts, so coarser (it is drawn at full size again once the stroke is written).
|
|
17
|
+
*/
|
|
18
|
+
export declare const STROKE_TILE_PX = 128;
|
|
19
|
+
/** A brush stroke's elevation while it is drawn (`null`: none, the board's is shown). */
|
|
20
|
+
export interface StrokePreview {
|
|
21
|
+
model: ElevationModel | null;
|
|
22
|
+
}
|
|
23
|
+
export declare function ElevationGroundLayer({ store, display, overscan, preview, mesh, }: {
|
|
24
|
+
store: BoardStore;
|
|
25
|
+
display: ReactiveStore<ElevationDisplay>;
|
|
26
|
+
/** Extra screen px of ground to draw past the viewport (a 3D view's far ground). */
|
|
27
|
+
overscan: ReactiveStore<{
|
|
28
|
+
px: number;
|
|
29
|
+
}>;
|
|
30
|
+
preview?: ReactiveStore<StrokePreview>;
|
|
31
|
+
/** While the 3D mesh draws the ground, this layer draws nothing. */
|
|
32
|
+
mesh?: ReactiveStore<{
|
|
33
|
+
drawing: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
}): import("react").JSX.Element | null;
|
|
36
|
+
//# sourceMappingURL=elevation-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elevation-layer.d.ts","sourceRoot":"","sources":["../src/elevation-layer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,UAAU,EAAoB,MAAM,uBAAuB,CAAC;AAG1E,OAAO,EAGN,KAAK,cAAc,EAGnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,KAAK,gBAAgB,EAAoB,MAAM,sBAAsB,CAAC;AAE/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAgC1D,4FAA4F;AAC5F,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAMlE;AAkDD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CA+BjG;AASD;;;GAGG;AACH,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,yFAAyF;AACzF,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;CAC7B;AAED,wBAAgB,oBAAoB,CAAC,EACpC,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,EACP,IAAI,GACJ,EAAE;IACF,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IACzC,oFAAoF;IACpF,QAAQ,EAAE,aAAa,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxC,OAAO,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IACvC,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAC3C,sCAyFA"}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// The flat board's view of the elevation: the visible tiles (chunks at a level of
|
|
3
|
+
// detail, see elevation-tiles.ts), each one <canvas> drawn once and kept until its
|
|
4
|
+
// heights, its resolution or the look change. Panning only moves one wrapper. Tiles are
|
|
5
|
+
// drawn a few per frame (see the draw queue), so zooming out over an infinite terrain
|
|
6
|
+
// never blocks a frame for long. Input goes to tools; the layer is pointer-events:none.
|
|
7
|
+
import { viewportRotation } from "@edv4h/usketch-shared";
|
|
8
|
+
import { memo, useEffect, useRef, useState } from "react";
|
|
9
|
+
import { chunkKey } from "./elevation-field.js";
|
|
10
|
+
import { boardElevation, elevationSampler, } from "./elevation-model.js";
|
|
11
|
+
import { renderTilePixels } from "./elevation-shade.js";
|
|
12
|
+
import { planTiles, visibleWorldRect } from "./elevation-tiles.js";
|
|
13
|
+
export const GROUND_LAYER_ID = "usketch-elevation:ground";
|
|
14
|
+
/**
|
|
15
|
+
* Pixels each tile's bitmap reaches past its edges: a scaled canvas fades its outermost
|
|
16
|
+
* pixels into transparency, so neighbours overlap by this much and no seam shows.
|
|
17
|
+
*/
|
|
18
|
+
const TILE_MARGIN = 2;
|
|
19
|
+
// ── Draw queue: tiles are drawn in the order they ask, within a time budget per frame ──
|
|
20
|
+
const FRAME_BUDGET_MS = 8;
|
|
21
|
+
const queue = new Map();
|
|
22
|
+
let scheduled = false;
|
|
23
|
+
function runQueue() {
|
|
24
|
+
scheduled = false;
|
|
25
|
+
const start = performance.now();
|
|
26
|
+
for (const [key, job] of queue) {
|
|
27
|
+
queue.delete(key);
|
|
28
|
+
job();
|
|
29
|
+
if (performance.now() - start > FRAME_BUDGET_MS)
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
if (queue.size > 0)
|
|
33
|
+
schedule();
|
|
34
|
+
}
|
|
35
|
+
function schedule() {
|
|
36
|
+
if (scheduled)
|
|
37
|
+
return;
|
|
38
|
+
scheduled = true;
|
|
39
|
+
if (typeof requestAnimationFrame === "function")
|
|
40
|
+
requestAnimationFrame(runQueue);
|
|
41
|
+
else
|
|
42
|
+
setTimeout(runQueue, 0);
|
|
43
|
+
}
|
|
44
|
+
/** Queue `job` under `key` (a later job for the same key replaces it). Returns a cancel. */
|
|
45
|
+
export function queueDraw(key, job) {
|
|
46
|
+
queue.set(key, job);
|
|
47
|
+
schedule();
|
|
48
|
+
return () => {
|
|
49
|
+
if (queue.get(key) === job)
|
|
50
|
+
queue.delete(key);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// ── Tile revisions: which deltas a tile reads ──
|
|
54
|
+
let nextArrayId = 1;
|
|
55
|
+
const arrayIds = new WeakMap();
|
|
56
|
+
const arrayId = (a) => {
|
|
57
|
+
let id = arrayIds.get(a);
|
|
58
|
+
if (id === undefined) {
|
|
59
|
+
id = nextArrayId++;
|
|
60
|
+
arrayIds.set(a, id);
|
|
61
|
+
}
|
|
62
|
+
return id;
|
|
63
|
+
};
|
|
64
|
+
const edgeKeys = new WeakMap();
|
|
65
|
+
/**
|
|
66
|
+
* A key for the strip of a neighbouring chunk that a level-0 tile reads (its samples
|
|
67
|
+
* within 2 of the tile, for the margin and the edge slopes), `null` when the strip is all
|
|
68
|
+
* zeros (the same as no chunk). So a brush stroke next to a tile redraws it only when
|
|
69
|
+
* the stroke reaches that strip. Cached per array (arrays are never mutated).
|
|
70
|
+
*/
|
|
71
|
+
function edgeKey(a, n, dx, dy) {
|
|
72
|
+
let byEdge = edgeKeys.get(a);
|
|
73
|
+
if (!byEdge) {
|
|
74
|
+
byEdge = new Map();
|
|
75
|
+
edgeKeys.set(a, byEdge);
|
|
76
|
+
}
|
|
77
|
+
const side = `${dx},${dy}`;
|
|
78
|
+
const hit = byEdge.get(side);
|
|
79
|
+
if (hit !== undefined)
|
|
80
|
+
return hit;
|
|
81
|
+
const range = (d) => d < 0 ? [n - 2, n - 1] : d > 0 ? [0, Math.min(2, n - 1)] : [0, n - 1];
|
|
82
|
+
const [i0, i1] = range(dx);
|
|
83
|
+
const [j0, j1] = range(dy);
|
|
84
|
+
let h = 0x811c9dc5;
|
|
85
|
+
let any = false;
|
|
86
|
+
for (let j = j0; j <= j1; j++) {
|
|
87
|
+
for (let i = i0; i <= i1; i++) {
|
|
88
|
+
const v = Math.round(a[j * n + i] * 64);
|
|
89
|
+
if (v !== 0)
|
|
90
|
+
any = true;
|
|
91
|
+
h = Math.imul(h ^ v, 0x01000193);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const key = any ? (h >>> 0).toString(36) : null;
|
|
95
|
+
byEdge.set(side, key);
|
|
96
|
+
return key;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A key that changes exactly when the deltas a tile reads change: the chunks under the
|
|
100
|
+
* tile and the ring of samples around it (its edge slopes). At level 0 a ring chunk counts
|
|
101
|
+
* by the strip the tile reads; at coarser levels by its array.
|
|
102
|
+
*/
|
|
103
|
+
export function tileRevision(model, level, tx, ty) {
|
|
104
|
+
const per = 2 ** level;
|
|
105
|
+
const n = model.field.chunk;
|
|
106
|
+
const cx0 = tx * per - 1;
|
|
107
|
+
const cx1 = (tx + 1) * per;
|
|
108
|
+
const cy0 = ty * per - 1;
|
|
109
|
+
const cy1 = (ty + 1) * per;
|
|
110
|
+
const parts = [];
|
|
111
|
+
const add = (cx, cy, a) => {
|
|
112
|
+
if (level === 0 && (cx !== tx || cy !== ty)) {
|
|
113
|
+
const k = edgeKey(a, n, cx - tx, cy - ty);
|
|
114
|
+
if (k !== null)
|
|
115
|
+
parts.push(`${cx},${cy}~${k}`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
parts.push(`${cx},${cy}:${arrayId(a)}`);
|
|
119
|
+
};
|
|
120
|
+
if ((per + 2) * (per + 2) <= model.chunks.size) {
|
|
121
|
+
for (let cy = cy0; cy <= cy1; cy++) {
|
|
122
|
+
for (let cx = cx0; cx <= cx1; cx++) {
|
|
123
|
+
const a = model.chunks.get(chunkKey(cx, cy));
|
|
124
|
+
if (a)
|
|
125
|
+
add(cx, cy, a);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
for (const [key, a] of model.chunks) {
|
|
131
|
+
const [cx, cy] = key.split(",").map(Number);
|
|
132
|
+
if (cx >= cx0 && cx <= cx1 && cy >= cy0 && cy <= cy1)
|
|
133
|
+
add(cx, cy, a);
|
|
134
|
+
}
|
|
135
|
+
parts.sort();
|
|
136
|
+
}
|
|
137
|
+
return parts.join(";");
|
|
138
|
+
}
|
|
139
|
+
/** What a tile's look depends on besides its deltas: the field's terrain settings. */
|
|
140
|
+
function fieldKey(model) {
|
|
141
|
+
const f = model.field;
|
|
142
|
+
const g = f.gen;
|
|
143
|
+
return `${f.id}|${f.spacing}|${f.chunk}|${f.seed}|${f.waterLevel}|${g.relief}|${g.scale}|${g.roughness}|${g.ridges}|${g.octaves}`;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Bitmap size of a tile a brush stroke is changing: drawn every frame while the stroke
|
|
147
|
+
* lasts, so coarser (it is drawn at full size again once the stroke is written).
|
|
148
|
+
*/
|
|
149
|
+
export const STROKE_TILE_PX = 128;
|
|
150
|
+
export function ElevationGroundLayer({ store, display, overscan, preview, mesh, }) {
|
|
151
|
+
const [, force] = useState(0);
|
|
152
|
+
const rafRef = useRef(0);
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
const rerender = () => {
|
|
155
|
+
cancelAnimationFrame(rafRef.current);
|
|
156
|
+
rafRef.current = requestAnimationFrame(() => force((n) => n + 1));
|
|
157
|
+
};
|
|
158
|
+
const offs = [
|
|
159
|
+
store.subscribe(rerender),
|
|
160
|
+
display.subscribe(rerender),
|
|
161
|
+
overscan.subscribe(rerender),
|
|
162
|
+
...(preview ? [preview.subscribe(rerender)] : []),
|
|
163
|
+
...(mesh ? [mesh.subscribe(rerender)] : []),
|
|
164
|
+
];
|
|
165
|
+
return () => {
|
|
166
|
+
for (const off of offs)
|
|
167
|
+
off();
|
|
168
|
+
cancelAnimationFrame(rafRef.current);
|
|
169
|
+
};
|
|
170
|
+
}, [store, display, overscan, preview, mesh]);
|
|
171
|
+
// The 3D mesh draws the ground: nothing to draw here (no tiles kept busy meanwhile).
|
|
172
|
+
if (mesh?.get().drawing)
|
|
173
|
+
return null;
|
|
174
|
+
const stored = boardElevation(store);
|
|
175
|
+
const drafting = preview?.get().model ?? null;
|
|
176
|
+
const model = drafting ?? stored;
|
|
177
|
+
if (!model)
|
|
178
|
+
return null;
|
|
179
|
+
const vp = store.getViewport();
|
|
180
|
+
const overscanPx = overscan.get().px;
|
|
181
|
+
const rect = visibleWorldRect(store, overscanPx);
|
|
182
|
+
const plan = rect ? planTiles(model.field, rect, vp.zoom) : null;
|
|
183
|
+
if (!plan)
|
|
184
|
+
return null;
|
|
185
|
+
const sampler = elevationSampler(model);
|
|
186
|
+
const look = display.get();
|
|
187
|
+
const fk = fieldKey(model);
|
|
188
|
+
const tiles = [];
|
|
189
|
+
for (let ty = plan.ty0; ty <= plan.ty1; ty++) {
|
|
190
|
+
for (let tx = plan.tx0; tx <= plan.tx1; tx++) {
|
|
191
|
+
const left = Math.round(tx * plan.worldSize * vp.zoom);
|
|
192
|
+
const top = Math.round(ty * plan.worldSize * vp.zoom);
|
|
193
|
+
const revision = tileRevision(model, plan.level, tx, ty);
|
|
194
|
+
// A tile the stroke is changing is redrawn every frame: draw it coarser.
|
|
195
|
+
const changing = drafting !== null && revision !== (stored ? tileRevision(stored, plan.level, tx, ty) : "");
|
|
196
|
+
tiles.push(_jsx(ElevationTile, { sampler: sampler, level: plan.level, tx: tx, ty: ty, px: changing ? Math.min(plan.px, STROKE_TILE_PX) : plan.px, left: left, top: top, width: Math.round((tx + 1) * plan.worldSize * vp.zoom) - left, height: Math.round((ty + 1) * plan.worldSize * vp.zoom) - top, revision: `${fk}#${revision}`, display: look }, `${plan.level}:${tx},${ty}`));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return (_jsx("div", { "data-usketch-elevation": "", style: {
|
|
200
|
+
position: "absolute",
|
|
201
|
+
inset: 0,
|
|
202
|
+
width: "100%",
|
|
203
|
+
height: "100%",
|
|
204
|
+
pointerEvents: "none",
|
|
205
|
+
// Ground drawn past the viewport (3D overscan) or turned with the camera must
|
|
206
|
+
// not be cut at the box.
|
|
207
|
+
overflow: overscanPx > 0 || viewportRotation(vp) !== 0 ? "visible" : "hidden",
|
|
208
|
+
}, children: _jsx("div", { style: {
|
|
209
|
+
position: "absolute",
|
|
210
|
+
left: 0,
|
|
211
|
+
top: 0,
|
|
212
|
+
transform: `translate(${vp.x}px, ${vp.y}px)`,
|
|
213
|
+
willChange: "transform",
|
|
214
|
+
}, children: tiles }) }));
|
|
215
|
+
}
|
|
216
|
+
/** One tile's canvas: redrawn only when its revision, resolution or the look change. */
|
|
217
|
+
const ElevationTile = memo(function ElevationTile(props) {
|
|
218
|
+
const ref = useRef(null);
|
|
219
|
+
const latest = useRef(props);
|
|
220
|
+
latest.current = props;
|
|
221
|
+
const { level, tx, ty, px, revision, display } = props;
|
|
222
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the sampler is read from `latest`; `revision` stands for it
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
const canvas = ref.current;
|
|
225
|
+
if (!canvas)
|
|
226
|
+
return;
|
|
227
|
+
return queueDraw(canvas, () => {
|
|
228
|
+
const ctx = canvas.getContext("2d");
|
|
229
|
+
if (!ctx)
|
|
230
|
+
return;
|
|
231
|
+
const pixels = renderTilePixels({
|
|
232
|
+
sampler: latest.current.sampler,
|
|
233
|
+
level,
|
|
234
|
+
tx,
|
|
235
|
+
ty,
|
|
236
|
+
size: px,
|
|
237
|
+
margin: TILE_MARGIN,
|
|
238
|
+
display,
|
|
239
|
+
});
|
|
240
|
+
const full = px + 2 * TILE_MARGIN;
|
|
241
|
+
ctx.putImageData(new ImageData(pixels, full, full), 0, 0);
|
|
242
|
+
});
|
|
243
|
+
}, [level, tx, ty, px, revision, display]);
|
|
244
|
+
// The bitmap's margin pixels reach past the tile's box on every side.
|
|
245
|
+
const mx = (props.width / px) * TILE_MARGIN;
|
|
246
|
+
const my = (props.height / px) * TILE_MARGIN;
|
|
247
|
+
return (_jsx("canvas", { ref: ref, width: px + 2 * TILE_MARGIN, height: px + 2 * TILE_MARGIN, style: {
|
|
248
|
+
position: "absolute",
|
|
249
|
+
left: props.left - mx,
|
|
250
|
+
top: props.top - my,
|
|
251
|
+
width: props.width + 2 * mx,
|
|
252
|
+
height: props.height + 2 * my,
|
|
253
|
+
} }));
|
|
254
|
+
},
|
|
255
|
+
// The sampler is a new object whenever ANY chunk changes; the revision says whether
|
|
256
|
+
// this tile's part did.
|
|
257
|
+
(a, b) => a.level === b.level &&
|
|
258
|
+
a.tx === b.tx &&
|
|
259
|
+
a.ty === b.ty &&
|
|
260
|
+
a.px === b.px &&
|
|
261
|
+
a.left === b.left &&
|
|
262
|
+
a.top === b.top &&
|
|
263
|
+
a.width === b.width &&
|
|
264
|
+
a.height === b.height &&
|
|
265
|
+
a.revision === b.revision &&
|
|
266
|
+
a.display === b.display);
|
|
267
|
+
//# sourceMappingURL=elevation-layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elevation-layer.js","sourceRoot":"","sources":["../src/elevation-layer.tsx"],"names":[],"mappings":";AAAA,kFAAkF;AAClF,mFAAmF;AACnF,wFAAwF;AACxF,sFAAsF;AACtF,wFAAwF;AACxF,OAAO,EAAmB,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EACN,cAAc,EAId,gBAAgB,GAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAyB,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGnE,MAAM,CAAC,MAAM,eAAe,GAAG,0BAA0B,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,0FAA0F;AAE1F,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;AAC5C,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,SAAS,QAAQ;IAChB,SA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";
|
|
2
|
+
import type { ElevationDisplay } from "./elevation-shade.js";
|
|
3
|
+
import type { ReactiveStore } from "./reactive-store.js";
|
|
4
|
+
export declare const MESH_LAYER_ID = "usketch-elevation:mesh";
|
|
5
|
+
/** Whether the mesh is drawing the ground now (the flat layer hides meanwhile). */
|
|
6
|
+
export interface MeshState {
|
|
7
|
+
drawing: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function ElevationMeshLayer({ store, display, overscan, view3d, state, }: {
|
|
10
|
+
store: BoardStore;
|
|
11
|
+
display: ReactiveStore<ElevationDisplay>;
|
|
12
|
+
overscan: ReactiveStore<{
|
|
13
|
+
px: number;
|
|
14
|
+
}>;
|
|
15
|
+
view3d: () => View3dApi | undefined;
|
|
16
|
+
state: ReactiveStore<MeshState>;
|
|
17
|
+
}): import("react").JSX.Element | null;
|
|
18
|
+
//# sourceMappingURL=elevation-mesh-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elevation-mesh-layer.d.ts","sourceRoot":"","sources":["../src/elevation-mesh-layer.tsx"],"names":[],"mappings":"AASA,OAAO,EACN,KAAK,UAAU,EACf,KAAK,SAAS,EAId,MAAM,uBAAuB,CAAC;AAc/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,eAAO,MAAM,aAAa,2BAA2B,CAAC;AAEtD,mFAAmF;AACnF,MAAM,WAAW,SAAS;IACzB,OAAO,EAAE,OAAO,CAAC;CACjB;AA0RD,wBAAgB,kBAAkB,CAAC,EAClC,KAAK,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,KAAK,GACL,EAAE;IACF,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IACzC,QAAQ,EAAE,aAAa,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxC,MAAM,EAAE,MAAM,SAAS,GAAG,SAAS,CAAC;IACpC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CAChC,sCAqBA"}
|