lecodes-cli 0.19.0 → 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.
Files changed (254) hide show
  1. package/dist/index.js +730 -235
  2. package/package.json +14 -13
  3. package/runtime/scene-harness.json +1 -1
  4. package/runtime/sdk-types.json +1 -1
  5. package/src/api.ts +302 -0
  6. package/src/browserAuth.ts +87 -0
  7. package/src/cmgenTool.ts +104 -0
  8. package/src/commands/app.ts +891 -0
  9. package/src/commands/appAndroid.ts +603 -0
  10. package/src/commands/appDesktop.ts +326 -0
  11. package/src/commands/appDesktopMac.ts +470 -0
  12. package/src/commands/appIcon.ts +187 -0
  13. package/src/commands/appShared.ts +448 -0
  14. package/src/commands/appTemplates.ts +883 -0
  15. package/src/commands/appTemplatesAndroid.ts +599 -0
  16. package/src/commands/appTemplatesGradlew.ts +9 -0
  17. package/src/commands/assets.ts +28 -0
  18. package/src/commands/clone.ts +60 -0
  19. package/src/commands/compile.ts +253 -0
  20. package/src/commands/create.ts +59 -0
  21. package/src/commands/design.ts +863 -0
  22. package/src/commands/designTemplates.ts +11 -0
  23. package/src/commands/desktop.ts +122 -0
  24. package/src/commands/dev.ts +214 -0
  25. package/src/commands/diff.ts +59 -0
  26. package/src/commands/init.ts +191 -0
  27. package/src/commands/install.ts +198 -0
  28. package/src/commands/lightmap.ts +290 -0
  29. package/src/commands/link.ts +147 -0
  30. package/src/commands/login.ts +24 -0
  31. package/src/commands/navmesh.ts +225 -0
  32. package/src/commands/pn.ts +305 -0
  33. package/src/commands/projectTemplates.ts +129 -0
  34. package/src/commands/pull.ts +109 -0
  35. package/src/commands/push.ts +173 -0
  36. package/src/commands/render.ts +414 -0
  37. package/src/commands/scene.ts +148 -0
  38. package/src/commands/shaders.ts +157 -0
  39. package/src/commands/status.ts +29 -0
  40. package/src/commands/test.ts +370 -0
  41. package/src/commands/thumbs.ts +178 -0
  42. package/src/commands/types.ts +87 -0
  43. package/src/commands/update.ts +190 -0
  44. package/src/compile/assetIcons.ts +214 -0
  45. package/src/compile/collect.ts +46 -0
  46. package/src/compile/collectLocal.ts +37 -0
  47. package/src/compile/designCompile.ts +104 -0
  48. package/src/compile/fonts.ts +156 -0
  49. package/src/compile/headlessBundle.ts +129 -0
  50. package/src/compile/nativeStack.ts +21 -0
  51. package/src/compile/projectCompile.ts +109 -0
  52. package/src/compile/sceneCompile.ts +113 -0
  53. package/src/compile/screenEntry.ts +127 -0
  54. package/src/compile/shaders.ts +245 -0
  55. package/src/config.ts +42 -0
  56. package/src/designMeta.ts +35 -0
  57. package/src/desktopRenderer.ts +532 -0
  58. package/src/desktopScript.ts +276 -0
  59. package/src/dev/clientTemplates.ts +160 -0
  60. package/src/dev/devServer.ts +292 -0
  61. package/src/dev/wsServer.ts +144 -0
  62. package/src/distRoot.ts +20 -0
  63. package/src/ignore.ts +163 -0
  64. package/src/index.ts +491 -0
  65. package/src/lecodes-3d-editor.d.ts +41 -0
  66. package/src/lecodes-assets.d.ts +7 -0
  67. package/src/lecodes-design.d.ts +191 -0
  68. package/src/lecodes-renderer.d.ts +131 -0
  69. package/src/localFiles.ts +144 -0
  70. package/src/manifest.ts +46 -0
  71. package/src/matcTool.ts +137 -0
  72. package/src/peers.ts +40 -0
  73. package/src/project.ts +61 -0
  74. package/src/projectEnv.ts +94 -0
  75. package/src/qrcode-terminal.d.ts +9 -0
  76. package/src/releases.ts +125 -0
  77. package/src/serverDiff.ts +78 -0
  78. package/src/textDiff.ts +103 -0
  79. package/src/types.ts +0 -0
  80. package/src/util.ts +146 -0
  81. package/runtime/sdk/animate/animate.ts +0 -238
  82. package/runtime/sdk/animate/bezier.ts +0 -138
  83. package/runtime/sdk/animate/easings.ts +0 -126
  84. package/runtime/sdk/canvas/Canvas.ts +0 -305
  85. package/runtime/sdk/compile/aspectMacro.ts +0 -86
  86. package/runtime/sdk/compile/assetIconMacro.ts +0 -384
  87. package/runtime/sdk/compile/assetMacro.ts +0 -146
  88. package/runtime/sdk/compile/assetName.ts +0 -50
  89. package/runtime/sdk/compile/bundler.ts +0 -287
  90. package/runtime/sdk/compile/compileProject.ts +0 -129
  91. package/runtime/sdk/compile/detectEntry.ts +0 -128
  92. package/runtime/sdk/compile/fontMacro.ts +0 -459
  93. package/runtime/sdk/compile/fontRegistry.ts +0 -78
  94. package/runtime/sdk/compile/header.ts +0 -67
  95. package/runtime/sdk/compile/index.ts +0 -100
  96. package/runtime/sdk/compile/libraryImports.ts +0 -52
  97. package/runtime/sdk/compile/liteMaterial.ts +0 -247
  98. package/runtime/sdk/compile/sceneEditor.ts +0 -88
  99. package/runtime/sdk/compile/serverSplit.ts +0 -233
  100. package/runtime/sdk/compile/serverTypes.ts +0 -227
  101. package/runtime/sdk/compile/sfnt.ts +0 -98
  102. package/runtime/sdk/compile/shaderSchema.ts +0 -202
  103. package/runtime/sdk/compile/shaderTargets.ts +0 -81
  104. package/runtime/sdk/compile/sourcemap.ts +0 -25
  105. package/runtime/sdk/core/Aspect.ts +0 -568
  106. package/runtime/sdk/core/InspectorUI.ts +0 -212
  107. package/runtime/sdk/core/StateMachine.ts +0 -308
  108. package/runtime/sdk/core/color.ts +0 -66
  109. package/runtime/sdk/core/compWrite.ts +0 -42
  110. package/runtime/sdk/core/events.ts +0 -38
  111. package/runtime/sdk/core/fields.ts +0 -120
  112. package/runtime/sdk/core/registry.ts +0 -23
  113. package/runtime/sdk/core/signals.ts +0 -277
  114. package/runtime/sdk/core/time.ts +0 -84
  115. package/runtime/sdk/g2/Camera2D.ts +0 -40
  116. package/runtime/sdk/g2/CharacterController2D.ts +0 -276
  117. package/runtime/sdk/g2/Node2D.ts +0 -267
  118. package/runtime/sdk/g2/OneWay2D.ts +0 -66
  119. package/runtime/sdk/g2/Physics2D.ts +0 -346
  120. package/runtime/sdk/g2/Scene2D.ts +0 -209
  121. package/runtime/sdk/g2/Shape2D.ts +0 -259
  122. package/runtime/sdk/g2/Sprite.ts +0 -89
  123. package/runtime/sdk/g2/SpriteAnimation.ts +0 -171
  124. package/runtime/sdk/g2/SpriteSheet.ts +0 -166
  125. package/runtime/sdk/g2/Texture2D.ts +0 -47
  126. package/runtime/sdk/g2/Tilemap.ts +0 -41
  127. package/runtime/sdk/g2/Tileset.ts +0 -71
  128. package/runtime/sdk/g2/Trigger2D.ts +0 -77
  129. package/runtime/sdk/g2/autotile.ts +0 -433
  130. package/runtime/sdk/g2/cells.ts +0 -91
  131. package/runtime/sdk/g2/defineScene2d.ts +0 -381
  132. package/runtime/sdk/g2/groups2d.ts +0 -106
  133. package/runtime/sdk/g2/loop.ts +0 -50
  134. package/runtime/sdk/g2/scenarios2d.ts +0 -69
  135. package/runtime/sdk/g2/touch.ts +0 -83
  136. package/runtime/sdk/gl/Camera.ts +0 -160
  137. package/runtime/sdk/gl/CameraPlace.ts +0 -52
  138. package/runtime/sdk/gl/CharacterController.ts +0 -238
  139. package/runtime/sdk/gl/Gearbox.ts +0 -212
  140. package/runtime/sdk/gl/Geometry.ts +0 -279
  141. package/runtime/sdk/gl/IK.ts +0 -193
  142. package/runtime/sdk/gl/InstancedMesh.ts +0 -132
  143. package/runtime/sdk/gl/Light.ts +0 -107
  144. package/runtime/sdk/gl/Lightmap.ts +0 -256
  145. package/runtime/sdk/gl/Material.ts +0 -260
  146. package/runtime/sdk/gl/Mesh.ts +0 -83
  147. package/runtime/sdk/gl/Model.ts +0 -124
  148. package/runtime/sdk/gl/NavAgent.ts +0 -337
  149. package/runtime/sdk/gl/NavMesh.ts +0 -397
  150. package/runtime/sdk/gl/Node.ts +0 -350
  151. package/runtime/sdk/gl/Noise.ts +0 -30
  152. package/runtime/sdk/gl/Particles.ts +0 -676
  153. package/runtime/sdk/gl/Physics.ts +0 -222
  154. package/runtime/sdk/gl/Plane.ts +0 -53
  155. package/runtime/sdk/gl/Ragdoll.ts +0 -270
  156. package/runtime/sdk/gl/Ray.ts +0 -16
  157. package/runtime/sdk/gl/Scene.ts +0 -486
  158. package/runtime/sdk/gl/Shape.ts +0 -409
  159. package/runtime/sdk/gl/Terrain.ts +0 -1092
  160. package/runtime/sdk/gl/Texture.ts +0 -63
  161. package/runtime/sdk/gl/Trigger.ts +0 -45
  162. package/runtime/sdk/gl/Vehicle.ts +0 -473
  163. package/runtime/sdk/gl/Wheel.ts +0 -240
  164. package/runtime/sdk/gl/animation/AnimationClip.ts +0 -204
  165. package/runtime/sdk/gl/animation/Animator.ts +0 -120
  166. package/runtime/sdk/gl/animation/Layer.ts +0 -31
  167. package/runtime/sdk/gl/animation/Loop.ts +0 -30
  168. package/runtime/sdk/gl/animation/Playback.ts +0 -44
  169. package/runtime/sdk/gl/animation/core.ts +0 -336
  170. package/runtime/sdk/gl/controls.ts +0 -95
  171. package/runtime/sdk/gl/physicsEvents.ts +0 -20
  172. package/runtime/sdk/gl/scenarios.ts +0 -291
  173. package/runtime/sdk/gl/state.ts +0 -6
  174. package/runtime/sdk/gl/terrainMesh.ts +0 -219
  175. package/runtime/sdk/gl/touch.ts +0 -68
  176. package/runtime/sdk/inject.ts +0 -197
  177. package/runtime/sdk/math/Mathf.ts +0 -118
  178. package/runtime/sdk/math/mat4.ts +0 -278
  179. package/runtime/sdk/math/quat.ts +0 -232
  180. package/runtime/sdk/math/vec.ts +0 -255
  181. package/runtime/sdk/net/codec.ts +0 -119
  182. package/runtime/sdk/net/core.ts +0 -384
  183. package/runtime/sdk/net/index.ts +0 -181
  184. package/runtime/sdk/net/replication.ts +0 -622
  185. package/runtime/sdk/plugins/camera.ts +0 -81
  186. package/runtime/sdk/plugins/geolocation.ts +0 -123
  187. package/runtime/sdk/plugins/oauth.ts +0 -61
  188. package/runtime/sdk/plugins/permission.ts +0 -7
  189. package/runtime/sdk/plugins/push.ts +0 -132
  190. package/runtime/sdk/plugins/qr.ts +0 -73
  191. package/runtime/sdk/plugins/service.ts +0 -47
  192. package/runtime/sdk/runtime/app.ts +0 -101
  193. package/runtime/sdk/runtime/appEvents.ts +0 -54
  194. package/runtime/sdk/runtime/channel.ts +0 -61
  195. package/runtime/sdk/runtime/clipboard.ts +0 -20
  196. package/runtime/sdk/runtime/datetime.ts +0 -329
  197. package/runtime/sdk/runtime/device.ts +0 -293
  198. package/runtime/sdk/runtime/fetch.ts +0 -77
  199. package/runtime/sdk/runtime/files.ts +0 -23
  200. package/runtime/sdk/runtime/input.ts +0 -175
  201. package/runtime/sdk/runtime/media.ts +0 -111
  202. package/runtime/sdk/runtime/misc.ts +0 -16
  203. package/runtime/sdk/runtime/net.ts +0 -36
  204. package/runtime/sdk/runtime/rpc.ts +0 -218
  205. package/runtime/sdk/runtime/service.ts +0 -83
  206. package/runtime/sdk/runtime/share.ts +0 -9
  207. package/runtime/sdk/runtime/storage.ts +0 -13
  208. package/runtime/sdk/runtime/touch.ts +0 -76
  209. package/runtime/sdk/scene/defineScene.ts +0 -1353
  210. package/runtime/sdk/scene/editorPlugins.ts +0 -110
  211. package/runtime/sdk/scene/gizmos.ts +0 -148
  212. package/runtime/sdk/scene/grammar.ts +0 -120
  213. package/runtime/sdk/scene/material.ts +0 -188
  214. package/runtime/sdk/server/auth/appConfig.ts +0 -12
  215. package/runtime/sdk/server/auth/global.ts +0 -80
  216. package/runtime/sdk/server/auth/host.ts +0 -318
  217. package/runtime/sdk/server/auth/models.ts +0 -83
  218. package/runtime/sdk/server/auth/types.ts +0 -50
  219. package/runtime/sdk/server/channel.ts +0 -56
  220. package/runtime/sdk/server/context.ts +0 -36
  221. package/runtime/sdk/server/db/defineDb.ts +0 -237
  222. package/runtime/sdk/server/db/fields.ts +0 -132
  223. package/runtime/sdk/server/db/httpTransport.ts +0 -93
  224. package/runtime/sdk/server/db/index.ts +0 -7
  225. package/runtime/sdk/server/db/marci/query.ts +0 -412
  226. package/runtime/sdk/server/db/types.ts +0 -202
  227. package/runtime/sdk/server/errors.ts +0 -12
  228. package/runtime/sdk/server/host.ts +0 -74
  229. package/runtime/sdk/server/inject.ts +0 -13
  230. package/runtime/sdk/server/runtime.ts +0 -133
  231. package/runtime/sdk/server/validate.ts +0 -87
  232. package/runtime/sdk/ui/NativeView.ts +0 -142
  233. package/runtime/sdk/ui/UI.ts +0 -39
  234. package/runtime/sdk/ui/UIBottomSheet.ts +0 -139
  235. package/runtime/sdk/ui/UIButton.ts +0 -101
  236. package/runtime/sdk/ui/UIContainer.ts +0 -60
  237. package/runtime/sdk/ui/UIImage.ts +0 -83
  238. package/runtime/sdk/ui/UIInput.ts +0 -185
  239. package/runtime/sdk/ui/UIModal.ts +0 -139
  240. package/runtime/sdk/ui/UINode.ts +0 -830
  241. package/runtime/sdk/ui/UIPager.ts +0 -362
  242. package/runtime/sdk/ui/UIPopover.ts +0 -100
  243. package/runtime/sdk/ui/UIScreen.ts +0 -123
  244. package/runtime/sdk/ui/UIScrollable.ts +0 -87
  245. package/runtime/sdk/ui/UISpacer.ts +0 -14
  246. package/runtime/sdk/ui/UITabs.ts +0 -236
  247. package/runtime/sdk/ui/UIText.ts +0 -51
  248. package/runtime/sdk/ui/UIVideo.ts +0 -88
  249. package/runtime/sdk/ui/UIVirtualizedList.ts +0 -241
  250. package/runtime/sdk/ui/UIWidget.ts +0 -127
  251. package/runtime/sdk/ui/fonts.ts +0 -13
  252. package/runtime/sdk/ui/presentable.ts +0 -117
  253. package/runtime/sdk/ui/router.ts +0 -132
  254. package/runtime/sdk/ui/theme.ts +0 -84
@@ -1,100 +0,0 @@
1
- // The public entry of the SDK's bundle build system. The backend, CLI, and local renderer import
2
- // from here instead of re-forking a bundler. (Node + Bun safe — no top-level host globals.)
3
-
4
- export { bundleProject, bundleProjectWithMap, scanModulesChisel, CLIENT_INJECT, SERVER_INJECT, type MemoryFiles } from "./bundler"
5
- export {
6
- compileServerBundle,
7
- scanServerExports,
8
- scanServerModules,
9
- stubServerEntries,
10
- serverStubSource,
11
- serverEntrySource,
12
- serverModuleId,
13
- isServerPath,
14
- SERVER_ENTRY_PATH,
15
- type CompileServerOptions,
16
- type ServerExport,
17
- type ServerExportKind,
18
- type ServerManifest,
19
- } from "./serverSplit"
20
- export { deriveEndpointParams, EndpointTypeError, type DeriveResult } from "./serverTypes"
21
- export {
22
- detectEntry,
23
- scanModulesFallback,
24
- ENTRY_CONVENTION,
25
- type DetectedEntry,
26
- type DetectEntryInput,
27
- type ModuleScanner,
28
- type ScanModule,
29
- } from "./detectEntry"
30
- export { sanitizeAssetName, isCanonicalAssetName } from "./assetName"
31
- export {
32
- PLATFORM_BUILD,
33
- LOCAL_PLATFORM_BUILD,
34
- ALL_PLATFORM_BUILD,
35
- LOCAL_ONLY_PLATFORMS,
36
- TARGET_MATRIX_GENERATION,
37
- externalSamplerReg,
38
- matcPlatformsFor,
39
- matcArgs,
40
- type MatcPlatform,
41
- type LocalMatcPlatform,
42
- type AnyMatcPlatform,
43
- type ShaderPlatform,
44
- type AnyShaderPlatform,
45
- } from "./shaderTargets"
46
- export {
47
- buildLiteMaterialArtifact,
48
- extractMatBlocks,
49
- parseJsonish,
50
- type LiteMaterialArtifact,
51
- type LiteMaterialParam,
52
- type JsonishValue,
53
- } from "./liteMaterial"
54
- export {
55
- parseShaderSchema,
56
- shaderDefaults,
57
- type ShaderSchema,
58
- type ShaderParam,
59
- type ShaderParamEditor,
60
- type ShaderParamValue,
61
- } from "./shaderSchema"
62
- export { offsetSourceMap, inlineSourceMapComment } from "./sourcemap"
63
- export { buildHeader, detectProjectKind, type HeaderOptions } from "./header"
64
- export {
65
- compileProject,
66
- type CompileEntry,
67
- type CompileOptions,
68
- type CompileFileType,
69
- } from "./compileProject"
70
- export {
71
- loadSceneHarness,
72
- sceneEditorEntries,
73
- SCENE_ENTRY_PATH,
74
- SCENE_HARNESS_DIR,
75
- } from "./sceneEditor"
76
- export {
77
- applyFontMacro,
78
- buildFontsHeaderValue,
79
- scanFontCalls,
80
- type FontCall,
81
- type FontFaceRef,
82
- type FontMacroEntry,
83
- type FontMacroOptions,
84
- } from "./fontMacro"
85
- export {
86
- applyAssetIconMacro,
87
- buildIconsHeaderValue,
88
- collectVendoredIcons,
89
- scanAssetIconCalls,
90
- rewriteAssetIcons,
91
- suggestIconNames,
92
- iconNotFoundError,
93
- ICON_ID,
94
- type IconCall,
95
- type AssetIconEntry,
96
- type AssetIconResolver,
97
- type RegistryReader,
98
- } from "./assetIconMacro"
99
- export { FONT_REGISTRY, DEFAULT_FONT_REGISTRY_BASE, fontRegistryBase, faceFileName, type FontFamilyMeta } from "./fontRegistry"
100
- export { parseSfnt, type SfntInfo } from "./sfnt"
@@ -1,52 +0,0 @@
1
- // Pre-chisel rewrite of user-library bare-specifier imports. chisel's resolver hard-errors on any
2
- // bare import (the whole SDK is globals), so a project that imports a component library by its slug
3
- // —`import { Card } from "acme-ui"`— is rewritten here to the injected library tree under
4
- // `/__lib/<slug>/…` BEFORE chisel runs. Only libraries present in the dependency map are known
5
- // slugs; any other bare specifier is an author error, surfaced with a friendly message instead of
6
- // chisel's generic one. Static string-literal specifiers only — dynamic `import()` is unsupported
7
- // (documented). Chisel itself is untouched. See docs/library-system-plan.md §4.
8
-
9
- /** Cheap pre-check so the regexes don't run over files with no imports at all. */
10
- export const hasImportStatement = (src: string): boolean => src.includes("import") || src.includes("from")
11
-
12
- // A static `from "…"` clause (import-from OR export-from). Anchored at a statement boundary
13
- // (line start / `;` / `}`) and disallowing quotes/backticks/semicolons between the keyword and
14
- // `from`, so it can never span into a string literal or a neighbouring statement. Named-import
15
- // lists may span multiple lines (newlines are allowed between the keyword and `from`).
16
- const IMPORT_FROM_RE = /(^|[;\n}])(\s*(?:import|export)\b[^"'`;]*?\bfrom\s*)(["'])([^"'\n]+)\3/g
17
-
18
- // A side-effect `import "…"` (a bare quote directly after the keyword — not `import x`, not `import(`).
19
- const SIDE_EFFECT_RE = /(^|[;\n}])(\s*import\s*)(["'])([^"'\n]+)\3/g
20
-
21
- const isRelativeOrAbsolute = (spec: string): boolean =>
22
- spec.startsWith("/") || spec.startsWith("./") || spec.startsWith("../")
23
-
24
- /**
25
- * Rewrite every known-library bare import in `src` to its `/__lib/<slug>/…` path. Relative and
26
- * absolute specifiers pass through untouched; an unknown bare specifier throws a friendly Error.
27
- * `slugs` is the set of library slugs available to this project (its dependency map's keys).
28
- */
29
- export const rewriteLibraryImports = (src: string, slugs: Set<string>): string => {
30
- const rewriteSpec = (spec: string): string => {
31
- if (isRelativeOrAbsolute(spec)) return spec
32
- const slash = spec.indexOf("/")
33
- const slug = slash === -1 ? spec : spec.slice(0, slash)
34
- if (slugs.has(slug)) {
35
- // `acme-ui` → `/__lib/acme-ui/index`; `acme-ui/theme` → `/__lib/acme-ui/theme`.
36
- const sub = slash === -1 ? "/index" : spec.slice(slash)
37
- return `/__lib/${slug}${sub}`
38
- }
39
- // Legacy worker-module imports (`import { UIScreen } from "ui"`) predate the globals-only SDK —
40
- // chisel would reject them anyway; say so here instead of "Unknown library".
41
- if (slug === "ui" || slug === "creator" || slug === "utils") {
42
- throw new Error(`import from "${slug}": the SDK needs no imports — UIScreen, Scene, etc. are globals; remove this import line.`)
43
- }
44
- throw new Error(`Unknown library "${slug}" — add it in Settings → Libraries, or use a relative path like "./${slug}".`)
45
- }
46
-
47
- let out = src.replace(IMPORT_FROM_RE, (_m, boundary, head, quote, spec) =>
48
- `${boundary}${head}${quote}${rewriteSpec(spec)}${quote}`)
49
- out = out.replace(SIDE_EFFECT_RE, (m, boundary, head, quote, spec) =>
50
- isRelativeOrAbsolute(spec) ? m : `${boundary}${head}${quote}${rewriteSpec(spec)}${quote}`)
51
- return out
52
- }
@@ -1,247 +0,0 @@
1
- // .mat source → Web Lite material artifact.
2
- //
3
- // matc validates and compiles the .mat for the native platforms; the lite web runtime
4
- // (packages/viewer-lite) has no Filament, so it gets this JSON artifact instead: the parsed
5
- // material definition (parameters, shading model, blending) plus the author's fragment body with
6
- // `materialParams.x` rewritten to `materialParams_x`. viewer-lite wraps that body in its own GLSL
7
- // template (src/gl/customMaterial.ts mirrors the artifact type) — GLSL knowledge stays there, this
8
- // module only owns .mat syntax.
9
- //
10
- // The parsed `params`/`samplers` lists are deliberately structured (filament type names kept
11
- // verbatim): they are also the metadata a future "typed materials" codegen needs — generating a
12
- // Material subclass with typed uniform setters straight from the shader's parameter list.
13
- //
14
- // This module is dependency-free and must never throw: an exotic material becomes an
15
- // `unsupported` artifact (viewer-lite falls back to unlit + warning), never a failed shader save.
16
-
17
- export type LiteMaterialParam = {
18
- name: string
19
- /** filament type name: float, float2..4, int..4, bool..4, float3x3, float4x4 */
20
- type: string
21
- /** array parameters ("float[9]") */
22
- size?: number
23
- }
24
-
25
- export type LiteMaterialArtifact = {
26
- lecodesLiteMaterial: 1
27
- shadingModel: "lit" | "unlit"
28
- blending: "opaque" | "transparent" | "fade" | "add" | "masked"
29
- maskThreshold: number
30
- doubleSided: boolean
31
- culling: "back" | "front" | "none"
32
- depthWrite: boolean
33
- /** Filament's shadow-catcher flag (unlit only, transparency mandatory — matc enforces both):
34
- * the fragment shows baseColor scaled by the received shadow amount, transparent elsewhere. */
35
- shadowMultiplier: boolean
36
- params: LiteMaterialParam[]
37
- /** sampler2d / samplerExternal parameters — all become sampler2D in lite */
38
- samplers: { name: string }[]
39
- /** the author's fragment block body, `materialParams.x` rewritten to `materialParams_x` */
40
- fragmentCode: string
41
- /** the fragment writes MaterialInputs.normal — the template adds the tangent-frame transform */
42
- writesNormal: boolean
43
- /** a vertex{} block was present and dropped (lite ignores custom vertex stages) */
44
- hasVertexBlock: boolean
45
- /** set when the material can't run in lite at all (parse failure, unsupported param type) */
46
- unsupported?: string
47
- }
48
-
49
- // ---- .mat block extraction ----------------------------------------------------------------------
50
-
51
- /** Split a .mat file into its top-level `name { ... }` blocks (material / fragment / vertex),
52
- * matching braces while skipping comments so `{` inside GLSL or comments can't derail it. */
53
- export const extractMatBlocks = (text: string): Record<string, string> => {
54
- const blocks: Record<string, string> = {}
55
- let i = 0
56
- const skipNoise = (): void => {
57
- for (;;) {
58
- while (i < text.length && /\s/.test(text[i]!)) i++
59
- if (text[i] === "/" && text[i + 1] === "/") { while (i < text.length && text[i] !== "\n") i++ }
60
- else if (text[i] === "/" && text[i + 1] === "*") {
61
- i += 2
62
- while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++
63
- i += 2
64
- } else return
65
- }
66
- }
67
- while (i < text.length) {
68
- skipNoise()
69
- const m = /^[A-Za-z_][A-Za-z0-9_]*/.exec(text.slice(i))
70
- if (!m) { i++; continue }
71
- i += m[0].length
72
- skipNoise()
73
- if (text[i] !== "{") continue
74
- // brace-match the block body, comment-aware
75
- let depth = 0
76
- const start = i
77
- while (i < text.length) {
78
- const c = text[i]
79
- if (c === "/" && text[i + 1] === "/") { while (i < text.length && text[i] !== "\n") i++ }
80
- else if (c === "/" && text[i + 1] === "*") {
81
- i += 2
82
- while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++
83
- i++ // lands on '/', loop increment steps past
84
- }
85
- else if (c === "{") depth++
86
- else if (c === "}") { depth--; if (depth === 0) break }
87
- i++
88
- }
89
- blocks[m[0]] = text.slice(start + 1, i)
90
- i++
91
- }
92
- return blocks
93
- }
94
-
95
- // ---- "jsonish" material-block parser --------------------------------------------------------------
96
- // matc's material block is relaxed JSON: unquoted keys/values, comments, optional commas, and both
97
- // `:` and `=` as separators. Small recursive-descent parser over that grammar.
98
-
99
- export type JsonishValue = string | number | boolean | JsonishValue[] | { [key: string]: JsonishValue }
100
-
101
- export const parseJsonish = (src: string): Record<string, JsonishValue> => {
102
- let i = 0
103
- const fail = (msg: string): never => { throw new Error(`material block: ${msg} at offset ${i}`) }
104
- const skip = (): void => {
105
- for (;;) {
106
- while (i < src.length && /[\s,]/.test(src[i]!)) i++
107
- if (src[i] === "/" && src[i + 1] === "/") { while (i < src.length && src[i] !== "\n") i++ }
108
- else if (src[i] === "/" && src[i + 1] === "*") {
109
- i += 2
110
- while (i < src.length && !(src[i] === "*" && src[i + 1] === "/")) i++
111
- i += 2
112
- } else return
113
- }
114
- }
115
- const quoted = (q: string): string => {
116
- i++
117
- const start = i
118
- while (i < src.length && src[i] !== q) i++
119
- return src.slice(start, i++)
120
- }
121
- const word = (): string => {
122
- const m = /^[^\s{}[\]:,="']+/.exec(src.slice(i))
123
- if (!m) fail("expected a value")
124
- i += m![0].length
125
- return m![0]
126
- }
127
- const value = (): JsonishValue => {
128
- skip()
129
- const c = src[i]
130
- if (c === "{") return object()
131
- if (c === "[") return array()
132
- if (c === '"' || c === "'") return quoted(c)
133
- const w = word()
134
- if (w === "true") return true
135
- if (w === "false") return false
136
- const n = Number(w)
137
- return Number.isNaN(n) ? w : n
138
- }
139
- const array = (): JsonishValue[] => {
140
- i++ // [
141
- const out: JsonishValue[] = []
142
- for (;;) {
143
- skip()
144
- if (i >= src.length) fail("unterminated array")
145
- if (src[i] === "]") { i++; return out }
146
- out.push(value())
147
- }
148
- }
149
- const object = (): Record<string, JsonishValue> => {
150
- i++ // {
151
- const out: Record<string, JsonishValue> = {}
152
- for (;;) {
153
- skip()
154
- if (i >= src.length) fail("unterminated object")
155
- if (src[i] === "}") { i++; return out }
156
- const key = src[i] === '"' || src[i] === "'" ? quoted(src[i]!) : word()
157
- skip()
158
- if (src[i] !== ":" && src[i] !== "=") fail(`expected ':' after key "${key}"`)
159
- i++
160
- out[key] = value()
161
- }
162
- }
163
- skip()
164
- if (src[i] !== "{") fail("expected '{'")
165
- return object()
166
- }
167
-
168
- // ---- artifact builder -----------------------------------------------------------------------------
169
-
170
- const PARAM_TYPES = new Set([
171
- "float", "float2", "float3", "float4",
172
- "int", "int2", "int3", "int4",
173
- "bool", "bool2", "bool3", "bool4",
174
- "float3x3", "float4x4",
175
- ])
176
- const SAMPLER_TYPES = new Set(["sampler2d", "samplerExternal"])
177
-
178
- const unsupported = (reason: string): LiteMaterialArtifact => ({
179
- lecodesLiteMaterial: 1, unsupported: reason,
180
- shadingModel: "unlit", blending: "opaque", maskThreshold: 0.4,
181
- doubleSided: false, culling: "back", depthWrite: true, shadowMultiplier: false,
182
- params: [], samplers: [], fragmentCode: "", writesNormal: false, hasVertexBlock: false,
183
- })
184
-
185
- export const buildLiteMaterialArtifact = (text: string): LiteMaterialArtifact => {
186
- try {
187
- const blocks = extractMatBlocks(text)
188
- if (blocks.material === undefined) return unsupported("no material block")
189
- if (blocks.fragment === undefined) return unsupported("no fragment block")
190
- const def = parseJsonish("{" + blocks.material + "}")
191
-
192
- const params: LiteMaterialParam[] = []
193
- const samplers: { name: string }[] = []
194
- const rawParams = def.parameters === undefined ? []
195
- : Array.isArray(def.parameters) ? def.parameters : [def.parameters]
196
- for (const raw of rawParams) {
197
- if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return unsupported("malformed parameter entry")
198
- const name = String((raw as Record<string, JsonishValue>).name ?? "")
199
- const typeRaw = String((raw as Record<string, JsonishValue>).type ?? "")
200
- const typeMatch = /^(\w+)(?:\[(\d+)\])?$/.exec(typeRaw)
201
- if (!name || !typeMatch) return unsupported(`malformed parameter "${name || typeRaw}"`)
202
- const [, type, size] = typeMatch
203
- if (SAMPLER_TYPES.has(type!)) {
204
- if (size) return unsupported(`sampler arrays are not supported ("${name}")`)
205
- samplers.push({ name })
206
- } else if (PARAM_TYPES.has(type!)) {
207
- params.push(size ? { name, type: type!, size: Number(size) } : { name, type: type! })
208
- } else {
209
- return unsupported(`parameter type "${typeRaw}" ("${name}")`)
210
- }
211
- }
212
-
213
- // cloth/subsurface/specularGlossiness approximate as lit — better than refusing outright.
214
- const shadingModel = def.shadingModel === "unlit" ? "unlit" : "lit"
215
- const blendingRaw = String(def.blending ?? "opaque")
216
- const blending =
217
- blendingRaw === "transparent" || blendingRaw === "fade" || blendingRaw === "add" || blendingRaw === "masked"
218
- ? blendingRaw
219
- : blendingRaw === "multiply" || blendingRaw === "screen" ? "transparent" // approximate
220
- : "opaque"
221
- const culling = def.culling === "none" ? "none" : def.culling === "front" ? "front" : "back"
222
- // Filament defaults: depth write on except for transparent/fade blending.
223
- const depthWrite = typeof def.depthWrite === "boolean" ? def.depthWrite
224
- : blending !== "transparent" && blending !== "fade" && blending !== "add"
225
-
226
- const fragmentCode = blocks.fragment.replace(/\bmaterialParams\./g, "materialParams_")
227
- if (!/\bvoid\s+material\s*\(/.test(fragmentCode)) return unsupported("fragment block has no material() function")
228
-
229
- return {
230
- lecodesLiteMaterial: 1,
231
- shadingModel,
232
- blending,
233
- maskThreshold: typeof def.maskThreshold === "number" ? def.maskThreshold : 0.4,
234
- doubleSided: def.doubleSided === true,
235
- culling,
236
- depthWrite,
237
- shadowMultiplier: def.shadowMultiplier === true,
238
- params,
239
- samplers,
240
- fragmentCode,
241
- writesNormal: /\.normal\s*=/.test(fragmentCode),
242
- hasVertexBlock: blocks.vertex !== undefined,
243
- }
244
- } catch (e) {
245
- return unsupported(e instanceof Error ? e.message : String(e))
246
- }
247
- }
@@ -1,88 +0,0 @@
1
- // The scene-editor compile composition, shared by every host that compiles an edit-mode bundle
2
- // for a .scene.ts file: the platform backend (src/scene/compileSceneEditor.ts), the standalone
3
- // scene-editor dev server, and (later) the lecodes CLI. One bundle on purpose: chisel's
4
- // method-granular DCE trims each bundle's SDK copy to its own calls, so a separately-compiled
5
- // harness could not call scene methods on objects the scene bundle created.
6
-
7
- import { existsSync, readdirSync, readFileSync } from "node:fs"
8
- import { join } from "node:path"
9
- import type { CompileEntry } from "./compileProject"
10
-
11
- /** Where the harness sources land in the compile's file map. The dotfolder can't collide with
12
- * project assets (the tree forbids leading-dot names) and reads clearly in compile errors. */
13
- export const SCENE_HARNESS_DIR = "./.scene-editor"
14
-
15
- /** The virtual entrypoint path (`entryOverride`). */
16
- export const SCENE_ENTRY_PATH = "./.scene-entry.ts"
17
-
18
- /**
19
- * Read the harness sources (packages/projects/src/scene-editor) from a directory:
20
- * `LECODES_SCENE_HARNESS_DIR` env override first (deployments vendor the sources, like
21
- * LECODES_SDK_INJECT does for the SDK), else the given fallback dir. Returns name → source.
22
- */
23
- export const loadSceneHarness = (fallbackDir?: string): Record<string, string> => {
24
- const override = process.env.LECODES_SCENE_HARNESS_DIR
25
- const dir = override && existsSync(override) ? override
26
- : fallbackDir && existsSync(fallbackDir) ? fallbackDir
27
- : null
28
- if (!dir) throw new Error("scene-editor harness sources not found (set LECODES_SCENE_HARNESS_DIR)")
29
- const out: Record<string, string> = {}
30
- for (const f of readdirSync(dir)) {
31
- if (f.endsWith(".ts")) out[f] = readFileSync(join(dir, f), "utf8")
32
- }
33
- return out
34
- }
35
-
36
- /**
37
- * The extra entries that turn a project compile into a scene-editor compile: the harness modules
38
- * plus a virtual entry that (1) sets the edit-mode flag in its own module — imports hoist, so the
39
- * flag must run as a module, first — (2) imports the scene, which registers its handle on
40
- * `__lecodesScenes`, (3) imports the project's `*.editor.ts` plugin files (editor bundles ONLY —
41
- * production compiles never import them, so they cost zero bytes in shipped `app.js`), and
42
- * (4) imports the harness main, which installs `__lecodesSceneHarness`.
43
- * FULL extensions everywhere — exact-match specifiers need no resolver guesswork on dotted names,
44
- * so even the unpatched published chisel resolves the `.scene.ts` import.
45
- *
46
- * `scenePath` is the project path of the scene file ("./scenes/city.scene.ts"); `projectPaths` is
47
- * the project's file list — `.editor.ts` entries are picked out of it. Compile with
48
- * `entryOverride: SCENE_ENTRY_PATH`, `header: false`, `format: "iife"`, `editor: true`.
49
- */
50
- export const sceneEditorEntries = (
51
- scenePath: string,
52
- harness: Record<string, string>,
53
- projectPaths: string[] = [],
54
- ): CompileEntry[] => {
55
- const entries: CompileEntry[] = Object.entries(harness).map(([ name, text ]) => ({
56
- path: `${SCENE_HARNESS_DIR}/${name}`,
57
- type: "text" as const,
58
- text,
59
- }))
60
- entries.push({
61
- path: `${SCENE_HARNESS_DIR}/.edit-mode.ts`,
62
- type: "text",
63
- text: `;(globalThis as any).__lecodesSceneEdit = true\nexport {}\n`,
64
- })
65
- const editorImports = projectPaths
66
- .filter((p) => p.endsWith(".editor.ts"))
67
- .map((p) => `import "${p}"\n`)
68
- .join("")
69
- // Every material asset registers on `__lecodesMaterials` BY PROJECT PATH, so the editor can
70
- // resolve a scene's `material: handle` reference (an import the doc sees as an identifier) to
71
- // the live handle and edit it in place. Imports dedupe with the scene's own, so a material the
72
- // scene uses is the same instance here.
73
- const materialPaths = projectPaths.filter((p) => p.endsWith(".material.ts"))
74
- const materialImports = materialPaths.map((p, i) => `import __mat${i} from "${p}"\n`).join("")
75
- const materialRegister = materialPaths.length === 0 ? ""
76
- : `;(globalThis as any).__lecodesMaterials = { ${materialPaths.map((p, i) => `${JSON.stringify(p)}: __mat${i}`).join(", ")} }\n`
77
- entries.push({
78
- path: SCENE_ENTRY_PATH,
79
- type: "text",
80
- text: `import "${SCENE_HARNESS_DIR}/.edit-mode.ts"\n`
81
- + materialImports
82
- + `import "${scenePath}"\n`
83
- + editorImports
84
- + `import "${SCENE_HARNESS_DIR}/main.ts"\n`
85
- + materialRegister,
86
- })
87
- return entries
88
- }