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.
Files changed (367) hide show
  1. package/README.md +114 -0
  2. package/dist/global.d.ts +503 -0
  3. package/dist/host.d.ts +61 -0
  4. package/dist/inject.js +4730 -0
  5. package/dist/types/animate/animate.d.ts +20 -0
  6. package/dist/types/animate/bezier.d.ts +2 -0
  7. package/dist/types/animate/easings.d.ts +21 -0
  8. package/dist/types/canvas/Canvas.d.ts +168 -0
  9. package/dist/types/core/Aspect.d.ts +171 -0
  10. package/dist/types/core/InspectorUI.d.ts +88 -0
  11. package/dist/types/core/StateMachine.d.ts +81 -0
  12. package/dist/types/core/color.d.ts +13 -0
  13. package/dist/types/core/compWrite.d.ts +11 -0
  14. package/dist/types/core/events.d.ts +11 -0
  15. package/dist/types/core/fields.d.ts +58 -0
  16. package/dist/types/core/registry.d.ts +7 -0
  17. package/dist/types/core/signals.d.ts +29 -0
  18. package/dist/types/core/time.d.ts +31 -0
  19. package/dist/types/g2/Camera2D.d.ts +19 -0
  20. package/dist/types/g2/CharacterController2D.d.ts +134 -0
  21. package/dist/types/g2/Node2D.d.ts +91 -0
  22. package/dist/types/g2/OneWay2D.d.ts +24 -0
  23. package/dist/types/g2/Physics2D.d.ts +147 -0
  24. package/dist/types/g2/Scene2D.d.ts +72 -0
  25. package/dist/types/g2/Shape2D.d.ts +58 -0
  26. package/dist/types/g2/Sprite.d.ts +51 -0
  27. package/dist/types/g2/SpriteAnimation.d.ts +50 -0
  28. package/dist/types/g2/SpriteSheet.d.ts +69 -0
  29. package/dist/types/g2/Texture2D.d.ts +16 -0
  30. package/dist/types/g2/Tilemap.d.ts +20 -0
  31. package/dist/types/g2/Tileset.d.ts +32 -0
  32. package/dist/types/g2/Trigger2D.d.ts +20 -0
  33. package/dist/types/g2/autotile.d.ts +133 -0
  34. package/dist/types/g2/cells.d.ts +14 -0
  35. package/dist/types/g2/defineScene2d.d.ts +141 -0
  36. package/dist/types/g2/groups2d.d.ts +16 -0
  37. package/dist/types/g2/loop.d.ts +4 -0
  38. package/dist/types/g2/scenarios2d.d.ts +30 -0
  39. package/dist/types/g2/touch.d.ts +2 -0
  40. package/dist/types/gl/Camera.d.ts +79 -0
  41. package/dist/types/gl/CameraPlace.d.ts +26 -0
  42. package/dist/types/gl/CharacterController.d.ts +98 -0
  43. package/dist/types/gl/Gearbox.d.ts +86 -0
  44. package/dist/types/gl/Geometry.d.ts +39 -0
  45. package/dist/types/gl/IK.d.ts +53 -0
  46. package/dist/types/gl/InstancedMesh.d.ts +46 -0
  47. package/dist/types/gl/Light.d.ts +73 -0
  48. package/dist/types/gl/Lightmap.d.ts +85 -0
  49. package/dist/types/gl/Locomotion.d.ts +279 -0
  50. package/dist/types/gl/Material.d.ts +100 -0
  51. package/dist/types/gl/Mesh.d.ts +33 -0
  52. package/dist/types/gl/Model.d.ts +53 -0
  53. package/dist/types/gl/NavAgent.d.ts +99 -0
  54. package/dist/types/gl/NavMesh.d.ts +169 -0
  55. package/dist/types/gl/Node.d.ts +99 -0
  56. package/dist/types/gl/Noise.d.ts +20 -0
  57. package/dist/types/gl/Particles.d.ts +277 -0
  58. package/dist/types/gl/Physics.d.ts +91 -0
  59. package/dist/types/gl/Plane.d.ts +19 -0
  60. package/dist/types/gl/Ragdoll.d.ts +86 -0
  61. package/dist/types/gl/Ray.d.ts +8 -0
  62. package/dist/types/gl/Scene.d.ts +221 -0
  63. package/dist/types/gl/Shape.d.ts +122 -0
  64. package/dist/types/gl/Terrain.d.ts +280 -0
  65. package/dist/types/gl/Texture.d.ts +27 -0
  66. package/dist/types/gl/Trigger.d.ts +10 -0
  67. package/dist/types/gl/Vehicle.d.ts +191 -0
  68. package/dist/types/gl/Wheel.d.ts +95 -0
  69. package/dist/types/gl/animation/AnimationClip.d.ts +60 -0
  70. package/dist/types/gl/animation/Animator.d.ts +219 -0
  71. package/dist/types/gl/animation/Layer.d.ts +31 -0
  72. package/dist/types/gl/animation/Loop.d.ts +17 -0
  73. package/dist/types/gl/animation/Playback.d.ts +36 -0
  74. package/dist/types/gl/animation/core.d.ts +367 -0
  75. package/dist/types/gl/controls.d.ts +19 -0
  76. package/dist/types/gl/physicsEvents.d.ts +1 -0
  77. package/dist/types/gl/scenarios.d.ts +98 -0
  78. package/dist/types/gl/state.d.ts +5 -0
  79. package/dist/types/gl/terrainMesh.d.ts +46 -0
  80. package/dist/types/gl/touch.d.ts +2 -0
  81. package/dist/types/inject.d.ts +123 -0
  82. package/dist/types/math/Mathf.d.ts +39 -0
  83. package/dist/types/math/mat4.d.ts +66 -0
  84. package/dist/types/math/quat.d.ts +53 -0
  85. package/dist/types/math/vec.d.ts +129 -0
  86. package/dist/types/net/codec.d.ts +25 -0
  87. package/dist/types/net/core.d.ts +106 -0
  88. package/dist/types/net/index.d.ts +80 -0
  89. package/dist/types/net/replication.d.ts +101 -0
  90. package/dist/types/plugins/camera.d.ts +25 -0
  91. package/dist/types/plugins/geolocation.d.ts +39 -0
  92. package/dist/types/plugins/oauth.d.ts +25 -0
  93. package/dist/types/plugins/permission.d.ts +1 -0
  94. package/dist/types/plugins/push.d.ts +46 -0
  95. package/dist/types/plugins/qr.d.ts +21 -0
  96. package/dist/types/plugins/service.d.ts +33 -0
  97. package/dist/types/runtime/app.d.ts +67 -0
  98. package/dist/types/runtime/appEvents.d.ts +7 -0
  99. package/dist/types/runtime/channel.d.ts +1 -0
  100. package/dist/types/runtime/clipboard.d.ts +7 -0
  101. package/dist/types/runtime/datetime.d.ts +80 -0
  102. package/dist/types/runtime/device.d.ts +126 -0
  103. package/dist/types/runtime/fetch.d.ts +31 -0
  104. package/dist/types/runtime/files.d.ts +33 -0
  105. package/dist/types/runtime/input.d.ts +121 -0
  106. package/dist/types/runtime/media.d.ts +46 -0
  107. package/dist/types/runtime/misc.d.ts +11 -0
  108. package/dist/types/runtime/net.d.ts +15 -0
  109. package/dist/types/runtime/rpc.d.ts +44 -0
  110. package/dist/types/runtime/service.d.ts +1 -0
  111. package/dist/types/runtime/share.d.ts +2 -0
  112. package/dist/types/runtime/storage.d.ts +5 -0
  113. package/dist/types/runtime/touch.d.ts +56 -0
  114. package/dist/types/scene/defineScene.d.ts +296 -0
  115. package/dist/types/scene/editorPlugins.d.ts +82 -0
  116. package/dist/types/scene/gizmos.d.ts +56 -0
  117. package/dist/types/scene/grammar.d.ts +56 -0
  118. package/dist/types/scene/level.d.ts +98 -0
  119. package/dist/types/scene/material.d.ts +76 -0
  120. package/dist/types/server/auth/appConfig.d.ts +16 -0
  121. package/dist/types/server/auth/global.d.ts +56 -0
  122. package/dist/types/server/auth/models.d.ts +164 -0
  123. package/dist/types/server/auth/types.d.ts +56 -0
  124. package/dist/types/server/channel.d.ts +28 -0
  125. package/dist/types/server/context.d.ts +27 -0
  126. package/dist/types/server/db/defineDb.d.ts +36 -0
  127. package/dist/types/server/db/fields.d.ts +146 -0
  128. package/dist/types/server/db/index.d.ts +6 -0
  129. package/dist/types/server/db/marci/query.d.ts +326 -0
  130. package/dist/types/server/db/types.d.ts +163 -0
  131. package/dist/types/server/errors.d.ts +8 -0
  132. package/dist/types/server/inject.d.ts +5 -0
  133. package/dist/types/ui/NativeView.d.ts +38 -0
  134. package/dist/types/ui/UI.d.ts +27 -0
  135. package/dist/types/ui/UIBottomSheet.d.ts +71 -0
  136. package/dist/types/ui/UIButton.d.ts +30 -0
  137. package/dist/types/ui/UIContainer.d.ts +33 -0
  138. package/dist/types/ui/UIImage.d.ts +35 -0
  139. package/dist/types/ui/UIInput.d.ts +110 -0
  140. package/dist/types/ui/UIModal.d.ts +70 -0
  141. package/dist/types/ui/UINode.d.ts +363 -0
  142. package/dist/types/ui/UIPager.d.ts +123 -0
  143. package/dist/types/ui/UIPopover.d.ts +39 -0
  144. package/dist/types/ui/UIScreen.d.ts +57 -0
  145. package/dist/types/ui/UIScrollable.d.ts +40 -0
  146. package/dist/types/ui/UISpacer.d.ts +9 -0
  147. package/dist/types/ui/UITabs.d.ts +96 -0
  148. package/dist/types/ui/UIText.d.ts +19 -0
  149. package/dist/types/ui/UIVideo.d.ts +28 -0
  150. package/dist/types/ui/UIVirtualizedList.d.ts +97 -0
  151. package/dist/types/ui/UIWidget.d.ts +65 -0
  152. package/dist/types/ui/fonts.d.ts +9 -0
  153. package/dist/types/ui/presentable.d.ts +68 -0
  154. package/dist/types/ui/router.d.ts +40 -0
  155. package/dist/types/ui/theme.d.ts +26 -0
  156. package/dist/types.json +1 -0
  157. package/package.json +46 -0
  158. package/prompts/2d.md +395 -0
  159. package/prompts/3d-scene-files.md +113 -0
  160. package/prompts/3d-scene.md +119 -0
  161. package/prompts/3d.md +303 -0
  162. package/prompts/README.md +142 -0
  163. package/prompts/ar.md +109 -0
  164. package/prompts/canvas.md +27 -0
  165. package/prompts/compose.ts +46 -0
  166. package/prompts/concept.md +49 -0
  167. package/prompts/core-design.md +75 -0
  168. package/prompts/core.md +264 -0
  169. package/prompts/design.md +218 -0
  170. package/prompts/dist/2d-game.md +1530 -0
  171. package/prompts/dist/3d-app.md +1672 -0
  172. package/prompts/dist/ar-app.md +1548 -0
  173. package/prompts/dist/concept.md +49 -0
  174. package/prompts/dist/design.md +498 -0
  175. package/prompts/dist/ui-app.md +1134 -0
  176. package/prompts/index.md +37 -0
  177. package/prompts/intake-prompt.md +33 -0
  178. package/prompts/namer-prompt.md +12 -0
  179. package/prompts/router-prompt.md +50 -0
  180. package/prompts/select.ts +111 -0
  181. package/prompts/ui-design.md +203 -0
  182. package/prompts/ui.md +803 -0
  183. package/src/animate/animate.ts +238 -0
  184. package/src/animate/bezier.ts +138 -0
  185. package/src/animate/easings.ts +126 -0
  186. package/src/bridges.d.ts +1345 -0
  187. package/src/canvas/Canvas.ts +305 -0
  188. package/src/compile/__tests__/assetIconMacro.test.ts +219 -0
  189. package/src/compile/__tests__/assetMacro.test.ts +74 -0
  190. package/src/compile/__tests__/assetName.test.ts +55 -0
  191. package/src/compile/__tests__/compile.test.ts +287 -0
  192. package/src/compile/__tests__/detectEntry.test.ts +132 -0
  193. package/src/compile/__tests__/fontMacro.test.ts +199 -0
  194. package/src/compile/aspectMacro.ts +86 -0
  195. package/src/compile/assetIconMacro.ts +384 -0
  196. package/src/compile/assetMacro.ts +146 -0
  197. package/src/compile/assetName.ts +50 -0
  198. package/src/compile/bundler.ts +287 -0
  199. package/src/compile/compileProject.ts +127 -0
  200. package/src/compile/detectEntry.ts +128 -0
  201. package/src/compile/fontMacro.ts +459 -0
  202. package/src/compile/fontRegistry.ts +78 -0
  203. package/src/compile/header.ts +67 -0
  204. package/src/compile/index.ts +100 -0
  205. package/src/compile/libraryImports.ts +52 -0
  206. package/src/compile/liteMaterial.ts +247 -0
  207. package/src/compile/sceneEditor.ts +88 -0
  208. package/src/compile/serverSplit.ts +233 -0
  209. package/src/compile/serverTypes.ts +227 -0
  210. package/src/compile/sfnt.ts +98 -0
  211. package/src/compile/shaderSchema.ts +202 -0
  212. package/src/compile/shaderTargets.ts +77 -0
  213. package/src/compile/sourcemap.ts +25 -0
  214. package/src/core/Aspect.ts +568 -0
  215. package/src/core/InspectorUI.ts +212 -0
  216. package/src/core/StateMachine.ts +308 -0
  217. package/src/core/__tests__/stateMachine.test.ts +132 -0
  218. package/src/core/color.ts +66 -0
  219. package/src/core/compWrite.ts +42 -0
  220. package/src/core/events.ts +38 -0
  221. package/src/core/fields.ts +120 -0
  222. package/src/core/registry.ts +23 -0
  223. package/src/core/signals.ts +277 -0
  224. package/src/core/time.ts +84 -0
  225. package/src/g2/Camera2D.ts +40 -0
  226. package/src/g2/CharacterController2D.ts +276 -0
  227. package/src/g2/Node2D.ts +267 -0
  228. package/src/g2/OneWay2D.ts +66 -0
  229. package/src/g2/Physics2D.ts +346 -0
  230. package/src/g2/Scene2D.ts +209 -0
  231. package/src/g2/Shape2D.ts +259 -0
  232. package/src/g2/Sprite.ts +89 -0
  233. package/src/g2/SpriteAnimation.ts +171 -0
  234. package/src/g2/SpriteSheet.ts +166 -0
  235. package/src/g2/Texture2D.ts +47 -0
  236. package/src/g2/Tilemap.ts +41 -0
  237. package/src/g2/Tileset.ts +71 -0
  238. package/src/g2/Trigger2D.ts +77 -0
  239. package/src/g2/autotile.ts +433 -0
  240. package/src/g2/cells.ts +91 -0
  241. package/src/g2/defineScene2d.ts +381 -0
  242. package/src/g2/groups2d.ts +106 -0
  243. package/src/g2/loop.ts +50 -0
  244. package/src/g2/scenarios2d.ts +69 -0
  245. package/src/g2/touch.ts +83 -0
  246. package/src/gl/Camera.ts +160 -0
  247. package/src/gl/CameraPlace.ts +52 -0
  248. package/src/gl/CharacterController.ts +238 -0
  249. package/src/gl/Gearbox.ts +212 -0
  250. package/src/gl/Geometry.ts +279 -0
  251. package/src/gl/IK.ts +193 -0
  252. package/src/gl/InstancedMesh.ts +132 -0
  253. package/src/gl/Light.ts +135 -0
  254. package/src/gl/Lightmap.ts +402 -0
  255. package/src/gl/Locomotion.ts +498 -0
  256. package/src/gl/Material.ts +279 -0
  257. package/src/gl/Mesh.ts +83 -0
  258. package/src/gl/Model.ts +124 -0
  259. package/src/gl/NavAgent.ts +337 -0
  260. package/src/gl/NavMesh.ts +397 -0
  261. package/src/gl/Node.ts +350 -0
  262. package/src/gl/Noise.ts +30 -0
  263. package/src/gl/Particles.ts +676 -0
  264. package/src/gl/Physics.ts +222 -0
  265. package/src/gl/Plane.ts +53 -0
  266. package/src/gl/Ragdoll.ts +270 -0
  267. package/src/gl/Ray.ts +16 -0
  268. package/src/gl/Scene.ts +505 -0
  269. package/src/gl/Shape.ts +409 -0
  270. package/src/gl/Terrain.ts +1092 -0
  271. package/src/gl/Texture.ts +63 -0
  272. package/src/gl/Trigger.ts +45 -0
  273. package/src/gl/Vehicle.ts +473 -0
  274. package/src/gl/Wheel.ts +240 -0
  275. package/src/gl/animation/AnimationClip.ts +204 -0
  276. package/src/gl/animation/Animator.ts +329 -0
  277. package/src/gl/animation/Layer.ts +39 -0
  278. package/src/gl/animation/Loop.ts +31 -0
  279. package/src/gl/animation/Playback.ts +52 -0
  280. package/src/gl/animation/core.ts +670 -0
  281. package/src/gl/controls.ts +95 -0
  282. package/src/gl/physicsEvents.ts +20 -0
  283. package/src/gl/scenarios.ts +291 -0
  284. package/src/gl/state.ts +6 -0
  285. package/src/gl/terrainMesh.ts +219 -0
  286. package/src/gl/touch.ts +68 -0
  287. package/src/host.d.ts +61 -0
  288. package/src/inject.ts +203 -0
  289. package/src/math/Mathf.ts +118 -0
  290. package/src/math/mat4.ts +278 -0
  291. package/src/math/quat.ts +232 -0
  292. package/src/math/vec.ts +255 -0
  293. package/src/net/codec.ts +119 -0
  294. package/src/net/core.ts +384 -0
  295. package/src/net/index.ts +181 -0
  296. package/src/net/replication.ts +622 -0
  297. package/src/plugins/camera.ts +81 -0
  298. package/src/plugins/geolocation.ts +123 -0
  299. package/src/plugins/oauth.ts +61 -0
  300. package/src/plugins/permission.ts +7 -0
  301. package/src/plugins/push.ts +132 -0
  302. package/src/plugins/qr.ts +73 -0
  303. package/src/plugins/service.ts +47 -0
  304. package/src/runtime/app.ts +101 -0
  305. package/src/runtime/appEvents.ts +54 -0
  306. package/src/runtime/channel.ts +61 -0
  307. package/src/runtime/clipboard.ts +20 -0
  308. package/src/runtime/datetime.ts +329 -0
  309. package/src/runtime/device.ts +293 -0
  310. package/src/runtime/fetch.ts +77 -0
  311. package/src/runtime/files.ts +108 -0
  312. package/src/runtime/input.ts +175 -0
  313. package/src/runtime/media.ts +111 -0
  314. package/src/runtime/misc.ts +16 -0
  315. package/src/runtime/net.ts +36 -0
  316. package/src/runtime/rpc.ts +218 -0
  317. package/src/runtime/service.ts +83 -0
  318. package/src/runtime/share.ts +9 -0
  319. package/src/runtime/storage.ts +13 -0
  320. package/src/runtime/touch.ts +76 -0
  321. package/src/scene/defineScene.ts +1396 -0
  322. package/src/scene/editorPlugins.ts +110 -0
  323. package/src/scene/gizmos.ts +148 -0
  324. package/src/scene/grammar.ts +120 -0
  325. package/src/scene/level.ts +296 -0
  326. package/src/scene/material.ts +188 -0
  327. package/src/server/auth/appConfig.ts +12 -0
  328. package/src/server/auth/global.ts +80 -0
  329. package/src/server/auth/host.ts +318 -0
  330. package/src/server/auth/models.ts +83 -0
  331. package/src/server/auth/types.ts +50 -0
  332. package/src/server/channel.ts +56 -0
  333. package/src/server/context.ts +36 -0
  334. package/src/server/db/defineDb.ts +237 -0
  335. package/src/server/db/fields.ts +132 -0
  336. package/src/server/db/httpTransport.ts +93 -0
  337. package/src/server/db/index.ts +7 -0
  338. package/src/server/db/marci/query.ts +412 -0
  339. package/src/server/db/types.ts +202 -0
  340. package/src/server/errors.ts +12 -0
  341. package/src/server/host.ts +74 -0
  342. package/src/server/inject.ts +13 -0
  343. package/src/server/runtime.ts +133 -0
  344. package/src/server/validate.ts +87 -0
  345. package/src/ui/NativeView.ts +142 -0
  346. package/src/ui/UI.ts +39 -0
  347. package/src/ui/UIBottomSheet.ts +139 -0
  348. package/src/ui/UIButton.ts +101 -0
  349. package/src/ui/UIContainer.ts +60 -0
  350. package/src/ui/UIImage.ts +83 -0
  351. package/src/ui/UIInput.ts +185 -0
  352. package/src/ui/UIModal.ts +139 -0
  353. package/src/ui/UINode.ts +830 -0
  354. package/src/ui/UIPager.ts +362 -0
  355. package/src/ui/UIPopover.ts +100 -0
  356. package/src/ui/UIScreen.ts +123 -0
  357. package/src/ui/UIScrollable.ts +87 -0
  358. package/src/ui/UISpacer.ts +14 -0
  359. package/src/ui/UITabs.ts +236 -0
  360. package/src/ui/UIText.ts +51 -0
  361. package/src/ui/UIVideo.ts +88 -0
  362. package/src/ui/UIVirtualizedList.ts +241 -0
  363. package/src/ui/UIWidget.ts +127 -0
  364. package/src/ui/fonts.ts +13 -0
  365. package/src/ui/presentable.ts +117 -0
  366. package/src/ui/router.ts +132 -0
  367. package/src/ui/theme.ts +84 -0
@@ -0,0 +1,279 @@
1
+ // A material instance over creator-gl. Uniforms are set through a Proxy that lowers each JS value to
2
+ // the right native uniform call. The common materials are static factories (Material.lit/unlit/
3
+ // video/shadow); Material.load brings in a custom compiled shader. Ported from worker/src/Material.ts,
4
+ // with the Lit/Unlit/... subclasses collapsed into factories and color accepting any ColorInput.
5
+
6
+ import { Color, type ColorInput } from "../core/color"
7
+ import { fetch, type FetchResponse } from "../runtime/fetch"
8
+ import { Texture } from "./Texture"
9
+ // Type-only (erased at build) so a 3D material never pulls the 2D-canvas runtime; the guard is inline.
10
+ import type { Canvas } from "../canvas/Canvas"
11
+
12
+ /** Duck-type a Canvas without importing it (keeps 3D material free of 2D-canvas code). */
13
+ const isCanvasSource = (v: unknown): v is Canvas =>
14
+ typeof v === "object" && v !== null && (v as { __canvas?: unknown }).__canvas === true
15
+
16
+ type UniformValue = string | Texture | number | boolean | number[] | Float32Array | null
17
+
18
+ const applyUniform = (id: number, key: string, value: UniformValue): void => {
19
+ if (typeof value === "string") {
20
+ if (value.length > 7) _creator.setUniformRgba(id, key, parseInt(value.slice(1), 16))
21
+ else _creator.setUniformRgb(id, key, parseInt(value.slice(1), 16))
22
+ } else if (typeof value === "number") {
23
+ _creator.setUniformFloat(id, key, value)
24
+ } else if (typeof value === "boolean") {
25
+ _creator.setUniformBoolean(id, key, value)
26
+ } else if (value instanceof Texture) {
27
+ _creator.setUniformTexture(id, key, value._id, value.wrapS, value.wrapT)
28
+ } else if (value instanceof Float32Array) {
29
+ _creator.setUniformArray(id, key, value)
30
+ } else if (Array.isArray(value)) {
31
+ _creator.setUniformArray(id, key, Float32Array.of(...value))
32
+ } else {
33
+ _creator.setUniformNull(id, key)
34
+ }
35
+ }
36
+
37
+ export type MaterialColorOptions = { color?: ColorInput, map?: Texture | Canvas | null }
38
+
39
+ /** `Material.unlit` options. */
40
+ export type UnlitMaterialOptions = MaterialColorOptions & {
41
+ /** Alpha-blend this material instead of drawing it opaque. Opaque is the default: a blended draw
42
+ * writes no depth, is sorted back-to-front and casts no shadow, which is rarely what a flat
43
+ * colour wants. Turn it on for anything that must show what is behind it — a glass pane, a
44
+ * fading marker, a sprite whose texture has cut-out alpha. Only then does `color`'s own alpha
45
+ * (`"#ffffff80"`) mean anything; the opaque material has no alpha channel at all. */
46
+ transparent?: boolean
47
+ }
48
+
49
+ /** `Material.particles` options — the default point-sprite material for particle systems. */
50
+ export type ParticlesMaterialOptions = {
51
+ /** Sprite texture — a single image or a flipbook sheet of frames. Unset = soft round dot. */
52
+ map?: Texture | null
53
+ /** Flipbook grid: `N` = an N×N sheet, `[cols, rows]` = a non-square one. Frames run
54
+ * left-to-right, top-to-bottom; drive the index via `particles.frame`. Default 1. */
55
+ sheet?: number | [number, number]
56
+ /** Extra brightness multiplier for a glow look (0 = off). */
57
+ emissive?: number
58
+ /** (`render` quad / stretch) a second sheet on the same grid, ADDED as `emissiveMap × emissiveColor`
59
+ * — keyed by `map`'s alpha, not tinted by the particle colour. A fireball = a smoke `map` whose
60
+ * colour curve goes dark + a fire `emissiveMap` that keeps glowing while alpha lasts. */
61
+ emissiveMap?: Texture | null
62
+ /** Multiplier for `emissiveMap`; an `[r, g, b]` array may exceed 1 (HDR glow). Default 0 (off). */
63
+ emissiveColor?: ColorInput
64
+ /** (`render` quad / stretch) crossfade each flipbook frame into the next by the fractional frame
65
+ * index instead of snapping — smooth sheet playback at any frame rate. Default false. */
66
+ frameBlend?: boolean
67
+ /** Compositing: `"alpha"` (default — smoke, dust) or `"add"` (fire, sparks, magic). */
68
+ blend?: "alpha" | "add"
69
+ /** Soft radial falloff toward the sprite edge. Defaults to true without a map, false with one. */
70
+ soft?: boolean
71
+ /** Soft particles: fade each sprite out over this many metres as it cuts into the scene geometry
72
+ * behind it (Unity's "Soft Particles Factor"), so smoke and dust no longer slice through the
73
+ * ground and walls with a hard edge. 0 = off (default). Reads the scene's depth buffer, which the
74
+ * engine keeps bound while any soft system is on screen — the extra depth pass is only paid then.
75
+ * Filament hosts (desktop / web / Android / Apple); web-lite draws such sprites unfaded. */
76
+ depthFade?: number
77
+ /** How each particle is drawn: `'point'` (default — GPU point sprites, cheapest), `'quad'`
78
+ * (real camera-facing quads — no driver size cap, geometric rotation), or `'stretch'`
79
+ * (quads stretched along velocity — sparks, rain, speed streaks). `'ribbon'` is what `Trail`
80
+ * uses internally. */
81
+ render?: "point" | "quad" | "stretch" | "ribbon"
82
+ /** (`render: 'stretch'`) extra sprite length in world units per unit of speed:
83
+ * length = size + stretch·|velocity|. Default 0.05. */
84
+ stretch?: number
85
+ }
86
+
87
+ /** @internal — the sheet option as whole [cols, rows], both ≥ 1. The particles shader divides
88
+ * by these with no guard of its own, so this clamp is the only thing between it and a NaN UV. */
89
+ export const _sheetColsRows = (sheet: number | [number, number] | undefined): [number, number] => {
90
+ const [ c, r ] = typeof sheet === "number" ? [ sheet, sheet ] : sheet ?? [ 1, 1 ]
91
+ return [ Math.max(1, Math.floor(c) || 1), Math.max(1, Math.floor(r) || 1) ]
92
+ }
93
+
94
+ /** `Material.lit` options — PBR scalars on top of the color/map pair. */
95
+ export type LitMaterialOptions = MaterialColorOptions & {
96
+ /** Perceptual roughness, 0 (mirror) … 1 (matte). Unset = the shader's default. */
97
+ roughness?: number
98
+ /** Metallic factor, 0 (dielectric) … 1 (metal). Unset = the shader's default. */
99
+ metallic?: number
100
+ }
101
+
102
+ export class Material {
103
+ /** @internal native material-instance handle. */
104
+ _id: number
105
+ readonly shader: FetchResponse | "unknown"
106
+ readonly uniforms: Record<string, UniformValue>
107
+
108
+ private _colorKey: string | null = null
109
+
110
+ constructor(shader: FetchResponse | number) {
111
+ if (typeof shader === "number") {
112
+ this.shader = "unknown"
113
+ this._id = shader
114
+ } else {
115
+ this.shader = shader
116
+ this._id = _creator.createMaterial((shader as any)._id)
117
+ }
118
+ const store: Record<string, UniformValue> = {}
119
+ const id = () => this._id
120
+ this.uniforms = new Proxy(store, {
121
+ get: (t, k: string) => t[k],
122
+ set: (t, k: string, v: UniformValue) => { t[k] = v; applyUniform(id(), k, v); return true },
123
+ })
124
+ }
125
+
126
+ /** Set a uniform (chainable). */
127
+ set(key: string, value: UniformValue): this {
128
+ this.uniforms[key] = value
129
+ return this
130
+ }
131
+
132
+ set color(c: ColorInput) {
133
+ if (this._colorKey) this.uniforms[this._colorKey] = Color.toHexString(c)
134
+ }
135
+
136
+ // lit/unlit shade baseColor × baseColorMap (factor×map; engines default both to white), so
137
+ // removing the map means resetting baseColorMap to the white 1×1 — no flag to clear. (Materials
138
+ // used to carry a `useBaseColorMap` bool for shaders that branched instead of multiplying; the
139
+ // last of those, the Apple unlit fork, is gone. Hosts still TRANSLATE the uniform when an older
140
+ // compiled bundle sets it — that's their compatibility path, not something the SDK emits.)
141
+ set map(value: Texture | Canvas | null) {
142
+ if (value === null) {
143
+ this.uniforms.baseColorMap = null
144
+ } else {
145
+ // A Canvas bakes to a (cached) 3D texture on assign — same as Sprite accepting a Canvas in 2D.
146
+ this.uniforms.baseColorMap = isCanvasSource(value) ? Texture.fromCanvas(value) : value
147
+ }
148
+ }
149
+
150
+ // --- factories ---
151
+
152
+ /** PBR lit material. */
153
+ static lit(options: LitMaterialOptions = {}): Material {
154
+ // The fetchLocal literal must be inline so the compiler's preload header captures the shader name.
155
+ const m = new Material({ _id: _creatorUtils.fetchLocal("lit.filamat") } as any)
156
+ m._colorKey = "baseColor"
157
+ if (options.color !== undefined) m.color = options.color
158
+ if (options.map) m.map = options.map
159
+ if (options.roughness !== undefined) m.uniforms.roughness = options.roughness
160
+ if (options.metallic !== undefined) m.uniforms.metallic = options.metallic
161
+ return m
162
+ }
163
+
164
+ /** Unlit (flat) material — opaque unless `transparent` asks for alpha blending. */
165
+ static unlit(options: UnlitMaterialOptions = {}): Material {
166
+ // Blending is baked into the shader package (a material instance can't change it), so the
167
+ // blended twin is its own file. Both fetchLocal literals stay inline — that is what puts the
168
+ // shader names in the compiler's preload header. A host that predates unlit-transparent answers
169
+ // -1; fall back to the opaque one rather than handing createMaterial a bad handle.
170
+ let id = -1
171
+ if (options.transparent) {
172
+ id = _creatorUtils.fetchLocal("unlit-transparent.filamat")
173
+ if (id < 0) console.warn("[material] this host ships no unlit-transparent.filamat — drawing opaque")
174
+ }
175
+ if (id < 0) id = _creatorUtils.fetchLocal("unlit.filamat")
176
+ const m = new Material({ _id: id } as any)
177
+ m._colorKey = "baseColor"
178
+ if (options.color !== undefined) m.color = options.color
179
+ if (options.map) m.map = options.map
180
+ return m
181
+ }
182
+
183
+ /** Default particle material — camera-facing point sprites with tint/opacity/rotation/flipbook
184
+ * driven by the particle curves. Uniforms all default to 0 on a fresh instance, so every look
185
+ * knob is primed here; JS writes after construction override them. */
186
+ static particles(options: ParticlesMaterialOptions = {}): Material {
187
+ const quad = options.render !== undefined && options.render !== "point"
188
+ // Both fetchLocal literals inline so the compiler's preload header captures the shader names.
189
+ const m = quad
190
+ ? new Material({ _id: _creatorUtils.fetchLocal("particles-quad.filamat") } as any)
191
+ : new Material({ _id: _creatorUtils.fetchLocal("particles.filamat") } as any)
192
+ m.uniforms.sheetSize = _sheetColsRows(options.sheet)
193
+ m.uniforms.emissive = options.emissive ?? 0
194
+ m.uniforms.additive = options.blend === "add" ? 1 : 0
195
+ m.uniforms.softness = (options.soft ?? !options.map) ? 1 : 0
196
+ m.uniforms.depthFade = options.depthFade ?? 0
197
+ if (quad) {
198
+ m.uniforms.mode = options.render === "ribbon" ? 2 : options.render === "stretch" ? 1 : 0
199
+ m.uniforms.stretch = options.stretch ?? (options.render === "stretch" ? 0.05 : 0)
200
+ if (options.emissiveMap) m.uniforms.emissiveMap = options.emissiveMap
201
+ if (options.emissiveColor !== undefined) m.uniforms.emissiveColor = Color.toRgb01(options.emissiveColor)
202
+ if (options.frameBlend) m.uniforms.frameBlend = 1
203
+ }
204
+ if (options.map) m.map = options.map
205
+ return m
206
+ }
207
+
208
+ /** Material that samples a VideoPlayer's texture. */
209
+ static video(map?: Texture): Material {
210
+ const m = new Material({ _id: _creatorUtils.fetchLocal("video.filamat") } as any)
211
+ if (map) m.uniforms.baseColorMap = map
212
+ return m
213
+ }
214
+
215
+ /** The lightmap material (docs/lightmap-plan.md): PBR base colour × a baked shadow/AO atlas on UV1.
216
+ * Models take it through `Model.load(…, { lightmap: true })`; `Lightmap.load` builds one per static
217
+ * Mesh. Parameters use gltfio's names (`baseColorFactor`, `baseColorMap`, `roughnessFactor`,
218
+ * `metallicFactor`) plus `lightmap`, `lightmapST`, `ambientScale`, `sunStrength` (the sun / IBL terms come from
219
+ * filament's per-frame uniforms inside the shader). */
220
+ static lightmap(): Material {
221
+ // Inline literal: the compiler's preload header captures the shader name from it.
222
+ const m = new Material({ _id: _creatorUtils.fetchLocal("lightmap.filamat") } as any)
223
+ m.set("baseColorFactor", "#ffffffff").set("roughnessFactor", 1).set("metallicFactor", 0)
224
+ m.set("lightmapST", [ 1, 1, 0, 0 ]).set("ambientScale", 1).set("sunStrength", 1).set("hasNormalMap", 0)
225
+ // lightScale 0 = no baked point lights until Lightmap.load binds a light atlas / volume
226
+ m.set("bakedAo", 1).set("lightScale", 0)
227
+ m.set("probeMin", [ 0, 0, 0, 0 ]).set("probeInvSize", [ 0, 0, 0, 0 ])
228
+ return m
229
+ }
230
+
231
+ /** The terrain splat material (docs/terrain-plan.md §1.5): four albedo (+ normal-map) layers blended by
232
+ * a control map on the terrain's own grid, per-layer `tiling` (metres per repeat) / `roughness` /
233
+ * `normalScale` / `triplanar`, lightmap-aware (the same `lightmap` / `lightmapST` block as
234
+ * `Material.lightmap`). `Terrain` builds and owns one per terrain; the uniforms are primed here so an
235
+ * unset layer is white and an unbaked terrain is fully lit. */
236
+ static terrain(): Material {
237
+ // Inline literal: the compiler's preload header captures the shader name from it.
238
+ const m = new Material({ _id: _creatorUtils.fetchLocal("terrain.filamat") } as any)
239
+ m.set("tiling", [ 8, 8, 8, 8 ]).set("roughness", [ 1, 1, 1, 1 ]).set("normalScale", [ 0, 0, 0, 0 ]).set("triplanar", [ 0, 0, 0, 0 ])
240
+ m.set("gridSize", [ 2, 2 ]).set("cellSize", 1).set("tint", "#ffffff")
241
+ m.set("lightmapST", [ 1, 1, 0, 0 ]).set("ambientScale", 1).set("sunStrength", 1).set("bakedAo", 1).set("lightScale", 0)
242
+ return m
243
+ }
244
+
245
+ /** @internal the shared template instance `Model.load({ lightmap })` hands the engine (its MATERIAL is what
246
+ * the GLB provider instantiates; the template itself never draws). */
247
+ static _lightmapTemplate(): Material { return (Material._lmTemplate ??= Material.lightmap()) }
248
+ private static _lmTemplate: Material | undefined
249
+
250
+ /** Shadow-catcher material (transparent except where shadows fall). */
251
+ static shadow(color: ColorInput = "#000000aa"): Material {
252
+ const m = new Material({ _id: _creatorUtils.fetchLocal("shadow.filamat") } as any)
253
+ m._colorKey = "color"
254
+ m.color = color
255
+ return m
256
+ }
257
+
258
+ /** Load a custom compiled shader (.mat URL) as a material. */
259
+ static load(url: string): Promise<Material> {
260
+ // "id:<n>" — the artifact is a LOCAL file the host already resolved through fetchLocal (a
261
+ // compile with no asset server: the desktop host reads it from next to the bundle). There is
262
+ // nothing to fetch, so the material is ready synchronously; -1 means the host found no such
263
+ // file, which would otherwise reach createMaterial as a bad handle.
264
+ if (url.startsWith("id:")) {
265
+ const id = Number(url.slice(3))
266
+ if (!(id >= 0)) {
267
+ return Promise.reject(new Error(`Shader not found next to the app (${url}). Compile it with \`lecodes shaders compile\`.`))
268
+ }
269
+ return Promise.resolve(new Material({ _id: id } as any))
270
+ }
271
+ return fetch(url, { useOnce: true }).then((resp) => {
272
+ if (resp.status >= 400) return Promise.reject(new Error(`Failed to fetch shader from ${url}. HTTP ${resp.status}`))
273
+ return new Material(resp)
274
+ })
275
+ }
276
+
277
+ /** @internal */
278
+ static idOf(material: Material): number { return material._id }
279
+ }
package/src/gl/Mesh.ts ADDED
@@ -0,0 +1,83 @@
1
+ // A renderable 3D node from raw geometry — the primitive shapes (box/sphere/cylinder/plane) and
2
+ // Mesh.from for a custom Geometry. A GLB import is a different kind: see Model.load.
3
+
4
+ import { cx, cy, cz, type Vec3Like } from "../math/vec"
5
+ import {
6
+ Geometry,
7
+ type CylinderOptions,
8
+ type PlaneOptions,
9
+ type SphereOptions,
10
+ } from "./Geometry"
11
+ import { Material } from "./Material"
12
+ import { Node } from "./Node"
13
+
14
+ /** Common transform/render options every primitive factory accepts. */
15
+ export type MeshOptions = {
16
+ material?: Material
17
+ position?: Vec3Like
18
+ eulerAngles?: Vec3Like
19
+ scale?: Vec3Like | number
20
+ name?: string
21
+ castShadows?: boolean
22
+ receiveShadows?: boolean
23
+ }
24
+
25
+ export class Mesh extends Node {
26
+ private _geometry?: Geometry
27
+
28
+ constructor(geometry?: Geometry, material?: Material) {
29
+ super()
30
+ if (geometry) {
31
+ const mat = material ?? Material.unlit()
32
+ this._geometry = geometry
33
+ this._materials = [ mat ]
34
+ _creator.setMesh(this.id, Material.idOf(mat), geometry.vertices, geometry.normals, geometry.indices, geometry.uv, geometry._meshKind, geometry.uv1)
35
+ }
36
+ }
37
+
38
+ override get geometry(): Geometry | undefined { return this._geometry }
39
+
40
+ /** A Mesh always carries a material (slot 0) — see Node.setMaterial for the slot API. */
41
+ override get material(): Material { return this._materials![0]! }
42
+ override set material(m: Material) { this.setMaterial(m, 0) }
43
+
44
+ set culling(v: boolean) { _creator.setCulling(this.id, v) }
45
+ set castShadows(v: boolean) { _creator.setCastShadows(this.id, v) }
46
+ set receiveShadows(v: boolean) { _creator.setReceiveShadows(this.id, v) }
47
+
48
+ // --- factories ---
49
+
50
+ static box(options: MeshOptions & { size?: Vec3Like | number } = {}): Mesh {
51
+ // the size goes into the geometry (not a scale after): the lightmap chart is laid out per face area
52
+ return apply(new Mesh(Geometry.box(options.size ?? 1), options.material), options)
53
+ }
54
+
55
+ static sphere(options: MeshOptions & SphereOptions = {}): Mesh {
56
+ return apply(new Mesh(Geometry.sphere(options), options.material), options)
57
+ }
58
+
59
+ static cylinder(options: MeshOptions & CylinderOptions = {}): Mesh {
60
+ return apply(new Mesh(Geometry.cylinder(options), options.material), options)
61
+ }
62
+
63
+ static plane(options: MeshOptions & PlaneOptions = {}): Mesh {
64
+ return apply(new Mesh(Geometry.plane(options), options.material), options)
65
+ }
66
+
67
+ /** Wrap a custom Geometry. */
68
+ static from(geometry: Geometry, options: MeshOptions = {}): Mesh {
69
+ return apply(new Mesh(geometry, options.material), options)
70
+ }
71
+ }
72
+
73
+ const sizeToVec = (s: Vec3Like | number): [number, number, number] => (typeof s === "number" ? [ s, s, s ] : [ cx(s), cy(s), cz(s) ])
74
+
75
+ const apply = (mesh: Mesh, o: MeshOptions): Mesh => {
76
+ if (o.position) mesh.position = o.position
77
+ if (o.eulerAngles) mesh.eulerAngles = o.eulerAngles
78
+ if (o.scale !== undefined) mesh.scale = typeof o.scale === "number" ? [ o.scale, o.scale, o.scale ] : o.scale
79
+ if (o.name !== undefined) mesh.name = o.name
80
+ if (o.castShadows !== undefined) mesh.castShadows = o.castShadows
81
+ if (o.receiveShadows !== undefined) mesh.receiveShadows = o.receiveShadows
82
+ return mesh
83
+ }
@@ -0,0 +1,124 @@
1
+ // A loaded GLB model — its own node kind (a GLB is a node hierarchy with baked animation clips),
2
+ // distinct from Mesh (raw primitives, no animation). Animation is always present, reached as
3
+ // model.anim (an Animator over the GLB's clips — crossfades, blend spaces, layers when you need them):
4
+ // const hero = await Model.load(asset('./hero.glb'))
5
+ // hero.anim.play('Run', { loop: true })
6
+
7
+ import { fetch, type FetchResponse } from "../runtime/fetch"
8
+ import { Node } from "./Node"
9
+ import { Animator, _pushLod, type LodMode } from "./animation/Animator"
10
+ import { Material } from "./Material"
11
+
12
+ export class Model extends Node {
13
+ /** The model's Animator — always present, its clip table = the GLB's embedded clips. Configure
14
+ * more (external clips, blend spaces, layers) with `model.aspect(Animator, {...})`. */
15
+ declare readonly anim: Animator
16
+ /** @internal loaded through the lightmap material (docs/lightmap-plan.md); clones inherit it. */
17
+ _lightmapped = false
18
+ /** @internal what `load` does without an explicit `lightmap` option: `'dynamic'` while a scene file with
19
+ * `env.lightmap.volume` runs (Lightmap sets it), so weapons, spawns and make() subtrees read the volume. */
20
+ static _lightmapDefault: false | "dynamic" = false
21
+ /** @internal the shadow pair, mirrored here because the bridge writes both at once. */
22
+ _castShadows = true
23
+ /** @internal */
24
+ _receiveShadows = true
25
+ /** @internal */
26
+ _culling = true
27
+ /** @internal -1 = auto (see `lod`) */
28
+ _lodMesh = -1
29
+
30
+ constructor(internalId: number) {
31
+ super(internalId)
32
+ this.aspect(Animator)
33
+ }
34
+
35
+ /** Does this model cast a real-time shadow? Unlike Mesh (one renderable) a GLB is a whole
36
+ * hierarchy, so the flag goes to EVERY renderable of the instance. A first-person viewmodel —
37
+ * arms, weapon, attachments — sets it false: it lives in front of the camera and its shadow
38
+ * is never wanted. */
39
+ get castShadows(): boolean { return this._castShadows }
40
+ set castShadows(v: boolean) { this._castShadows = v; this._applyShadows() }
41
+
42
+ /** Is this model lit by other casters' shadows? Same instance-wide reach as castShadows. */
43
+ get receiveShadows(): boolean { return this._receiveShadows }
44
+ set receiveShadows(v: boolean) { this._receiveShadows = v; this._applyShadows() }
45
+
46
+ /** Frustum culling for the whole instance: a model the camera cannot see skips the draw and the
47
+ * shadow pass. ON by default where the host keeps a skinned mesh's bounds honest — the engine refits
48
+ * them to the joints every frame, so a walking, kneeling or ragdolled body is never culled while on
49
+ * screen (`_creator.skinnedCullingSupported`); OFF (always draw) on hosts without that, where
50
+ * Filament would cull an animated body by its bind-pose box. `false` = always draw (a skybox-sized
51
+ * mesh, a debugging aid); `true` forces it on regardless of the host. */
52
+ get culling(): boolean { return this._culling }
53
+ set culling(v: boolean) { this._culling = v; _creator.setGlbCulling(this.id, v) }
54
+ /** Level of detail (docs/lod-plan.md). `'auto'` (default): the engine shows the `_LOD<n>` mesh level
55
+ * that fits the model's size on screen (`lecodes assets doctor --lod` makes them) and scales the
56
+ * animation rate with it; a number 0–3 pins that level for both — `0` = always full detail (a hero,
57
+ * a showcase), `2`/`3` = always cheap (a crowd filler). `model.anim.lod = 'full'` keeps the animation
58
+ * exact while the mesh still switches. No-op on hosts without the LOD pass. */
59
+ get lod(): LodMode { return this._lodMesh < 0 ? "auto" : (this._lodMesh as 0 | 1 | 2 | 3) }
60
+ set lod(v: LodMode) { this._lodMesh = v === "auto" ? -1 : Math.max(0, Math.min(3, Math.round(v))); _pushLod(this) }
61
+
62
+ /** @internal the default for a fresh instance (load / clone), decided once per host. */
63
+ static _cullingDefault(): boolean {
64
+ if (Model._cullDefault === undefined) Model._cullDefault = !!_creator.skinnedCullingSupported?.()
65
+ return Model._cullDefault
66
+ }
67
+ private static _cullDefault: boolean | undefined
68
+
69
+ /** @internal both flags travel together — the bridge walks the instance once. */
70
+ _applyShadows(): void { _creator.setGlbShadows?.(this.id, this._castShadows, this._receiveShadows) }
71
+
72
+ /** Duplicate this model — a deep copy of the GLB (meshes, skeleton, animation clips), attached to
73
+ * the same parent and scene and sharing this model's current transform. The clone has its own
74
+ * independent animation state (reach it via clone.anim). Mirrors this model's culling flag. */
75
+ clone(): Model {
76
+ const id = _creator.cloneEntity(this.id)
77
+ const m = new Model(id)
78
+ m._lightmapped = this._lightmapped
79
+ if (!this._culling) { m._culling = false; _creator.setGlbCulling(id, false) } // the engine default is on
80
+ if (this._lodMesh >= 0) { m._lodMesh = this._lodMesh; _pushLod(m) }
81
+ // the clone is a FRESH gltfio instance — it comes back with the asset's own shadow flags,
82
+ // not this model's, so a cleared flag has to be re-applied
83
+ m._castShadows = this._castShadows
84
+ m._receiveShadows = this._receiveShadows
85
+ if (!this._castShadows || !this._receiveShadows) m._applyShadows()
86
+ return m
87
+ }
88
+
89
+ /** Load a GLB model. Returns its root as a Model; play its baked clips via model.anim. */
90
+ static load(
91
+ source: string | FetchResponse,
92
+ options: {
93
+ /** Frustum culling — see `culling` (default: on where the host refits skinned bounds, else off). */
94
+ culling?: boolean
95
+ onProgress?: (p: { loaded: number, total?: number }) => void
96
+ /** Baked lighting (docs/lightmap-plan.md). `true` = a STATIC: loads through the lightmap material so
97
+ * `Lightmap.load` can bind its atlas rect (the GLB needs TEXCOORD_1 — `lecodes assets doctor
98
+ * --lightmap-uv`). `'dynamic'` = a mover: the same material, lit by the level's light VOLUME instead
99
+ * (no UV1 needed). Omitted: `'dynamic'` while a scene file with `env.lightmap.volume` is running,
100
+ * else off. `false` = the standard shader. Hosts without lightmap support ignore it. */
101
+ lightmap?: boolean | "dynamic"
102
+ } = {},
103
+ ): Promise<Model> {
104
+ if (typeof source === "string") {
105
+ return fetch(source, { useOnce: true, onProgress: options.onProgress }).then((resp) => {
106
+ if (resp.status >= 400) return Promise.reject(new Error(`Failed to load GLB from ${source}. HTTP ${resp.status}`))
107
+ return Model.load(resp, options)
108
+ })
109
+ }
110
+ return new Promise<Model>((resolve, reject) => {
111
+ const mode = options.lightmap ?? Model._lightmapDefault
112
+ const lightmapped = !!mode && !!_creator.setNextGlbLightmapped
113
+ if (lightmapped) _creator.setNextGlbLightmapped!(Material.idOf(Material._lightmapTemplate()))
114
+ _creator.createGlb((source as unknown as { _id: number })._id, (entityId: number) => {
115
+ if (entityId === 0) { reject(new Error("Failed to load GLB")); return }
116
+ const model = new Model(entityId)
117
+ model._lightmapped = lightmapped
118
+ const culling = options.culling ?? Model._cullingDefault()
119
+ if (!culling) { model._culling = false; _creator.setGlbCulling(entityId, false) }
120
+ resolve(model)
121
+ }, reject)
122
+ })
123
+ }
124
+ }