lecodes-sdk 1.0.0 → 1.2.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 (94) hide show
  1. package/dist/global.d.ts +18 -4
  2. package/dist/inject.js +260 -361
  3. package/dist/types/animate/tween/Animation.d.ts +69 -0
  4. package/dist/types/animate/tween/Timeline.d.ts +55 -0
  5. package/dist/types/animate/tween/animateValue.d.ts +27 -0
  6. package/dist/types/animate/tween/easing.d.ts +29 -0
  7. package/dist/types/animate/tween/spec.d.ts +178 -0
  8. package/dist/types/g2/Node2D.d.ts +16 -0
  9. package/dist/types/g2/Sprite.d.ts +11 -1
  10. package/dist/types/gl/Camera.d.ts +15 -1
  11. package/dist/types/gl/Foliage.d.ts +47 -0
  12. package/dist/types/gl/Geometry.d.ts +24 -0
  13. package/dist/types/gl/Light.d.ts +28 -7
  14. package/dist/types/gl/Lightmap.d.ts +90 -60
  15. package/dist/types/gl/Material.d.ts +28 -20
  16. package/dist/types/gl/Model.d.ts +7 -5
  17. package/dist/types/gl/Node.d.ts +18 -0
  18. package/dist/types/gl/Particles.d.ts +55 -1
  19. package/dist/types/gl/Scene.d.ts +20 -0
  20. package/dist/types/gl/animation/AnimationClip.d.ts +19 -0
  21. package/dist/types/gl/animation/Animator.d.ts +27 -0
  22. package/dist/types/gl/animation/DynamicBone.d.ts +19 -8
  23. package/dist/types/gl/animation/IK.d.ts +86 -30
  24. package/dist/types/gl/animation/Locomotion.d.ts +52 -3
  25. package/dist/types/gl/animation/Warp.d.ts +2 -1
  26. package/dist/types/gl/animation/core.d.ts +35 -4
  27. package/dist/types/gl/physics/Ragdoll.d.ts +87 -12
  28. package/dist/types/gl/terrain/Terrain.d.ts +12 -2
  29. package/dist/types/inject.d.ts +8 -2
  30. package/dist/types/runtime/input.d.ts +7 -0
  31. package/dist/types/scene/defineScene.d.ts +44 -32
  32. package/dist/types/ui/UIButton.d.ts +3 -1
  33. package/dist/types/ui/UIInput.d.ts +5 -1
  34. package/dist/types/ui/UINode.d.ts +24 -24
  35. package/dist/types.json +1 -1
  36. package/package.json +1 -1
  37. package/prompts/README.md +142 -142
  38. package/prompts/core-design.md +27 -4
  39. package/prompts/core.md +35 -6
  40. package/prompts/dist/2d-game.md +197 -408
  41. package/prompts/dist/3d-app.md +166 -491
  42. package/prompts/dist/ar-app.md +163 -373
  43. package/prompts/dist/design.md +87 -83
  44. package/prompts/dist/ui-app.md +136 -325
  45. package/prompts/select.ts +19 -4
  46. package/src/animate/tween/Animation.ts +378 -0
  47. package/src/animate/tween/Timeline.ts +175 -0
  48. package/src/animate/tween/animateValue.ts +100 -0
  49. package/src/animate/tween/easing.ts +172 -0
  50. package/src/animate/tween/spec.ts +479 -0
  51. package/src/audio/audio.ts +161 -161
  52. package/src/bridges.d.ts +235 -65
  53. package/src/compile/__tests__/assetMacro.test.ts +26 -0
  54. package/src/compile/__tests__/detectEntry.test.ts +19 -0
  55. package/src/compile/__tests__/serverSplit.test.ts +27 -0
  56. package/src/compile/bundler.ts +34 -4
  57. package/src/compile/compileProject.ts +31 -1
  58. package/src/compile/detectEntry.ts +8 -3
  59. package/src/compile/index.ts +2 -0
  60. package/src/compile/serverSplit.ts +9 -3
  61. package/src/g2/Node2D.ts +38 -0
  62. package/src/g2/Sprite.ts +20 -1
  63. package/src/gl/Camera.ts +34 -1
  64. package/src/gl/CameraPlace.ts +52 -52
  65. package/src/gl/Foliage.ts +102 -0
  66. package/src/gl/Geometry.ts +393 -348
  67. package/src/gl/Light.ts +49 -16
  68. package/src/gl/Lightmap.ts +439 -275
  69. package/src/gl/Material.ts +59 -47
  70. package/src/gl/Mesh.ts +120 -120
  71. package/src/gl/Model.ts +23 -12
  72. package/src/gl/Node.ts +39 -0
  73. package/src/gl/Particles.ts +80 -2
  74. package/src/gl/Scene.ts +34 -1
  75. package/src/gl/animation/AnimationClip.ts +52 -0
  76. package/src/gl/animation/Animator.ts +42 -2
  77. package/src/gl/animation/DynamicBone.ts +35 -12
  78. package/src/gl/animation/IK.ts +173 -152
  79. package/src/gl/animation/Locomotion.ts +72 -8
  80. package/src/gl/animation/Playback.ts +5 -4
  81. package/src/gl/animation/Warp.ts +5 -2
  82. package/src/gl/animation/core.ts +65 -4
  83. package/src/gl/physics/Ragdoll.ts +451 -272
  84. package/src/gl/scenarios.ts +291 -291
  85. package/src/gl/terrain/Terrain.ts +33 -2
  86. package/src/inject.ts +236 -226
  87. package/src/runtime/input.ts +11 -0
  88. package/src/scene/defineScene.ts +72 -62
  89. package/src/scene/gizmos.ts +148 -148
  90. package/src/ui/UIButton.ts +2 -2
  91. package/src/ui/UIInput.ts +3 -3
  92. package/src/ui/UINode.ts +61 -36
  93. package/dist/types/animate/animate.d.ts +0 -20
  94. 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. */
@@ -19,6 +27,9 @@ export type SunOptions = {
19
27
  * 3 - 2048 map, contact-hardening soft edges (PCSS: sharp where the caster touches, softer
20
28
  * away; discrete-GPU territory, ~+60 % of a frame on an iGPU)
21
29
  * A lightmapped level already carries every static shadow, so 0 is a legitimate choice there.
30
+ * On a level with a baked light grid the variance / PCSS filters cannot be used (they need every
31
+ * receiver in the shadow map, and the baked statics are kept out of it): 3 renders as PCSS on the
32
+ * depth map - the same contact-hardening look - and 2 renders as 1.
22
33
  */
23
34
  shadowsQuality?: 0 | 1 | 2 | 3
24
35
  /**
@@ -46,26 +57,42 @@ export type PointOptions = {
46
57
  /** Point-light shadows are a cubemap render per light; off by default. */
47
58
  castShadows?: boolean
48
59
  /**
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.
60
+ * Whether `lecodes lightmap bake` bakes this light into the level's lightmap. A baked lamp lights the statics
61
+ * from the atlas and the MOVERS from the level's light grid, and is held dark in real time while that grid is
62
+ * loaded (without a grid it keeps lighting the movers live); a light
63
+ * that must reach the statics live too — a flicker, a lamp the player can shoot out, a muzzle flash —
64
+ * says `baked: false`: it is kept out of the bake and put on the statics' light channel. Default true.
54
65
  */
55
66
  baked?: boolean
67
+ /**
68
+ * THE BAKE'S SHAPE of this lamp: `[width, height]` in metres = an AREA light - a rectangle in the light's local XZ
69
+ * plane, emitting along its local -Y (down, for an unrotated node) with the same lumens: a ceiling panel. The bake
70
+ * lights from the whole rectangle (soft shadows, light from where the panel is and not from a point inside the
71
+ * fixture). Real time it is still the point light above. Ignored with `baked: false`.
72
+ */
73
+ bakeArea?: readonly [number, number]
56
74
  }
57
75
 
58
76
  export class Light extends Node {
59
77
  private _intensity = 0
78
+
79
+ /** Tween `intensity` / `color` (a flash, a sunrise) and the transform — see {@link Node.animateTo}. */
80
+ override animateTo(props: LightTweenProps & TweenMeta): Animation { return super.animateTo(props) }
81
+ override animateFrom(props: LightTweenProps & TweenMeta): Animation { return super.animateFrom(props) }
82
+ /** @internal */
83
+ override _tweenChannel(prop: string): TweenChannel | null {
84
+ const id = () => this.id
85
+ if (prop === "intensity") return { domain: DOM_GL_LIGHT, id, value: floatValue, commit: (v) => { this._intensity = v as number } }
86
+ if (prop === "color") return { domain: DOM_GL_LIGHT, id, value: (v) => colorValue(v, Color.toRgba01) }
87
+ return super._tweenChannel(prop)
88
+ }
60
89
  /** @internal PointOptions.baked — a candidate for the lightmap bake (default true). */
61
90
  _baked = true
62
- /** @internal the bake carries this light: the real-time one is held dark (Lightmap.load). */
63
- _bakedOff = false
64
91
  /** @internal every live point light, for the bake / the switch-off; a destroyed one leaves. */
65
92
  static _points = new Set<Light>()
66
- /** @internal sun direction as created (the engine keeps it; Lightmap.load reads it back). */
93
+ /** @internal sun direction as created (the engine keeps it). */
67
94
  _direction: [number, number, number] = [ 0, -1, 0 ]
68
- /** The most recently created sun — what `Lightmap.load` uses unless told otherwise. */
95
+ /** The most recently created sun. */
69
96
  static lastSun: Light | null = null
70
97
  /** @internal the colour as created / last set (a settings menu recreates a sun from these). */
71
98
  _color: ColorInput = 0xffffff
@@ -113,6 +140,9 @@ export class Light extends Node {
113
140
  options.range ?? 10,
114
141
  options.castShadows ?? false,
115
142
  )
143
+ if (options.bakeArea && light._baked) _creator.setLightBakeArea?.(light.id, options.bakeArea[0], options.bakeArea[1])
144
+ // an unbaked lamp lights the baked statics live: Filament channel 1 (see Lightmap)
145
+ if (!light._baked) _creator.setLightChannel?.(light.id, 1, true)
116
146
  return light
117
147
  }
118
148
 
@@ -123,14 +153,17 @@ export class Light extends Node {
123
153
  get intensity(): number { return this._intensity }
124
154
  set intensity(value: number) {
125
155
  this._intensity = value
126
- _creator.setLightIntensity?.(this.id, this._bakedOff ? 0 : value)
156
+ if (!this._heldDark) _creator.setLightIntensity?.(this.id, value)
127
157
  }
128
158
 
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)
159
+ /** @internal A BAKED lamp is held dark while the level's LIGHT GRID is loaded (Lightmap): the statics have it in the
160
+ * atlas and the movers in the grid's ambient cubes - left burning it lit every mover and unbaked prop a second time,
161
+ * without a shadow (through walls), and put a hot spot on its own fixture. `intensity` keeps the authored value. */
162
+ _heldDark = false
163
+ _holdDark(dark: boolean): void {
164
+ if (this._heldDark === dark) return
165
+ this._heldDark = dark
166
+ _creator.setLightIntensity?.(this.id, dark ? 0 : this._intensity)
134
167
  }
135
168
 
136
169
  destroy(): void {