@world-engines/spatial-authoring 0.1.0-alpha.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.
@@ -0,0 +1,310 @@
1
+ /* @ts-self-types="./plane-generator.d.ts" */
2
+
3
+ /**
4
+ * @param {string} input
5
+ * @returns {string}
6
+ */
7
+ export function generate_plane_json(input) {
8
+ let deferred3_0;
9
+ let deferred3_1;
10
+ try {
11
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
12
+ const len0 = WASM_VECTOR_LEN;
13
+ const ret = wasm.generate_plane_json(ptr0, len0);
14
+ var ptr2 = ret[0];
15
+ var len2 = ret[1];
16
+ if (ret[3]) {
17
+ ptr2 = 0; len2 = 0;
18
+ throw takeFromExternrefTable0(ret[2]);
19
+ }
20
+ deferred3_0 = ptr2;
21
+ deferred3_1 = len2;
22
+ return getStringFromWasm0(ptr2, len2);
23
+ } finally {
24
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
25
+ }
26
+ }
27
+
28
+ /**
29
+ * 原始 terrain-roads-v1 core ABI,供行为测试和非 plane adapter 调用。
30
+ * @param {string} input
31
+ * @returns {string}
32
+ */
33
+ export function generate_road_network_json(input) {
34
+ let deferred3_0;
35
+ let deferred3_1;
36
+ try {
37
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
38
+ const len0 = WASM_VECTOR_LEN;
39
+ const ret = wasm.generate_road_network_json(ptr0, len0);
40
+ var ptr2 = ret[0];
41
+ var len2 = ret[1];
42
+ if (ret[3]) {
43
+ ptr2 = 0; len2 = 0;
44
+ throw takeFromExternrefTable0(ret[2]);
45
+ }
46
+ deferred3_0 = ptr2;
47
+ deferred3_1 = len2;
48
+ return getStringFromWasm0(ptr2, len2);
49
+ } finally {
50
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * 为旧平面地形生成固定、与相机无关的道路缓存。
56
+ *
57
+ * sphere-climate-v2 尚未接入此 plane-only adapter;调用者须按 profile
58
+ * 明确选择适配器,不能把球面参数悄然降级为平面。
59
+ * @param {string} input
60
+ * @returns {string}
61
+ */
62
+ export function generate_world_roads_json(input) {
63
+ let deferred3_0;
64
+ let deferred3_1;
65
+ try {
66
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
67
+ const len0 = WASM_VECTOR_LEN;
68
+ const ret = wasm.generate_world_roads_json(ptr0, len0);
69
+ var ptr2 = ret[0];
70
+ var len2 = ret[1];
71
+ if (ret[3]) {
72
+ ptr2 = 0; len2 = 0;
73
+ throw takeFromExternrefTable0(ret[2]);
74
+ }
75
+ deferred3_0 = ptr2;
76
+ deferred3_1 = len2;
77
+ return getStringFromWasm0(ptr2, len2);
78
+ } finally {
79
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
80
+ }
81
+ }
82
+
83
+ /**
84
+ * @param {string} input
85
+ * @returns {string}
86
+ */
87
+ export function sample_plane_tile_json(input) {
88
+ let deferred3_0;
89
+ let deferred3_1;
90
+ try {
91
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
92
+ const len0 = WASM_VECTOR_LEN;
93
+ const ret = wasm.sample_plane_tile_json(ptr0, len0);
94
+ var ptr2 = ret[0];
95
+ var len2 = ret[1];
96
+ if (ret[3]) {
97
+ ptr2 = 0; len2 = 0;
98
+ throw takeFromExternrefTable0(ret[2]);
99
+ }
100
+ deferred3_0 = ptr2;
101
+ deferred3_1 = len2;
102
+ return getStringFromWasm0(ptr2, len2);
103
+ } finally {
104
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
105
+ }
106
+ }
107
+ function __wbg_get_imports() {
108
+ const import0 = {
109
+ __proto__: null,
110
+ __wbindgen_generic_0000000000000001: function(arg0, arg1) {
111
+ // Cast intrinsic for `Ref(String) -> Externref`.
112
+ const ret = getStringFromWasm0(arg0, arg1);
113
+ return ret;
114
+ },
115
+ __wbindgen_init_externref_table: function() {
116
+ const table = wasm.__wbindgen_externrefs;
117
+ const offset = table.grow(4);
118
+ table.set(0, undefined);
119
+ table.set(offset + 0, undefined);
120
+ table.set(offset + 1, null);
121
+ table.set(offset + 2, true);
122
+ table.set(offset + 3, false);
123
+ },
124
+ };
125
+ return {
126
+ __proto__: null,
127
+ "./plane-generator_bg.js": import0,
128
+ };
129
+ }
130
+
131
+ function getStringFromWasm0(ptr, len) {
132
+ return decodeText(ptr >>> 0, len);
133
+ }
134
+
135
+ let cachedUint8ArrayMemory0 = null;
136
+ function getUint8ArrayMemory0() {
137
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
138
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
139
+ }
140
+ return cachedUint8ArrayMemory0;
141
+ }
142
+
143
+ function passStringToWasm0(arg, malloc, realloc) {
144
+ if (realloc === undefined) {
145
+ const buf = cachedTextEncoder.encode(arg);
146
+ const ptr = malloc(buf.length, 1) >>> 0;
147
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
148
+ WASM_VECTOR_LEN = buf.length;
149
+ return ptr;
150
+ }
151
+
152
+ let len = arg.length;
153
+ let ptr = malloc(len, 1) >>> 0;
154
+
155
+ const mem = getUint8ArrayMemory0();
156
+
157
+ let offset = 0;
158
+
159
+ for (; offset < len; offset++) {
160
+ const code = arg.charCodeAt(offset);
161
+ if (code > 0x7F) break;
162
+ mem[ptr + offset] = code;
163
+ }
164
+ if (offset !== len) {
165
+ if (offset !== 0) {
166
+ arg = arg.slice(offset);
167
+ }
168
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
169
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
170
+ const ret = cachedTextEncoder.encodeInto(arg, view);
171
+
172
+ offset += ret.written;
173
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
174
+ }
175
+
176
+ WASM_VECTOR_LEN = offset;
177
+ return ptr;
178
+ }
179
+
180
+ function takeFromExternrefTable0(idx) {
181
+ const value = wasm.__wbindgen_externrefs.get(idx);
182
+ wasm.__externref_table_dealloc(idx);
183
+ return value;
184
+ }
185
+
186
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
187
+ cachedTextDecoder.decode();
188
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
189
+ let numBytesDecoded = 0;
190
+ function decodeText(ptr, len) {
191
+ numBytesDecoded += len;
192
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
193
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
194
+ cachedTextDecoder.decode();
195
+ numBytesDecoded = len;
196
+ }
197
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
198
+ }
199
+
200
+ const cachedTextEncoder = new TextEncoder();
201
+
202
+ if (!('encodeInto' in cachedTextEncoder)) {
203
+ cachedTextEncoder.encodeInto = function (arg, view) {
204
+ const buf = cachedTextEncoder.encode(arg);
205
+ view.set(buf);
206
+ return {
207
+ read: arg.length,
208
+ written: buf.length
209
+ };
210
+ };
211
+ }
212
+
213
+ let WASM_VECTOR_LEN = 0;
214
+
215
+ let wasmModule, wasmInstance, wasm;
216
+ function __wbg_finalize_init(instance, module) {
217
+ wasmInstance = instance;
218
+ wasm = instance.exports;
219
+ wasmModule = module;
220
+ cachedUint8ArrayMemory0 = null;
221
+ wasm.__wbindgen_start();
222
+ return wasm;
223
+ }
224
+
225
+ async function __wbg_load(module, imports) {
226
+ if (typeof Response === 'function' && module instanceof Response) {
227
+ if (!module.ok) {
228
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
229
+ }
230
+
231
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
232
+ try {
233
+ return await WebAssembly.instantiateStreaming(module, imports);
234
+ } catch (e) {
235
+ const validResponse = expectedResponseType(module.type);
236
+
237
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
238
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
239
+
240
+ } else { throw e; }
241
+ }
242
+ }
243
+
244
+ const bytes = await module.arrayBuffer();
245
+ return await WebAssembly.instantiate(bytes, imports);
246
+ } else {
247
+ const instance = await WebAssembly.instantiate(module, imports);
248
+
249
+ if (instance instanceof WebAssembly.Instance) {
250
+ return { instance, module };
251
+ } else {
252
+ return instance;
253
+ }
254
+ }
255
+
256
+ function expectedResponseType(type) {
257
+ switch (type) {
258
+ case 'basic': case 'cors': case 'default': return true;
259
+ }
260
+ return false;
261
+ }
262
+ }
263
+
264
+ function initSync(module) {
265
+ if (wasm !== undefined) return wasm;
266
+
267
+
268
+ if (module !== undefined) {
269
+ if (Object.getPrototypeOf(module) === Object.prototype) {
270
+ ({module} = module)
271
+ } else {
272
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
273
+ }
274
+ }
275
+
276
+ const imports = __wbg_get_imports();
277
+ if (!(module instanceof WebAssembly.Module)) {
278
+ module = new WebAssembly.Module(module);
279
+ }
280
+ const instance = new WebAssembly.Instance(module, imports);
281
+ return __wbg_finalize_init(instance, module);
282
+ }
283
+
284
+ async function __wbg_init(module_or_path) {
285
+ if (wasm !== undefined) return wasm;
286
+
287
+
288
+ if (module_or_path !== undefined) {
289
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
290
+ ({module_or_path} = module_or_path)
291
+ } else {
292
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
293
+ }
294
+ }
295
+
296
+ if (module_or_path === undefined) {
297
+ module_or_path = new URL('plane-generator_bg.wasm', import.meta.url);
298
+ }
299
+ const imports = __wbg_get_imports();
300
+
301
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
302
+ module_or_path = fetch(module_or_path);
303
+ }
304
+
305
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
306
+
307
+ return __wbg_finalize_init(instance, module);
308
+ }
309
+
310
+ export { initSync, __wbg_init as default };
@@ -0,0 +1,13 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const generate_plane_json: (a: number, b: number) => [number, number, number, number];
5
+ export const generate_road_network_json: (a: number, b: number) => [number, number, number, number];
6
+ export const generate_world_roads_json: (a: number, b: number) => [number, number, number, number];
7
+ export const sample_plane_tile_json: (a: number, b: number) => [number, number, number, number];
8
+ export const __wbindgen_externrefs: WebAssembly.Table;
9
+ export const __wbindgen_malloc: (a: number, b: number) => number;
10
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
11
+ export const __externref_table_dealloc: (a: number) => void;
12
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
13
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,135 @@
1
+ export declare const PROCEDURAL_WORLD_PROFILE: "procedural-world-v1";
2
+ import { type SpatialTemplateConfigurationV1 } from "./spatial-templates.js";
3
+ /**
4
+ * 该字符串绑定 profile、算法版本与下方 canonical 规则字节的 SHA-256。
5
+ * 算法语义变化时必须发布新 identity,禁止让旧 seed 静默产生不同世界。
6
+ */
7
+ export declare const PROCEDURAL_GENERATOR_RULES_CANONICAL: "{\"building\":\"parcel-entry-v1\",\"city\":\"clipped-orthogonal-lattice-v1\",\"hash\":\"fnv1a32-avalanche-v1\",\"interior\":\"central-corridor-v1\",\"landUse\":\"weighted-hash-v1\",\"metrics\":\"meters\",\"terrain\":\"parcel-buildability-sampler-v1\"}";
8
+ export declare const PROCEDURAL_GENERATOR_IDENTITY: "chat.worldengine.procedural-city/v1;rules-sha256=8bcf4d18e9827049e4addca1b2c43480325d904bb1cb1fbe9b09a170b4152632";
9
+ export declare const PROCEDURAL_CITY_BUDGET: Readonly<{
10
+ maxCitiesPerWorld: 256;
11
+ maxRoadsPerCity: 2048;
12
+ maxParcelsPerCity: 65536;
13
+ maxRoadsPerWorld: 16384;
14
+ maxParcelsPerWorld: 262144;
15
+ maxBuildingsPerParcel: 4;
16
+ maxRoomsPerBuilding: 24;
17
+ }>;
18
+ export type LandUse = "residential" | "commercial" | "industrial" | "civic" | "park";
19
+ export interface PaletteEntry {
20
+ readonly label: string;
21
+ readonly color: `#${string}`;
22
+ }
23
+ /** 城市用途颜色的唯一 authority。 */
24
+ export declare const PALETTE: Readonly<Record<LandUse, PaletteEntry>>;
25
+ export interface LandUseWeights {
26
+ readonly residential: number;
27
+ readonly commercial: number;
28
+ readonly industrial: number;
29
+ readonly civic: number;
30
+ readonly park: number;
31
+ }
32
+ export interface CityDescriptorV1 {
33
+ readonly id: string;
34
+ readonly label: string;
35
+ readonly x: number;
36
+ readonly y: number;
37
+ readonly seed: number;
38
+ readonly parameters: {
39
+ readonly radiusMeters: number;
40
+ readonly blockSizeMeters: number;
41
+ readonly roadWidthMeters: number;
42
+ readonly landUseWeights: LandUseWeights;
43
+ };
44
+ }
45
+ export interface ProceduralWorldV1 {
46
+ readonly profile: typeof PROCEDURAL_WORLD_PROFILE;
47
+ readonly identity: typeof PROCEDURAL_GENERATOR_IDENTITY;
48
+ readonly worldSeed: number;
49
+ readonly cities: readonly CityDescriptorV1[];
50
+ /** 显式模板选择只影响后续可重建 layout;缺失时必须保持 legacy 输出。 */
51
+ readonly templates?: SpatialTemplateConfigurationV1 | undefined;
52
+ }
53
+ export interface ProceduralWorldExtent {
54
+ readonly widthMeters: number;
55
+ readonly heightMeters: number;
56
+ }
57
+ export interface Point2D {
58
+ readonly x: number;
59
+ readonly y: number;
60
+ }
61
+ export interface Bounds2D extends Point2D {
62
+ readonly width: number;
63
+ readonly height: number;
64
+ }
65
+ export interface ProceduralRoad {
66
+ readonly id: string;
67
+ readonly points: readonly [Point2D, Point2D];
68
+ readonly widthMeters: number;
69
+ }
70
+ export interface ProceduralParcel {
71
+ readonly id: string;
72
+ readonly cityId: string;
73
+ readonly landUse: LandUse;
74
+ readonly bounds: Bounds2D;
75
+ /** 路网地块的真实轮廓;bounds 始终是其内部的建筑安全矩形。 */
76
+ readonly polygon?: readonly Point2D[];
77
+ }
78
+ export interface CityLayout {
79
+ readonly roads: readonly ProceduralRoad[];
80
+ readonly parcels: readonly ProceduralParcel[];
81
+ }
82
+ export interface ParcelBuildabilitySample {
83
+ readonly cityId: string;
84
+ readonly latticeX: number;
85
+ readonly latticeY: number;
86
+ readonly bounds: Bounds2D;
87
+ }
88
+ export interface CityLayoutOptions {
89
+ /** 返回 false 可剔除水面、陡坡等不可建地块;sampler 本身必须可重放。 */
90
+ readonly buildabilitySampler?: (sample: ParcelBuildabilitySample) => boolean;
91
+ /** city slot 是创建 CityDescriptor 的默认值;此处只消费 parcel slot。 */
92
+ readonly templates?: SpatialTemplateConfigurationV1 | undefined;
93
+ }
94
+ export interface BuildingEntrance extends Point2D {
95
+ readonly edge: "west" | "east";
96
+ }
97
+ export interface ProceduralBuilding {
98
+ readonly id: string;
99
+ readonly cityId: string;
100
+ readonly parcelId: string;
101
+ readonly landUse: Exclude<LandUse, "park">;
102
+ readonly footprint: Bounds2D;
103
+ readonly entrance: BuildingEntrance;
104
+ readonly floors: number;
105
+ readonly heightMeters: number;
106
+ }
107
+ export type InteriorRoomKind = "corridor" | "living" | "kitchen" | "bedroom" | "bathroom" | "lobby" | "retail" | "office" | "storage" | "workshop" | "utility" | "hall" | "service";
108
+ export interface InteriorRoom {
109
+ readonly id: string;
110
+ readonly kind: InteriorRoomKind;
111
+ readonly bounds: Bounds2D;
112
+ }
113
+ export interface InteriorDoor {
114
+ readonly id: string;
115
+ readonly kind: "interior" | "entrance";
116
+ readonly position: Point2D;
117
+ readonly connects: readonly string[];
118
+ }
119
+ export interface BuildingInterior {
120
+ readonly buildingId: string;
121
+ readonly rooms: readonly InteriorRoom[];
122
+ readonly doors: readonly InteriorDoor[];
123
+ }
124
+ /** 严格验证 exact-key 世界描述;返回不可变 canonical 副本。 */
125
+ export declare function validateProceduralWorld(input: unknown, extent?: ProceduralWorldExtent): ProceduralWorldV1;
126
+ /** 只生成可重建的道路与地块 cache;绝不提前生成建筑。 */
127
+ export declare function generateCityLayout(worldSeedInput: number, cityInput: CityDescriptorV1, options?: CityLayoutOptions): CityLayout;
128
+ /** 按地块进入 gate 调用;park 固定为空,其余用途生成 1-N 个稳定 footprint。 */
129
+ export declare function generateParcelBuildings(worldSeedInput: number, cityInput: CityDescriptorV1, parcelInput: ProceduralParcel, options?: {
130
+ readonly templates?: SpatialTemplateConfigurationV1 | undefined;
131
+ }): readonly ProceduralBuilding[];
132
+ /** 按建筑进入 gate 调用;返回有界且通过中央走廊全连通的房间/门 cache。 */
133
+ export declare function generateBuildingInterior(worldSeedInput: number, buildingInput: ProceduralBuilding, options?: {
134
+ readonly templates?: SpatialTemplateConfigurationV1 | undefined;
135
+ }): BuildingInterior;