lecodes-sdk 1.0.0 → 1.1.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.
Files changed (78) hide show
  1. package/dist/global.d.ts +18 -4
  2. package/dist/types/animate/tween/Animation.d.ts +69 -0
  3. package/dist/types/animate/tween/Timeline.d.ts +55 -0
  4. package/dist/types/animate/tween/animateValue.d.ts +27 -0
  5. package/dist/types/animate/tween/easing.d.ts +29 -0
  6. package/dist/types/animate/tween/spec.d.ts +178 -0
  7. package/dist/types/g2/Node2D.d.ts +16 -0
  8. package/dist/types/g2/Sprite.d.ts +11 -1
  9. package/dist/types/gl/Camera.d.ts +15 -1
  10. package/dist/types/gl/Foliage.d.ts +47 -0
  11. package/dist/types/gl/Geometry.d.ts +24 -0
  12. package/dist/types/gl/Light.d.ts +25 -7
  13. package/dist/types/gl/Lightmap.d.ts +90 -60
  14. package/dist/types/gl/Material.d.ts +28 -20
  15. package/dist/types/gl/Model.d.ts +7 -5
  16. package/dist/types/gl/Node.d.ts +18 -0
  17. package/dist/types/gl/Particles.d.ts +40 -1
  18. package/dist/types/gl/Scene.d.ts +20 -0
  19. package/dist/types/gl/animation/AnimationClip.d.ts +19 -0
  20. package/dist/types/gl/animation/Animator.d.ts +27 -0
  21. package/dist/types/gl/animation/DynamicBone.d.ts +19 -8
  22. package/dist/types/gl/animation/IK.d.ts +86 -30
  23. package/dist/types/gl/animation/Warp.d.ts +2 -1
  24. package/dist/types/gl/animation/core.d.ts +35 -4
  25. package/dist/types/gl/physics/Ragdoll.d.ts +87 -12
  26. package/dist/types/gl/terrain/Terrain.d.ts +4 -2
  27. package/dist/types/inject.d.ts +8 -2
  28. package/dist/types/scene/defineScene.d.ts +44 -32
  29. package/dist/types/ui/UIButton.d.ts +3 -1
  30. package/dist/types/ui/UIInput.d.ts +5 -1
  31. package/dist/types/ui/UINode.d.ts +24 -24
  32. package/dist/types.json +1 -1
  33. package/package.json +1 -1
  34. package/prompts/core-design.md +27 -4
  35. package/prompts/core.md +35 -6
  36. package/prompts/select.ts +19 -4
  37. package/src/animate/tween/Animation.ts +378 -0
  38. package/src/animate/tween/Timeline.ts +175 -0
  39. package/src/animate/tween/animateValue.ts +100 -0
  40. package/src/animate/tween/easing.ts +172 -0
  41. package/src/animate/tween/spec.ts +479 -0
  42. package/src/bridges.d.ts +226 -65
  43. package/src/compile/__tests__/assetMacro.test.ts +26 -0
  44. package/src/compile/__tests__/detectEntry.test.ts +19 -0
  45. package/src/compile/__tests__/serverSplit.test.ts +27 -0
  46. package/src/compile/bundler.ts +34 -4
  47. package/src/compile/compileProject.ts +31 -1
  48. package/src/compile/detectEntry.ts +8 -3
  49. package/src/compile/index.ts +2 -0
  50. package/src/compile/serverSplit.ts +9 -3
  51. package/src/g2/Node2D.ts +38 -0
  52. package/src/g2/Sprite.ts +20 -1
  53. package/src/gl/Camera.ts +34 -1
  54. package/src/gl/Foliage.ts +102 -0
  55. package/src/gl/Geometry.ts +393 -348
  56. package/src/gl/Light.ts +46 -16
  57. package/src/gl/Lightmap.ts +439 -275
  58. package/src/gl/Material.ts +59 -47
  59. package/src/gl/Model.ts +167 -156
  60. package/src/gl/Node.ts +39 -0
  61. package/src/gl/Particles.ts +61 -2
  62. package/src/gl/Scene.ts +34 -1
  63. package/src/gl/animation/AnimationClip.ts +52 -0
  64. package/src/gl/animation/Animator.ts +42 -2
  65. package/src/gl/animation/DynamicBone.ts +482 -459
  66. package/src/gl/animation/IK.ts +173 -152
  67. package/src/gl/animation/Playback.ts +5 -4
  68. package/src/gl/animation/Warp.ts +5 -2
  69. package/src/gl/animation/core.ts +65 -4
  70. package/src/gl/physics/Ragdoll.ts +451 -272
  71. package/src/gl/terrain/Terrain.ts +4 -2
  72. package/src/inject.ts +12 -2
  73. package/src/scene/defineScene.ts +72 -62
  74. package/src/ui/UIButton.ts +2 -2
  75. package/src/ui/UIInput.ts +3 -3
  76. package/src/ui/UINode.ts +61 -36
  77. package/dist/types/animate/animate.d.ts +0 -20
  78. package/src/animate/animate.ts +0 -238
package/src/gl/Light.ts CHANGED
@@ -3,7 +3,15 @@
3
3
 
4
4
  import { Color, type ColorInput } from "../core/color"
5
5
  import type { Vec3Like } from "../math/vec"
6
- import { Node } from "./Node"
6
+ import { Node, type NodeTweenProps } from "./Node"
7
+ import { DOM_GL_LIGHT, colorValue, floatValue, type TweenChannel, type TweenMeta } from "../animate/tween/spec"
8
+ import type { Animation } from "../animate/tween/Animation"
9
+
10
+ /** Animatable light props on top of the node transform. */
11
+ export type LightTweenProps = NodeTweenProps & {
12
+ intensity?: number | number[],
13
+ color?: ColorInput | ColorInput[],
14
+ }
7
15
 
8
16
  export type SunOptions = {
9
17
  /** Light direction (points where the light travels). Defaults to a typical key-light angle. */
@@ -46,26 +54,42 @@ export type PointOptions = {
46
54
  /** Point-light shadows are a cubemap render per light; off by default. */
47
55
  castShadows?: boolean
48
56
  /**
49
- * Whether `lecodes lightmap bake` bakes this light into the level's lightmap (docs/lightmap-plan.md).
50
- * A baked light is switched OFF at runtime once the bake applies — statics read it from the atlas,
51
- * movers from the light volume — so it costs nothing per frame; a light that must stay live (a
52
- * flicker, a lamp the player can shoot out) says `baked: false` and is kept out of the bake.
53
- * Lights created after the level loads (a muzzle flash) are never in a bake. Default true.
57
+ * Whether `lecodes lightmap bake` bakes this light into the level's lightmap. A baked lamp lights the statics
58
+ * from the atlas and the MOVERS from the level's light grid, and is held dark in real time while that grid is
59
+ * loaded (without a grid it keeps lighting the movers live); a light
60
+ * that must reach the statics live too — a flicker, a lamp the player can shoot out, a muzzle flash —
61
+ * says `baked: false`: it is kept out of the bake and put on the statics' light channel. Default true.
54
62
  */
55
63
  baked?: boolean
64
+ /**
65
+ * THE BAKE'S SHAPE of this lamp: `[width, height]` in metres = an AREA light - a rectangle in the light's local XZ
66
+ * plane, emitting along its local -Y (down, for an unrotated node) with the same lumens: a ceiling panel. The bake
67
+ * lights from the whole rectangle (soft shadows, light from where the panel is and not from a point inside the
68
+ * fixture). Real time it is still the point light above. Ignored with `baked: false`.
69
+ */
70
+ bakeArea?: readonly [number, number]
56
71
  }
57
72
 
58
73
  export class Light extends Node {
59
74
  private _intensity = 0
75
+
76
+ /** Tween `intensity` / `color` (a flash, a sunrise) and the transform — see {@link Node.animateTo}. */
77
+ override animateTo(props: LightTweenProps & TweenMeta): Animation { return super.animateTo(props) }
78
+ override animateFrom(props: LightTweenProps & TweenMeta): Animation { return super.animateFrom(props) }
79
+ /** @internal */
80
+ override _tweenChannel(prop: string): TweenChannel | null {
81
+ const id = () => this.id
82
+ if (prop === "intensity") return { domain: DOM_GL_LIGHT, id, value: floatValue, commit: (v) => { this._intensity = v as number } }
83
+ if (prop === "color") return { domain: DOM_GL_LIGHT, id, value: (v) => colorValue(v, Color.toRgba01) }
84
+ return super._tweenChannel(prop)
85
+ }
60
86
  /** @internal PointOptions.baked — a candidate for the lightmap bake (default true). */
61
87
  _baked = true
62
- /** @internal the bake carries this light: the real-time one is held dark (Lightmap.load). */
63
- _bakedOff = false
64
88
  /** @internal every live point light, for the bake / the switch-off; a destroyed one leaves. */
65
89
  static _points = new Set<Light>()
66
- /** @internal sun direction as created (the engine keeps it; Lightmap.load reads it back). */
90
+ /** @internal sun direction as created (the engine keeps it). */
67
91
  _direction: [number, number, number] = [ 0, -1, 0 ]
68
- /** The most recently created sun — what `Lightmap.load` uses unless told otherwise. */
92
+ /** The most recently created sun. */
69
93
  static lastSun: Light | null = null
70
94
  /** @internal the colour as created / last set (a settings menu recreates a sun from these). */
71
95
  _color: ColorInput = 0xffffff
@@ -113,6 +137,9 @@ export class Light extends Node {
113
137
  options.range ?? 10,
114
138
  options.castShadows ?? false,
115
139
  )
140
+ if (options.bakeArea && light._baked) _creator.setLightBakeArea?.(light.id, options.bakeArea[0], options.bakeArea[1])
141
+ // an unbaked lamp lights the baked statics live: Filament channel 1 (see Lightmap)
142
+ if (!light._baked) _creator.setLightChannel?.(light.id, 1, true)
116
143
  return light
117
144
  }
118
145
 
@@ -123,14 +150,17 @@ export class Light extends Node {
123
150
  get intensity(): number { return this._intensity }
124
151
  set intensity(value: number) {
125
152
  this._intensity = value
126
- _creator.setLightIntensity?.(this.id, this._bakedOff ? 0 : value)
153
+ if (!this._heldDark) _creator.setLightIntensity?.(this.id, value)
127
154
  }
128
155
 
129
- /** @internal Hold a baked point light dark (the atlas / volume carries it) or hand it back to the real-time path. */
130
- _setBakedOff(off: boolean): void {
131
- if (this._bakedOff === off) return
132
- this._bakedOff = off
133
- _creator.setLightIntensity?.(this.id, off ? 0 : this._intensity)
156
+ /** @internal A BAKED lamp is held dark while the level's LIGHT GRID is loaded (Lightmap): the statics have it in the
157
+ * atlas and the movers in the grid's ambient cubes - left burning it lit every mover and unbaked prop a second time,
158
+ * without a shadow (through walls), and put a hot spot on its own fixture. `intensity` keeps the authored value. */
159
+ _heldDark = false
160
+ _holdDark(dark: boolean): void {
161
+ if (this._heldDark === dark) return
162
+ this._heldDark = dark
163
+ _creator.setLightIntensity?.(this.id, dark ? 0 : this._intensity)
134
164
  }
135
165
 
136
166
  destroy(): void {