lecodes-cli 0.17.1 → 0.18.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/dist/index.js +1340 -648
- package/package.json +3 -3
- package/runtime/scene-harness.json +1 -1
- package/runtime/sdk/compile/bundler.ts +1 -1
- package/runtime/sdk/compile/compileProject.ts +16 -1
- package/runtime/sdk/compile/header.ts +6 -1
- package/runtime/sdk/compile/index.ts +16 -0
- package/runtime/sdk/compile/liteMaterial.ts +247 -0
- package/runtime/sdk/compile/shaderTargets.ts +42 -0
- package/runtime/sdk/core/Aspect.ts +255 -244
- package/runtime/sdk/g2/CharacterController2D.ts +2 -2
- package/runtime/sdk/gl/Camera.ts +41 -0
- package/runtime/sdk/gl/CameraPlace.ts +51 -0
- package/runtime/sdk/gl/CharacterController.ts +6 -2
- package/runtime/sdk/gl/IK.ts +193 -174
- package/runtime/sdk/gl/Material.ts +23 -0
- package/runtime/sdk/gl/Model.ts +7 -6
- package/runtime/sdk/gl/Node.ts +270 -285
- package/runtime/sdk/gl/Particles.ts +676 -625
- package/runtime/sdk/gl/Physics.ts +53 -1
- package/runtime/sdk/gl/Scene.ts +323 -291
- package/runtime/sdk/gl/Shape.ts +248 -8
- package/runtime/sdk/gl/Trigger.ts +50 -46
- package/runtime/sdk/gl/Vehicle.ts +519 -0
- package/runtime/sdk/gl/{AnimationClip.ts → animation/AnimationClip.ts} +37 -7
- package/runtime/sdk/gl/animation/Animator.ts +87 -0
- package/runtime/sdk/gl/animation/Layer.ts +29 -0
- package/runtime/sdk/gl/animation/Loop.ts +25 -0
- package/runtime/sdk/gl/animation/Playback.ts +43 -0
- package/runtime/sdk/gl/animation/core.ts +294 -0
- package/runtime/sdk/gl/scenarios.ts +26 -58
- package/runtime/sdk/inject.ts +18 -9
- package/runtime/sdk/runtime/app.ts +13 -0
- package/runtime/sdk/runtime/input.ts +169 -6
- package/runtime/sdk/scene/defineScene.ts +182 -26
- package/runtime/sdk/scene/gizmos.ts +128 -0
- package/runtime/sdk-types.json +1 -1
- package/runtime/sdk/gl/Animator.ts +0 -642
- package/runtime/sdk/gl/ModelAnimation.ts +0 -95
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Editor gizmos: immediate-mode line drawing for code that runs while a scene is EDITED — a
|
|
2
|
+
// generator aspect's `rebuild()`, a `make()` factory, an editor tool's hooks. Nothing here touches
|
|
3
|
+
// the scene: calls accumulate WORLD-space line segments into the buffer of the run that is
|
|
4
|
+
// currently executing (an ambient scope the scene loader opens around each synchronous call), and
|
|
5
|
+
// the scene editor pushes those buffers to the lite engine's overlay layer, which draws them over
|
|
6
|
+
// the picture — never outlined, never picked, never rendered by Filament, absent in play mode.
|
|
7
|
+
//
|
|
8
|
+
// rebuild() {
|
|
9
|
+
// Gizmos.polyline(points, { color: "#5b8ef0", closed: true })
|
|
10
|
+
// for (const p of points) Gizmos.cross(p, 0.07)
|
|
11
|
+
// }
|
|
12
|
+
//
|
|
13
|
+
// Every run starts with an EMPTY buffer — what a call draws is the whole picture (like
|
|
14
|
+
// `generated.clear()`, only implicit). Outside any scope (play mode, hand-attached aspects, a call
|
|
15
|
+
// after an `await` inside rebuild) the calls are no-ops: rebuild is synchronous by contract.
|
|
16
|
+
|
|
17
|
+
import { Mat4, type Mat4Like } from "../math/mat4"
|
|
18
|
+
import type { Vec3Like } from "../math/vec"
|
|
19
|
+
|
|
20
|
+
export type GizmoStyle = {
|
|
21
|
+
/** CSS hex color (`#rgb` / `#rrggbb`); default a neutral light gray. */
|
|
22
|
+
color?: string
|
|
23
|
+
/** 0..1, default 1. */
|
|
24
|
+
alpha?: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** One color batch of world-space LINES (flat `[x,y,z, x,y,z]` per segment) — what a host hands
|
|
28
|
+
* the engine. */
|
|
29
|
+
export type GizmoBatch = { color: string, alpha: number, segments: number[] }
|
|
30
|
+
|
|
31
|
+
const DEFAULT_COLOR = "#cfd4dd"
|
|
32
|
+
|
|
33
|
+
/** The per-run collector (owned by the scene loader's EditorRun). Batches are keyed by style so a
|
|
34
|
+
* hundred same-colored segments cost one draw. */
|
|
35
|
+
export class GizmoBuffer {
|
|
36
|
+
batches: GizmoBatch[] = []
|
|
37
|
+
private _byStyle = new Map<string, GizmoBatch>()
|
|
38
|
+
|
|
39
|
+
clear(): void {
|
|
40
|
+
this.batches = []
|
|
41
|
+
this._byStyle.clear()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
segments(style: GizmoStyle | undefined): number[] {
|
|
45
|
+
const color = style?.color ?? DEFAULT_COLOR
|
|
46
|
+
const alpha = Math.max(0, Math.min(1, style?.alpha ?? 1))
|
|
47
|
+
const key = `${color}@${alpha}`
|
|
48
|
+
let b = this._byStyle.get(key)
|
|
49
|
+
if (!b) {
|
|
50
|
+
b = { color, alpha, segments: [] }
|
|
51
|
+
this._byStyle.set(key, b)
|
|
52
|
+
this.batches.push(b)
|
|
53
|
+
}
|
|
54
|
+
return b.segments
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let current: GizmoBuffer | null = null
|
|
59
|
+
let warnedOutOfScope = false
|
|
60
|
+
|
|
61
|
+
const xyz = (p: Vec3Like): [number, number, number] =>
|
|
62
|
+
Array.isArray(p) ? [ p[0] ?? 0, p[1] ?? 0, p[2] ?? 0 ] : [ (p as { x: number }).x, (p as { y: number }).y, (p as { z: number }).z ]
|
|
63
|
+
|
|
64
|
+
const target = (style: GizmoStyle | undefined): number[] | null => {
|
|
65
|
+
if (current) return current.segments(style)
|
|
66
|
+
if (!warnedOutOfScope && (globalThis as { __lecodesSceneEdit?: boolean }).__lecodesSceneEdit) {
|
|
67
|
+
warnedOutOfScope = true
|
|
68
|
+
console.warn("[Gizmos] draw call outside an editor run — gizmos must be drawn synchronously inside rebuild() / a make() factory / a tool hook")
|
|
69
|
+
}
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** @internal Run `fn` with `buffer` as the ambient gizmo target (cleared first). Nested scopes
|
|
74
|
+
* restore the outer one. */
|
|
75
|
+
export const withGizmoScope = <T>(buffer: GizmoBuffer, fn: () => T): T => {
|
|
76
|
+
const prev = current
|
|
77
|
+
buffer.clear()
|
|
78
|
+
current = buffer
|
|
79
|
+
try { return fn() } finally { current = prev }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Editor-only line drawing, available inside generator `rebuild()`, `make()` factories and editor
|
|
84
|
+
* tool hooks. Points are WORLD space. Drawn by the scene editor's viewport overlay (depth-test
|
|
85
|
+
* off — a path through a wall is still a path); invisible everywhere else.
|
|
86
|
+
*/
|
|
87
|
+
export const Gizmos = {
|
|
88
|
+
/** One segment from `a` to `b`. */
|
|
89
|
+
line(a: Vec3Like, b: Vec3Like, style?: GizmoStyle): void {
|
|
90
|
+
const out = target(style)
|
|
91
|
+
if (!out) return
|
|
92
|
+
out.push(...xyz(a), ...xyz(b))
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
/** Consecutive segments through `points`; `closed` joins the last point back to the first. */
|
|
96
|
+
polyline(points: readonly Vec3Like[], style?: GizmoStyle & { closed?: boolean }): void {
|
|
97
|
+
if (points.length < 2) return
|
|
98
|
+
const out = target(style)
|
|
99
|
+
if (!out) return
|
|
100
|
+
const n = points.length
|
|
101
|
+
const last = style?.closed ? n : n - 1
|
|
102
|
+
for (let i = 0; i < last; i++) out.push(...xyz(points[i]!), ...xyz(points[(i + 1) % n]!))
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
/** A wireframe camera frustum looking down a node's local −Z (the `CameraPlace` marker): the
|
|
106
|
+
* four edges from the node origin to a far rect `length` metres ahead sized by `fov` (vertical,
|
|
107
|
+
* degrees) × `aspect`, plus an "up" fin above the rect. Points are transformed by `worldMatrix`. */
|
|
108
|
+
frustum(worldMatrix: Mat4Like, fov: number, aspect = 16 / 9, length = 0.6, style?: GizmoStyle): void {
|
|
109
|
+
const out = target(style)
|
|
110
|
+
if (!out) return
|
|
111
|
+
const m = new Mat4(worldMatrix)
|
|
112
|
+
const h = Math.tan((fov * Math.PI) / 360) * length, w = h * aspect, z = -length
|
|
113
|
+
const P = (x: number, y: number, zz: number): [number, number, number] => { const v = m.transformPoint([ x, y, zz ]); return [ v.x, v.y, v.z ] }
|
|
114
|
+
const o = P(0, 0, 0)
|
|
115
|
+
const c = [ P(-w, -h, z), P(w, -h, z), P(w, h, z), P(-w, h, z) ]
|
|
116
|
+
for (const q of c) out.push(...o, ...q)
|
|
117
|
+
for (let i = 0; i < 4; i++) out.push(...c[i]!, ...c[(i + 1) % 4]!)
|
|
118
|
+
out.push(...P(-w * 0.4, h, z), ...P(0, h * 1.6, z), ...P(0, h * 1.6, z), ...P(w * 0.4, h, z))
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
/** A three-axis cross centred on `p` (a point marker); `size` = half extent, default 0.1. */
|
|
122
|
+
cross(p: Vec3Like, size = 0.1, style?: GizmoStyle): void {
|
|
123
|
+
const out = target(style)
|
|
124
|
+
if (!out) return
|
|
125
|
+
const [ x, y, z ] = xyz(p)
|
|
126
|
+
out.push(x - size, y, z, x + size, y, z, x, y - size, z, x, y + size, z, x, y, z - size, x, y, z + size)
|
|
127
|
+
},
|
|
128
|
+
}
|