lecodes-cli 0.18.1 → 0.18.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.
- package/dist/index.js +1008 -488
- package/package.json +1 -1
- package/runtime/scene-harness.json +1 -1
- package/runtime/sdk/gl/Camera.ts +39 -0
- package/runtime/sdk/gl/CameraPlace.ts +52 -52
- package/runtime/sdk/gl/Scene.ts +13 -0
- package/runtime/sdk/gl/Trigger.ts +45 -45
- package/runtime/sdk/gl/scenarios.ts +291 -291
- package/runtime/sdk/gl/state.ts +6 -6
- package/runtime/sdk/runtime/device.ts +102 -1
- package/runtime/sdk/scene/defineScene.ts +1227 -1227
- package/runtime/sdk/scene/gizmos.ts +148 -148
- package/runtime/sdk-types.json +1 -1
- package/runtime/sdk/compile/aspectMacro.ts +0 -86
- package/runtime/sdk/compile/assetIconMacro.ts +0 -384
- package/runtime/sdk/compile/assetMacro.ts +0 -146
- package/runtime/sdk/compile/assetName.ts +0 -50
- package/runtime/sdk/compile/bundler.ts +0 -287
- package/runtime/sdk/compile/compileProject.ts +0 -129
- package/runtime/sdk/compile/detectEntry.ts +0 -128
- package/runtime/sdk/compile/fontMacro.ts +0 -459
- package/runtime/sdk/compile/fontRegistry.ts +0 -78
- package/runtime/sdk/compile/header.ts +0 -67
- package/runtime/sdk/compile/index.ts +0 -100
- package/runtime/sdk/compile/libraryImports.ts +0 -52
- package/runtime/sdk/compile/liteMaterial.ts +0 -247
- package/runtime/sdk/compile/sceneEditor.ts +0 -88
- package/runtime/sdk/compile/serverSplit.ts +0 -233
- package/runtime/sdk/compile/serverTypes.ts +0 -227
- package/runtime/sdk/compile/sfnt.ts +0 -98
- package/runtime/sdk/compile/shaderSchema.ts +0 -202
- package/runtime/sdk/compile/shaderTargets.ts +0 -81
- package/runtime/sdk/compile/sourcemap.ts +0 -25
|
@@ -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
|
-
}
|