lecodes-cli 0.19.0 → 0.20.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 +1 -0
- package/dist/index.js +1069 -396
- package/package.json +14 -13
- package/runtime/scene-harness.json +1 -1
- package/runtime/sdk-types.json +1 -1
- package/runtime/web/assets/Roboto-Variable-DHm9jpd-.woff2 +0 -0
- package/runtime/web/assets/__vite-browser-external-BIHI7g3E.js +1 -0
- package/runtime/web/assets/basis-C64VHDVD.js +1 -0
- package/runtime/web/assets/basis_transcoder-VXdx5NbI.wasm +0 -0
- package/runtime/web/assets/createViewerLite-BvHobVhp.js +852 -0
- package/runtime/web/assets/draco-BiISTFcR.js +118 -0
- package/runtime/web/assets/draco_decoder-DsQ12WqX.wasm +0 -0
- package/runtime/web/assets/index-CfNCCBjN.js +2 -0
- package/runtime/web/assets/mapViewImpl-B2JcES8l.js +810 -0
- package/runtime/web/assets/maplibre-gl-worker-CJfwIrte.js +8 -0
- package/runtime/web/assets/neutral_ibl128-D-lzdkLN.ktx +0 -0
- package/runtime/web/assets/worker-Caf-yYEI.js +2 -0
- package/runtime/web/embed.html +32 -0
- package/runtime/web/embed.js +171 -0
- package/src/api.ts +302 -0
- package/src/browserAuth.ts +87 -0
- package/src/cmgenTool.ts +104 -0
- package/src/commands/app.ts +896 -0
- package/src/commands/appAndroid.ts +603 -0
- package/src/commands/appDesktop.ts +339 -0
- package/src/commands/appDesktopMac.ts +470 -0
- package/src/commands/appIcon.ts +187 -0
- package/src/commands/appShared.ts +542 -0
- package/src/commands/appTemplates.ts +907 -0
- package/src/commands/appTemplatesAndroid.ts +599 -0
- package/src/commands/appTemplatesGradlew.ts +9 -0
- package/src/commands/assets.ts +28 -0
- package/src/commands/clone.ts +60 -0
- package/src/commands/compile.ts +253 -0
- package/src/commands/create.ts +59 -0
- package/src/commands/design.ts +863 -0
- package/src/commands/designTemplates.ts +11 -0
- package/src/commands/desktop.ts +127 -0
- package/src/commands/dev.ts +236 -0
- package/src/commands/diff.ts +59 -0
- package/src/commands/init.ts +191 -0
- package/src/commands/install.ts +198 -0
- package/src/commands/lightmap.ts +290 -0
- package/src/commands/link.ts +147 -0
- package/src/commands/login.ts +24 -0
- package/src/commands/navmesh.ts +225 -0
- package/src/commands/pn.ts +305 -0
- package/src/commands/projectTemplates.ts +130 -0
- package/src/commands/pull.ts +109 -0
- package/src/commands/push.ts +173 -0
- package/src/commands/render.ts +416 -0
- package/src/commands/scene.ts +148 -0
- package/src/commands/shaders.ts +157 -0
- package/src/commands/status.ts +29 -0
- package/src/commands/test.ts +371 -0
- package/src/commands/thumbs.ts +178 -0
- package/src/commands/types.ts +87 -0
- package/src/commands/update.ts +190 -0
- package/src/compile/assetIcons.ts +214 -0
- package/src/compile/collect.ts +46 -0
- package/src/compile/collectLocal.ts +37 -0
- package/src/compile/designCompile.ts +104 -0
- package/src/compile/fonts.ts +156 -0
- package/src/compile/headlessBundle.ts +129 -0
- package/src/compile/nativeStack.ts +21 -0
- package/src/compile/projectCompile.ts +109 -0
- package/src/compile/sceneCompile.ts +113 -0
- package/src/compile/screenEntry.ts +127 -0
- package/src/compile/shaders.ts +245 -0
- package/src/config.ts +42 -0
- package/src/designMeta.ts +35 -0
- package/src/desktopRenderer.ts +545 -0
- package/src/desktopScript.ts +276 -0
- package/src/dev/clientTemplates.ts +160 -0
- package/src/dev/devServer.ts +333 -0
- package/src/dev/webRunner.ts +22 -0
- package/src/dev/wsServer.ts +144 -0
- package/src/distRoot.ts +20 -0
- package/src/ignore.ts +163 -0
- package/src/index.ts +494 -0
- package/src/lecodes-3d-editor.d.ts +41 -0
- package/src/lecodes-assets.d.ts +7 -0
- package/src/lecodes-design.d.ts +191 -0
- package/src/lecodes-renderer.d.ts +131 -0
- package/src/localFiles.ts +144 -0
- package/src/manifest.ts +46 -0
- package/src/matcTool.ts +137 -0
- package/src/peers.ts +40 -0
- package/src/project.ts +61 -0
- package/src/projectEnv.ts +94 -0
- package/src/qrcode-terminal.d.ts +9 -0
- package/src/releases.ts +125 -0
- package/src/serverDiff.ts +78 -0
- package/src/textDiff.ts +103 -0
- package/src/types.ts +0 -0
- package/src/util.ts +146 -0
- package/runtime/sdk/animate/animate.ts +0 -238
- package/runtime/sdk/animate/bezier.ts +0 -138
- package/runtime/sdk/animate/easings.ts +0 -126
- package/runtime/sdk/canvas/Canvas.ts +0 -305
- package/runtime/sdk/compile/aspectMacro.ts +0 -86
- package/runtime/sdk/compile/assetIconMacro.ts +0 -384
- package/runtime/sdk/compile/assetMacro.ts +0 -146
- package/runtime/sdk/compile/assetName.ts +0 -50
- package/runtime/sdk/compile/bundler.ts +0 -287
- package/runtime/sdk/compile/compileProject.ts +0 -129
- package/runtime/sdk/compile/detectEntry.ts +0 -128
- package/runtime/sdk/compile/fontMacro.ts +0 -459
- package/runtime/sdk/compile/fontRegistry.ts +0 -78
- package/runtime/sdk/compile/header.ts +0 -67
- package/runtime/sdk/compile/index.ts +0 -100
- package/runtime/sdk/compile/libraryImports.ts +0 -52
- package/runtime/sdk/compile/liteMaterial.ts +0 -247
- package/runtime/sdk/compile/sceneEditor.ts +0 -88
- package/runtime/sdk/compile/serverSplit.ts +0 -233
- package/runtime/sdk/compile/serverTypes.ts +0 -227
- package/runtime/sdk/compile/sfnt.ts +0 -98
- package/runtime/sdk/compile/shaderSchema.ts +0 -202
- package/runtime/sdk/compile/shaderTargets.ts +0 -81
- package/runtime/sdk/compile/sourcemap.ts +0 -25
- package/runtime/sdk/core/Aspect.ts +0 -568
- package/runtime/sdk/core/InspectorUI.ts +0 -212
- package/runtime/sdk/core/StateMachine.ts +0 -308
- package/runtime/sdk/core/color.ts +0 -66
- package/runtime/sdk/core/compWrite.ts +0 -42
- package/runtime/sdk/core/events.ts +0 -38
- package/runtime/sdk/core/fields.ts +0 -120
- package/runtime/sdk/core/registry.ts +0 -23
- package/runtime/sdk/core/signals.ts +0 -277
- package/runtime/sdk/core/time.ts +0 -84
- package/runtime/sdk/g2/Camera2D.ts +0 -40
- package/runtime/sdk/g2/CharacterController2D.ts +0 -276
- package/runtime/sdk/g2/Node2D.ts +0 -267
- package/runtime/sdk/g2/OneWay2D.ts +0 -66
- package/runtime/sdk/g2/Physics2D.ts +0 -346
- package/runtime/sdk/g2/Scene2D.ts +0 -209
- package/runtime/sdk/g2/Shape2D.ts +0 -259
- package/runtime/sdk/g2/Sprite.ts +0 -89
- package/runtime/sdk/g2/SpriteAnimation.ts +0 -171
- package/runtime/sdk/g2/SpriteSheet.ts +0 -166
- package/runtime/sdk/g2/Texture2D.ts +0 -47
- package/runtime/sdk/g2/Tilemap.ts +0 -41
- package/runtime/sdk/g2/Tileset.ts +0 -71
- package/runtime/sdk/g2/Trigger2D.ts +0 -77
- package/runtime/sdk/g2/autotile.ts +0 -433
- package/runtime/sdk/g2/cells.ts +0 -91
- package/runtime/sdk/g2/defineScene2d.ts +0 -381
- package/runtime/sdk/g2/groups2d.ts +0 -106
- package/runtime/sdk/g2/loop.ts +0 -50
- package/runtime/sdk/g2/scenarios2d.ts +0 -69
- package/runtime/sdk/g2/touch.ts +0 -83
- package/runtime/sdk/gl/Camera.ts +0 -160
- package/runtime/sdk/gl/CameraPlace.ts +0 -52
- package/runtime/sdk/gl/CharacterController.ts +0 -238
- package/runtime/sdk/gl/Gearbox.ts +0 -212
- package/runtime/sdk/gl/Geometry.ts +0 -279
- package/runtime/sdk/gl/IK.ts +0 -193
- package/runtime/sdk/gl/InstancedMesh.ts +0 -132
- package/runtime/sdk/gl/Light.ts +0 -107
- package/runtime/sdk/gl/Lightmap.ts +0 -256
- package/runtime/sdk/gl/Material.ts +0 -260
- package/runtime/sdk/gl/Mesh.ts +0 -83
- package/runtime/sdk/gl/Model.ts +0 -124
- package/runtime/sdk/gl/NavAgent.ts +0 -337
- package/runtime/sdk/gl/NavMesh.ts +0 -397
- package/runtime/sdk/gl/Node.ts +0 -350
- package/runtime/sdk/gl/Noise.ts +0 -30
- package/runtime/sdk/gl/Particles.ts +0 -676
- package/runtime/sdk/gl/Physics.ts +0 -222
- package/runtime/sdk/gl/Plane.ts +0 -53
- package/runtime/sdk/gl/Ragdoll.ts +0 -270
- package/runtime/sdk/gl/Ray.ts +0 -16
- package/runtime/sdk/gl/Scene.ts +0 -486
- package/runtime/sdk/gl/Shape.ts +0 -409
- package/runtime/sdk/gl/Terrain.ts +0 -1092
- package/runtime/sdk/gl/Texture.ts +0 -63
- package/runtime/sdk/gl/Trigger.ts +0 -45
- package/runtime/sdk/gl/Vehicle.ts +0 -473
- package/runtime/sdk/gl/Wheel.ts +0 -240
- package/runtime/sdk/gl/animation/AnimationClip.ts +0 -204
- package/runtime/sdk/gl/animation/Animator.ts +0 -120
- package/runtime/sdk/gl/animation/Layer.ts +0 -31
- package/runtime/sdk/gl/animation/Loop.ts +0 -30
- package/runtime/sdk/gl/animation/Playback.ts +0 -44
- package/runtime/sdk/gl/animation/core.ts +0 -336
- package/runtime/sdk/gl/controls.ts +0 -95
- package/runtime/sdk/gl/physicsEvents.ts +0 -20
- package/runtime/sdk/gl/scenarios.ts +0 -291
- package/runtime/sdk/gl/state.ts +0 -6
- package/runtime/sdk/gl/terrainMesh.ts +0 -219
- package/runtime/sdk/gl/touch.ts +0 -68
- package/runtime/sdk/inject.ts +0 -197
- package/runtime/sdk/math/Mathf.ts +0 -118
- package/runtime/sdk/math/mat4.ts +0 -278
- package/runtime/sdk/math/quat.ts +0 -232
- package/runtime/sdk/math/vec.ts +0 -255
- package/runtime/sdk/net/codec.ts +0 -119
- package/runtime/sdk/net/core.ts +0 -384
- package/runtime/sdk/net/index.ts +0 -181
- package/runtime/sdk/net/replication.ts +0 -622
- package/runtime/sdk/plugins/camera.ts +0 -81
- package/runtime/sdk/plugins/geolocation.ts +0 -123
- package/runtime/sdk/plugins/oauth.ts +0 -61
- package/runtime/sdk/plugins/permission.ts +0 -7
- package/runtime/sdk/plugins/push.ts +0 -132
- package/runtime/sdk/plugins/qr.ts +0 -73
- package/runtime/sdk/plugins/service.ts +0 -47
- package/runtime/sdk/runtime/app.ts +0 -101
- package/runtime/sdk/runtime/appEvents.ts +0 -54
- package/runtime/sdk/runtime/channel.ts +0 -61
- package/runtime/sdk/runtime/clipboard.ts +0 -20
- package/runtime/sdk/runtime/datetime.ts +0 -329
- package/runtime/sdk/runtime/device.ts +0 -293
- package/runtime/sdk/runtime/fetch.ts +0 -77
- package/runtime/sdk/runtime/files.ts +0 -23
- package/runtime/sdk/runtime/input.ts +0 -175
- package/runtime/sdk/runtime/media.ts +0 -111
- package/runtime/sdk/runtime/misc.ts +0 -16
- package/runtime/sdk/runtime/net.ts +0 -36
- package/runtime/sdk/runtime/rpc.ts +0 -218
- package/runtime/sdk/runtime/service.ts +0 -83
- package/runtime/sdk/runtime/share.ts +0 -9
- package/runtime/sdk/runtime/storage.ts +0 -13
- package/runtime/sdk/runtime/touch.ts +0 -76
- package/runtime/sdk/scene/defineScene.ts +0 -1353
- package/runtime/sdk/scene/editorPlugins.ts +0 -110
- package/runtime/sdk/scene/gizmos.ts +0 -148
- package/runtime/sdk/scene/grammar.ts +0 -120
- package/runtime/sdk/scene/material.ts +0 -188
- package/runtime/sdk/server/auth/appConfig.ts +0 -12
- package/runtime/sdk/server/auth/global.ts +0 -80
- package/runtime/sdk/server/auth/host.ts +0 -318
- package/runtime/sdk/server/auth/models.ts +0 -83
- package/runtime/sdk/server/auth/types.ts +0 -50
- package/runtime/sdk/server/channel.ts +0 -56
- package/runtime/sdk/server/context.ts +0 -36
- package/runtime/sdk/server/db/defineDb.ts +0 -237
- package/runtime/sdk/server/db/fields.ts +0 -132
- package/runtime/sdk/server/db/httpTransport.ts +0 -93
- package/runtime/sdk/server/db/index.ts +0 -7
- package/runtime/sdk/server/db/marci/query.ts +0 -412
- package/runtime/sdk/server/db/types.ts +0 -202
- package/runtime/sdk/server/errors.ts +0 -12
- package/runtime/sdk/server/host.ts +0 -74
- package/runtime/sdk/server/inject.ts +0 -13
- package/runtime/sdk/server/runtime.ts +0 -133
- package/runtime/sdk/server/validate.ts +0 -87
- package/runtime/sdk/ui/NativeView.ts +0 -142
- package/runtime/sdk/ui/UI.ts +0 -39
- package/runtime/sdk/ui/UIBottomSheet.ts +0 -139
- package/runtime/sdk/ui/UIButton.ts +0 -101
- package/runtime/sdk/ui/UIContainer.ts +0 -60
- package/runtime/sdk/ui/UIImage.ts +0 -83
- package/runtime/sdk/ui/UIInput.ts +0 -185
- package/runtime/sdk/ui/UIModal.ts +0 -139
- package/runtime/sdk/ui/UINode.ts +0 -830
- package/runtime/sdk/ui/UIPager.ts +0 -362
- package/runtime/sdk/ui/UIPopover.ts +0 -100
- package/runtime/sdk/ui/UIScreen.ts +0 -123
- package/runtime/sdk/ui/UIScrollable.ts +0 -87
- package/runtime/sdk/ui/UISpacer.ts +0 -14
- package/runtime/sdk/ui/UITabs.ts +0 -236
- package/runtime/sdk/ui/UIText.ts +0 -51
- package/runtime/sdk/ui/UIVideo.ts +0 -88
- package/runtime/sdk/ui/UIVirtualizedList.ts +0 -241
- package/runtime/sdk/ui/UIWidget.ts +0 -127
- package/runtime/sdk/ui/fonts.ts +0 -13
- package/runtime/sdk/ui/presentable.ts +0 -117
- package/runtime/sdk/ui/router.ts +0 -132
- package/runtime/sdk/ui/theme.ts +0 -84
package/runtime/sdk/inject.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
// THE aggregation point. Every public global the SDK provides is re-exported here under the exact
|
|
2
|
-
// name user code uses it as. The bundler passes this file to esbuild's `inject:` option, so user
|
|
3
|
-
// code references `Scene`, `Sprite`, `toast`, … with no imports; esbuild tree-shakes away whatever
|
|
4
|
-
// a given project does not use (so a pure-2D project drops all 3D classes, and vice versa).
|
|
5
|
-
//
|
|
6
|
-
// Rule: this is the ONLY file that `export`s public names. Everything else is internal and imported
|
|
7
|
-
// by it. Host-provided globals (setLoop, console, setTimeout, DEG2RAD, asset, …) are NOT here —
|
|
8
|
-
// they live in src/host.d.ts as declarations and stay as free references at runtime.
|
|
9
|
-
|
|
10
|
-
// ---- math ----
|
|
11
|
-
export { Mathf } from "./math/Mathf"
|
|
12
|
-
export { Vec2, Vec3 } from "./math/vec"
|
|
13
|
-
export { Quat } from "./math/quat"
|
|
14
|
-
export { Mat4 } from "./math/mat4"
|
|
15
|
-
export { Color } from "./core/color"
|
|
16
|
-
|
|
17
|
-
// ---- aspects (attachable node capabilities) ----
|
|
18
|
-
export { Aspect, System, type With, type SystemHost } from "./core/Aspect"
|
|
19
|
-
export { type EventMap } from "./core/events"
|
|
20
|
-
export { Time } from "./core/time"
|
|
21
|
-
export { StateMachine, defineStates, type StateDef, type StatesDef, type StateGuard, type StateHandler, type StateMachineEvents } from "./core/StateMachine"
|
|
22
|
-
export { InspectorUI } from "./core/InspectorUI"
|
|
23
|
-
|
|
24
|
-
// ---- reactivity (signals; UI text/style props also accept `() => value` bindings) ----
|
|
25
|
-
export { signal, computed, effect, type Signal, type Computed } from "./core/signals"
|
|
26
|
-
export { __compWrite, __compOp, type CompAxis, type CompWriter } from "./core/compWrite"
|
|
27
|
-
|
|
28
|
-
// ---- canvas (core 2D drawing that bakes to a texture; shared by 2D/3D/UI) ----
|
|
29
|
-
export { Canvas, Bitmap } from "./canvas/Canvas"
|
|
30
|
-
|
|
31
|
-
// ---- platform runtime (injected globals; the host provides the lower-level _creator* bridges) ----
|
|
32
|
-
export { toast, openURL, SvgSource } from "./runtime/misc"
|
|
33
|
-
export { app, type AppState, type OrientationLock } from "./runtime/app"
|
|
34
|
-
export { clipboard } from "./runtime/clipboard"
|
|
35
|
-
export { date, type DateValue, type DateInput, type Unit, type Locale } from "./runtime/datetime"
|
|
36
|
-
export { fetch, fetchLocal, FormData, File, type FetchResponse } from "./runtime/fetch"
|
|
37
|
-
export { localStorage } from "./runtime/storage"
|
|
38
|
-
export { device, type HapticStyle, type MotionOptions } from "./runtime/device"
|
|
39
|
-
export { Input, InputChannel, type InputKeyEvent, type InputGamepadEvent, type InputEventName, type GamepadState, type GamepadAxisName } from "./runtime/input"
|
|
40
|
-
export { WebSocket } from "./runtime/net"
|
|
41
|
-
// Multiplayer (docs/multiplayer-plan.md): roles, players, JSON messages over the _creatorNet transport.
|
|
42
|
-
export { Net, NetPlayer, Replicated, NetEntity, type NetMessage, type NetRole, type NetStatus, type NetEvents, type NetLaunch, type NetInput, type NetKind, type NetTransform } from "./net"
|
|
43
|
-
// App-backend transport: the compiler-generated stubs of `*.server.ts` modules call these; user code
|
|
44
|
-
// only ever imports its server functions (docs/backend-plan.md §4).
|
|
45
|
-
export { __rpc, __channel, __serverOnly, RpcError, type ClientChannel } from "./runtime/rpc"
|
|
46
|
-
export { AudioPlayer, VideoPlayer } from "./runtime/media"
|
|
47
|
-
export { openFilePicker } from "./runtime/files"
|
|
48
|
-
export { share } from "./runtime/share"
|
|
49
|
-
export { ClickEvent, TouchStartEvent, LongPressEvent } from "./runtime/touch"
|
|
50
|
-
|
|
51
|
-
// ---- 2D engine (creator-2d) ----
|
|
52
|
-
export { Scene2D } from "./g2/Scene2D"
|
|
53
|
-
export { Node2D } from "./g2/Node2D"
|
|
54
|
-
export { Camera2D } from "./g2/Camera2D"
|
|
55
|
-
export { Sprite } from "./g2/Sprite"
|
|
56
|
-
export { SpriteAnimation } from "./g2/SpriteAnimation"
|
|
57
|
-
export { Shape2D } from "./g2/Shape2D"
|
|
58
|
-
export { Physics2D } from "./g2/Physics2D"
|
|
59
|
-
export { Trigger2D } from "./g2/Trigger2D"
|
|
60
|
-
export { CharacterController2D } from "./g2/CharacterController2D"
|
|
61
|
-
export { OneWay2D } from "./g2/OneWay2D"
|
|
62
|
-
export { PhysicsGroup2D } from "./g2/groups2d"
|
|
63
|
-
export { Tilemap } from "./g2/Tilemap"
|
|
64
|
-
export { Texture2D } from "./g2/Texture2D"
|
|
65
|
-
// sprite sheets as data (.sprite.ts files — see src/g2/SpriteSheet.ts)
|
|
66
|
-
export { SpriteSheet, defineSpriteSheet } from "./g2/SpriteSheet"
|
|
67
|
-
export type { SpriteSheetDef, SheetSprite, SpriteMakeOptions } from "./g2/SpriteSheet"
|
|
68
|
-
// tilesets as data (.tiles.ts files — autotile materials, see src/g2/Tileset.ts + autotile.ts)
|
|
69
|
-
export { Tileset, defineTileset, Autotile2D } from "./g2/Tileset"
|
|
70
|
-
export { rawCell, isRawCell, rawIndex } from "./g2/autotile"
|
|
71
|
-
export { rot90, rot180, rot270, flipX, packTile, tileIndex, tileTurns, tileFlip, tileOriented } from "./g2/autotile"
|
|
72
|
-
export type {
|
|
73
|
-
TilesetDef, TileMaterial, PatchMaterial, PathMaterial, PatchSlots, EdgeSlot, FillBlock, BlockEntry,
|
|
74
|
-
TileBlock, TilePart,
|
|
75
|
-
} from "./g2/autotile"
|
|
76
|
-
// 2D scenes as data (.scene2d.ts files — see src/g2/defineScene2d.ts) + the cells('…') payload
|
|
77
|
-
export { defineScene2d, Scene2dHandle } from "./g2/defineScene2d"
|
|
78
|
-
export type { Scene2dDef, Scene2dNodeDef, Scene2dEnv, SpriteSourceDef, TilemapSourceDef, Camera2dNodeDef, LoadedScene2d } from "./g2/defineScene2d"
|
|
79
|
-
export { cells, encodeCells, type CellsData } from "./g2/cells"
|
|
80
|
-
// no-code 2D scenario aspects (attachable in scene files — see src/g2/scenarios2d.ts)
|
|
81
|
-
export { CameraFollow } from "./g2/scenarios2d"
|
|
82
|
-
|
|
83
|
-
// ---- UI (creator-ui) ----
|
|
84
|
-
export {
|
|
85
|
-
UIScreen, type UIScreenStyle,
|
|
86
|
-
UIRow, UIColumn, UIBox, type UIContainerStyle,
|
|
87
|
-
UIText, type UITextStyle,
|
|
88
|
-
UIButton, type UIButtonStyle,
|
|
89
|
-
UIImage, type UIImageStyle,
|
|
90
|
-
UIVideo, type UIVideoStyle,
|
|
91
|
-
UIInput, UITextArea, type UIInputStyle,
|
|
92
|
-
UIScrollable, type UIScrollableStyle,
|
|
93
|
-
UIPager, type UIPagerStyle,
|
|
94
|
-
UITabs, type UITabDef,
|
|
95
|
-
defineTabs, type TabDef, type TabsHandle,
|
|
96
|
-
UIWidget, type UIWidgetStyle,
|
|
97
|
-
UIModal, type UIModalStyle,
|
|
98
|
-
UIBottomSheet, type UIBottomSheetStyle,
|
|
99
|
-
UIPopover, type UIPopoverStyle,
|
|
100
|
-
UISpacer, type UISpacerStyle,
|
|
101
|
-
UIVirtualizedList,
|
|
102
|
-
Router,
|
|
103
|
-
NativeView, type UINativeViewStyle,
|
|
104
|
-
registerFont,
|
|
105
|
-
__uiMap,
|
|
106
|
-
__UIColumn, __UIRow, __UIBox, __UIButton, __UIScreen, __UIScrollable, __UIWidget,
|
|
107
|
-
} from "./ui/UI"
|
|
108
|
-
// The Presentable navigation contract (docs/navigation-presentable-plan.md). `Presentable` is
|
|
109
|
-
// interface + runtime companion (declaration merging): `Presentable.current` = what's on screen.
|
|
110
|
-
export { Presentable } from "./ui/UI"
|
|
111
|
-
export type { PresentOptions, Transition, TransitionName, TransitionSpec, TransitionTransform } from "./ui/UI"
|
|
112
|
-
// The base node type + the union a container accepts as children — documented as the signature of
|
|
113
|
-
// UIColumn/UIRow/append/etc., so they must be global (type-only; erased at runtime).
|
|
114
|
-
export type { UINode, UINodeChild } from "./ui/UINode"
|
|
115
|
-
// App theme variables (docs/ui-theme-plan.md): theme({...}) merges + returns typed var()
|
|
116
|
-
// accessors; system vars are static props (theme.primaryColor, theme["comfort-top"], …).
|
|
117
|
-
export { theme, type ThemeValues, type ThemeAccessors } from "./ui/theme"
|
|
118
|
-
|
|
119
|
-
// ---- animate ----
|
|
120
|
-
export { animate, animateMat4, stopAnimation, pauseAnimation, resumeAnimation } from "./animate/animate"
|
|
121
|
-
export { cubicBezier } from "./animate/bezier"
|
|
122
|
-
export { easeIn, easeOut, easeInOut } from "./animate/easings"
|
|
123
|
-
|
|
124
|
-
// ---- plugins (optional, host-provided capabilities — typed NativeView/service wrappers, see src/plugins/) ----
|
|
125
|
-
export { QRScanner } from "./plugins/qr"
|
|
126
|
-
export { CameraView, type CameraFacing } from "./plugins/camera"
|
|
127
|
-
export { Geolocation, type GeoPosition, type GeoOptions, type GeoWatch } from "./plugins/geolocation"
|
|
128
|
-
export { Push, type PushPayload, type PushStatus, type PushRegisterOptions, type PushEvent } from "./plugins/push"
|
|
129
|
-
export { OAuth, type OAuthCredential, type OAuthProviderName } from "./plugins/oauth"
|
|
130
|
-
export { Service } from "./plugins/service"
|
|
131
|
-
|
|
132
|
-
// ---- scenes as data (.scene.ts files — see src/scene/defineScene.ts) ----
|
|
133
|
-
export { defineScene, use, ref, make, SceneHandle, applyEditorPose as __applyEditorPose } from "./scene/defineScene"
|
|
134
|
-
export {
|
|
135
|
-
defineMaterial, MaterialHandle,
|
|
136
|
-
// editor-harness helpers (the scene editor's live material paths — not app API)
|
|
137
|
-
assignMaterialDef as __assignMaterialDef, applyMaterialParam as __applyMaterialParam,
|
|
138
|
-
} from "./scene/material"
|
|
139
|
-
export type { MaterialData, MaterialParamValue, ShaderMaterialDef, LitMaterialDef, UnlitMaterialDef } from "./scene/material"
|
|
140
|
-
export type { SceneDef, SceneNodeDef, MeshDef, LightDef, MaterialDef, CameraNodeDef, AspectEntry, MakeEntry, LoadedScene, SceneInstance } from "./scene/defineScene"
|
|
141
|
-
export { CameraPlace } from "./gl/CameraPlace"
|
|
142
|
-
export type { FieldMeta } from "./core/fields"
|
|
143
|
-
// Editor-only line drawing from generator rebuild() / make() factories / tool hooks — drawn by the
|
|
144
|
-
// scene editor's viewport overlay, a no-op everywhere else (see src/scene/gizmos.ts).
|
|
145
|
-
export { Gizmos, GizmoBuffer as __GizmoBuffer, withGizmoScope as __withGizmoScope } from "./scene/gizmos"
|
|
146
|
-
export type { GizmoStyle, GizmoAnchor } from "./scene/gizmos"
|
|
147
|
-
|
|
148
|
-
// ---- no-code scenario aspects (attachable in the scene editor — see src/gl/scenarios.ts) ----
|
|
149
|
-
export { MoveTo, FollowPath, Spin, LookAt, PlayAnimation } from "./gl/scenarios"
|
|
150
|
-
|
|
151
|
-
// ---- editor plugins (called from `*.editor.ts` files — editor bundles only; DCE'd from apps) ----
|
|
152
|
-
export { registerEditorWindow, registerEditorTool, __editorPlugins } from "./scene/editorPlugins"
|
|
153
|
-
export type { EditorApi, EditorRayHit, EditorToolHooks, EditorWindowFn } from "./scene/editorPlugins"
|
|
154
|
-
|
|
155
|
-
// ---- 3D engine (creator-gl) ----
|
|
156
|
-
export { Scene, ARScene, VRScene } from "./gl/Scene"
|
|
157
|
-
export { Node } from "./gl/Node"
|
|
158
|
-
export { Mesh } from "./gl/Mesh"
|
|
159
|
-
export { Model } from "./gl/Model"
|
|
160
|
-
export { Shape } from "./gl/Shape"
|
|
161
|
-
export { Physics } from "./gl/Physics"
|
|
162
|
-
export { Trigger } from "./gl/Trigger"
|
|
163
|
-
export { CharacterController } from "./gl/CharacterController"
|
|
164
|
-
export { Vehicle } from "./gl/Vehicle"
|
|
165
|
-
export type { DriveLayout, DifferentialMode, EngineConfig, SteeringConfig, AeroConfig } from "./gl/Vehicle"
|
|
166
|
-
export { Wheel } from "./gl/Wheel"
|
|
167
|
-
export { Ragdoll } from "./gl/Ragdoll"
|
|
168
|
-
export type { RagdollPart, RagdollHinge } from "./gl/Ragdoll"
|
|
169
|
-
export type { TireCurve, WheelSuspension, WheelTire, WheelVisual } from "./gl/Wheel"
|
|
170
|
-
export { Gearbox } from "./gl/Gearbox"
|
|
171
|
-
export { AnimationClip } from "./gl/animation/AnimationClip"
|
|
172
|
-
export type { ClipDef, ClipTrackDef, ClipKey } from "./gl/animation/AnimationClip"
|
|
173
|
-
export { Animator } from "./gl/animation/Animator"
|
|
174
|
-
export { Playback } from "./gl/animation/Playback"
|
|
175
|
-
export { Loop } from "./gl/animation/Loop"
|
|
176
|
-
export { Layer } from "./gl/animation/Layer"
|
|
177
|
-
export type { PlayOptions, StopOptions, LayerOptions, LoopOptions, LoopDef, BlendPosition, ActiveClip } from "./gl/animation/core"
|
|
178
|
-
export { IK } from "./gl/IK"
|
|
179
|
-
export type { IKTwoBone, IKLookAt } from "./gl/IK"
|
|
180
|
-
export { Light } from "./gl/Light"
|
|
181
|
-
export { Lightmap } from "./gl/Lightmap"
|
|
182
|
-
export { Terrain } from "./gl/Terrain"
|
|
183
|
-
export type { TerrainOptions, TerrainLayer, TerrainRegion, ConformOptions, RibbonOptions, AutoPaintRules, SculptOptions, TerrainHit, TerrainSnapshot } from "./gl/Terrain"
|
|
184
|
-
export { NavMesh, NavCrowd } from "./gl/NavMesh"
|
|
185
|
-
export type { NavMeshLoadOptions, NavMeshInfo, NavPath, NavQueryOptions, NavRaycastHit, NavAgentSize } from "./gl/NavMesh"
|
|
186
|
-
export { NavAgent } from "./gl/NavAgent"
|
|
187
|
-
export type { NavAgentState, NavAgentAvoidance, NavAgentDrive, NavAgentEvents } from "./gl/NavAgent"
|
|
188
|
-
export { Material } from "./gl/Material"
|
|
189
|
-
export { Geometry } from "./gl/Geometry"
|
|
190
|
-
export { InstancedMesh } from "./gl/InstancedMesh"
|
|
191
|
-
export type { InstanceTransform } from "./gl/InstancedMesh"
|
|
192
|
-
export { Texture } from "./gl/Texture"
|
|
193
|
-
export { Camera } from "./gl/Camera"
|
|
194
|
-
export { Ray } from "./gl/Ray"
|
|
195
|
-
export { Plane } from "./gl/Plane"
|
|
196
|
-
export { Noise } from "./gl/Noise"
|
|
197
|
-
export { Particles, Trail, curve, colorCurve } from "./gl/Particles"
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
// Scalar / general math helpers, exposed to user code as the `Mathf` global. Vector & quaternion
|
|
2
|
-
// helpers live with the engine that uses them (vec2 in g2/, vec3+quat in gl/). `smoothDamp` works on
|
|
3
|
-
// both numbers and numeric arrays here (no gl-matrix), which covers 2D (vec2) and 3D position damping.
|
|
4
|
-
|
|
5
|
-
export type Damper<T extends number | number[]> = ((target: T, dt: number) => T) & {
|
|
6
|
-
/** Snap the damper's internal current value (e.g. on teleport). */
|
|
7
|
-
setValue(value: T): void
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const clamp = (v: number, min: number, max: number): number => (v < min ? min : v > max ? max : v)
|
|
11
|
-
|
|
12
|
-
const smoothDampNumber = (initial: number, smoothTime: number, maxSpeed: number): Damper<number> => {
|
|
13
|
-
let current = initial
|
|
14
|
-
let velocity = 0
|
|
15
|
-
const damp = ((target: number, dt: number): number => {
|
|
16
|
-
smoothTime = Math.max(0.0001, smoothTime)
|
|
17
|
-
const omega = 2 / smoothTime
|
|
18
|
-
const x = omega * dt
|
|
19
|
-
const exp = 1 / (1 + x + 0.48 * x * x + 0.235 * x * x * x)
|
|
20
|
-
const maxDelta = maxSpeed * smoothTime
|
|
21
|
-
let delta = clamp(current - target, -maxDelta, maxDelta)
|
|
22
|
-
const newTarget = current - delta
|
|
23
|
-
const temp = (velocity + omega * delta) * dt
|
|
24
|
-
velocity = (velocity - omega * temp) * exp
|
|
25
|
-
current = newTarget + (delta + temp) * exp
|
|
26
|
-
return current
|
|
27
|
-
}) as Damper<number>
|
|
28
|
-
damp.setValue = (v) => { current = v; velocity = 0 }
|
|
29
|
-
return damp
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function smoothDamp(initial: number, smoothTime: number, maxSpeed?: number): Damper<number>
|
|
33
|
-
function smoothDamp(initial: number[], smoothTime: number, maxSpeed?: number): Damper<number[]>
|
|
34
|
-
function smoothDamp(initial: any, smoothTime: number, maxSpeed = Infinity): any {
|
|
35
|
-
return typeof initial === "number"
|
|
36
|
-
? smoothDampNumber(initial, smoothTime, maxSpeed)
|
|
37
|
-
: smoothDampArray(initial, smoothTime, maxSpeed)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const smoothDampArray = (initial: number[], smoothTime: number, maxSpeed: number): Damper<number[]> => {
|
|
41
|
-
const n = initial.length
|
|
42
|
-
let current = initial.slice()
|
|
43
|
-
const velocity = new Array(n).fill(0)
|
|
44
|
-
const damp = ((target: number[], dt: number): number[] => {
|
|
45
|
-
smoothTime = Math.max(0.0001, smoothTime)
|
|
46
|
-
const omega = 2 / smoothTime
|
|
47
|
-
const x = omega * dt
|
|
48
|
-
const exp = 1 / (1 + x + 0.48 * x * x + 0.235 * x * x * x)
|
|
49
|
-
const maxDelta = maxSpeed * smoothTime
|
|
50
|
-
|
|
51
|
-
const delta = new Array(n)
|
|
52
|
-
let mag = 0
|
|
53
|
-
for (let i = 0; i < n; i++) { delta[i] = current[i] - target[i]; mag += delta[i] * delta[i] }
|
|
54
|
-
mag = Math.sqrt(mag)
|
|
55
|
-
if (mag > maxDelta && mag > 0) {
|
|
56
|
-
const s = maxDelta / mag
|
|
57
|
-
for (let i = 0; i < n; i++) delta[i] *= s
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const out = new Array(n)
|
|
61
|
-
for (let i = 0; i < n; i++) {
|
|
62
|
-
const newTarget = current[i] - delta[i]
|
|
63
|
-
const temp = (velocity[i] + omega * delta[i]) * dt
|
|
64
|
-
velocity[i] = (velocity[i] - omega * temp) * exp
|
|
65
|
-
out[i] = newTarget + (delta[i] + temp) * exp
|
|
66
|
-
}
|
|
67
|
-
current = out
|
|
68
|
-
return out.slice()
|
|
69
|
-
}) as Damper<number[]>
|
|
70
|
-
damp.setValue = (v) => { current = v.slice(); velocity.fill(0) }
|
|
71
|
-
return damp
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export const Mathf = {
|
|
75
|
-
PI: Math.PI,
|
|
76
|
-
TAU: Math.PI * 2,
|
|
77
|
-
EPSILON: 1e-6,
|
|
78
|
-
DEG2RAD: Math.PI / 180,
|
|
79
|
-
RAD2DEG: 180 / Math.PI,
|
|
80
|
-
|
|
81
|
-
deg2rad: (deg: number): number => deg * (Math.PI / 180),
|
|
82
|
-
rad2deg: (rad: number): number => rad * (180 / Math.PI),
|
|
83
|
-
|
|
84
|
-
clamp,
|
|
85
|
-
clamp01: (v: number): number => clamp(v, 0, 1),
|
|
86
|
-
lerp: (a: number, b: number, t: number): number => a + (b - a) * t,
|
|
87
|
-
inverseLerp: (a: number, b: number, v: number): number => (a === b ? 0 : (v - a) / (b - a)),
|
|
88
|
-
remap: (v: number, inMin: number, inMax: number, outMin: number, outMax: number): number =>
|
|
89
|
-
outMin + ((v - inMin) / (inMax - inMin)) * (outMax - outMin),
|
|
90
|
-
|
|
91
|
-
/** Move `a` toward `b` by at most `maxDelta`. */
|
|
92
|
-
moveTowards: (a: number, b: number, maxDelta: number): number => {
|
|
93
|
-
const d = b - a
|
|
94
|
-
return Math.abs(d) <= maxDelta ? b : a + Math.sign(d) * maxDelta
|
|
95
|
-
},
|
|
96
|
-
/** Frame-rate-independent exponential approach (good default: lambda 5..15). */
|
|
97
|
-
damp: (a: number, b: number, lambda: number, dt: number): number => a + (b - a) * (1 - Math.exp(-lambda * dt)),
|
|
98
|
-
|
|
99
|
-
sign: Math.sign,
|
|
100
|
-
/** Loop a value into [0, length). */
|
|
101
|
-
repeat: (t: number, length: number): number => clamp(t - Math.floor(t / length) * length, 0, length),
|
|
102
|
-
/** Ping-pong a value in [0, length]. */
|
|
103
|
-
pingPong: (t: number, length: number): number => {
|
|
104
|
-
const r = clamp(t - Math.floor(t / (length * 2)) * (length * 2), 0, length * 2)
|
|
105
|
-
return length - Math.abs(r - length)
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
random: (min = 0, max = 1): number => min + Math.random() * (max - min),
|
|
109
|
-
randomInt: (min: number, max: number): number => Math.floor(min + Math.random() * (max - min + 1)),
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Critically-damped follow (Unity SmoothDamp). Returns a stateful damper you call every frame:
|
|
113
|
-
* const d = Mathf.smoothDamp([x, y], 0.15)
|
|
114
|
-
* pos = d(targetPos, dt)
|
|
115
|
-
* Works on a number or a numeric array (vec2 / vec3).
|
|
116
|
-
*/
|
|
117
|
-
smoothDamp,
|
|
118
|
-
}
|
package/runtime/sdk/math/mat4.ts
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
// Fluent 4×4 matrix (column-major) — the SDK's transform/projection type. Same contract as Vec/Quat:
|
|
2
|
-
// the methods are PURE (each returns a new Mat4), but — per the "never wrap away the metal" rule — the
|
|
3
|
-
// raw backing array is PUBLIC as `.m` (length 16). So low-level numeric surgery (`mat.m[12] += vx*dt`)
|
|
4
|
-
// drops straight to the array with zero ceremony, while the fluent methods express the high-level logic.
|
|
5
|
-
//
|
|
6
|
-
// Backing is a plain `number[]` (not a Float32Array) so a future optimizer can see through it; the
|
|
7
|
-
// Float32Array the host bridge wants is produced only at the edge via `toFloat32Array()`.
|
|
8
|
-
//
|
|
9
|
-
// This folds in the old `math/transform.ts` decomposition (position / scale / rotation / euler).
|
|
10
|
-
|
|
11
|
-
import { Vec3, type Vec3Like } from "./vec"
|
|
12
|
-
import { Quat, quatFromColMajor, eulerFromColMajor, type QuatLike, type EulerOrder } from "./quat"
|
|
13
|
-
|
|
14
|
-
export type Mat4Like = Mat4 | number[] | Float32Array | readonly number[]
|
|
15
|
-
|
|
16
|
-
const arr = (m: Mat4Like): ArrayLike<number> => (m as { m?: ArrayLike<number> }).m ?? (m as ArrayLike<number>)
|
|
17
|
-
const IDENTITY = [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
|
|
18
|
-
|
|
19
|
-
export class Mat4 {
|
|
20
|
-
/** The raw column-major elements (length 16). Public on purpose — read/write directly when you want
|
|
21
|
-
* the metal: `mat.m[12] += vx * dt`. The fluent methods never mutate it (they return a new Mat4). */
|
|
22
|
-
m: number[]
|
|
23
|
-
|
|
24
|
-
constructor(src?: Mat4Like) {
|
|
25
|
-
if (src === undefined) { this.m = IDENTITY.slice(); return }
|
|
26
|
-
const s = arr(src)
|
|
27
|
-
this.m = [ s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15] ]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// --- mutation ---
|
|
31
|
-
set(values: ArrayLike<number>): this { for (let i = 0; i < 16; i++) this.m[i] = values[i]; return this }
|
|
32
|
-
copy(src: Mat4Like): this { return this.set(arr(src)) }
|
|
33
|
-
|
|
34
|
-
// --- products (pure) ---
|
|
35
|
-
/** `this · b` (apply `b` first in local space, then `this`). */
|
|
36
|
-
mul(b: Mat4Like): Mat4 {
|
|
37
|
-
const a = this.m, o = arr(b), out = new Array(16)
|
|
38
|
-
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3]
|
|
39
|
-
const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7]
|
|
40
|
-
const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11]
|
|
41
|
-
const a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]
|
|
42
|
-
for (let i = 0; i < 4; i++) {
|
|
43
|
-
const b0 = o[i * 4], b1 = o[i * 4 + 1], b2 = o[i * 4 + 2], b3 = o[i * 4 + 3]
|
|
44
|
-
out[i * 4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30
|
|
45
|
-
out[i * 4 + 1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31
|
|
46
|
-
out[i * 4 + 2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32
|
|
47
|
-
out[i * 4 + 3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33
|
|
48
|
-
}
|
|
49
|
-
return fromArray(out)
|
|
50
|
-
}
|
|
51
|
-
/** `b · this` — multiply on the other side (apply `this` first, then `b`). */
|
|
52
|
-
premul(b: Mat4Like): Mat4 { return new Mat4(b).mul(this) }
|
|
53
|
-
|
|
54
|
-
invert(): Mat4 {
|
|
55
|
-
const a = this.m
|
|
56
|
-
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3]
|
|
57
|
-
const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7]
|
|
58
|
-
const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11]
|
|
59
|
-
const a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]
|
|
60
|
-
const b00 = a00 * a11 - a01 * a10, b01 = a00 * a12 - a02 * a10, b02 = a00 * a13 - a03 * a10
|
|
61
|
-
const b03 = a01 * a12 - a02 * a11, b04 = a01 * a13 - a03 * a11, b05 = a02 * a13 - a03 * a12
|
|
62
|
-
const b06 = a20 * a31 - a21 * a30, b07 = a20 * a32 - a22 * a30, b08 = a20 * a33 - a23 * a30
|
|
63
|
-
const b09 = a21 * a32 - a22 * a31, b10 = a21 * a33 - a23 * a31, b11 = a22 * a33 - a23 * a32
|
|
64
|
-
let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06
|
|
65
|
-
if (!det) return new Mat4() // singular → identity
|
|
66
|
-
det = 1 / det
|
|
67
|
-
return fromArray([
|
|
68
|
-
(a11 * b11 - a12 * b10 + a13 * b09) * det, (a02 * b10 - a01 * b11 - a03 * b09) * det,
|
|
69
|
-
(a31 * b05 - a32 * b04 + a33 * b03) * det, (a22 * b04 - a21 * b05 - a23 * b03) * det,
|
|
70
|
-
(a12 * b08 - a10 * b11 - a13 * b07) * det, (a00 * b11 - a02 * b08 + a03 * b07) * det,
|
|
71
|
-
(a32 * b02 - a30 * b05 - a33 * b01) * det, (a20 * b05 - a22 * b02 + a23 * b01) * det,
|
|
72
|
-
(a10 * b10 - a11 * b08 + a13 * b06) * det, (a01 * b08 - a00 * b10 - a03 * b06) * det,
|
|
73
|
-
(a30 * b04 - a31 * b02 + a33 * b00) * det, (a21 * b02 - a20 * b04 - a23 * b00) * det,
|
|
74
|
-
(a11 * b07 - a10 * b09 - a12 * b06) * det, (a00 * b09 - a01 * b07 + a02 * b06) * det,
|
|
75
|
-
(a31 * b01 - a30 * b03 - a32 * b00) * det, (a20 * b03 - a21 * b01 + a22 * b00) * det,
|
|
76
|
-
])
|
|
77
|
-
}
|
|
78
|
-
transpose(): Mat4 {
|
|
79
|
-
const a = this.m
|
|
80
|
-
return fromArray([ a[0], a[4], a[8], a[12], a[1], a[5], a[9], a[13], a[2], a[6], a[10], a[14], a[3], a[7], a[11], a[15] ])
|
|
81
|
-
}
|
|
82
|
-
determinant(): number {
|
|
83
|
-
const a = this.m
|
|
84
|
-
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3]
|
|
85
|
-
const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7]
|
|
86
|
-
const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11]
|
|
87
|
-
const a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]
|
|
88
|
-
const b0 = a00 * a11 - a01 * a10, b1 = a00 * a12 - a02 * a10, b2 = a01 * a12 - a02 * a11
|
|
89
|
-
const b3 = a20 * a31 - a21 * a30, b4 = a20 * a32 - a22 * a30, b5 = a21 * a32 - a22 * a31
|
|
90
|
-
const b6 = a00 * b5 - a01 * b4 + a02 * b3, b7 = a10 * b5 - a11 * b4 + a12 * b3
|
|
91
|
-
const b8 = a20 * b2 - a21 * b1 + a22 * b0, b9 = a30 * b2 - a31 * b1 + a32 * b0
|
|
92
|
-
return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// --- local-space transforms (post-multiply: this · T) ---
|
|
96
|
-
/** `this · translate(v)`. */
|
|
97
|
-
translate(v: Vec3Like): Mat4 {
|
|
98
|
-
const a = this.m, x = ax(v), y = ay(v), z = az(v), out = a.slice()
|
|
99
|
-
out[12] = a[0] * x + a[4] * y + a[8] * z + a[12]
|
|
100
|
-
out[13] = a[1] * x + a[5] * y + a[9] * z + a[13]
|
|
101
|
-
out[14] = a[2] * x + a[6] * y + a[10] * z + a[14]
|
|
102
|
-
out[15] = a[3] * x + a[7] * y + a[11] * z + a[15]
|
|
103
|
-
return fromArray(out)
|
|
104
|
-
}
|
|
105
|
-
/** `this · scale(v)`. Accepts a vector or a uniform scalar. */
|
|
106
|
-
scale(v: Vec3Like | number): Mat4 {
|
|
107
|
-
const a = this.m
|
|
108
|
-
const x = typeof v === "number" ? v : ax(v), y = typeof v === "number" ? v : ay(v), z = typeof v === "number" ? v : az(v)
|
|
109
|
-
return fromArray([
|
|
110
|
-
a[0] * x, a[1] * x, a[2] * x, a[3] * x, a[4] * y, a[5] * y, a[6] * y, a[7] * y,
|
|
111
|
-
a[8] * z, a[9] * z, a[10] * z, a[11] * z, a[12], a[13], a[14], a[15],
|
|
112
|
-
])
|
|
113
|
-
}
|
|
114
|
-
/** `this · rotate(axis, rad)`. */
|
|
115
|
-
rotate(rad: number, axis: Vec3Like): Mat4 {
|
|
116
|
-
let x = ax(axis), y = ay(axis), z = az(axis)
|
|
117
|
-
let len = Math.hypot(x, y, z)
|
|
118
|
-
if (len < 1e-6) return this.clone()
|
|
119
|
-
len = 1 / len; x *= len; y *= len; z *= len
|
|
120
|
-
const s = Math.sin(rad), c = Math.cos(rad), t = 1 - c
|
|
121
|
-
const a = this.m
|
|
122
|
-
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3]
|
|
123
|
-
const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7]
|
|
124
|
-
const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11]
|
|
125
|
-
const b00 = x * x * t + c, b01 = y * x * t + z * s, b02 = z * x * t - y * s
|
|
126
|
-
const b10 = x * y * t - z * s, b11 = y * y * t + c, b12 = z * y * t + x * s
|
|
127
|
-
const b20 = x * z * t + y * s, b21 = y * z * t - x * s, b22 = z * z * t + c
|
|
128
|
-
return fromArray([
|
|
129
|
-
a00 * b00 + a10 * b01 + a20 * b02, a01 * b00 + a11 * b01 + a21 * b02, a02 * b00 + a12 * b01 + a22 * b02, a03 * b00 + a13 * b01 + a23 * b02,
|
|
130
|
-
a00 * b10 + a10 * b11 + a20 * b12, a01 * b10 + a11 * b11 + a21 * b12, a02 * b10 + a12 * b11 + a22 * b12, a03 * b10 + a13 * b11 + a23 * b12,
|
|
131
|
-
a00 * b20 + a10 * b21 + a20 * b22, a01 * b20 + a11 * b21 + a21 * b22, a02 * b20 + a12 * b21 + a22 * b22, a03 * b20 + a13 * b21 + a23 * b22,
|
|
132
|
-
a[12], a[13], a[14], a[15],
|
|
133
|
-
])
|
|
134
|
-
}
|
|
135
|
-
rotateX(rad: number): Mat4 { return this.rotate(rad, AXIS_X) }
|
|
136
|
-
rotateY(rad: number): Mat4 { return this.rotate(rad, AXIS_Y) }
|
|
137
|
-
rotateZ(rad: number): Mat4 { return this.rotate(rad, AXIS_Z) }
|
|
138
|
-
|
|
139
|
-
// --- vector transforms ---
|
|
140
|
-
/** Transform a point (applies translation + perspective divide). */
|
|
141
|
-
transformPoint(v: Vec3Like): Vec3 { return new Vec3(v).transform(this) }
|
|
142
|
-
/** Transform a direction (rotation/scale only — no translation, no divide). */
|
|
143
|
-
transformDirection(v: Vec3Like): Vec3 {
|
|
144
|
-
const a = this.m, x = ax(v), y = ay(v), z = az(v)
|
|
145
|
-
return new Vec3(a[0] * x + a[4] * y + a[8] * z, a[1] * x + a[5] * y + a[9] * z, a[2] * x + a[6] * y + a[10] * z)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// --- decomposition (folded from transform.ts) ---
|
|
149
|
-
get position(): Vec3 { const a = this.m; return new Vec3(a[12], a[13], a[14]) }
|
|
150
|
-
get scaling(): Vec3 {
|
|
151
|
-
const a = this.m
|
|
152
|
-
return new Vec3(Math.hypot(a[0], a[1], a[2]), Math.hypot(a[4], a[5], a[6]), Math.hypot(a[8], a[9], a[10]))
|
|
153
|
-
}
|
|
154
|
-
get rotation(): Quat { return quatFromColMajor(rotationOnly(this.m)) }
|
|
155
|
-
get eulerAngles(): Vec3 { return eulerFromColMajor(rotationOnly(this.m), "YXZ") }
|
|
156
|
-
toEuler(order: EulerOrder = "YXZ"): Vec3 { return eulerFromColMajor(rotationOnly(this.m), order) }
|
|
157
|
-
/** `{ position, rotation, scale }` in one shot. */
|
|
158
|
-
decompose(): { position: Vec3, rotation: Quat, scale: Vec3 } {
|
|
159
|
-
return { position: this.position, rotation: this.rotation, scale: this.scaling }
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** Column basis vectors (the local X / Y / Z axes in world space). */
|
|
163
|
-
get basisX(): Vec3 { const a = this.m; return new Vec3(a[0], a[1], a[2]) }
|
|
164
|
-
get basisY(): Vec3 { const a = this.m; return new Vec3(a[4], a[5], a[6]) }
|
|
165
|
-
get basisZ(): Vec3 { const a = this.m; return new Vec3(a[8], a[9], a[10]) }
|
|
166
|
-
|
|
167
|
-
// --- interop ---
|
|
168
|
-
clone(): Mat4 { return new Mat4(this) }
|
|
169
|
-
toArray(): number[] { return this.m.slice() }
|
|
170
|
-
toFloat32Array(): Float32Array { return Float32Array.from(this.m) }
|
|
171
|
-
equals(b: Mat4Like, eps = 1e-6): boolean {
|
|
172
|
-
const o = arr(b)
|
|
173
|
-
for (let i = 0; i < 16; i++) {
|
|
174
|
-
if (Math.abs(this.m[i] - o[i]) > eps * Math.max(1, Math.abs(this.m[i]), Math.abs(o[i]))) return false
|
|
175
|
-
}
|
|
176
|
-
return true
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// --- factories ---
|
|
180
|
-
static identity(): Mat4 { return new Mat4() }
|
|
181
|
-
static from(src: Mat4Like): Mat4 { return new Mat4(src) }
|
|
182
|
-
|
|
183
|
-
/** Translation · Rotation · Scale into one matrix. `scale` defaults to 1 and accepts a scalar. */
|
|
184
|
-
static compose(position: Vec3Like, rotation: QuatLike, scale: Vec3Like | number = 1): Mat4 {
|
|
185
|
-
const x = qx(rotation), y = qy(rotation), z = qz(rotation), w = qw(rotation)
|
|
186
|
-
const x2 = x + x, y2 = y + y, z2 = z + z
|
|
187
|
-
const xx = x * x2, xy = x * y2, xz = x * z2
|
|
188
|
-
const yy = y * y2, yz = y * z2, zz = z * z2
|
|
189
|
-
const wx = w * x2, wy = w * y2, wz = w * z2
|
|
190
|
-
const sx = typeof scale === "number" ? scale : ax(scale)
|
|
191
|
-
const sy = typeof scale === "number" ? scale : ay(scale)
|
|
192
|
-
const sz = typeof scale === "number" ? scale : az(scale)
|
|
193
|
-
return fromArray([
|
|
194
|
-
(1 - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,
|
|
195
|
-
(xy - wz) * sy, (1 - (xx + zz)) * sy, (yz + wx) * sy, 0,
|
|
196
|
-
(xz + wy) * sz, (yz - wx) * sz, (1 - (xx + yy)) * sz, 0,
|
|
197
|
-
ax(position), ay(position), az(position), 1,
|
|
198
|
-
])
|
|
199
|
-
}
|
|
200
|
-
static fromQuat(q: QuatLike): Mat4 { return Mat4.compose(ORIGIN, q, 1) }
|
|
201
|
-
static fromTranslation(v: Vec3Like): Mat4 { const m = new Mat4(); m.m[12] = ax(v); m.m[13] = ay(v); m.m[14] = az(v); return m }
|
|
202
|
-
static fromScale(v: Vec3Like | number): Mat4 { return new Mat4().scale(v) }
|
|
203
|
-
static fromEuler(x: number, y: number, z: number, order: EulerOrder = "YXZ"): Mat4 {
|
|
204
|
-
return Mat4.fromQuat(Quat.fromEuler(x, y, z, order))
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/** A view matrix that looks from `eye` toward `center` with `up`. */
|
|
208
|
-
static lookAt(eye: Vec3Like, center: Vec3Like, up: Vec3Like = Vec3.up): Mat4 {
|
|
209
|
-
const ex = ax(eye), ey = ay(eye), ez = az(eye)
|
|
210
|
-
let z0 = ex - ax(center), z1 = ey - ay(center), z2 = ez - az(center)
|
|
211
|
-
let len = Math.hypot(z0, z1, z2)
|
|
212
|
-
if (len < 1e-6) return new Mat4()
|
|
213
|
-
len = 1 / len; z0 *= len; z1 *= len; z2 *= len
|
|
214
|
-
const ux = ax(up), uy = ay(up), uz = az(up)
|
|
215
|
-
let x0 = uy * z2 - uz * z1, x1 = uz * z0 - ux * z2, x2 = ux * z1 - uy * z0
|
|
216
|
-
len = Math.hypot(x0, x1, x2)
|
|
217
|
-
if (len) { len = 1 / len; x0 *= len; x1 *= len; x2 *= len } else { x0 = x1 = x2 = 0 }
|
|
218
|
-
const y0 = z1 * x2 - z2 * x1, y1 = z2 * x0 - z0 * x2, y2 = z0 * x1 - z1 * x0
|
|
219
|
-
return fromArray([
|
|
220
|
-
x0, y0, z0, 0, x1, y1, z1, 0, x2, y2, z2, 0,
|
|
221
|
-
-(x0 * ex + x1 * ey + x2 * ez), -(y0 * ex + y1 * ey + y2 * ez), -(z0 * ex + z1 * ey + z2 * ez), 1,
|
|
222
|
-
])
|
|
223
|
-
}
|
|
224
|
-
/** A world matrix that places something at `eye` oriented to look at `target`. */
|
|
225
|
-
static targetTo(eye: Vec3Like, target: Vec3Like, up: Vec3Like = Vec3.up): Mat4 {
|
|
226
|
-
const ex = ax(eye), ey = ay(eye), ez = az(eye)
|
|
227
|
-
let z0 = ex - ax(target), z1 = ey - ay(target), z2 = ez - az(target)
|
|
228
|
-
let len = z0 * z0 + z1 * z1 + z2 * z2
|
|
229
|
-
if (len > 0) { len = 1 / Math.sqrt(len); z0 *= len; z1 *= len; z2 *= len }
|
|
230
|
-
const ux = ax(up), uy = ay(up), uz = az(up)
|
|
231
|
-
let x0 = uy * z2 - uz * z1, x1 = uz * z0 - ux * z2, x2 = ux * z1 - uy * z0
|
|
232
|
-
len = x0 * x0 + x1 * x1 + x2 * x2
|
|
233
|
-
if (len > 0) { len = 1 / Math.sqrt(len); x0 *= len; x1 *= len; x2 *= len }
|
|
234
|
-
return fromArray([
|
|
235
|
-
x0, x1, x2, 0, z1 * x2 - z2 * x1, z2 * x0 - z0 * x2, z0 * x1 - z1 * x0, 0,
|
|
236
|
-
z0, z1, z2, 0, ex, ey, ez, 1,
|
|
237
|
-
])
|
|
238
|
-
}
|
|
239
|
-
/** Perspective projection (WebGL/OpenGL clip, NDC z ∈ [−1, 1]). `fovy` is in RADIANS. */
|
|
240
|
-
static perspective(fovy: number, aspect: number, near: number, far: number): Mat4 {
|
|
241
|
-
const f = 1 / Math.tan(fovy / 2), out = new Array(16).fill(0)
|
|
242
|
-
out[0] = f / aspect; out[5] = f; out[11] = -1
|
|
243
|
-
if (far !== Infinity) { const nf = 1 / (near - far); out[10] = (far + near) * nf; out[14] = 2 * far * near * nf }
|
|
244
|
-
else { out[10] = -1; out[14] = -2 * near }
|
|
245
|
-
return fromArray(out)
|
|
246
|
-
}
|
|
247
|
-
/** Orthographic projection (WebGL/OpenGL clip, NDC z ∈ [−1, 1]). */
|
|
248
|
-
static ortho(left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4 {
|
|
249
|
-
const lr = 1 / (left - right), bt = 1 / (bottom - top), nf = 1 / (near - far)
|
|
250
|
-
return fromArray([
|
|
251
|
-
-2 * lr, 0, 0, 0, 0, -2 * bt, 0, 0, 0, 0, 2 * nf, 0,
|
|
252
|
-
(left + right) * lr, (top + bottom) * bt, (far + near) * nf, 1,
|
|
253
|
-
])
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// fast path: wrap an already-built length-16 array as a Mat4 without re-copying it.
|
|
258
|
-
const fromArray = (m: number[]): Mat4 => { const r = Object.create(Mat4.prototype) as Mat4; r.m = m; return r }
|
|
259
|
-
|
|
260
|
-
/** The 3×3 rotation part with scale divided out, as a column-major length-≥11 array (for quat/euler). */
|
|
261
|
-
const rotationOnly = (a: ArrayLike<number>): number[] => {
|
|
262
|
-
const sx = Math.hypot(a[0], a[1], a[2]) || 1, sy = Math.hypot(a[4], a[5], a[6]) || 1, sz = Math.hypot(a[8], a[9], a[10]) || 1
|
|
263
|
-
const i1 = 1 / sx, i2 = 1 / sy, i3 = 1 / sz
|
|
264
|
-
return [ a[0] * i1, a[1] * i1, a[2] * i1, 0, a[4] * i2, a[5] * i2, a[6] * i2, 0, a[8] * i3, a[9] * i3, a[10] * i3 ]
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const ax = (v: Vec3Like): number => (v as { x?: number }).x ?? (v as ArrayLike<number>)[0]
|
|
268
|
-
const ay = (v: Vec3Like): number => (v as { y?: number }).y ?? (v as ArrayLike<number>)[1]
|
|
269
|
-
const az = (v: Vec3Like): number => (v as { z?: number }).z ?? (v as ArrayLike<number>)[2]
|
|
270
|
-
const qx = (q: QuatLike): number => (q as { x?: number }).x ?? (q as ArrayLike<number>)[0]
|
|
271
|
-
const qy = (q: QuatLike): number => (q as { y?: number }).y ?? (q as ArrayLike<number>)[1]
|
|
272
|
-
const qz = (q: QuatLike): number => (q as { z?: number }).z ?? (q as ArrayLike<number>)[2]
|
|
273
|
-
const qw = (q: QuatLike): number => (q as { w?: number }).w ?? (q as ArrayLike<number>)[3]
|
|
274
|
-
|
|
275
|
-
const AXIS_X: Vec3Like = [ 1, 0, 0 ]
|
|
276
|
-
const AXIS_Y: Vec3Like = [ 0, 1, 0 ]
|
|
277
|
-
const AXIS_Z: Vec3Like = [ 0, 0, 1 ]
|
|
278
|
-
const ORIGIN: Vec3Like = [ 0, 0, 0 ]
|