@vulfram/engine 0.14.8-alpha → 0.19.2-alpha
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 +106 -0
- package/package.json +60 -4
- package/src/core.ts +14 -0
- package/src/ecs.ts +1 -0
- package/src/engine/api.ts +222 -24
- package/src/engine/bridge/dispatch.ts +260 -40
- package/src/engine/bridge/guards.ts +4 -1
- package/src/engine/bridge/protocol.ts +69 -52
- package/src/engine/ecs/components.ts +340 -0
- package/src/engine/ecs/index.ts +3 -518
- package/src/engine/ecs/intents.ts +184 -0
- package/src/engine/ecs/systems.ts +26 -0
- package/src/engine/intents/store.ts +72 -0
- package/src/engine/state.ts +136 -5
- package/src/engine/systems/command-intent.ts +159 -14
- package/src/engine/systems/constraint-solve.ts +167 -0
- package/src/engine/systems/core-command-builder.ts +9 -268
- package/src/engine/systems/diagnostics.ts +20 -29
- package/src/engine/systems/index.ts +3 -1
- package/src/engine/systems/input-mirror.ts +257 -21
- package/src/engine/systems/resource-upload.ts +108 -58
- package/src/engine/systems/response-decode.ts +86 -15
- package/src/engine/systems/scene-sync.ts +305 -0
- package/src/engine/systems/ui-bridge.ts +381 -0
- package/src/engine/systems/utils.ts +86 -1
- package/src/engine/systems/world-lifecycle.ts +43 -114
- package/src/engine/window/manager.ts +168 -0
- package/src/engine/world/entities.ts +998 -91
- package/src/engine/world/mount.ts +195 -0
- package/src/engine/world/types.ts +71 -0
- package/src/engine/world/world-ui.ts +313 -0
- package/src/engine/world/world3d.ts +529 -0
- package/src/helpers/collision.ts +487 -0
- package/src/helpers/index.ts +2 -0
- package/src/helpers/raycast.ts +442 -0
- package/src/index.ts +30 -1
- package/src/mount.ts +2 -0
- package/src/types/cmds/audio.ts +73 -48
- package/src/types/cmds/camera.ts +12 -8
- package/src/types/cmds/environment.ts +9 -3
- package/src/types/cmds/geometry.ts +15 -16
- package/src/types/cmds/index.ts +234 -162
- package/src/types/cmds/input.ts +39 -0
- package/src/types/cmds/light.ts +12 -11
- package/src/types/cmds/material.ts +19 -21
- package/src/types/cmds/model.ts +17 -15
- package/src/types/cmds/realm.ts +23 -0
- package/src/types/cmds/system.ts +29 -0
- package/src/types/cmds/target.ts +96 -0
- package/src/types/cmds/texture.ts +13 -3
- package/src/types/cmds/ui.ts +220 -0
- package/src/types/cmds/window.ts +41 -204
- package/src/types/events/index.ts +4 -1
- package/src/types/events/keyboard.ts +2 -2
- package/src/types/events/pointer.ts +85 -13
- package/src/types/events/system.ts +188 -30
- package/src/types/events/ui.ts +21 -0
- package/src/types/index.ts +1 -0
- package/src/types/json.ts +15 -0
- package/src/window.ts +8 -0
- package/src/world-ui.ts +2 -0
- package/src/world3d.ts +10 -0
- package/tsconfig.json +0 -29
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import { createWorld3D as createWorld3DRaw } from '../api';
|
|
2
|
+
import type {
|
|
3
|
+
CameraProps,
|
|
4
|
+
GeometryProps,
|
|
5
|
+
LightProps,
|
|
6
|
+
MaterialProps,
|
|
7
|
+
ModelProps,
|
|
8
|
+
TagProps,
|
|
9
|
+
TextureProps,
|
|
10
|
+
TransformProps,
|
|
11
|
+
} from '../ecs';
|
|
12
|
+
import type {
|
|
13
|
+
CmdAudioListenerUpdateArgs,
|
|
14
|
+
CmdAudioResourceUpsertArgs,
|
|
15
|
+
CmdAudioSourceCreateArgs,
|
|
16
|
+
CmdAudioSourceTransportArgs,
|
|
17
|
+
} from '../../types/cmds/audio';
|
|
18
|
+
import type {
|
|
19
|
+
CmdInputTargetListenerDisposeArgs,
|
|
20
|
+
CmdInputTargetListenerListArgs,
|
|
21
|
+
CmdInputTargetListenerUpsertArgs,
|
|
22
|
+
} from '../../types/cmds/input';
|
|
23
|
+
import type { EnvironmentConfig } from '../../types/cmds/environment';
|
|
24
|
+
import type {
|
|
25
|
+
CmdGizmoDrawAabbArgs,
|
|
26
|
+
CmdGizmoDrawLineArgs,
|
|
27
|
+
} from '../../types/cmds/gizmo';
|
|
28
|
+
import type { CmdPoseUpdateArgs } from '../../types/cmds/model';
|
|
29
|
+
import type { ShadowConfig } from '../../types/cmds/shadow';
|
|
30
|
+
import type { CmdTargetMeasurementArgs } from '../../types/cmds/target';
|
|
31
|
+
import type { NotificationLevel } from '../../types/kinds';
|
|
32
|
+
export { KeyCode } from '../../types/events/keyboard';
|
|
33
|
+
import type { SystemEvent } from '../../types/events/system';
|
|
34
|
+
import {
|
|
35
|
+
audioListenerUpdate as audioListenerUpdateRaw,
|
|
36
|
+
audioResourceCreate as audioResourceCreateRaw,
|
|
37
|
+
audioSourceCreate as audioSourceCreateRaw,
|
|
38
|
+
audioSourcePlay as audioSourcePlayRaw,
|
|
39
|
+
configureEnvironment as configureEnvironmentRaw,
|
|
40
|
+
configureShadows as configureShadowsRaw,
|
|
41
|
+
createCamera as createCameraRaw,
|
|
42
|
+
createEntity as createEntityRaw,
|
|
43
|
+
createGeometry as createGeometryRaw,
|
|
44
|
+
createLight as createLightRaw,
|
|
45
|
+
createMaterial as createMaterialRaw,
|
|
46
|
+
createModel as createModelRaw,
|
|
47
|
+
createTexture as createTextureRaw,
|
|
48
|
+
createTag as createTagRaw,
|
|
49
|
+
disposeGeometry as disposeGeometryRaw,
|
|
50
|
+
disposeMaterial as disposeMaterialRaw,
|
|
51
|
+
disposeTexture as disposeTextureRaw,
|
|
52
|
+
drawGizmoAabb as drawGizmoAabbRaw,
|
|
53
|
+
drawGizmoLine as drawGizmoLineRaw,
|
|
54
|
+
disposeInputTargetListener as disposeInputTargetListenerRaw,
|
|
55
|
+
getSystemEvents as getSystemEventsRaw,
|
|
56
|
+
getImeCommitText as getImeCommitTextRaw,
|
|
57
|
+
getImeCursorRange as getImeCursorRangeRaw,
|
|
58
|
+
getImePreeditText as getImePreeditTextRaw,
|
|
59
|
+
getModelId as getModelIdRaw,
|
|
60
|
+
getPointerDelta as getPointerDeltaRaw,
|
|
61
|
+
getPointerPosition as getPointerPositionRaw,
|
|
62
|
+
getPointerTargetSize as getPointerTargetSizeRaw,
|
|
63
|
+
getPointerTargetDelta as getPointerTargetDeltaRaw,
|
|
64
|
+
getPointerTargetId as getPointerTargetIdRaw,
|
|
65
|
+
getPointerTargetPosition as getPointerTargetPositionRaw,
|
|
66
|
+
getPointerTargetUv as getPointerTargetUvRaw,
|
|
67
|
+
getPointerWindowSize as getPointerWindowSizeRaw,
|
|
68
|
+
getWindowSize as getWindowSizeRaw,
|
|
69
|
+
getWorldRealmId as getWorldRealmIdRaw,
|
|
70
|
+
isImeEnabled as isImeEnabledRaw,
|
|
71
|
+
isKeyPressed as isKeyPressedRaw,
|
|
72
|
+
isPointerButtonJustPressed as isPointerButtonJustPressedRaw,
|
|
73
|
+
isPointerButtonPressed as isPointerButtonPressedRaw,
|
|
74
|
+
isWindowCloseRequested as isWindowCloseRequestedRaw,
|
|
75
|
+
listCameras as listCamerasRaw,
|
|
76
|
+
listGeometries as listGeometriesRaw,
|
|
77
|
+
listLights as listLightsRaw,
|
|
78
|
+
listMaterials as listMaterialsRaw,
|
|
79
|
+
listModels as listModelsRaw,
|
|
80
|
+
listTextures as listTexturesRaw,
|
|
81
|
+
measureTarget as measureTargetRaw,
|
|
82
|
+
poseUpdate as poseUpdateRaw,
|
|
83
|
+
removeEntity as removeEntityRaw,
|
|
84
|
+
sendNotification as sendNotificationRaw,
|
|
85
|
+
setParent as setParentRaw,
|
|
86
|
+
upsertInputTargetListener as upsertInputTargetListenerRaw,
|
|
87
|
+
listInputTargetListeners as listInputTargetListenersRaw,
|
|
88
|
+
updateTransform as updateTransformRaw,
|
|
89
|
+
} from './entities';
|
|
90
|
+
import type {
|
|
91
|
+
CommandId,
|
|
92
|
+
EntityId,
|
|
93
|
+
GeometryId,
|
|
94
|
+
MaterialId,
|
|
95
|
+
TextureId,
|
|
96
|
+
World3DId,
|
|
97
|
+
} from './types';
|
|
98
|
+
import {
|
|
99
|
+
asCommandId,
|
|
100
|
+
asEntityId,
|
|
101
|
+
asGeometryId,
|
|
102
|
+
asMaterialId,
|
|
103
|
+
asTextureId,
|
|
104
|
+
asWorld3DId,
|
|
105
|
+
asWorldNumber,
|
|
106
|
+
} from './types';
|
|
107
|
+
|
|
108
|
+
export type Create3DWorldOptions = {
|
|
109
|
+
importance?: number;
|
|
110
|
+
cachePolicy?: number;
|
|
111
|
+
flags?: number;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
type Create3DAudioSourceArgs = Omit<
|
|
115
|
+
CmdAudioSourceCreateArgs,
|
|
116
|
+
'realmId' | 'modelId'
|
|
117
|
+
> &
|
|
118
|
+
({ modelId: number } | { entityId: EntityId });
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Creates a 3D world.
|
|
122
|
+
*
|
|
123
|
+
* The world is realm-backed internally, but realm details are hidden from this API.
|
|
124
|
+
* Use `Mount.mountWorld(...)` to present this world into one or more targets.
|
|
125
|
+
*/
|
|
126
|
+
export function create3DWorld(options?: Create3DWorldOptions): World3DId {
|
|
127
|
+
return asWorld3DId(createWorld3DRaw(options));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Creates an entity in a 3D world. */
|
|
131
|
+
export function create3DEntity(worldId: World3DId): EntityId {
|
|
132
|
+
return asEntityId(createEntityRaw(asWorldNumber(worldId)));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Removes an entity and all mirrored components from a 3D world. */
|
|
136
|
+
export function remove3DEntity(worldId: World3DId, entityId: EntityId): void {
|
|
137
|
+
removeEntityRaw(asWorldNumber(worldId), entityId as number);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Upserts camera component intent for an entity in a 3D world. */
|
|
141
|
+
export function create3DCamera(
|
|
142
|
+
worldId: World3DId,
|
|
143
|
+
entityId: EntityId,
|
|
144
|
+
props: CameraProps,
|
|
145
|
+
): void {
|
|
146
|
+
createCameraRaw(asWorldNumber(worldId), entityId as number, props);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Upserts light component intent for an entity in a 3D world. */
|
|
150
|
+
export function create3DLight(
|
|
151
|
+
worldId: World3DId,
|
|
152
|
+
entityId: EntityId,
|
|
153
|
+
props: LightProps,
|
|
154
|
+
): void {
|
|
155
|
+
createLightRaw(asWorldNumber(worldId), entityId as number, props);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Upserts model component intent for an entity in a 3D world. */
|
|
159
|
+
export function create3DModel(
|
|
160
|
+
worldId: World3DId,
|
|
161
|
+
entityId: EntityId,
|
|
162
|
+
props: ModelProps,
|
|
163
|
+
): void {
|
|
164
|
+
createModelRaw(asWorldNumber(worldId), entityId as number, props);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Upserts transform component intent for an entity in a 3D world. */
|
|
168
|
+
export function update3DTransform(
|
|
169
|
+
worldId: World3DId,
|
|
170
|
+
entityId: EntityId,
|
|
171
|
+
props: TransformProps,
|
|
172
|
+
): void {
|
|
173
|
+
updateTransformRaw(asWorldNumber(worldId), entityId as number, props);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Attaches or updates a tag component in a 3D world. */
|
|
177
|
+
export function create3DTag(
|
|
178
|
+
worldId: World3DId,
|
|
179
|
+
entityId: EntityId,
|
|
180
|
+
props: TagProps,
|
|
181
|
+
): void {
|
|
182
|
+
createTagRaw(asWorldNumber(worldId), entityId as number, props);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Sets parent-child relationship between entities. */
|
|
186
|
+
export function set3DParent(
|
|
187
|
+
worldId: World3DId,
|
|
188
|
+
childEntityId: EntityId,
|
|
189
|
+
parentEntityId: EntityId | null,
|
|
190
|
+
): void {
|
|
191
|
+
setParentRaw(
|
|
192
|
+
asWorldNumber(worldId),
|
|
193
|
+
childEntityId as number,
|
|
194
|
+
parentEntityId as number | null,
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Creates a material resource and returns its typed id. */
|
|
199
|
+
export function create3DMaterial(
|
|
200
|
+
worldId: World3DId,
|
|
201
|
+
props: MaterialProps,
|
|
202
|
+
): MaterialId {
|
|
203
|
+
return asMaterialId(createMaterialRaw(asWorldNumber(worldId), props));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Creates a geometry resource and returns its typed id. */
|
|
207
|
+
export function create3DGeometry(
|
|
208
|
+
worldId: World3DId,
|
|
209
|
+
props: GeometryProps,
|
|
210
|
+
): GeometryId {
|
|
211
|
+
return asGeometryId(createGeometryRaw(asWorldNumber(worldId), props));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Creates a texture resource and returns its typed id. */
|
|
215
|
+
export function create3DTexture(
|
|
216
|
+
worldId: World3DId,
|
|
217
|
+
props: TextureProps,
|
|
218
|
+
): TextureId {
|
|
219
|
+
return asTextureId(createTextureRaw(asWorldNumber(worldId), props));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Disposes a material resource from a 3D world. */
|
|
223
|
+
export function dispose3DMaterial(
|
|
224
|
+
worldId: World3DId,
|
|
225
|
+
materialId: MaterialId,
|
|
226
|
+
): void {
|
|
227
|
+
disposeMaterialRaw(asWorldNumber(worldId), materialId as number);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Disposes a geometry resource from a 3D world. */
|
|
231
|
+
export function dispose3DGeometry(
|
|
232
|
+
worldId: World3DId,
|
|
233
|
+
geometryId: GeometryId,
|
|
234
|
+
): void {
|
|
235
|
+
disposeGeometryRaw(asWorldNumber(worldId), geometryId as number);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Disposes a texture resource from a 3D world. */
|
|
239
|
+
export function dispose3DTexture(
|
|
240
|
+
worldId: World3DId,
|
|
241
|
+
textureId: TextureId,
|
|
242
|
+
): void {
|
|
243
|
+
disposeTextureRaw(asWorldNumber(worldId), textureId as number);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Configures environment/post-processing for a 3D world. */
|
|
247
|
+
export function configure3DEnvironment(
|
|
248
|
+
worldId: World3DId,
|
|
249
|
+
config: EnvironmentConfig,
|
|
250
|
+
): void {
|
|
251
|
+
configureEnvironmentRaw(asWorldNumber(worldId), config);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Configures shadows for a 3D world. */
|
|
255
|
+
export function configure3DShadows(
|
|
256
|
+
worldId: World3DId,
|
|
257
|
+
config: ShadowConfig,
|
|
258
|
+
): void {
|
|
259
|
+
configureShadowsRaw(asWorldNumber(worldId), config);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Draws a debug line gizmo. */
|
|
263
|
+
export function draw3DGizmoLine(
|
|
264
|
+
worldId: World3DId,
|
|
265
|
+
args: CmdGizmoDrawLineArgs,
|
|
266
|
+
): void {
|
|
267
|
+
drawGizmoLineRaw(asWorldNumber(worldId), args);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Draws a debug axis-aligned bounding box gizmo. */
|
|
271
|
+
export function draw3DGizmoAabb(
|
|
272
|
+
worldId: World3DId,
|
|
273
|
+
args: CmdGizmoDrawAabbArgs,
|
|
274
|
+
): void {
|
|
275
|
+
drawGizmoAabbRaw(asWorldNumber(worldId), args);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Updates pose data for XR/trackers. */
|
|
279
|
+
export function update3DPose(
|
|
280
|
+
worldId: World3DId,
|
|
281
|
+
args: CmdPoseUpdateArgs,
|
|
282
|
+
): CommandId {
|
|
283
|
+
return asCommandId(poseUpdateRaw(asWorldNumber(worldId), args));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** Requests a model list from core for this world. */
|
|
287
|
+
export function list3DModels(worldId: World3DId): CommandId {
|
|
288
|
+
return asCommandId(listModelsRaw(asWorldNumber(worldId)));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Requests a material list from core for this world. */
|
|
292
|
+
export function list3DMaterials(worldId: World3DId): CommandId {
|
|
293
|
+
return asCommandId(listMaterialsRaw(asWorldNumber(worldId)));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Requests a texture list from core for this world. */
|
|
297
|
+
export function list3DTextures(worldId: World3DId): CommandId {
|
|
298
|
+
return asCommandId(listTexturesRaw(asWorldNumber(worldId)));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** Requests a geometry list from core for this world. */
|
|
302
|
+
export function list3DGeometries(worldId: World3DId): CommandId {
|
|
303
|
+
return asCommandId(listGeometriesRaw(asWorldNumber(worldId)));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Requests a light list from core for this world. */
|
|
307
|
+
export function list3DLights(worldId: World3DId): CommandId {
|
|
308
|
+
return asCommandId(listLightsRaw(asWorldNumber(worldId)));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Requests a camera list from core for this world. */
|
|
312
|
+
export function list3DCameras(worldId: World3DId): CommandId {
|
|
313
|
+
return asCommandId(listCamerasRaw(asWorldNumber(worldId)));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Requests target measurement for this world context. */
|
|
317
|
+
export function measure3DTarget(
|
|
318
|
+
worldId: World3DId,
|
|
319
|
+
args: CmdTargetMeasurementArgs,
|
|
320
|
+
): CommandId {
|
|
321
|
+
return asCommandId(measureTargetRaw(asWorldNumber(worldId), args));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Creates or updates a pointer listener routed by target id. */
|
|
325
|
+
export function upsert3DInputTargetListener(
|
|
326
|
+
worldId: World3DId,
|
|
327
|
+
args: CmdInputTargetListenerUpsertArgs,
|
|
328
|
+
): CommandId {
|
|
329
|
+
return asCommandId(
|
|
330
|
+
upsertInputTargetListenerRaw(asWorldNumber(worldId), args),
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** Disposes a pointer listener routed by target id. */
|
|
335
|
+
export function dispose3DInputTargetListener(
|
|
336
|
+
worldId: World3DId,
|
|
337
|
+
args: CmdInputTargetListenerDisposeArgs,
|
|
338
|
+
): CommandId {
|
|
339
|
+
return asCommandId(
|
|
340
|
+
disposeInputTargetListenerRaw(asWorldNumber(worldId), args),
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** Requests current pointer listener list from core. */
|
|
345
|
+
export function list3DInputTargetListeners(
|
|
346
|
+
worldId: World3DId,
|
|
347
|
+
args: CmdInputTargetListenerListArgs = {},
|
|
348
|
+
): CommandId {
|
|
349
|
+
return asCommandId(
|
|
350
|
+
listInputTargetListenersRaw(asWorldNumber(worldId), args),
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Returns system events filtered to input-target-listener-event.
|
|
356
|
+
*/
|
|
357
|
+
export function get3DTargetPointerEvents(
|
|
358
|
+
worldId: World3DId,
|
|
359
|
+
): Extract<SystemEvent, { event: 'input-target-listener-event' }>[] {
|
|
360
|
+
const events = getSystemEventsRaw(asWorldNumber(worldId));
|
|
361
|
+
return events.filter(
|
|
362
|
+
(
|
|
363
|
+
event,
|
|
364
|
+
): event is Extract<SystemEvent, { event: 'input-target-listener-event' }> =>
|
|
365
|
+
event.event === 'input-target-listener-event',
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** Returns true while a key is pressed in this world input state. */
|
|
370
|
+
export function is3DKeyPressed(worldId: World3DId, keyCode: number): boolean {
|
|
371
|
+
return isKeyPressedRaw(asWorldNumber(worldId), keyCode);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** Returns true while IME composition is active in this world. */
|
|
375
|
+
export function is3DImeEnabled(worldId: World3DId): boolean {
|
|
376
|
+
return isImeEnabledRaw(asWorldNumber(worldId));
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** Returns current IME preedit text, if any. */
|
|
380
|
+
export function get3DImePreeditText(worldId: World3DId): string | null {
|
|
381
|
+
return getImePreeditTextRaw(asWorldNumber(worldId));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** Returns current IME cursor range inside preedit text, if available. */
|
|
385
|
+
export function get3DImeCursorRange(
|
|
386
|
+
worldId: World3DId,
|
|
387
|
+
): [number, number] | null {
|
|
388
|
+
return getImeCursorRangeRaw(asWorldNumber(worldId));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Returns last IME committed text for the current frame, if any. */
|
|
392
|
+
export function get3DImeCommitText(worldId: World3DId): string | null {
|
|
393
|
+
return getImeCommitTextRaw(asWorldNumber(worldId));
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** Returns true when close was requested for this world's primary window. */
|
|
397
|
+
export function is3DWindowCloseRequested(worldId: World3DId): boolean {
|
|
398
|
+
return isWindowCloseRequestedRaw(asWorldNumber(worldId));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Returns current size for this world's primary window. */
|
|
402
|
+
export function get3DWindowSize(worldId: World3DId): [number, number] {
|
|
403
|
+
return getWindowSizeRaw(asWorldNumber(worldId));
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** Returns current pointer position in window space. */
|
|
407
|
+
export function get3DPointerPosition(worldId: World3DId): [number, number] {
|
|
408
|
+
return getPointerPositionRaw(asWorldNumber(worldId));
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** Returns real drawn window size from the latest pointer event, if available. */
|
|
412
|
+
export function get3DPointerWindowSize(
|
|
413
|
+
worldId: World3DId,
|
|
414
|
+
): [number, number] | null {
|
|
415
|
+
return getPointerWindowSizeRaw(asWorldNumber(worldId));
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** Returns pointer delta in window space for the current frame. */
|
|
419
|
+
export function get3DPointerDelta(worldId: World3DId): [number, number] {
|
|
420
|
+
return getPointerDeltaRaw(asWorldNumber(worldId));
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** Returns pointer position relative to routed target, if available. */
|
|
424
|
+
export function get3DPointerTargetPosition(
|
|
425
|
+
worldId: World3DId,
|
|
426
|
+
): [number, number] | null {
|
|
427
|
+
return getPointerTargetPositionRaw(asWorldNumber(worldId));
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** Returns real drawn target size from the latest pointer event, if available. */
|
|
431
|
+
export function get3DPointerTargetSize(
|
|
432
|
+
worldId: World3DId,
|
|
433
|
+
): [number, number] | null {
|
|
434
|
+
return getPointerTargetSizeRaw(asWorldNumber(worldId));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** Returns pointer delta relative to routed target for the current frame. */
|
|
438
|
+
export function get3DPointerTargetDelta(
|
|
439
|
+
worldId: World3DId,
|
|
440
|
+
): [number, number] | null {
|
|
441
|
+
return getPointerTargetDeltaRaw(asWorldNumber(worldId));
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/** Returns routed target id under pointer, when available. */
|
|
445
|
+
export function get3DPointerTargetId(worldId: World3DId): number | null {
|
|
446
|
+
return getPointerTargetIdRaw(asWorldNumber(worldId));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** Returns pointer UV (0..1) in routed target space, when available. */
|
|
450
|
+
export function get3DPointerTargetUv(
|
|
451
|
+
worldId: World3DId,
|
|
452
|
+
): [number, number] | null {
|
|
453
|
+
return getPointerTargetUvRaw(asWorldNumber(worldId));
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** Returns true while a pointer button is pressed in this world. */
|
|
457
|
+
export function is3DPointerButtonPressed(
|
|
458
|
+
worldId: World3DId,
|
|
459
|
+
button: number,
|
|
460
|
+
): boolean {
|
|
461
|
+
return isPointerButtonPressedRaw(asWorldNumber(worldId), button);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** Returns true when a pointer button was pressed in this frame. */
|
|
465
|
+
export function is3DPointerButtonJustPressed(
|
|
466
|
+
worldId: World3DId,
|
|
467
|
+
button: number,
|
|
468
|
+
): boolean {
|
|
469
|
+
return isPointerButtonJustPressedRaw(asWorldNumber(worldId), button);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** Sends a host notification scoped to this world. */
|
|
473
|
+
export function send3DNotification(
|
|
474
|
+
worldId: World3DId,
|
|
475
|
+
args: { level: NotificationLevel; title: string; message: string },
|
|
476
|
+
): void {
|
|
477
|
+
sendNotificationRaw(asWorldNumber(worldId), args);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** Updates audio listener parameters. */
|
|
481
|
+
export function update3DAudioListener(
|
|
482
|
+
worldId: World3DId,
|
|
483
|
+
args: CmdAudioListenerUpdateArgs,
|
|
484
|
+
): CommandId {
|
|
485
|
+
return asCommandId(audioListenerUpdateRaw(asWorldNumber(worldId), args));
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/** Creates or updates an audio resource. */
|
|
489
|
+
export function create3DAudioResource(
|
|
490
|
+
worldId: World3DId,
|
|
491
|
+
args: CmdAudioResourceUpsertArgs,
|
|
492
|
+
): CommandId {
|
|
493
|
+
return asCommandId(audioResourceCreateRaw(asWorldNumber(worldId), args));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** Creates an audio source with realm id resolved internally from world state. */
|
|
497
|
+
export function create3DAudioSource(
|
|
498
|
+
worldId: World3DId,
|
|
499
|
+
args: Create3DAudioSourceArgs,
|
|
500
|
+
): CommandId {
|
|
501
|
+
const rawWorldId = asWorldNumber(worldId);
|
|
502
|
+
const realmId = getWorldRealmIdRaw(rawWorldId) ?? rawWorldId;
|
|
503
|
+
|
|
504
|
+
const modelId =
|
|
505
|
+
'modelId' in args
|
|
506
|
+
? args.modelId
|
|
507
|
+
: (getModelIdRaw(rawWorldId, args.entityId as number) ??
|
|
508
|
+
(args.entityId as number));
|
|
509
|
+
const baseArgs =
|
|
510
|
+
'modelId' in args
|
|
511
|
+
? args
|
|
512
|
+
: (({ entityId: _entityId, ...rest }) => rest)(args);
|
|
513
|
+
|
|
514
|
+
return asCommandId(
|
|
515
|
+
audioSourceCreateRaw(rawWorldId, {
|
|
516
|
+
...baseArgs,
|
|
517
|
+
modelId,
|
|
518
|
+
realmId,
|
|
519
|
+
}),
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** Starts playback on an audio source. */
|
|
524
|
+
export function play3DAudioSource(
|
|
525
|
+
worldId: World3DId,
|
|
526
|
+
args: Omit<CmdAudioSourceTransportArgs, 'action'>,
|
|
527
|
+
): CommandId {
|
|
528
|
+
return asCommandId(audioSourcePlayRaw(asWorldNumber(worldId), args));
|
|
529
|
+
}
|