lecodes-cli 0.18.2 → 0.19.2
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/dist/index.js +1866 -301
- package/package.json +14 -12
- package/runtime/scene-harness.json +1 -1
- package/runtime/sdk-types.json +1 -1
- package/src/api.ts +302 -0
- package/src/browserAuth.ts +87 -0
- package/src/cmgenTool.ts +104 -0
- package/src/commands/app.ts +891 -0
- package/src/commands/appAndroid.ts +603 -0
- package/src/commands/appDesktop.ts +326 -0
- package/src/commands/appDesktopMac.ts +470 -0
- package/src/commands/appIcon.ts +187 -0
- package/src/commands/appShared.ts +448 -0
- package/src/commands/appTemplates.ts +883 -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 +122 -0
- package/src/commands/dev.ts +214 -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 +129 -0
- package/src/commands/pull.ts +109 -0
- package/src/commands/push.ts +173 -0
- package/src/commands/render.ts +414 -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 +370 -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 +532 -0
- package/src/desktopScript.ts +276 -0
- package/src/dev/clientTemplates.ts +160 -0
- package/src/dev/devServer.ts +292 -0
- package/src/dev/wsServer.ts +144 -0
- package/src/distRoot.ts +20 -0
- package/src/ignore.ts +163 -0
- package/src/index.ts +491 -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/core/Aspect.ts +0 -512
- package/runtime/sdk/core/InspectorUI.ts +0 -212
- 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 -81
- 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 -99
- package/runtime/sdk/gl/Lightmap.ts +0 -179
- package/runtime/sdk/gl/Material.ts +0 -245
- package/runtime/sdk/gl/Mesh.ts +0 -83
- package/runtime/sdk/gl/Model.ts +0 -64
- 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/Ray.ts +0 -16
- package/runtime/sdk/gl/Scene.ts +0 -479
- package/runtime/sdk/gl/Shape.ts +0 -377
- package/runtime/sdk/gl/Texture.ts +0 -46
- 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 -87
- package/runtime/sdk/gl/animation/Layer.ts +0 -29
- package/runtime/sdk/gl/animation/Loop.ts +0 -25
- package/runtime/sdk/gl/animation/Playback.ts +0 -43
- package/runtime/sdk/gl/animation/core.ts +0 -294
- 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/touch.ts +0 -68
- package/runtime/sdk/inject.ts +0 -186
- 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/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 -1227
- package/runtime/sdk/scene/editorPlugins.ts +0 -92
- 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 -826
- 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
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
// Rigid body as an aspect on a 3D Node, backed by a JoltPhysics body in creator-gl. Requires a Shape
|
|
2
|
-
// aspect on the same node (its geometry becomes the body's collision shape).
|
|
3
|
-
//
|
|
4
|
-
// Physics.configure({ gravity: [0, -9.81, 0] }) // once, before creating bodies
|
|
5
|
-
// ground.aspect(Shape, { box: [20, 0.5, 20] }).aspect(Physics, { motion: 'static' })
|
|
6
|
-
// crate.aspect(Shape, {}).aspect(Physics, { mass: 2 }) // auto box from the mesh
|
|
7
|
-
// crate.physics.applyImpulse([0, 6, 0])
|
|
8
|
-
// crate.addEventListener('enter', other => …) // contact / trigger overlap began
|
|
9
|
-
//
|
|
10
|
-
// For a `dynamic` body, physics OWNS the transform — do NOT set node.position per frame; drive it via
|
|
11
|
-
// velocity / applyImpulse. Reading node.position is free (native already wrote it). A `position` write
|
|
12
|
-
// is a TELEPORT that reaches the body (Shape routes it), which is how a kinematic body is placed too.
|
|
13
|
-
|
|
14
|
-
import { Aspect } from "../core/Aspect"
|
|
15
|
-
import type { FieldMeta } from "../core/fields"
|
|
16
|
-
import type { CompAxis, CompWriter } from "../core/compWrite"
|
|
17
|
-
import { Vec3, cx, cy, cz, type Vec3Like } from "../math/vec"
|
|
18
|
-
import { nodeRegistry, type Node } from "./Node"
|
|
19
|
-
import { Shape } from "./Shape"
|
|
20
|
-
|
|
21
|
-
export type MotionType = "static" | "dynamic" | "kinematic"
|
|
22
|
-
const MOTION: Record<MotionType, number> = { static: 0, kinematic: 1, dynamic: 2 }
|
|
23
|
-
// Jolt's angular velocity is rad/s; every angle the SDK exposes is in degrees (like `eulerAngles`).
|
|
24
|
-
const DEG2RAD = Math.PI / 180
|
|
25
|
-
const RAD2DEG = 180 / Math.PI
|
|
26
|
-
// Scratch for velocity reads (one per module, never handed out) — a read allocates the Vec3 only.
|
|
27
|
-
const scratch = new Float32Array(3)
|
|
28
|
-
|
|
29
|
-
export interface PhysicsConfig {
|
|
30
|
-
/** Gravity in world units/s² (Y-up: down is negative). Default [0, -9.81, 0]. */
|
|
31
|
-
gravity?: Vec3Like
|
|
32
|
-
/** Max simultaneous bodies (resizes the world; only before any body exists). Default 4096. */
|
|
33
|
-
maxBodies?: number
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Closest raycast hit. */
|
|
37
|
-
export interface RayHit {
|
|
38
|
-
node: Node | null
|
|
39
|
-
point: Vec3
|
|
40
|
-
normal: Vec3
|
|
41
|
-
fraction: number
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* What a body's friction already is the moment the host creates it. This is part of the ABI, not an
|
|
46
|
-
* assumption: bridges.d.ts states it, so every host owes us this value. Knowing it lets attach skip
|
|
47
|
-
* a bridge call per body whenever nobody named a surface.
|
|
48
|
-
*/
|
|
49
|
-
export const DEFAULT_FRICTION = 0.6
|
|
50
|
-
|
|
51
|
-
export class Physics extends Aspect<"physics", Node> implements CompWriter {
|
|
52
|
-
static readonly aspect = "physics"
|
|
53
|
-
|
|
54
|
-
/** Render interpolation of body transforms between the fixed 60 Hz steps (global; default on). Turn
|
|
55
|
-
* off to save per-frame transform writes when you have many moving bodies / don't need >60 Hz
|
|
56
|
-
* smoothness — bodies then advance in discrete steps. */
|
|
57
|
-
private static _interpolation = true
|
|
58
|
-
static get interpolation(): boolean { return Physics._interpolation }
|
|
59
|
-
static set interpolation(on: boolean) { Physics._interpolation = on; _creator.setInterpolation(on) }
|
|
60
|
-
|
|
61
|
-
/** Default "dynamic". */
|
|
62
|
-
motion: MotionType = "dynamic"
|
|
63
|
-
/** Mass in kg for dynamic bodies (default 1). Ignored for static/kinematic. */
|
|
64
|
-
mass = 1
|
|
65
|
-
/**
|
|
66
|
-
* Surface friction: 0 = ice, ~1 = grippy asphalt, and values above 1 are allowed (rubber on
|
|
67
|
-
* tarmac).
|
|
68
|
-
*
|
|
69
|
-
* The engine COMBINES the two touching bodies as `sqrt(a * b)`, so the LOWER value dominates and
|
|
70
|
-
* the floor caps everything standing on it. The default **0.6** is a neutral solid surface (the
|
|
71
|
-
* raw Jolt default of 0.2 is ice by game standards); dry tarmac a car should corner on wants a
|
|
72
|
-
* `1`, ice `0.02`. A Vehicle's tires read the GROUND body's value, so this is the single number
|
|
73
|
-
* that decides how well a car corners.
|
|
74
|
-
*
|
|
75
|
-
* Change it at runtime by re-configuring — `floor.aspect(Physics, { friction: 0.02 })` (an ice
|
|
76
|
-
* patch) — or by assigning `floor.physics.friction = 0.02`; either way the setter pushes the new
|
|
77
|
-
* surface to the live body at once. (chisel keeps an instance setter whose name appears as an
|
|
78
|
-
* object-literal key anywhere in the bundle, so the config-object route survives tree-shaking
|
|
79
|
-
* even when no code reads `.friction`.)
|
|
80
|
-
*/
|
|
81
|
-
get friction(): number { return this._friction }
|
|
82
|
-
set friction(v: number) {
|
|
83
|
-
this._friction = v
|
|
84
|
-
// Unconditional on a live body, unlike attach: it may be on its way BACK to the default from
|
|
85
|
-
// something else, and skipping that would leave the ice patch in place.
|
|
86
|
-
if (this._bodyId) _creator.physicsSetFriction?.(this._bodyId, v)
|
|
87
|
-
}
|
|
88
|
-
private _friction = DEFAULT_FRICTION
|
|
89
|
-
|
|
90
|
-
/** Scene-editor inspector: `motion` as a dropdown (a string default alone infers a text box). */
|
|
91
|
-
static fields: FieldMeta<Physics> = {
|
|
92
|
-
motion: { options: [ "static", "kinematic", "dynamic" ] },
|
|
93
|
-
mass: { min: 0, step: 0.1 },
|
|
94
|
-
friction: { min: 0, max: 2, step: 0.05 },
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
private _bodyId = 0
|
|
98
|
-
|
|
99
|
-
onAttach(): void {
|
|
100
|
-
if (!_creator.physicsHasSupport || !_creator.physicsHasSupport()) return
|
|
101
|
-
const shape = this.node.get(Shape)
|
|
102
|
-
if (!shape) {
|
|
103
|
-
throw new Error("Physics requires a Shape aspect — add it first: node.aspect(Shape, {…}).aspect(Physics, {…})")
|
|
104
|
-
}
|
|
105
|
-
if (this.motion === "dynamic" && shape._isTriangleMesh) {
|
|
106
|
-
throw new Error("Physics: a dynamic body cannot use Shape { mesh: true } (triangle meshes are static/kinematic only) — use { mesh: 'convex' } or a primitive shape")
|
|
107
|
-
}
|
|
108
|
-
const shapeId = shape._claim() // drop the pick-only body; reuse its shape
|
|
109
|
-
this._bodyId = _creator.physicsCreateBody(this.node.id, shapeId, MOTION[this.motion], this.mass, false, false)
|
|
110
|
-
// A fresh body already carries DEFAULT_FRICTION host-side, so only a NAMED surface has to
|
|
111
|
-
// travel — the common case costs no bridge call at all.
|
|
112
|
-
if (this._friction !== DEFAULT_FRICTION) _creator.physicsSetFriction?.(this._bodyId, this._friction)
|
|
113
|
-
shape._ownBody(this._bodyId)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
onDetach(): void {
|
|
117
|
-
if (this._bodyId) { _creator.physicsRemoveBody(this._bodyId); this._bodyId = 0 }
|
|
118
|
-
const shape = this.node.get(Shape)
|
|
119
|
-
if (shape) {
|
|
120
|
-
shape._ownBody(0) // the Shape held OUR body id — forget it, or its own detach removes it twice (native crash)
|
|
121
|
-
shape._recreatePickBody() // keep the node pickable if the Shape stays
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Native Jolt body id. 0 until attached, or if the build has no physics support. */
|
|
126
|
-
get id(): number { return this._bodyId }
|
|
127
|
-
|
|
128
|
-
/** Linear velocity in world units/second (fresh Vec3 on read; `velocity.y = 5` written directly on
|
|
129
|
-
* the aspect is compiled to a component write — see `_writeComp`). */
|
|
130
|
-
get velocity(): Vec3 {
|
|
131
|
-
if (!this._bodyId) return new Vec3(0, 0, 0)
|
|
132
|
-
_creator.physicsGetLinearVelocity(this._bodyId, scratch)
|
|
133
|
-
return new Vec3(scratch[0], scratch[1], scratch[2])
|
|
134
|
-
}
|
|
135
|
-
set velocity(v: Vec3Like) {
|
|
136
|
-
if (this._bodyId) _creator.physicsSetLinearVelocity(this._bodyId, cx(v), cy(v), cz(v))
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Angular velocity — **degrees/second about each world axis** (the SDK's angle unit everywhere;
|
|
141
|
-
* the engine works in radians and converts here). Fresh Vec3 on read.
|
|
142
|
-
*
|
|
143
|
-
* This is the only handle on a body's spin, and placing an object usually needs it: a `position`
|
|
144
|
-
* write is a pure teleport, so a crate that was tumbling keeps tumbling at its new home. Putting
|
|
145
|
-
* something down is `body.velocity = [0,0,0]; body.angularVelocity = [0,0,0]; node.position = p`.
|
|
146
|
-
*/
|
|
147
|
-
get angularVelocity(): Vec3 {
|
|
148
|
-
if (!this._bodyId || !_creator.physicsGetAngularVelocity) return new Vec3(0, 0, 0)
|
|
149
|
-
_creator.physicsGetAngularVelocity(this._bodyId, scratch)
|
|
150
|
-
return new Vec3(scratch[0] * RAD2DEG, scratch[1] * RAD2DEG, scratch[2] * RAD2DEG)
|
|
151
|
-
}
|
|
152
|
-
set angularVelocity(v: Vec3Like) {
|
|
153
|
-
if (this._bodyId && _creator.physicsSetAngularVelocity) {
|
|
154
|
-
_creator.physicsSetAngularVelocity(this._bodyId, cx(v) * DEG2RAD, cy(v) * DEG2RAD, cz(v) * DEG2RAD)
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** @internal chisel `comp_write` (see core/compWrite.ts): `body.velocity.y = v` / `body.angularVelocity.z
|
|
159
|
-
* = v` written directly on the aspect compile to a call here — one read into the scratch, one set, no
|
|
160
|
-
* vector. The list is compile-time data. */
|
|
161
|
-
static _comps = [ "velocity", "angularVelocity" ]
|
|
162
|
-
_writeComp(prop: string, axis: CompAxis, v: number): void {
|
|
163
|
-
if (!this._bodyId || axis === "w") return
|
|
164
|
-
const i = axis === "x" ? 0 : axis === "y" ? 1 : 2
|
|
165
|
-
if (prop === "velocity") {
|
|
166
|
-
_creator.physicsGetLinearVelocity(this._bodyId, scratch)
|
|
167
|
-
scratch[i] = v
|
|
168
|
-
_creator.physicsSetLinearVelocity(this._bodyId, scratch[0], scratch[1], scratch[2])
|
|
169
|
-
} else if (_creator.physicsGetAngularVelocity && _creator.physicsSetAngularVelocity) {
|
|
170
|
-
_creator.physicsGetAngularVelocity(this._bodyId, scratch)
|
|
171
|
-
scratch[i] = v * DEG2RAD
|
|
172
|
-
_creator.physicsSetAngularVelocity(this._bodyId, scratch[0], scratch[1], scratch[2])
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/** Apply an instantaneous impulse (kg·m/s) and wake the body. */
|
|
177
|
-
applyImpulse(v: Vec3Like): this {
|
|
178
|
-
if (this._bodyId) _creator.physicsApplyImpulse(this._bodyId, cx(v), cy(v), cz(v))
|
|
179
|
-
return this
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/** The same impulse applied at a WORLD-SPACE point instead of the centre of mass: the lever arm
|
|
183
|
-
* becomes angular impulse, so the body spins as well as moves (a bullet hitting a crate off
|
|
184
|
-
* centre, a blast lifting it by its base). Falls back to the central impulse on an older host. */
|
|
185
|
-
applyImpulseAt(v: Vec3Like, point: Vec3Like): this {
|
|
186
|
-
if (!this._bodyId) return this
|
|
187
|
-
if (_creator.physicsApplyImpulseAt) {
|
|
188
|
-
_creator.physicsApplyImpulseAt(this._bodyId, cx(v), cy(v), cz(v), cx(point), cy(point), cz(point))
|
|
189
|
-
} else {
|
|
190
|
-
_creator.physicsApplyImpulse(this._bodyId, cx(v), cy(v), cz(v))
|
|
191
|
-
}
|
|
192
|
-
return this
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// No moveTo(): `node.position = p` IS the move. Shape hands the body id to the node, so a position
|
|
196
|
-
// write reaches the body — one way to place anything, whether or not physics is involved.
|
|
197
|
-
|
|
198
|
-
// --- world (static) -------------------------------------------------------------------------
|
|
199
|
-
/** Configure gravity / limits. Call once before creating bodies. */
|
|
200
|
-
static configure(config: PhysicsConfig = {}): void {
|
|
201
|
-
const g = config.gravity ?? [0, -9.81, 0]
|
|
202
|
-
_creator.physicsConfigure(cx(g), cy(g), cz(g), config.maxBodies ?? 0)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/** Whether this build has physics support (CREATOR_GL_PHYSICS). */
|
|
206
|
-
static get supported(): boolean {
|
|
207
|
-
return !!_creator.physicsHasSupport && _creator.physicsHasSupport()
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/** Closest pickable body hit by the ray from `origin` along `dir` (up to `maxDist`), or null. */
|
|
211
|
-
static raycast(origin: Vec3Like, dir: Vec3Like, maxDist = 1000): RayHit | null {
|
|
212
|
-
const out = new Float32Array(7)
|
|
213
|
-
const id = _creator.physicsRaycast(cx(origin), cy(origin), cz(origin), cx(dir), cy(dir), cz(dir), maxDist, out)
|
|
214
|
-
if (!id) return null
|
|
215
|
-
return {
|
|
216
|
-
node: nodeRegistry.get(id) ?? null,
|
|
217
|
-
point: new Vec3(out[0], out[1], out[2]),
|
|
218
|
-
normal: new Vec3(out[3], out[4], out[5]),
|
|
219
|
-
fraction: out[6],
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
package/runtime/sdk/gl/Plane.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// A geometric plane (point + normal) with ray intersection. Ported from worker/src/utils/Plane.ts
|
|
2
|
-
// onto the SDK's fluent Vec3 (the mat4 transform() method is omitted — add if needed).
|
|
3
|
-
|
|
4
|
-
import { Vec3, type Vec3Like } from "../math/vec"
|
|
5
|
-
import type { Ray } from "./Ray"
|
|
6
|
-
|
|
7
|
-
export class Plane {
|
|
8
|
-
/** Unit normal. */
|
|
9
|
-
readonly normal: Vec3
|
|
10
|
-
/** Scalar offset: dot(normal, point). */
|
|
11
|
-
readonly d: number
|
|
12
|
-
|
|
13
|
-
constructor(normal: Vec3Like, point: Vec3Like) {
|
|
14
|
-
this.normal = new Vec3(normal).normalize()
|
|
15
|
-
this.d = this.normal.dot(point)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static fromPoints(a: Vec3Like, b: Vec3Like, c: Vec3Like): Plane {
|
|
19
|
-
const A = new Vec3(a)
|
|
20
|
-
return new Plane(new Vec3(b).sub(A).cross(new Vec3(c).sub(A)), a)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static fromCoefficients(a: number, b: number, c: number, d: number): Plane {
|
|
24
|
-
const len = Math.hypot(a, b, c)
|
|
25
|
-
const l2 = len * len
|
|
26
|
-
return new Plane([ a, b, c ], [ (a * d) / l2, (b * d) / l2, (c * d) / l2 ])
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Ray-plane parameter t (≥0), or null on a miss (parallel / behind origin). */
|
|
30
|
-
intersectRay(ray: Ray): number | null {
|
|
31
|
-
const denom = this.normal.dot(ray.dir)
|
|
32
|
-
if (Math.abs(denom) < 1e-8) return null
|
|
33
|
-
const t = (this.d - this.normal.dot(ray.origin)) / denom
|
|
34
|
-
return t < 0 ? null : t
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Like intersectRay but allows hits behind the origin (line-plane). */
|
|
38
|
-
intersectLine(ray: Ray): number | null {
|
|
39
|
-
const denom = this.normal.dot(ray.dir)
|
|
40
|
-
if (Math.abs(denom) < 1e-8) return null
|
|
41
|
-
return (this.d - this.normal.dot(ray.origin)) / denom
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Signed distance from a point (positive on the normal's side). */
|
|
45
|
-
signedDistance(point: Vec3Like): number {
|
|
46
|
-
return this.normal.dot(point) - this.d
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Project a point onto the plane. */
|
|
50
|
-
projectPoint(point: Vec3Like): Vec3 {
|
|
51
|
-
return new Vec3(point).scaleAndAdd(this.normal, -this.signedDistance(point))
|
|
52
|
-
}
|
|
53
|
-
}
|
package/runtime/sdk/gl/Ray.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// A ray defined by an origin and a (not necessarily normalized) direction.
|
|
2
|
-
|
|
3
|
-
import { Vec3, type Vec3Like } from "../math/vec"
|
|
4
|
-
|
|
5
|
-
export class Ray {
|
|
6
|
-
readonly origin: Vec3
|
|
7
|
-
readonly dir: Vec3
|
|
8
|
-
|
|
9
|
-
constructor(origin: Vec3Like, dir: Vec3Like) {
|
|
10
|
-
this.origin = new Vec3(origin)
|
|
11
|
-
this.dir = new Vec3(dir)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** The world-space point origin + t·dir. */
|
|
15
|
-
getPoint(t: number): Vec3 { return this.origin.scaleAndAdd(this.dir, t) }
|
|
16
|
-
}
|