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.
Files changed (270) hide show
  1. package/README.md +1 -0
  2. package/dist/index.js +1069 -396
  3. package/package.json +14 -13
  4. package/runtime/scene-harness.json +1 -1
  5. package/runtime/sdk-types.json +1 -1
  6. package/runtime/web/assets/Roboto-Variable-DHm9jpd-.woff2 +0 -0
  7. package/runtime/web/assets/__vite-browser-external-BIHI7g3E.js +1 -0
  8. package/runtime/web/assets/basis-C64VHDVD.js +1 -0
  9. package/runtime/web/assets/basis_transcoder-VXdx5NbI.wasm +0 -0
  10. package/runtime/web/assets/createViewerLite-BvHobVhp.js +852 -0
  11. package/runtime/web/assets/draco-BiISTFcR.js +118 -0
  12. package/runtime/web/assets/draco_decoder-DsQ12WqX.wasm +0 -0
  13. package/runtime/web/assets/index-CfNCCBjN.js +2 -0
  14. package/runtime/web/assets/mapViewImpl-B2JcES8l.js +810 -0
  15. package/runtime/web/assets/maplibre-gl-worker-CJfwIrte.js +8 -0
  16. package/runtime/web/assets/neutral_ibl128-D-lzdkLN.ktx +0 -0
  17. package/runtime/web/assets/worker-Caf-yYEI.js +2 -0
  18. package/runtime/web/embed.html +32 -0
  19. package/runtime/web/embed.js +171 -0
  20. package/src/api.ts +302 -0
  21. package/src/browserAuth.ts +87 -0
  22. package/src/cmgenTool.ts +104 -0
  23. package/src/commands/app.ts +896 -0
  24. package/src/commands/appAndroid.ts +603 -0
  25. package/src/commands/appDesktop.ts +339 -0
  26. package/src/commands/appDesktopMac.ts +470 -0
  27. package/src/commands/appIcon.ts +187 -0
  28. package/src/commands/appShared.ts +542 -0
  29. package/src/commands/appTemplates.ts +907 -0
  30. package/src/commands/appTemplatesAndroid.ts +599 -0
  31. package/src/commands/appTemplatesGradlew.ts +9 -0
  32. package/src/commands/assets.ts +28 -0
  33. package/src/commands/clone.ts +60 -0
  34. package/src/commands/compile.ts +253 -0
  35. package/src/commands/create.ts +59 -0
  36. package/src/commands/design.ts +863 -0
  37. package/src/commands/designTemplates.ts +11 -0
  38. package/src/commands/desktop.ts +127 -0
  39. package/src/commands/dev.ts +236 -0
  40. package/src/commands/diff.ts +59 -0
  41. package/src/commands/init.ts +191 -0
  42. package/src/commands/install.ts +198 -0
  43. package/src/commands/lightmap.ts +290 -0
  44. package/src/commands/link.ts +147 -0
  45. package/src/commands/login.ts +24 -0
  46. package/src/commands/navmesh.ts +225 -0
  47. package/src/commands/pn.ts +305 -0
  48. package/src/commands/projectTemplates.ts +130 -0
  49. package/src/commands/pull.ts +109 -0
  50. package/src/commands/push.ts +173 -0
  51. package/src/commands/render.ts +416 -0
  52. package/src/commands/scene.ts +148 -0
  53. package/src/commands/shaders.ts +157 -0
  54. package/src/commands/status.ts +29 -0
  55. package/src/commands/test.ts +371 -0
  56. package/src/commands/thumbs.ts +178 -0
  57. package/src/commands/types.ts +87 -0
  58. package/src/commands/update.ts +190 -0
  59. package/src/compile/assetIcons.ts +214 -0
  60. package/src/compile/collect.ts +46 -0
  61. package/src/compile/collectLocal.ts +37 -0
  62. package/src/compile/designCompile.ts +104 -0
  63. package/src/compile/fonts.ts +156 -0
  64. package/src/compile/headlessBundle.ts +129 -0
  65. package/src/compile/nativeStack.ts +21 -0
  66. package/src/compile/projectCompile.ts +109 -0
  67. package/src/compile/sceneCompile.ts +113 -0
  68. package/src/compile/screenEntry.ts +127 -0
  69. package/src/compile/shaders.ts +245 -0
  70. package/src/config.ts +42 -0
  71. package/src/designMeta.ts +35 -0
  72. package/src/desktopRenderer.ts +545 -0
  73. package/src/desktopScript.ts +276 -0
  74. package/src/dev/clientTemplates.ts +160 -0
  75. package/src/dev/devServer.ts +333 -0
  76. package/src/dev/webRunner.ts +22 -0
  77. package/src/dev/wsServer.ts +144 -0
  78. package/src/distRoot.ts +20 -0
  79. package/src/ignore.ts +163 -0
  80. package/src/index.ts +494 -0
  81. package/src/lecodes-3d-editor.d.ts +41 -0
  82. package/src/lecodes-assets.d.ts +7 -0
  83. package/src/lecodes-design.d.ts +191 -0
  84. package/src/lecodes-renderer.d.ts +131 -0
  85. package/src/localFiles.ts +144 -0
  86. package/src/manifest.ts +46 -0
  87. package/src/matcTool.ts +137 -0
  88. package/src/peers.ts +40 -0
  89. package/src/project.ts +61 -0
  90. package/src/projectEnv.ts +94 -0
  91. package/src/qrcode-terminal.d.ts +9 -0
  92. package/src/releases.ts +125 -0
  93. package/src/serverDiff.ts +78 -0
  94. package/src/textDiff.ts +103 -0
  95. package/src/types.ts +0 -0
  96. package/src/util.ts +146 -0
  97. package/runtime/sdk/animate/animate.ts +0 -238
  98. package/runtime/sdk/animate/bezier.ts +0 -138
  99. package/runtime/sdk/animate/easings.ts +0 -126
  100. package/runtime/sdk/canvas/Canvas.ts +0 -305
  101. package/runtime/sdk/compile/aspectMacro.ts +0 -86
  102. package/runtime/sdk/compile/assetIconMacro.ts +0 -384
  103. package/runtime/sdk/compile/assetMacro.ts +0 -146
  104. package/runtime/sdk/compile/assetName.ts +0 -50
  105. package/runtime/sdk/compile/bundler.ts +0 -287
  106. package/runtime/sdk/compile/compileProject.ts +0 -129
  107. package/runtime/sdk/compile/detectEntry.ts +0 -128
  108. package/runtime/sdk/compile/fontMacro.ts +0 -459
  109. package/runtime/sdk/compile/fontRegistry.ts +0 -78
  110. package/runtime/sdk/compile/header.ts +0 -67
  111. package/runtime/sdk/compile/index.ts +0 -100
  112. package/runtime/sdk/compile/libraryImports.ts +0 -52
  113. package/runtime/sdk/compile/liteMaterial.ts +0 -247
  114. package/runtime/sdk/compile/sceneEditor.ts +0 -88
  115. package/runtime/sdk/compile/serverSplit.ts +0 -233
  116. package/runtime/sdk/compile/serverTypes.ts +0 -227
  117. package/runtime/sdk/compile/sfnt.ts +0 -98
  118. package/runtime/sdk/compile/shaderSchema.ts +0 -202
  119. package/runtime/sdk/compile/shaderTargets.ts +0 -81
  120. package/runtime/sdk/compile/sourcemap.ts +0 -25
  121. package/runtime/sdk/core/Aspect.ts +0 -568
  122. package/runtime/sdk/core/InspectorUI.ts +0 -212
  123. package/runtime/sdk/core/StateMachine.ts +0 -308
  124. package/runtime/sdk/core/color.ts +0 -66
  125. package/runtime/sdk/core/compWrite.ts +0 -42
  126. package/runtime/sdk/core/events.ts +0 -38
  127. package/runtime/sdk/core/fields.ts +0 -120
  128. package/runtime/sdk/core/registry.ts +0 -23
  129. package/runtime/sdk/core/signals.ts +0 -277
  130. package/runtime/sdk/core/time.ts +0 -84
  131. package/runtime/sdk/g2/Camera2D.ts +0 -40
  132. package/runtime/sdk/g2/CharacterController2D.ts +0 -276
  133. package/runtime/sdk/g2/Node2D.ts +0 -267
  134. package/runtime/sdk/g2/OneWay2D.ts +0 -66
  135. package/runtime/sdk/g2/Physics2D.ts +0 -346
  136. package/runtime/sdk/g2/Scene2D.ts +0 -209
  137. package/runtime/sdk/g2/Shape2D.ts +0 -259
  138. package/runtime/sdk/g2/Sprite.ts +0 -89
  139. package/runtime/sdk/g2/SpriteAnimation.ts +0 -171
  140. package/runtime/sdk/g2/SpriteSheet.ts +0 -166
  141. package/runtime/sdk/g2/Texture2D.ts +0 -47
  142. package/runtime/sdk/g2/Tilemap.ts +0 -41
  143. package/runtime/sdk/g2/Tileset.ts +0 -71
  144. package/runtime/sdk/g2/Trigger2D.ts +0 -77
  145. package/runtime/sdk/g2/autotile.ts +0 -433
  146. package/runtime/sdk/g2/cells.ts +0 -91
  147. package/runtime/sdk/g2/defineScene2d.ts +0 -381
  148. package/runtime/sdk/g2/groups2d.ts +0 -106
  149. package/runtime/sdk/g2/loop.ts +0 -50
  150. package/runtime/sdk/g2/scenarios2d.ts +0 -69
  151. package/runtime/sdk/g2/touch.ts +0 -83
  152. package/runtime/sdk/gl/Camera.ts +0 -160
  153. package/runtime/sdk/gl/CameraPlace.ts +0 -52
  154. package/runtime/sdk/gl/CharacterController.ts +0 -238
  155. package/runtime/sdk/gl/Gearbox.ts +0 -212
  156. package/runtime/sdk/gl/Geometry.ts +0 -279
  157. package/runtime/sdk/gl/IK.ts +0 -193
  158. package/runtime/sdk/gl/InstancedMesh.ts +0 -132
  159. package/runtime/sdk/gl/Light.ts +0 -107
  160. package/runtime/sdk/gl/Lightmap.ts +0 -256
  161. package/runtime/sdk/gl/Material.ts +0 -260
  162. package/runtime/sdk/gl/Mesh.ts +0 -83
  163. package/runtime/sdk/gl/Model.ts +0 -124
  164. package/runtime/sdk/gl/NavAgent.ts +0 -337
  165. package/runtime/sdk/gl/NavMesh.ts +0 -397
  166. package/runtime/sdk/gl/Node.ts +0 -350
  167. package/runtime/sdk/gl/Noise.ts +0 -30
  168. package/runtime/sdk/gl/Particles.ts +0 -676
  169. package/runtime/sdk/gl/Physics.ts +0 -222
  170. package/runtime/sdk/gl/Plane.ts +0 -53
  171. package/runtime/sdk/gl/Ragdoll.ts +0 -270
  172. package/runtime/sdk/gl/Ray.ts +0 -16
  173. package/runtime/sdk/gl/Scene.ts +0 -486
  174. package/runtime/sdk/gl/Shape.ts +0 -409
  175. package/runtime/sdk/gl/Terrain.ts +0 -1092
  176. package/runtime/sdk/gl/Texture.ts +0 -63
  177. package/runtime/sdk/gl/Trigger.ts +0 -45
  178. package/runtime/sdk/gl/Vehicle.ts +0 -473
  179. package/runtime/sdk/gl/Wheel.ts +0 -240
  180. package/runtime/sdk/gl/animation/AnimationClip.ts +0 -204
  181. package/runtime/sdk/gl/animation/Animator.ts +0 -120
  182. package/runtime/sdk/gl/animation/Layer.ts +0 -31
  183. package/runtime/sdk/gl/animation/Loop.ts +0 -30
  184. package/runtime/sdk/gl/animation/Playback.ts +0 -44
  185. package/runtime/sdk/gl/animation/core.ts +0 -336
  186. package/runtime/sdk/gl/controls.ts +0 -95
  187. package/runtime/sdk/gl/physicsEvents.ts +0 -20
  188. package/runtime/sdk/gl/scenarios.ts +0 -291
  189. package/runtime/sdk/gl/state.ts +0 -6
  190. package/runtime/sdk/gl/terrainMesh.ts +0 -219
  191. package/runtime/sdk/gl/touch.ts +0 -68
  192. package/runtime/sdk/inject.ts +0 -197
  193. package/runtime/sdk/math/Mathf.ts +0 -118
  194. package/runtime/sdk/math/mat4.ts +0 -278
  195. package/runtime/sdk/math/quat.ts +0 -232
  196. package/runtime/sdk/math/vec.ts +0 -255
  197. package/runtime/sdk/net/codec.ts +0 -119
  198. package/runtime/sdk/net/core.ts +0 -384
  199. package/runtime/sdk/net/index.ts +0 -181
  200. package/runtime/sdk/net/replication.ts +0 -622
  201. package/runtime/sdk/plugins/camera.ts +0 -81
  202. package/runtime/sdk/plugins/geolocation.ts +0 -123
  203. package/runtime/sdk/plugins/oauth.ts +0 -61
  204. package/runtime/sdk/plugins/permission.ts +0 -7
  205. package/runtime/sdk/plugins/push.ts +0 -132
  206. package/runtime/sdk/plugins/qr.ts +0 -73
  207. package/runtime/sdk/plugins/service.ts +0 -47
  208. package/runtime/sdk/runtime/app.ts +0 -101
  209. package/runtime/sdk/runtime/appEvents.ts +0 -54
  210. package/runtime/sdk/runtime/channel.ts +0 -61
  211. package/runtime/sdk/runtime/clipboard.ts +0 -20
  212. package/runtime/sdk/runtime/datetime.ts +0 -329
  213. package/runtime/sdk/runtime/device.ts +0 -293
  214. package/runtime/sdk/runtime/fetch.ts +0 -77
  215. package/runtime/sdk/runtime/files.ts +0 -23
  216. package/runtime/sdk/runtime/input.ts +0 -175
  217. package/runtime/sdk/runtime/media.ts +0 -111
  218. package/runtime/sdk/runtime/misc.ts +0 -16
  219. package/runtime/sdk/runtime/net.ts +0 -36
  220. package/runtime/sdk/runtime/rpc.ts +0 -218
  221. package/runtime/sdk/runtime/service.ts +0 -83
  222. package/runtime/sdk/runtime/share.ts +0 -9
  223. package/runtime/sdk/runtime/storage.ts +0 -13
  224. package/runtime/sdk/runtime/touch.ts +0 -76
  225. package/runtime/sdk/scene/defineScene.ts +0 -1353
  226. package/runtime/sdk/scene/editorPlugins.ts +0 -110
  227. package/runtime/sdk/scene/gizmos.ts +0 -148
  228. package/runtime/sdk/scene/grammar.ts +0 -120
  229. package/runtime/sdk/scene/material.ts +0 -188
  230. package/runtime/sdk/server/auth/appConfig.ts +0 -12
  231. package/runtime/sdk/server/auth/global.ts +0 -80
  232. package/runtime/sdk/server/auth/host.ts +0 -318
  233. package/runtime/sdk/server/auth/models.ts +0 -83
  234. package/runtime/sdk/server/auth/types.ts +0 -50
  235. package/runtime/sdk/server/channel.ts +0 -56
  236. package/runtime/sdk/server/context.ts +0 -36
  237. package/runtime/sdk/server/db/defineDb.ts +0 -237
  238. package/runtime/sdk/server/db/fields.ts +0 -132
  239. package/runtime/sdk/server/db/httpTransport.ts +0 -93
  240. package/runtime/sdk/server/db/index.ts +0 -7
  241. package/runtime/sdk/server/db/marci/query.ts +0 -412
  242. package/runtime/sdk/server/db/types.ts +0 -202
  243. package/runtime/sdk/server/errors.ts +0 -12
  244. package/runtime/sdk/server/host.ts +0 -74
  245. package/runtime/sdk/server/inject.ts +0 -13
  246. package/runtime/sdk/server/runtime.ts +0 -133
  247. package/runtime/sdk/server/validate.ts +0 -87
  248. package/runtime/sdk/ui/NativeView.ts +0 -142
  249. package/runtime/sdk/ui/UI.ts +0 -39
  250. package/runtime/sdk/ui/UIBottomSheet.ts +0 -139
  251. package/runtime/sdk/ui/UIButton.ts +0 -101
  252. package/runtime/sdk/ui/UIContainer.ts +0 -60
  253. package/runtime/sdk/ui/UIImage.ts +0 -83
  254. package/runtime/sdk/ui/UIInput.ts +0 -185
  255. package/runtime/sdk/ui/UIModal.ts +0 -139
  256. package/runtime/sdk/ui/UINode.ts +0 -830
  257. package/runtime/sdk/ui/UIPager.ts +0 -362
  258. package/runtime/sdk/ui/UIPopover.ts +0 -100
  259. package/runtime/sdk/ui/UIScreen.ts +0 -123
  260. package/runtime/sdk/ui/UIScrollable.ts +0 -87
  261. package/runtime/sdk/ui/UISpacer.ts +0 -14
  262. package/runtime/sdk/ui/UITabs.ts +0 -236
  263. package/runtime/sdk/ui/UIText.ts +0 -51
  264. package/runtime/sdk/ui/UIVideo.ts +0 -88
  265. package/runtime/sdk/ui/UIVirtualizedList.ts +0 -241
  266. package/runtime/sdk/ui/UIWidget.ts +0 -127
  267. package/runtime/sdk/ui/fonts.ts +0 -13
  268. package/runtime/sdk/ui/presentable.ts +0 -117
  269. package/runtime/sdk/ui/router.ts +0 -132
  270. package/runtime/sdk/ui/theme.ts +0 -84
@@ -1,202 +0,0 @@
1
- // .mat source → the shader's PARAMETER SCHEMA: what the scene editor's material card renders and
2
- // what `lecodes shaders` prints. Filament's material block carries name + type only, so the rest
3
- // (widget kind, range, default, tooltip) comes from ANNOTATIONS in the comment that follows each
4
- // parameter entry — the same trailing comments shader authors already write:
5
- //
6
- // parameters : [
7
- // { type : float3, name : tint }, // @color what the coating does to the world behind it
8
- // { type : float, name : opacity }, // @range(0, 1) @default(0.22) how much the glass darkens
9
- // { type : sampler2d, name : mask }, // the reticle mask, white on alpha
10
- // ]
11
- //
12
- // Tags: `@color` (float3/float4 = a colour picker; `@vec` forces the plain vector — without either,
13
- // a float3/float4 whose NAME reads like a colour is one), `@range(min, max)` (slider), `@step(s)`,
14
- // `@default(v)` (a number, `#hex`, `[x, y, z]`, `true`/`false`). Whatever text is left is the
15
- // tooltip. A full-line comment directly above the entry counts too. Unknown tags are ignored; a
16
- // malformed one lands in `errors` and the parameter still lists.
17
- //
18
- // Built on liteMaterial's block extraction + relaxed-JSON parser (the ONLY .mat syntax knowledge
19
- // in the repo — do not fork it). Dependency-free, browser-safe, never throws.
20
-
21
- import { extractMatBlocks, parseJsonish, type JsonishValue } from "./liteMaterial"
22
-
23
- export type ShaderParamEditor =
24
- | "number" | "int" | "switch" | "vec2" | "vec3" | "vec4" | "color" | "texture" | "matrix" | "array"
25
-
26
- export type ShaderParamValue = number | boolean | string | number[] | null
27
-
28
- export type ShaderParam = {
29
- name: string
30
- /** filament type name, verbatim (float, float3, sampler2d, …) */
31
- type: string
32
- /** array parameters ("float[9]") */
33
- size?: number
34
- editor: ShaderParamEditor
35
- /** The value a new material starts with (from `@default`, else the type's zero — white for a colour). */
36
- default: ShaderParamValue
37
- min?: number
38
- max?: number
39
- step?: number
40
- tooltip?: string
41
- }
42
-
43
- export type ShaderSchema = {
44
- name: string
45
- shadingModel: string
46
- blending: string
47
- params: ShaderParam[]
48
- errors: string[]
49
- }
50
-
51
- const SAMPLER_TYPES = new Set([ "sampler2d", "samplerExternal", "sampler2dArray", "samplerCubemap", "sampler3d" ])
52
- const COLOR_NAME = /colou?r|tint|albedo|emissive|glare|glow/i
53
-
54
- const zeroFor = (type: string, editor: ShaderParamEditor): ShaderParamValue => {
55
- switch (editor) {
56
- case "number": return 0
57
- case "int": return 0
58
- case "switch": return false
59
- case "vec2": return [ 0, 0 ]
60
- case "vec3": return [ 0, 0, 0 ]
61
- case "vec4": return [ 0, 0, 0, 0 ]
62
- case "color": return type === "float4" ? "#ffffffff" : "#ffffff"
63
- case "texture": return null
64
- default: return null
65
- }
66
- }
67
-
68
- /** Parse one `@default(...)` payload. */
69
- const parseDefault = (raw: string, editor: ShaderParamEditor): ShaderParamValue | undefined => {
70
- const s = raw.trim()
71
- if (s === "true") return true
72
- if (s === "false") return false
73
- if (/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(s)) return s.toLowerCase()
74
- if (/^-?\d+(\.\d+)?$/.test(s)) return editor === "switch" ? Number(s) !== 0 : Number(s)
75
- const arr = /^\[(.*)\]$/.exec(s)
76
- if (arr) {
77
- const nums = arr[1]!.split(",").map((p) => Number(p.trim()))
78
- if (nums.length > 0 && nums.every((n) => Number.isFinite(n))) return nums
79
- }
80
- return undefined
81
- }
82
-
83
- type Annotation = { color?: boolean, vec?: boolean, range?: [number, number], step?: number, default?: string, tooltip: string, errors: string[] }
84
-
85
- /** Split a comment into tags + the remaining tooltip text. */
86
- const parseAnnotation = (comment: string): Annotation => {
87
- const out: Annotation = { tooltip: "", errors: [] }
88
- let rest = comment
89
- rest = rest.replace(/@(color|vec)\b/g, (_m, tag: string) => { out[tag as "color" | "vec"] = true; return " " })
90
- rest = rest.replace(/@(range|step|default)\s*\(([^)]*)\)/g, (_m, tag: string, body: string) => {
91
- if (tag === "range") {
92
- const parts = body.split(",").map((p) => Number(p.trim()))
93
- if (parts.length === 2 && parts.every((n) => Number.isFinite(n))) out.range = [ parts[0]!, parts[1]! ]
94
- else out.errors.push(`@range expects two numbers, got "${body.trim()}"`)
95
- } else if (tag === "step") {
96
- const n = Number(body.trim())
97
- if (Number.isFinite(n) && n > 0) out.step = n
98
- else out.errors.push(`@step expects a positive number, got "${body.trim()}"`)
99
- } else {
100
- out.default = body
101
- }
102
- return " "
103
- })
104
- rest = rest.replace(/@\w+(\([^)]*\))?/g, " ") // unknown tags: dropped
105
- out.tooltip = rest.replace(/\s+/g, " ").trim()
106
- return out
107
- }
108
-
109
- /** The comment attached to each parameter entry, by parameter name: the trailing `//` on the
110
- * entry's line, else the full-line comment(s) directly above it. Scans the raw block text
111
- * (the relaxed-JSON parser drops comments). */
112
- const collectComments = (materialBlock: string): Map<string, string> => {
113
- const out = new Map<string, string>()
114
- const start = materialBlock.search(/\bparameters\s*[:=]/)
115
- if (start < 0) return out
116
- const lines = materialBlock.slice(start).split("\n")
117
- let above: string[] = []
118
- for (const line of lines) {
119
- const trimmed = line.trim()
120
- const name = /\bname\s*[:=]\s*"?([A-Za-z_]\w*)"?/.exec(line)?.[1]
121
- if (name) {
122
- const trailing = /\}[^/\n]*\/\/(.*)$/.exec(line)?.[1] ?? /\/\/(.*)$/.exec(line.slice(line.indexOf("}") + 1))?.[1]
123
- const text = trailing !== undefined ? trailing : above.join(" ")
124
- if (text.trim() !== "") out.set(name, text.trim())
125
- above = []
126
- } else if (trimmed.startsWith("//")) {
127
- above.push(trimmed.slice(2).trim())
128
- } else if (trimmed !== "" && trimmed !== "[" && trimmed !== "],") {
129
- above = []
130
- }
131
- }
132
- return out
133
- }
134
-
135
- /** Parse a `.mat` source into its parameter schema. Never throws: an unreadable file yields an
136
- * empty schema whose `errors` say why. */
137
- export const parseShaderSchema = (text: string): ShaderSchema => {
138
- const schema: ShaderSchema = { name: "", shadingModel: "lit", blending: "opaque", params: [], errors: [] }
139
- let block: string | undefined
140
- let def: Record<string, JsonishValue>
141
- try {
142
- block = extractMatBlocks(text).material
143
- if (block === undefined) { schema.errors.push("no material block"); return schema }
144
- def = parseJsonish("{" + block + "}")
145
- } catch (e) {
146
- schema.errors.push(e instanceof Error ? e.message : String(e))
147
- return schema
148
- }
149
- schema.name = typeof def.name === "string" ? def.name : ""
150
- schema.shadingModel = typeof def.shadingModel === "string" ? def.shadingModel : "lit"
151
- schema.blending = typeof def.blending === "string" ? def.blending : "opaque"
152
-
153
- const comments = collectComments(block)
154
- const rawParams = def.parameters === undefined ? [] : Array.isArray(def.parameters) ? def.parameters : [ def.parameters ]
155
- for (const raw of rawParams) {
156
- if (typeof raw !== "object" || raw === null || Array.isArray(raw)) { schema.errors.push("malformed parameter entry"); continue }
157
- const entry = raw as Record<string, JsonishValue>
158
- const name = String(entry.name ?? "")
159
- const typeRaw = String(entry.type ?? "")
160
- const typeMatch = /^(\w+)(?:\[(\d+)\])?$/.exec(typeRaw)
161
- if (!name || !typeMatch) { schema.errors.push(`malformed parameter "${name || typeRaw}"`); continue }
162
- const type = typeMatch[1]!
163
- const size = typeMatch[2] ? Number(typeMatch[2]) : undefined
164
- const ann = parseAnnotation(comments.get(name) ?? "")
165
- for (const e of ann.errors) schema.errors.push(`${name}: ${e}`)
166
-
167
- let editor: ShaderParamEditor
168
- if (size !== undefined) editor = "array"
169
- else if (SAMPLER_TYPES.has(type)) editor = "texture"
170
- else if (type === "float") editor = "number"
171
- else if (type === "int" || type === "uint") editor = "int"
172
- else if (type === "bool") editor = "switch"
173
- else if (type === "float2") editor = "vec2"
174
- else if (type === "float3" || type === "float4") {
175
- const isColor = ann.color === true || (ann.vec !== true && COLOR_NAME.test(name))
176
- editor = isColor ? "color" : type === "float3" ? "vec3" : "vec4"
177
- } else if (/^(int|uint|bool)[234]$/.test(type)) editor = `vec${type.slice(-1)}` as ShaderParamEditor
178
- else if (/^float[234]x[234]$/.test(type)) editor = "matrix"
179
- else editor = "array"
180
-
181
- const param: ShaderParam = { name, type, editor, default: zeroFor(type, editor) }
182
- if (size !== undefined) param.size = size
183
- if (ann.range) { param.min = ann.range[0]; param.max = ann.range[1] }
184
- if (ann.step !== undefined) param.step = ann.step
185
- if (ann.default !== undefined) {
186
- const v = parseDefault(ann.default, editor)
187
- if (v === undefined) schema.errors.push(`${name}: unreadable @default(${ann.default.trim()})`)
188
- else param.default = v
189
- }
190
- if (ann.tooltip) param.tooltip = ann.tooltip
191
- schema.params.push(param)
192
- }
193
- return schema
194
- }
195
-
196
- /** The parameter values a NEW material starts with for this shader (the schema defaults, textures
197
- * left out — an unset sampler stays the engine's white). */
198
- export const shaderDefaults = (schema: ShaderSchema): Record<string, ShaderParamValue> => {
199
- const out: Record<string, ShaderParamValue> = {}
200
- for (const p of schema.params) if (p.editor !== "texture" && p.default !== null) out[p.name] = p.default
201
- return out
202
- }
@@ -1,81 +0,0 @@
1
- // The one shader-compile target matrix, shared by the backend's server-side compile
2
- // (backend/src/utils/compileShader.ts) and the CLI's local compile (lecodes-cli
3
- // src/compile/shaders.ts). Both must produce the SAME artifact family for a .mat source —
4
- // the compiled bundle derives per-backend URLs by substituting `_creator.subBackend ??
5
- // _creator.backend` into the opengl src (compileProject.ts), so the set of names is ABI.
6
-
7
- export const externalSamplerReg = /type\s*:\s*samplerExternal/g
8
-
9
- // matc invocation per target. `profile` is matc's -p (mobile = shader model MOBILE / ESSL3,
10
- // desktop = shader model DESKTOP / GLSL 4.1); `api` is -a. WebGL and the Windows desktop host
11
- // both run OpenGL without external (OES) sampler support, so they get samplerExternal rewritten
12
- // to sampler2d. The desktop variant exists because the desktop Filament engine rejects the mobile
13
- // _opengl shader ("not built for desktop"); _creator.backend returns "desktop" there.
14
- //
15
- // These names are opaque identities for a (profile, api, rewrite) triple, not API names — hence
16
- // "opengl" (mobile profile) and "desktop" (desktop profile) both being OpenGL. Their only job is to
17
- // be stable and unique: the runtime substitutes one into `<hash>_<name>.filamat`.
18
- export const PLATFORM_BUILD = {
19
- opengl: { profile: "mobile", api: "opengl", replaceExternal: false },
20
- metal: { profile: "mobile", api: "metal", replaceExternal: false },
21
- webgl: { profile: "mobile", api: "opengl", replaceExternal: true },
22
- desktop: { profile: "desktop", api: "opengl", replaceExternal: true },
23
- } as const
24
- export type MatcPlatform = keyof typeof PLATFORM_BUILD
25
-
26
- // Targets the CLI compiles LOCALLY and the platform does not. Deliberately a separate table, not
27
- // another PLATFORM_BUILD entry: `MatcPlatform` feeds the backend's `Platform` type, which is checked
28
- // against the `shaderPlatform` pg enum — widening it would break the backend's inserts at compile
29
- // time for a value the server never produces. Keep local-only targets here until the platform grows
30
- // the matching enum value (docs/desktop-vulkan-release-plan.md §4 "Known limitation").
31
- //
32
- // 'desktop-vulkan' = the Windows Vulkan desktop host: same DESKTOP shader model as 'desktop' but
33
- // SPIR-V, and the two are not interchangeable — Filament rejects a foreign one outright ("not built
34
- // for any of the OpenGL backend's supported shader languages"). `_creator.backend` returns
35
- // "desktop-vulkan" on that host.
36
- export const LOCAL_PLATFORM_BUILD = {
37
- "desktop-vulkan": { profile: "desktop", api: "vulkan", replaceExternal: true },
38
- } as const
39
- export type LocalMatcPlatform = keyof typeof LOCAL_PLATFORM_BUILD
40
-
41
- /** Every matc target, local-only ones included — the lookup table for matcArgs. */
42
- export const ALL_PLATFORM_BUILD = { ...PLATFORM_BUILD, ...LOCAL_PLATFORM_BUILD }
43
- export type AnyMatcPlatform = MatcPlatform | LocalMatcPlatform
44
-
45
- /** The local-only targets, as a list (order matters where it feeds an artifact family). */
46
- export const LOCAL_ONLY_PLATFORMS: LocalMatcPlatform[] = ["desktop-vulkan"]
47
-
48
- // 'webgl-lite' is not a matc target: viewer-lite gets a JSON artifact (parsed .mat — see
49
- // liteMaterial.ts) that it wraps in its own GLSL template at runtime.
50
- export type ShaderPlatform = MatcPlatform | "webgl-lite"
51
-
52
- /** Every platform the LOCAL compile can produce (matc targets + the lite JSON). */
53
- export type AnyShaderPlatform = AnyMatcPlatform | "webgl-lite"
54
-
55
- /** Bump when the matc invocation for an EXISTING target name changes (a different -p/-a/rewrite for
56
- * a name that already exists). The CLI folds this into its artifact cache key, so such a change
57
- * invalidates caches that would otherwise look complete — adding or removing a target name is
58
- * already caught by the artifact-family check, but changing the argv behind a name is not.
59
- * 1 = 'desktop-vulkan' added (2026-08-24). */
60
- export const TARGET_MATRIX_GENERATION = 1
61
-
62
- /** The matc platforms a .mat source needs compiled. WebGL is matc-compiled only when the shader
63
- * has an external sampler: its samplerExternal → sampler2d rewrite makes the output differ from
64
- * the mobile opengl build. Without one the WebGL artifact is byte-identical to the mobile shader,
65
- * so callers copy it from the opengl output instead of running matc again. Either way a _webgl
66
- * artifact must always exist — the web runtime always requests one (via _creator.subBackend).
67
- *
68
- * This is the SERVER's contract — it deliberately does not include LOCAL_ONLY_PLATFORMS. The CLI
69
- * appends those itself (lecodes-cli src/compile/shaders.ts). */
70
- export const matcPlatformsFor = (text: string): MatcPlatform[] => {
71
- externalSamplerReg.lastIndex = 0
72
- return externalSamplerReg.test(text)
73
- ? ["opengl", "metal", "webgl", "desktop"]
74
- : ["opengl", "metal", "desktop"]
75
- }
76
-
77
- /** The matc argv (without the executable) for one target. */
78
- export const matcArgs = (platform: AnyMatcPlatform, outPath: string, inPath: string): string[] => {
79
- const build = ALL_PLATFORM_BUILD[platform]
80
- return ["-p", build.profile, "--no-essl1", "-a", build.api, "-o", outPath, inPath]
81
- }
@@ -1,25 +0,0 @@
1
- // Helpers for serving the bundler's source map alongside the bundle. The map's generated positions
2
- // are relative to the bundle code; when the deploy/preview prepends a comment header, the map must be
3
- // shifted down by that many lines, then inlined into the bundle as a data URL (the preview executes
4
- // the bundle via `new Function(string)`, which has no URL identity, so an external `.map` can't be
5
- // fetched — it must be inline).
6
-
7
- /** Shift every generated position in `mapJson` down by `lines` (each VLQ line is `;`-separated). */
8
- export const offsetSourceMap = (mapJson: string, lines: number): string => {
9
- if (lines <= 0) return mapJson
10
- const map = JSON.parse(mapJson) as { mappings: string }
11
- map.mappings = ";".repeat(lines) + map.mappings
12
- return JSON.stringify(map)
13
- }
14
-
15
- /**
16
- * Inline the map into a bundle string under a **non-standard** directive (`lecodesMap`, not
17
- * `sourceMappingURL`), so the browser does NOT auto-apply it. The bundle runs via `new Function`, and
18
- * the browser maps the raw stack position *including* the `new Function` wrapper (~2-3 lines) which the
19
- * map can't subtract — so its native source location would be off by those lines. Our preview mapper
20
- * reads `lecodesMap` and subtracts the (calibrated) wrapper itself, so its locations are correct.
21
- */
22
- export const inlineSourceMapComment = (mapJson: string): string => {
23
- const b64 = Buffer.from(mapJson, "utf8").toString("base64")
24
- return `//# lecodesMap=data:application/json;charset=utf-8;base64,${b64}`
25
- }