lecodes-sdk 0.19.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/README.md +114 -0
- package/dist/global.d.ts +503 -0
- package/dist/host.d.ts +61 -0
- package/dist/inject.js +4730 -0
- package/dist/types/animate/animate.d.ts +20 -0
- package/dist/types/animate/bezier.d.ts +2 -0
- package/dist/types/animate/easings.d.ts +21 -0
- package/dist/types/canvas/Canvas.d.ts +168 -0
- package/dist/types/core/Aspect.d.ts +171 -0
- package/dist/types/core/InspectorUI.d.ts +88 -0
- package/dist/types/core/StateMachine.d.ts +81 -0
- package/dist/types/core/color.d.ts +13 -0
- package/dist/types/core/compWrite.d.ts +11 -0
- package/dist/types/core/events.d.ts +11 -0
- package/dist/types/core/fields.d.ts +58 -0
- package/dist/types/core/registry.d.ts +7 -0
- package/dist/types/core/signals.d.ts +29 -0
- package/dist/types/core/time.d.ts +31 -0
- package/dist/types/g2/Camera2D.d.ts +19 -0
- package/dist/types/g2/CharacterController2D.d.ts +134 -0
- package/dist/types/g2/Node2D.d.ts +91 -0
- package/dist/types/g2/OneWay2D.d.ts +24 -0
- package/dist/types/g2/Physics2D.d.ts +147 -0
- package/dist/types/g2/Scene2D.d.ts +72 -0
- package/dist/types/g2/Shape2D.d.ts +58 -0
- package/dist/types/g2/Sprite.d.ts +51 -0
- package/dist/types/g2/SpriteAnimation.d.ts +50 -0
- package/dist/types/g2/SpriteSheet.d.ts +69 -0
- package/dist/types/g2/Texture2D.d.ts +16 -0
- package/dist/types/g2/Tilemap.d.ts +20 -0
- package/dist/types/g2/Tileset.d.ts +32 -0
- package/dist/types/g2/Trigger2D.d.ts +20 -0
- package/dist/types/g2/autotile.d.ts +133 -0
- package/dist/types/g2/cells.d.ts +14 -0
- package/dist/types/g2/defineScene2d.d.ts +141 -0
- package/dist/types/g2/groups2d.d.ts +16 -0
- package/dist/types/g2/loop.d.ts +4 -0
- package/dist/types/g2/scenarios2d.d.ts +30 -0
- package/dist/types/g2/touch.d.ts +2 -0
- package/dist/types/gl/Camera.d.ts +79 -0
- package/dist/types/gl/CameraPlace.d.ts +26 -0
- package/dist/types/gl/CharacterController.d.ts +98 -0
- package/dist/types/gl/Gearbox.d.ts +86 -0
- package/dist/types/gl/Geometry.d.ts +39 -0
- package/dist/types/gl/IK.d.ts +53 -0
- package/dist/types/gl/InstancedMesh.d.ts +46 -0
- package/dist/types/gl/Light.d.ts +73 -0
- package/dist/types/gl/Lightmap.d.ts +85 -0
- package/dist/types/gl/Locomotion.d.ts +279 -0
- package/dist/types/gl/Material.d.ts +100 -0
- package/dist/types/gl/Mesh.d.ts +33 -0
- package/dist/types/gl/Model.d.ts +53 -0
- package/dist/types/gl/NavAgent.d.ts +99 -0
- package/dist/types/gl/NavMesh.d.ts +169 -0
- package/dist/types/gl/Node.d.ts +99 -0
- package/dist/types/gl/Noise.d.ts +20 -0
- package/dist/types/gl/Particles.d.ts +277 -0
- package/dist/types/gl/Physics.d.ts +91 -0
- package/dist/types/gl/Plane.d.ts +19 -0
- package/dist/types/gl/Ragdoll.d.ts +86 -0
- package/dist/types/gl/Ray.d.ts +8 -0
- package/dist/types/gl/Scene.d.ts +221 -0
- package/dist/types/gl/Shape.d.ts +122 -0
- package/dist/types/gl/Terrain.d.ts +280 -0
- package/dist/types/gl/Texture.d.ts +27 -0
- package/dist/types/gl/Trigger.d.ts +10 -0
- package/dist/types/gl/Vehicle.d.ts +191 -0
- package/dist/types/gl/Wheel.d.ts +95 -0
- package/dist/types/gl/animation/AnimationClip.d.ts +60 -0
- package/dist/types/gl/animation/Animator.d.ts +219 -0
- package/dist/types/gl/animation/Layer.d.ts +31 -0
- package/dist/types/gl/animation/Loop.d.ts +17 -0
- package/dist/types/gl/animation/Playback.d.ts +36 -0
- package/dist/types/gl/animation/core.d.ts +367 -0
- package/dist/types/gl/controls.d.ts +19 -0
- package/dist/types/gl/physicsEvents.d.ts +1 -0
- package/dist/types/gl/scenarios.d.ts +98 -0
- package/dist/types/gl/state.d.ts +5 -0
- package/dist/types/gl/terrainMesh.d.ts +46 -0
- package/dist/types/gl/touch.d.ts +2 -0
- package/dist/types/inject.d.ts +123 -0
- package/dist/types/math/Mathf.d.ts +39 -0
- package/dist/types/math/mat4.d.ts +66 -0
- package/dist/types/math/quat.d.ts +53 -0
- package/dist/types/math/vec.d.ts +129 -0
- package/dist/types/net/codec.d.ts +25 -0
- package/dist/types/net/core.d.ts +106 -0
- package/dist/types/net/index.d.ts +80 -0
- package/dist/types/net/replication.d.ts +101 -0
- package/dist/types/plugins/camera.d.ts +25 -0
- package/dist/types/plugins/geolocation.d.ts +39 -0
- package/dist/types/plugins/oauth.d.ts +25 -0
- package/dist/types/plugins/permission.d.ts +1 -0
- package/dist/types/plugins/push.d.ts +46 -0
- package/dist/types/plugins/qr.d.ts +21 -0
- package/dist/types/plugins/service.d.ts +33 -0
- package/dist/types/runtime/app.d.ts +67 -0
- package/dist/types/runtime/appEvents.d.ts +7 -0
- package/dist/types/runtime/channel.d.ts +1 -0
- package/dist/types/runtime/clipboard.d.ts +7 -0
- package/dist/types/runtime/datetime.d.ts +80 -0
- package/dist/types/runtime/device.d.ts +126 -0
- package/dist/types/runtime/fetch.d.ts +31 -0
- package/dist/types/runtime/files.d.ts +33 -0
- package/dist/types/runtime/input.d.ts +121 -0
- package/dist/types/runtime/media.d.ts +46 -0
- package/dist/types/runtime/misc.d.ts +11 -0
- package/dist/types/runtime/net.d.ts +15 -0
- package/dist/types/runtime/rpc.d.ts +44 -0
- package/dist/types/runtime/service.d.ts +1 -0
- package/dist/types/runtime/share.d.ts +2 -0
- package/dist/types/runtime/storage.d.ts +5 -0
- package/dist/types/runtime/touch.d.ts +56 -0
- package/dist/types/scene/defineScene.d.ts +296 -0
- package/dist/types/scene/editorPlugins.d.ts +82 -0
- package/dist/types/scene/gizmos.d.ts +56 -0
- package/dist/types/scene/grammar.d.ts +56 -0
- package/dist/types/scene/level.d.ts +98 -0
- package/dist/types/scene/material.d.ts +76 -0
- package/dist/types/server/auth/appConfig.d.ts +16 -0
- package/dist/types/server/auth/global.d.ts +56 -0
- package/dist/types/server/auth/models.d.ts +164 -0
- package/dist/types/server/auth/types.d.ts +56 -0
- package/dist/types/server/channel.d.ts +28 -0
- package/dist/types/server/context.d.ts +27 -0
- package/dist/types/server/db/defineDb.d.ts +36 -0
- package/dist/types/server/db/fields.d.ts +146 -0
- package/dist/types/server/db/index.d.ts +6 -0
- package/dist/types/server/db/marci/query.d.ts +326 -0
- package/dist/types/server/db/types.d.ts +163 -0
- package/dist/types/server/errors.d.ts +8 -0
- package/dist/types/server/inject.d.ts +5 -0
- package/dist/types/ui/NativeView.d.ts +38 -0
- package/dist/types/ui/UI.d.ts +27 -0
- package/dist/types/ui/UIBottomSheet.d.ts +71 -0
- package/dist/types/ui/UIButton.d.ts +30 -0
- package/dist/types/ui/UIContainer.d.ts +33 -0
- package/dist/types/ui/UIImage.d.ts +35 -0
- package/dist/types/ui/UIInput.d.ts +110 -0
- package/dist/types/ui/UIModal.d.ts +70 -0
- package/dist/types/ui/UINode.d.ts +363 -0
- package/dist/types/ui/UIPager.d.ts +123 -0
- package/dist/types/ui/UIPopover.d.ts +39 -0
- package/dist/types/ui/UIScreen.d.ts +57 -0
- package/dist/types/ui/UIScrollable.d.ts +40 -0
- package/dist/types/ui/UISpacer.d.ts +9 -0
- package/dist/types/ui/UITabs.d.ts +96 -0
- package/dist/types/ui/UIText.d.ts +19 -0
- package/dist/types/ui/UIVideo.d.ts +28 -0
- package/dist/types/ui/UIVirtualizedList.d.ts +97 -0
- package/dist/types/ui/UIWidget.d.ts +65 -0
- package/dist/types/ui/fonts.d.ts +9 -0
- package/dist/types/ui/presentable.d.ts +68 -0
- package/dist/types/ui/router.d.ts +40 -0
- package/dist/types/ui/theme.d.ts +26 -0
- package/dist/types.json +1 -0
- package/package.json +46 -0
- package/prompts/2d.md +395 -0
- package/prompts/3d-scene-files.md +113 -0
- package/prompts/3d-scene.md +119 -0
- package/prompts/3d.md +303 -0
- package/prompts/README.md +142 -0
- package/prompts/ar.md +109 -0
- package/prompts/canvas.md +27 -0
- package/prompts/compose.ts +46 -0
- package/prompts/concept.md +49 -0
- package/prompts/core-design.md +75 -0
- package/prompts/core.md +264 -0
- package/prompts/design.md +218 -0
- package/prompts/dist/2d-game.md +1530 -0
- package/prompts/dist/3d-app.md +1672 -0
- package/prompts/dist/ar-app.md +1548 -0
- package/prompts/dist/concept.md +49 -0
- package/prompts/dist/design.md +498 -0
- package/prompts/dist/ui-app.md +1134 -0
- package/prompts/index.md +37 -0
- package/prompts/intake-prompt.md +33 -0
- package/prompts/namer-prompt.md +12 -0
- package/prompts/router-prompt.md +50 -0
- package/prompts/select.ts +111 -0
- package/prompts/ui-design.md +203 -0
- package/prompts/ui.md +803 -0
- package/src/animate/animate.ts +238 -0
- package/src/animate/bezier.ts +138 -0
- package/src/animate/easings.ts +126 -0
- package/src/bridges.d.ts +1345 -0
- package/src/canvas/Canvas.ts +305 -0
- package/src/compile/__tests__/assetIconMacro.test.ts +219 -0
- package/src/compile/__tests__/assetMacro.test.ts +74 -0
- package/src/compile/__tests__/assetName.test.ts +55 -0
- package/src/compile/__tests__/compile.test.ts +287 -0
- package/src/compile/__tests__/detectEntry.test.ts +132 -0
- package/src/compile/__tests__/fontMacro.test.ts +199 -0
- package/src/compile/aspectMacro.ts +86 -0
- package/src/compile/assetIconMacro.ts +384 -0
- package/src/compile/assetMacro.ts +146 -0
- package/src/compile/assetName.ts +50 -0
- package/src/compile/bundler.ts +287 -0
- package/src/compile/compileProject.ts +127 -0
- package/src/compile/detectEntry.ts +128 -0
- package/src/compile/fontMacro.ts +459 -0
- package/src/compile/fontRegistry.ts +78 -0
- package/src/compile/header.ts +67 -0
- package/src/compile/index.ts +100 -0
- package/src/compile/libraryImports.ts +52 -0
- package/src/compile/liteMaterial.ts +247 -0
- package/src/compile/sceneEditor.ts +88 -0
- package/src/compile/serverSplit.ts +233 -0
- package/src/compile/serverTypes.ts +227 -0
- package/src/compile/sfnt.ts +98 -0
- package/src/compile/shaderSchema.ts +202 -0
- package/src/compile/shaderTargets.ts +77 -0
- package/src/compile/sourcemap.ts +25 -0
- package/src/core/Aspect.ts +568 -0
- package/src/core/InspectorUI.ts +212 -0
- package/src/core/StateMachine.ts +308 -0
- package/src/core/__tests__/stateMachine.test.ts +132 -0
- package/src/core/color.ts +66 -0
- package/src/core/compWrite.ts +42 -0
- package/src/core/events.ts +38 -0
- package/src/core/fields.ts +120 -0
- package/src/core/registry.ts +23 -0
- package/src/core/signals.ts +277 -0
- package/src/core/time.ts +84 -0
- package/src/g2/Camera2D.ts +40 -0
- package/src/g2/CharacterController2D.ts +276 -0
- package/src/g2/Node2D.ts +267 -0
- package/src/g2/OneWay2D.ts +66 -0
- package/src/g2/Physics2D.ts +346 -0
- package/src/g2/Scene2D.ts +209 -0
- package/src/g2/Shape2D.ts +259 -0
- package/src/g2/Sprite.ts +89 -0
- package/src/g2/SpriteAnimation.ts +171 -0
- package/src/g2/SpriteSheet.ts +166 -0
- package/src/g2/Texture2D.ts +47 -0
- package/src/g2/Tilemap.ts +41 -0
- package/src/g2/Tileset.ts +71 -0
- package/src/g2/Trigger2D.ts +77 -0
- package/src/g2/autotile.ts +433 -0
- package/src/g2/cells.ts +91 -0
- package/src/g2/defineScene2d.ts +381 -0
- package/src/g2/groups2d.ts +106 -0
- package/src/g2/loop.ts +50 -0
- package/src/g2/scenarios2d.ts +69 -0
- package/src/g2/touch.ts +83 -0
- package/src/gl/Camera.ts +160 -0
- package/src/gl/CameraPlace.ts +52 -0
- package/src/gl/CharacterController.ts +238 -0
- package/src/gl/Gearbox.ts +212 -0
- package/src/gl/Geometry.ts +279 -0
- package/src/gl/IK.ts +193 -0
- package/src/gl/InstancedMesh.ts +132 -0
- package/src/gl/Light.ts +135 -0
- package/src/gl/Lightmap.ts +402 -0
- package/src/gl/Locomotion.ts +498 -0
- package/src/gl/Material.ts +279 -0
- package/src/gl/Mesh.ts +83 -0
- package/src/gl/Model.ts +124 -0
- package/src/gl/NavAgent.ts +337 -0
- package/src/gl/NavMesh.ts +397 -0
- package/src/gl/Node.ts +350 -0
- package/src/gl/Noise.ts +30 -0
- package/src/gl/Particles.ts +676 -0
- package/src/gl/Physics.ts +222 -0
- package/src/gl/Plane.ts +53 -0
- package/src/gl/Ragdoll.ts +270 -0
- package/src/gl/Ray.ts +16 -0
- package/src/gl/Scene.ts +505 -0
- package/src/gl/Shape.ts +409 -0
- package/src/gl/Terrain.ts +1092 -0
- package/src/gl/Texture.ts +63 -0
- package/src/gl/Trigger.ts +45 -0
- package/src/gl/Vehicle.ts +473 -0
- package/src/gl/Wheel.ts +240 -0
- package/src/gl/animation/AnimationClip.ts +204 -0
- package/src/gl/animation/Animator.ts +329 -0
- package/src/gl/animation/Layer.ts +39 -0
- package/src/gl/animation/Loop.ts +31 -0
- package/src/gl/animation/Playback.ts +52 -0
- package/src/gl/animation/core.ts +670 -0
- package/src/gl/controls.ts +95 -0
- package/src/gl/physicsEvents.ts +20 -0
- package/src/gl/scenarios.ts +291 -0
- package/src/gl/state.ts +6 -0
- package/src/gl/terrainMesh.ts +219 -0
- package/src/gl/touch.ts +68 -0
- package/src/host.d.ts +61 -0
- package/src/inject.ts +203 -0
- package/src/math/Mathf.ts +118 -0
- package/src/math/mat4.ts +278 -0
- package/src/math/quat.ts +232 -0
- package/src/math/vec.ts +255 -0
- package/src/net/codec.ts +119 -0
- package/src/net/core.ts +384 -0
- package/src/net/index.ts +181 -0
- package/src/net/replication.ts +622 -0
- package/src/plugins/camera.ts +81 -0
- package/src/plugins/geolocation.ts +123 -0
- package/src/plugins/oauth.ts +61 -0
- package/src/plugins/permission.ts +7 -0
- package/src/plugins/push.ts +132 -0
- package/src/plugins/qr.ts +73 -0
- package/src/plugins/service.ts +47 -0
- package/src/runtime/app.ts +101 -0
- package/src/runtime/appEvents.ts +54 -0
- package/src/runtime/channel.ts +61 -0
- package/src/runtime/clipboard.ts +20 -0
- package/src/runtime/datetime.ts +329 -0
- package/src/runtime/device.ts +293 -0
- package/src/runtime/fetch.ts +77 -0
- package/src/runtime/files.ts +108 -0
- package/src/runtime/input.ts +175 -0
- package/src/runtime/media.ts +111 -0
- package/src/runtime/misc.ts +16 -0
- package/src/runtime/net.ts +36 -0
- package/src/runtime/rpc.ts +218 -0
- package/src/runtime/service.ts +83 -0
- package/src/runtime/share.ts +9 -0
- package/src/runtime/storage.ts +13 -0
- package/src/runtime/touch.ts +76 -0
- package/src/scene/defineScene.ts +1396 -0
- package/src/scene/editorPlugins.ts +110 -0
- package/src/scene/gizmos.ts +148 -0
- package/src/scene/grammar.ts +120 -0
- package/src/scene/level.ts +296 -0
- package/src/scene/material.ts +188 -0
- package/src/server/auth/appConfig.ts +12 -0
- package/src/server/auth/global.ts +80 -0
- package/src/server/auth/host.ts +318 -0
- package/src/server/auth/models.ts +83 -0
- package/src/server/auth/types.ts +50 -0
- package/src/server/channel.ts +56 -0
- package/src/server/context.ts +36 -0
- package/src/server/db/defineDb.ts +237 -0
- package/src/server/db/fields.ts +132 -0
- package/src/server/db/httpTransport.ts +93 -0
- package/src/server/db/index.ts +7 -0
- package/src/server/db/marci/query.ts +412 -0
- package/src/server/db/types.ts +202 -0
- package/src/server/errors.ts +12 -0
- package/src/server/host.ts +74 -0
- package/src/server/inject.ts +13 -0
- package/src/server/runtime.ts +133 -0
- package/src/server/validate.ts +87 -0
- package/src/ui/NativeView.ts +142 -0
- package/src/ui/UI.ts +39 -0
- package/src/ui/UIBottomSheet.ts +139 -0
- package/src/ui/UIButton.ts +101 -0
- package/src/ui/UIContainer.ts +60 -0
- package/src/ui/UIImage.ts +83 -0
- package/src/ui/UIInput.ts +185 -0
- package/src/ui/UIModal.ts +139 -0
- package/src/ui/UINode.ts +830 -0
- package/src/ui/UIPager.ts +362 -0
- package/src/ui/UIPopover.ts +100 -0
- package/src/ui/UIScreen.ts +123 -0
- package/src/ui/UIScrollable.ts +87 -0
- package/src/ui/UISpacer.ts +14 -0
- package/src/ui/UITabs.ts +236 -0
- package/src/ui/UIText.ts +51 -0
- package/src/ui/UIVideo.ts +88 -0
- package/src/ui/UIVirtualizedList.ts +241 -0
- package/src/ui/UIWidget.ts +127 -0
- package/src/ui/fonts.ts +13 -0
- package/src/ui/presentable.ts +117 -0
- package/src/ui/router.ts +132 -0
- package/src/ui/theme.ts +84 -0
|
@@ -0,0 +1,202 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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.backend` into the
|
|
5
|
+
// 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. The Windows desktop host runs OpenGL
|
|
11
|
+
// without external (OES) sampler support, so it gets samplerExternal rewritten to sampler2d. The
|
|
12
|
+
// desktop variant exists because the desktop Filament engine rejects the mobile _opengl shader
|
|
13
|
+
// ("not built for desktop"); _creator.backend returns "desktop" there.
|
|
14
|
+
//
|
|
15
|
+
// The web runtime (Filament wasm) loads the mobile `_opengl` artifact as-is: the engine rewrites
|
|
16
|
+
// `samplerExternalOES` to `sampler2D` at shader-compile time on contexts without
|
|
17
|
+
// OES_EGL_image_external_essl3 (fork commit `lecodes 0020`), so WebGL needs no artifact of its own.
|
|
18
|
+
// The former `webgl` target (a source-rewritten copy of the mobile build) is gone since 2026-08-29.
|
|
19
|
+
//
|
|
20
|
+
// These names are opaque identities for a (profile, api, rewrite) triple, not API names — hence
|
|
21
|
+
// "opengl" (mobile profile) and "desktop" (desktop profile) both being OpenGL. Their only job is to
|
|
22
|
+
// be stable and unique: the runtime substitutes one into `<hash>_<name>.filamat`.
|
|
23
|
+
export const PLATFORM_BUILD = {
|
|
24
|
+
opengl: { profile: "mobile", api: "opengl", replaceExternal: false },
|
|
25
|
+
metal: { profile: "mobile", api: "metal", replaceExternal: false },
|
|
26
|
+
desktop: { profile: "desktop", api: "opengl", replaceExternal: true },
|
|
27
|
+
} as const
|
|
28
|
+
export type MatcPlatform = keyof typeof PLATFORM_BUILD
|
|
29
|
+
|
|
30
|
+
// Targets the CLI compiles LOCALLY and the platform does not. Deliberately a separate table, not
|
|
31
|
+
// another PLATFORM_BUILD entry: `MatcPlatform` feeds the backend's `Platform` type, which is checked
|
|
32
|
+
// against the `shaderPlatform` pg enum — widening it would break the backend's inserts at compile
|
|
33
|
+
// time for a value the server never produces. Keep local-only targets here until the platform grows
|
|
34
|
+
// the matching enum value (docs/desktop-vulkan-release-plan.md §4 "Known limitation").
|
|
35
|
+
//
|
|
36
|
+
// 'desktop-vulkan' = the Windows Vulkan desktop host: same DESKTOP shader model as 'desktop' but
|
|
37
|
+
// SPIR-V, and the two are not interchangeable — Filament rejects a foreign one outright ("not built
|
|
38
|
+
// for any of the OpenGL backend's supported shader languages"). `_creator.backend` returns
|
|
39
|
+
// "desktop-vulkan" on that host.
|
|
40
|
+
export const LOCAL_PLATFORM_BUILD = {
|
|
41
|
+
"desktop-vulkan": { profile: "desktop", api: "vulkan", replaceExternal: true },
|
|
42
|
+
} as const
|
|
43
|
+
export type LocalMatcPlatform = keyof typeof LOCAL_PLATFORM_BUILD
|
|
44
|
+
|
|
45
|
+
/** Every matc target, local-only ones included — the lookup table for matcArgs. */
|
|
46
|
+
export const ALL_PLATFORM_BUILD = { ...PLATFORM_BUILD, ...LOCAL_PLATFORM_BUILD }
|
|
47
|
+
export type AnyMatcPlatform = MatcPlatform | LocalMatcPlatform
|
|
48
|
+
|
|
49
|
+
/** The local-only targets, as a list (order matters where it feeds an artifact family). */
|
|
50
|
+
export const LOCAL_ONLY_PLATFORMS: LocalMatcPlatform[] = ["desktop-vulkan"]
|
|
51
|
+
|
|
52
|
+
// 'webgl-lite' is not a matc target: viewer-lite gets a JSON artifact (parsed .mat — see
|
|
53
|
+
// liteMaterial.ts) that it wraps in its own GLSL template at runtime. `_creator.backend` is
|
|
54
|
+
// "webgl-lite" on that host.
|
|
55
|
+
export type ShaderPlatform = MatcPlatform | "webgl-lite"
|
|
56
|
+
|
|
57
|
+
/** Every platform the LOCAL compile can produce (matc targets + the lite JSON). */
|
|
58
|
+
export type AnyShaderPlatform = AnyMatcPlatform | "webgl-lite"
|
|
59
|
+
|
|
60
|
+
/** Bump when the matc invocation for an EXISTING target name changes (a different -p/-a/rewrite for
|
|
61
|
+
* a name that already exists). The CLI folds this into its artifact cache key, so such a change
|
|
62
|
+
* invalidates caches that would otherwise look complete — adding or removing a target name is
|
|
63
|
+
* already caught by the artifact-family check, but changing the argv behind a name is not.
|
|
64
|
+
* 1 = 'desktop-vulkan' added (2026-08-24). */
|
|
65
|
+
export const TARGET_MATRIX_GENERATION = 1
|
|
66
|
+
|
|
67
|
+
/** The matc platforms every .mat source is compiled for — the SERVER's contract. It deliberately
|
|
68
|
+
* does not include LOCAL_ONLY_PLATFORMS; the CLI appends those itself (lecodes-cli
|
|
69
|
+
* src/compile/shaders.ts). opengl leads: its src is the template the bundle substitutes the
|
|
70
|
+
* runtime backend into. */
|
|
71
|
+
export const MATC_PLATFORMS: MatcPlatform[] = ["opengl", "metal", "desktop"]
|
|
72
|
+
|
|
73
|
+
/** The matc argv (without the executable) for one target. */
|
|
74
|
+
export const matcArgs = (platform: AnyMatcPlatform, outPath: string, inPath: string): string[] => {
|
|
75
|
+
const build = ALL_PLATFORM_BUILD[platform]
|
|
76
|
+
return ["-p", build.profile, "--no-essl1", "-a", build.api, "-o", outPath, inPath]
|
|
77
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
}
|