@skenora/runtime 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/README.md +92 -0
  2. package/dist/core/built-in-runtime-capabilities.d.ts +21 -0
  3. package/dist/core/built-in-runtime-capabilities.d.ts.map +1 -0
  4. package/dist/core/built-in-runtime-capabilities.js +175 -0
  5. package/dist/core/built-in-runtime-capabilities.js.map +1 -0
  6. package/dist/core/runtime-capability-registry.d.ts +90 -0
  7. package/dist/core/runtime-capability-registry.d.ts.map +1 -0
  8. package/dist/core/runtime-capability-registry.js +42 -0
  9. package/dist/core/runtime-capability-registry.js.map +1 -0
  10. package/dist/core/runtime-document-coordinator.d.ts +28 -0
  11. package/dist/core/runtime-document-coordinator.d.ts.map +1 -0
  12. package/dist/core/runtime-document-coordinator.js +124 -0
  13. package/dist/core/runtime-document-coordinator.js.map +1 -0
  14. package/dist/core/runtime-events.d.ts +43 -0
  15. package/dist/core/runtime-events.d.ts.map +1 -0
  16. package/dist/core/runtime-events.js +2 -0
  17. package/dist/core/runtime-events.js.map +1 -0
  18. package/dist/core/runtime-session.d.ts +93 -0
  19. package/dist/core/runtime-session.d.ts.map +1 -0
  20. package/dist/core/runtime-session.js +1344 -0
  21. package/dist/core/runtime-session.js.map +1 -0
  22. package/dist/editor-tools/camera-path-editing-controller.d.ts +36 -0
  23. package/dist/editor-tools/camera-path-editing-controller.d.ts.map +1 -0
  24. package/dist/editor-tools/camera-path-editing-controller.js +212 -0
  25. package/dist/editor-tools/camera-path-editing-controller.js.map +1 -0
  26. package/dist/editor-tools/camera-path-visualizer.d.ts +28 -0
  27. package/dist/editor-tools/camera-path-visualizer.d.ts.map +1 -0
  28. package/dist/editor-tools/camera-path-visualizer.js +151 -0
  29. package/dist/editor-tools/camera-path-visualizer.js.map +1 -0
  30. package/dist/editor-tools/drop-preview-controller.d.ts +34 -0
  31. package/dist/editor-tools/drop-preview-controller.d.ts.map +1 -0
  32. package/dist/editor-tools/drop-preview-controller.js +209 -0
  33. package/dist/editor-tools/drop-preview-controller.js.map +1 -0
  34. package/dist/editor-tools/grid-helper.d.ts +18 -0
  35. package/dist/editor-tools/grid-helper.d.ts.map +1 -0
  36. package/dist/editor-tools/grid-helper.js +27 -0
  37. package/dist/editor-tools/grid-helper.js.map +1 -0
  38. package/dist/editor-tools/light-editing-controller.d.ts +25 -0
  39. package/dist/editor-tools/light-editing-controller.d.ts.map +1 -0
  40. package/dist/editor-tools/light-editing-controller.js +207 -0
  41. package/dist/editor-tools/light-editing-controller.js.map +1 -0
  42. package/dist/editor-tools/node-operations.d.ts +51 -0
  43. package/dist/editor-tools/node-operations.d.ts.map +1 -0
  44. package/dist/editor-tools/node-operations.js +182 -0
  45. package/dist/editor-tools/node-operations.js.map +1 -0
  46. package/dist/editor-tools/selection-controller.d.ts +44 -0
  47. package/dist/editor-tools/selection-controller.d.ts.map +1 -0
  48. package/dist/editor-tools/selection-controller.js +299 -0
  49. package/dist/editor-tools/selection-controller.js.map +1 -0
  50. package/dist/editor-tools/shape-drawing-controller.d.ts +45 -0
  51. package/dist/editor-tools/shape-drawing-controller.d.ts.map +1 -0
  52. package/dist/editor-tools/shape-drawing-controller.js +205 -0
  53. package/dist/editor-tools/shape-drawing-controller.js.map +1 -0
  54. package/dist/editor-tools/shape-editing-controller.d.ts +40 -0
  55. package/dist/editor-tools/shape-editing-controller.d.ts.map +1 -0
  56. package/dist/editor-tools/shape-editing-controller.js +340 -0
  57. package/dist/editor-tools/shape-editing-controller.js.map +1 -0
  58. package/dist/editor.d.ts +12 -0
  59. package/dist/editor.d.ts.map +1 -0
  60. package/dist/editor.js +12 -0
  61. package/dist/editor.js.map +1 -0
  62. package/dist/index.d.ts +2 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +2 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/inspection/node-tools.d.ts +51 -0
  67. package/dist/inspection/node-tools.d.ts.map +1 -0
  68. package/dist/inspection/node-tools.js +282 -0
  69. package/dist/inspection/node-tools.js.map +1 -0
  70. package/dist/interaction/runtime-third-person-controller.d.ts +24 -0
  71. package/dist/interaction/runtime-third-person-controller.d.ts.map +1 -0
  72. package/dist/interaction/runtime-third-person-controller.js +71 -0
  73. package/dist/interaction/runtime-third-person-controller.js.map +1 -0
  74. package/dist/interaction/third-person-controller.d.ts +61 -0
  75. package/dist/interaction/third-person-controller.d.ts.map +1 -0
  76. package/dist/interaction/third-person-controller.js +400 -0
  77. package/dist/interaction/third-person-controller.js.map +1 -0
  78. package/dist/interaction.d.ts +3 -0
  79. package/dist/interaction.d.ts.map +1 -0
  80. package/dist/interaction.js +3 -0
  81. package/dist/interaction.js.map +1 -0
  82. package/dist/presentation/scene-renderer.d.ts +75 -0
  83. package/dist/presentation/scene-renderer.d.ts.map +1 -0
  84. package/dist/presentation/scene-renderer.js +324 -0
  85. package/dist/presentation/scene-renderer.js.map +1 -0
  86. package/dist/presentation/viewport-controller.d.ts +13 -0
  87. package/dist/presentation/viewport-controller.d.ts.map +1 -0
  88. package/dist/presentation/viewport-controller.js +186 -0
  89. package/dist/presentation/viewport-controller.js.map +1 -0
  90. package/dist/projection/annotation-projector.d.ts +28 -0
  91. package/dist/projection/annotation-projector.d.ts.map +1 -0
  92. package/dist/projection/annotation-projector.js +98 -0
  93. package/dist/projection/annotation-projector.js.map +1 -0
  94. package/dist/projection/built-in-entity-projectors.d.ts +7 -0
  95. package/dist/projection/built-in-entity-projectors.d.ts.map +1 -0
  96. package/dist/projection/built-in-entity-projectors.js +75 -0
  97. package/dist/projection/built-in-entity-projectors.js.map +1 -0
  98. package/dist/projection/camera-entity-factory.d.ts +9 -0
  99. package/dist/projection/camera-entity-factory.d.ts.map +1 -0
  100. package/dist/projection/camera-entity-factory.js +93 -0
  101. package/dist/projection/camera-entity-factory.js.map +1 -0
  102. package/dist/projection/document-applier.d.ts +38 -0
  103. package/dist/projection/document-applier.d.ts.map +1 -0
  104. package/dist/projection/document-applier.js +219 -0
  105. package/dist/projection/document-applier.js.map +1 -0
  106. package/dist/projection/entity-projection-registry.d.ts +56 -0
  107. package/dist/projection/entity-projection-registry.d.ts.map +1 -0
  108. package/dist/projection/entity-projection-registry.js +121 -0
  109. package/dist/projection/entity-projection-registry.js.map +1 -0
  110. package/dist/projection/model-importer.d.ts +41 -0
  111. package/dist/projection/model-importer.d.ts.map +1 -0
  112. package/dist/projection/model-importer.js +469 -0
  113. package/dist/projection/model-importer.js.map +1 -0
  114. package/dist/projection/particle-capability.d.ts +5 -0
  115. package/dist/projection/particle-capability.d.ts.map +1 -0
  116. package/dist/projection/particle-capability.js +2 -0
  117. package/dist/projection/particle-capability.js.map +1 -0
  118. package/dist/projection/particle-factory.d.ts +18 -0
  119. package/dist/projection/particle-factory.d.ts.map +1 -0
  120. package/dist/projection/particle-factory.js +313 -0
  121. package/dist/projection/particle-factory.js.map +1 -0
  122. package/dist/projection/primitive-factory.d.ts +5 -0
  123. package/dist/projection/primitive-factory.d.ts.map +1 -0
  124. package/dist/projection/primitive-factory.js +55 -0
  125. package/dist/projection/primitive-factory.js.map +1 -0
  126. package/dist/projection/procedural-factory.d.ts +6 -0
  127. package/dist/projection/procedural-factory.d.ts.map +1 -0
  128. package/dist/projection/procedural-factory.js +34 -0
  129. package/dist/projection/procedural-factory.js.map +1 -0
  130. package/dist/projection/runtime-projection-state.d.ts +19 -0
  131. package/dist/projection/runtime-projection-state.d.ts.map +1 -0
  132. package/dist/projection/runtime-projection-state.js +58 -0
  133. package/dist/projection/runtime-projection-state.js.map +1 -0
  134. package/dist/projection/shape-factory.d.ts +5 -0
  135. package/dist/projection/shape-factory.d.ts.map +1 -0
  136. package/dist/projection/shape-factory.js +101 -0
  137. package/dist/projection/shape-factory.js.map +1 -0
  138. package/dist/projection-entry.d.ts +10 -0
  139. package/dist/projection-entry.d.ts.map +1 -0
  140. package/dist/projection-entry.js +8 -0
  141. package/dist/projection-entry.js.map +1 -0
  142. package/dist/simulation/fixed-step-scheduler.d.ts +13 -0
  143. package/dist/simulation/fixed-step-scheduler.d.ts.map +1 -0
  144. package/dist/simulation/fixed-step-scheduler.js +45 -0
  145. package/dist/simulation/fixed-step-scheduler.js.map +1 -0
  146. package/dist/simulation/simulation-runtime-model.d.ts +24 -0
  147. package/dist/simulation/simulation-runtime-model.d.ts.map +1 -0
  148. package/dist/simulation/simulation-runtime-model.js +63 -0
  149. package/dist/simulation/simulation-runtime-model.js.map +1 -0
  150. package/dist/simulation/simulation-wgsl.d.ts +3 -0
  151. package/dist/simulation/simulation-wgsl.d.ts.map +1 -0
  152. package/dist/simulation/simulation-wgsl.js +294 -0
  153. package/dist/simulation/simulation-wgsl.js.map +1 -0
  154. package/dist/simulation/webgpu-simulation-renderer.d.ts +67 -0
  155. package/dist/simulation/webgpu-simulation-renderer.d.ts.map +1 -0
  156. package/dist/simulation/webgpu-simulation-renderer.js +504 -0
  157. package/dist/simulation/webgpu-simulation-renderer.js.map +1 -0
  158. package/dist/simulation/webgpu-types.d.ts +90 -0
  159. package/dist/simulation/webgpu-types.d.ts.map +1 -0
  160. package/dist/simulation/webgpu-types.js +10 -0
  161. package/dist/simulation/webgpu-types.js.map +1 -0
  162. package/dist/simulation.d.ts +4 -0
  163. package/dist/simulation.d.ts.map +1 -0
  164. package/dist/simulation.js +4 -0
  165. package/dist/simulation.js.map +1 -0
  166. package/dist/systems/animation-controller.d.ts +52 -0
  167. package/dist/systems/animation-controller.d.ts.map +1 -0
  168. package/dist/systems/animation-controller.js +146 -0
  169. package/dist/systems/animation-controller.js.map +1 -0
  170. package/dist/systems/camera-controller.d.ts +41 -0
  171. package/dist/systems/camera-controller.d.ts.map +1 -0
  172. package/dist/systems/camera-controller.js +207 -0
  173. package/dist/systems/camera-controller.js.map +1 -0
  174. package/dist/systems/camera-path-controller.d.ts +39 -0
  175. package/dist/systems/camera-path-controller.d.ts.map +1 -0
  176. package/dist/systems/camera-path-controller.js +287 -0
  177. package/dist/systems/camera-path-controller.js.map +1 -0
  178. package/dist/systems/environment-controller.d.ts +18 -0
  179. package/dist/systems/environment-controller.d.ts.map +1 -0
  180. package/dist/systems/environment-controller.js +251 -0
  181. package/dist/systems/environment-controller.js.map +1 -0
  182. package/dist/systems/environment-texture.d.ts +7 -0
  183. package/dist/systems/environment-texture.d.ts.map +1 -0
  184. package/dist/systems/environment-texture.js +57 -0
  185. package/dist/systems/environment-texture.js.map +1 -0
  186. package/dist/systems/fog-controller.d.ts +12 -0
  187. package/dist/systems/fog-controller.d.ts.map +1 -0
  188. package/dist/systems/fog-controller.js +60 -0
  189. package/dist/systems/fog-controller.js.map +1 -0
  190. package/dist/systems/generated-texture-cache.d.ts +33 -0
  191. package/dist/systems/generated-texture-cache.d.ts.map +1 -0
  192. package/dist/systems/generated-texture-cache.js +101 -0
  193. package/dist/systems/generated-texture-cache.js.map +1 -0
  194. package/dist/systems/glass-transmission-controller.d.ts +21 -0
  195. package/dist/systems/glass-transmission-controller.d.ts.map +1 -0
  196. package/dist/systems/glass-transmission-controller.js +119 -0
  197. package/dist/systems/glass-transmission-controller.js.map +1 -0
  198. package/dist/systems/gpu-program-cache.d.ts +19 -0
  199. package/dist/systems/gpu-program-cache.d.ts.map +1 -0
  200. package/dist/systems/gpu-program-cache.js +95 -0
  201. package/dist/systems/gpu-program-cache.js.map +1 -0
  202. package/dist/systems/ground-controller.d.ts +14 -0
  203. package/dist/systems/ground-controller.d.ts.map +1 -0
  204. package/dist/systems/ground-controller.js +121 -0
  205. package/dist/systems/ground-controller.js.map +1 -0
  206. package/dist/systems/lighting-controller.d.ts +23 -0
  207. package/dist/systems/lighting-controller.d.ts.map +1 -0
  208. package/dist/systems/lighting-controller.js +204 -0
  209. package/dist/systems/lighting-controller.js.map +1 -0
  210. package/dist/systems/material-animation-controller.d.ts +26 -0
  211. package/dist/systems/material-animation-controller.d.ts.map +1 -0
  212. package/dist/systems/material-animation-controller.js +221 -0
  213. package/dist/systems/material-animation-controller.js.map +1 -0
  214. package/dist/systems/material-binding-resolver.d.ts +16 -0
  215. package/dist/systems/material-binding-resolver.d.ts.map +1 -0
  216. package/dist/systems/material-binding-resolver.js +54 -0
  217. package/dist/systems/material-binding-resolver.js.map +1 -0
  218. package/dist/systems/material-controller.d.ts +29 -0
  219. package/dist/systems/material-controller.d.ts.map +1 -0
  220. package/dist/systems/material-controller.js +233 -0
  221. package/dist/systems/material-controller.js.map +1 -0
  222. package/dist/systems/material-preparation.d.ts +9 -0
  223. package/dist/systems/material-preparation.d.ts.map +1 -0
  224. package/dist/systems/material-preparation.js +51 -0
  225. package/dist/systems/material-preparation.js.map +1 -0
  226. package/dist/systems/material-slots.d.ts +18 -0
  227. package/dist/systems/material-slots.d.ts.map +1 -0
  228. package/dist/systems/material-slots.js +78 -0
  229. package/dist/systems/material-slots.js.map +1 -0
  230. package/dist/systems/owned-material-controller.d.ts +20 -0
  231. package/dist/systems/owned-material-controller.d.ts.map +1 -0
  232. package/dist/systems/owned-material-controller.js +611 -0
  233. package/dist/systems/owned-material-controller.js.map +1 -0
  234. package/dist/systems/pbr-material.d.ts +22 -0
  235. package/dist/systems/pbr-material.d.ts.map +1 -0
  236. package/dist/systems/pbr-material.js +358 -0
  237. package/dist/systems/pbr-material.js.map +1 -0
  238. package/dist/systems/post-process-controller.d.ts +17 -0
  239. package/dist/systems/post-process-controller.d.ts.map +1 -0
  240. package/dist/systems/post-process-controller.js +246 -0
  241. package/dist/systems/post-process-controller.js.map +1 -0
  242. package/dist/systems/runtime-clock.d.ts +9 -0
  243. package/dist/systems/runtime-clock.d.ts.map +1 -0
  244. package/dist/systems/runtime-clock.js +25 -0
  245. package/dist/systems/runtime-clock.js.map +1 -0
  246. package/dist/systems/skybox-controller.d.ts +15 -0
  247. package/dist/systems/skybox-controller.d.ts.map +1 -0
  248. package/dist/systems/skybox-controller.js +282 -0
  249. package/dist/systems/skybox-controller.js.map +1 -0
  250. package/dist/systems/sprite-sheet-controller.d.ts +52 -0
  251. package/dist/systems/sprite-sheet-controller.d.ts.map +1 -0
  252. package/dist/systems/sprite-sheet-controller.js +187 -0
  253. package/dist/systems/sprite-sheet-controller.js.map +1 -0
  254. package/dist/systems/surface-effect-plugin.d.ts +26 -0
  255. package/dist/systems/surface-effect-plugin.d.ts.map +1 -0
  256. package/dist/systems/surface-effect-plugin.js +204 -0
  257. package/dist/systems/surface-effect-plugin.js.map +1 -0
  258. package/dist/systems/surface-program-plugin.d.ts +29 -0
  259. package/dist/systems/surface-program-plugin.d.ts.map +1 -0
  260. package/dist/systems/surface-program-plugin.js +139 -0
  261. package/dist/systems/surface-program-plugin.js.map +1 -0
  262. package/dist/systems/texture-animation-controller.d.ts +18 -0
  263. package/dist/systems/texture-animation-controller.d.ts.map +1 -0
  264. package/dist/systems/texture-animation-controller.js +147 -0
  265. package/dist/systems/texture-animation-controller.js.map +1 -0
  266. package/dist/systems/weather-controller.d.ts +16 -0
  267. package/dist/systems/weather-controller.d.ts.map +1 -0
  268. package/dist/systems/weather-controller.js +205 -0
  269. package/dist/systems/weather-controller.js.map +1 -0
  270. package/package.json +63 -0
@@ -0,0 +1,16 @@
1
+ import type { Material } from "@babylonjs/core/Materials/material";
2
+ import type { Scene } from "@babylonjs/core/scene";
3
+ import type { MaterialBindingRecord } from "@skenora/contracts";
4
+ /**
5
+ * Resolves document material ids and bindings against the current Babylon
6
+ * scene without owning the resolved materials.
7
+ */
8
+ export declare class MaterialBindingResolver {
9
+ #private;
10
+ constructor(scene: Scene);
11
+ get(materialId: string): Material | null;
12
+ resolve(binding: Readonly<MaterialBindingRecord>): Material | null;
13
+ setBindings(bindings: Readonly<Record<string, MaterialBindingRecord>>): void;
14
+ clear(): void;
15
+ }
16
+ //# sourceMappingURL=material-binding-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"material-binding-resolver.d.ts","sourceRoot":"","sources":["../../src/systems/material-binding-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;GAGG;AACH,qBAAa,uBAAuB;;gBAItB,KAAK,EAAE,KAAK;IAIxB,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI;IAOxC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,QAAQ,GAAG,IAAI;IAkBlE,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,GAAG,IAAI;IAW5E,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Resolves document material ids and bindings against the current Babylon
3
+ * scene without owning the resolved materials.
4
+ */
5
+ export class MaterialBindingResolver {
6
+ #scene;
7
+ #bindings = new Map();
8
+ constructor(scene) {
9
+ this.#scene = scene;
10
+ }
11
+ get(materialId) {
12
+ const binding = this.#bindings.get(materialId)?.[0];
13
+ return binding
14
+ ? this.resolve(binding)
15
+ : this.#scene.getMaterialById(materialId);
16
+ }
17
+ resolve(binding) {
18
+ const mesh = this.#scene.meshes.find((candidate) => belongsToEntity(candidate, binding.entityId) &&
19
+ candidate.material !== null &&
20
+ (!binding.targetName ||
21
+ candidate.material.id === binding.targetName ||
22
+ candidate.material.name === binding.targetName));
23
+ if (mesh?.material)
24
+ return mesh.material;
25
+ return (this.#scene.getMaterialById(binding.materialId) ??
26
+ (binding.targetName
27
+ ? this.#scene.getMaterialByName(binding.targetName)
28
+ : null));
29
+ }
30
+ setBindings(bindings) {
31
+ this.#bindings.clear();
32
+ for (const binding of Object.values(bindings)) {
33
+ const materialBindings = this.#bindings.get(binding.materialId);
34
+ this.#bindings.set(binding.materialId, [
35
+ ...(materialBindings ?? []),
36
+ binding,
37
+ ]);
38
+ }
39
+ }
40
+ clear() {
41
+ this.#bindings.clear();
42
+ }
43
+ }
44
+ function belongsToEntity(node, entityId) {
45
+ let current = node;
46
+ while (current && typeof current === "object") {
47
+ const candidate = current;
48
+ if (candidate.metadata?.skenora?.entityId === entityId)
49
+ return true;
50
+ current = candidate.parent;
51
+ }
52
+ return false;
53
+ }
54
+ //# sourceMappingURL=material-binding-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"material-binding-resolver.js","sourceRoot":"","sources":["../../src/systems/material-binding-resolver.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IACzB,MAAM,CAAQ;IACd,SAAS,GAAG,IAAI,GAAG,EAA4C,CAAC;IAEzE,YAAY,KAAY;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,GAAG,CAAC,UAAkB;QACpB,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACpD,OAAO,OAAO;YACZ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YACvB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,CAAC,OAAwC;QAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAClC,CAAC,SAAS,EAAE,EAAE,CACZ,eAAe,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC;YAC5C,SAAS,CAAC,QAAQ,KAAK,IAAI;YAC3B,CAAC,CAAC,OAAO,CAAC,UAAU;gBAClB,SAAS,CAAC,QAAQ,CAAC,EAAE,KAAK,OAAO,CAAC,UAAU;gBAC5C,SAAS,CAAC,QAAQ,CAAC,IAAI,KAAK,OAAO,CAAC,UAAU,CAAC,CACpD,CAAC;QACF,IAAI,IAAI,EAAE,QAAQ;YAAE,OAAO,IAAI,CAAC,QAAQ,CAAC;QACzC,OAAO,CACL,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC;YAC/C,CAAC,OAAO,CAAC,UAAU;gBACjB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,UAAU,CAAC;gBACnD,CAAC,CAAC,IAAI,CAAC,CACV,CAAC;IACJ,CAAC;IAED,WAAW,CAAC,QAAyD;QACnE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9C,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAChE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE;gBACrC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC;gBAC3B,OAAO;aACR,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACF;AAED,SAAS,eAAe,CACtB,IAA4C,EAC5C,QAAgB;IAEhB,IAAI,OAAO,GAAY,IAAI,CAAC;IAC5B,OAAO,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,OAGjB,CAAC;QACF,IAAI,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QACpE,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC;IAC7B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,29 @@
1
+ /** Applies document-owned material overrides to imported materials. */
2
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
3
+ import type { Material } from "@babylonjs/core/Materials/material";
4
+ import type { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh";
5
+ import type { Scene } from "@babylonjs/core/scene";
6
+ import type { MaterialBindingRecord, MaterialOverride, SceneDocumentData, MaterialExecutionPolicy, MaterialPreparationEvent, MaterialEffectRuntimeProperty, GpuProgramPreparationReport } from "@skenora/contracts";
7
+ import type { ResourceResolver } from "@skenora/resources";
8
+ import type { GpuProgramCache } from "./gpu-program-cache.js";
9
+ export type MaterialResolver = (binding: Readonly<MaterialBindingRecord>) => Material | null;
10
+ export interface MaterialControllerOptions {
11
+ policy?: MaterialExecutionPolicy;
12
+ onPreparation?: (event: MaterialPreparationEvent) => void;
13
+ onGpuProgramPreparation?: (event: GpuProgramPreparationReport) => void;
14
+ gpuProgramCache?: GpuProgramCache;
15
+ }
16
+ /** Applies document-owned PBR overrides without owning imported materials. */
17
+ export declare class MaterialController {
18
+ #private;
19
+ readonly scene: Scene;
20
+ readonly resources: ResourceResolver;
21
+ constructor(scene: Scene, resources: ResourceResolver, resolve: MaterialResolver, options?: MaterialControllerOptions);
22
+ apply(document: Readonly<SceneDocumentData>, isCurrent?: () => boolean): Promise<void>;
23
+ getOwnedMaterials(materialId: string): readonly PBRMaterial[] | null;
24
+ setEffectProperty(materialId: string, property: MaterialEffectRuntimeProperty, value: unknown): void;
25
+ readOriginalMaterial(mesh: AbstractMesh): Material | null;
26
+ capture(material: PBRMaterial, identity: Pick<MaterialOverride, "id">): MaterialOverride;
27
+ dispose(): void;
28
+ }
29
+ //# sourceMappingURL=material-controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"material-controller.d.ts","sourceRoot":"","sources":["../../src/systems/material-controller.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAGxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,KA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,EAAE,YAAY,GAAG,QAAQ,GAAG,IAAI;IAIzD,OAAO,CACL,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,GACrC,gBAAgB;IAoGnB,OAAO,IAAI,IAAI;CAuEhB"}
@@ -0,0 +1,233 @@
1
+ /** Applies document-owned material overrides to imported materials. */
2
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
3
+ import { Texture } from "@babylonjs/core/Materials/Textures/texture";
4
+ import { MATERIAL_TEXTURE_SLOT_NAMES } from "@skenora/contracts";
5
+ import { applyPbrOverride, assignTextureSlot, createTexture, readManagedReference, readTextureSlot, toColorValue, } from "./pbr-material.js";
6
+ /** Applies document-owned PBR overrides without owning imported materials. */
7
+ export class MaterialController {
8
+ scene;
9
+ resources;
10
+ #resolve;
11
+ #options;
12
+ #bindings = new Map();
13
+ #originals = new Map();
14
+ #owned = null;
15
+ #resourceScope = null;
16
+ #revision = 0;
17
+ #disposed = false;
18
+ constructor(scene, resources, resolve, options = {}) {
19
+ this.scene = scene;
20
+ this.resources = resources;
21
+ this.#resolve = resolve;
22
+ this.#options = options;
23
+ }
24
+ async apply(document, isCurrent = () => !this.#disposed) {
25
+ this.#assertActive();
26
+ const revision = ++this.#revision;
27
+ const current = () => isCurrent() && revision === this.#revision;
28
+ if (!this.#owned &&
29
+ Object.values(document.materials).some((material) => material.creation)) {
30
+ const { OwnedMaterialController } = await import("./owned-material-controller.js");
31
+ if (!current())
32
+ return;
33
+ this.#owned ??= new OwnedMaterialController(this.scene, this.resources, this.#options.policy, this.#options.onPreparation, this.#options.gpuProgramCache, this.#options.onGpuProgramPreparation);
34
+ }
35
+ await this.#owned?.apply(document, current);
36
+ if (!current())
37
+ return;
38
+ this.#releaseTextures();
39
+ this.#restoreOverrides();
40
+ for (const binding of Object.values(document.materialBindings)) {
41
+ if (!current())
42
+ return;
43
+ const override = document.materials[binding.materialId];
44
+ if (!override || override.creation)
45
+ continue;
46
+ const material = this.#resolve(binding);
47
+ if (!(material instanceof PBRMaterial))
48
+ continue;
49
+ if (!this.#originals.has(material)) {
50
+ this.#originals.set(material, {
51
+ definition: this.capture(material, { id: override.id }),
52
+ transparencyMode: material.transparencyMode,
53
+ });
54
+ }
55
+ applyPbrOverride(material, override);
56
+ await this.#applyTextures(document, material, override, current);
57
+ }
58
+ }
59
+ getOwnedMaterials(materialId) {
60
+ return this.#owned?.get(materialId) ?? null;
61
+ }
62
+ setEffectProperty(materialId, property, value) {
63
+ if (!this.#owned)
64
+ throw new Error("Owned material effects are not active");
65
+ this.#owned.setEffectProperty(materialId, property, value);
66
+ }
67
+ readOriginalMaterial(mesh) {
68
+ return this.#owned ? this.#owned.readOriginal(mesh) : mesh.material;
69
+ }
70
+ capture(material, identity) {
71
+ const textures = Object.fromEntries(MATERIAL_TEXTURE_SLOT_NAMES.flatMap((slot) => {
72
+ const texture = readTextureSlot(material, slot);
73
+ const reference = texture instanceof Texture ? readManagedReference(texture) : null;
74
+ return reference ? [[slot, reference]] : [];
75
+ }));
76
+ const effects = this.#owned?.captureEffects(material);
77
+ return {
78
+ ...identity,
79
+ ...(effects ? { effects } : {}),
80
+ workflow: material.metallic === null && material.roughness === null
81
+ ? "specular-glossiness"
82
+ : "metallic-roughness",
83
+ baseColor: toColorValue(material.albedoColor),
84
+ reflectivityColor: toColorValue(material.reflectivityColor),
85
+ ambientColor: toColorValue(material.ambientColor),
86
+ metallic: material.metallic,
87
+ roughness: material.roughness,
88
+ microSurface: material.microSurface,
89
+ metallicF0Factor: material.metallicF0Factor,
90
+ alpha: material.alpha,
91
+ emissiveColor: toColorValue(material.emissiveColor),
92
+ emissiveIntensity: material.emissiveIntensity,
93
+ indexOfRefraction: material.indexOfRefraction,
94
+ ...(material.transparencyMode === null
95
+ ? {}
96
+ : { transparencyMode: material.transparencyMode }),
97
+ alphaCutOff: material.alphaCutOff,
98
+ useAlphaFromBaseColorTexture: material.useAlphaFromAlbedoTexture,
99
+ useLightmapAsShadowmap: material.useLightmapAsShadowmap,
100
+ useAmbientInGrayScale: material.useAmbientInGrayScale,
101
+ useMicroSurfaceFromReflectivityMapAlpha: material.useMicroSurfaceFromReflectivityMapAlpha,
102
+ useAutoMicroSurfaceFromReflectivityMap: material.useAutoMicroSurfaceFromReflectivityMap,
103
+ unlit: material.unlit,
104
+ doubleSided: !material.backFaceCulling,
105
+ clearCoat: {
106
+ enabled: material.clearCoat.isEnabled,
107
+ intensity: material.clearCoat.intensity,
108
+ roughness: material.clearCoat.roughness,
109
+ indexOfRefraction: material.clearCoat.indexOfRefraction,
110
+ remapF0OnInterfaceChange: material.clearCoat.remapF0OnInterfaceChange,
111
+ tintEnabled: material.clearCoat.isTintEnabled,
112
+ tintColor: toColorValue(material.clearCoat.tintColor),
113
+ tintThickness: material.clearCoat.tintThickness,
114
+ tintColorAtDistance: material.clearCoat.tintColorAtDistance,
115
+ },
116
+ sheen: {
117
+ enabled: material.sheen.isEnabled,
118
+ intensity: material.sheen.intensity,
119
+ roughness: material.sheen.roughness ?? 0,
120
+ color: toColorValue(material.sheen.color),
121
+ linkWithBaseColor: material.sheen.linkSheenWithAlbedo,
122
+ useRoughnessFromMainTexture: material.sheen.useRoughnessFromMainTexture,
123
+ },
124
+ anisotropy: {
125
+ enabled: material.anisotropy.isEnabled,
126
+ intensity: material.anisotropy.intensity,
127
+ direction: {
128
+ x: material.anisotropy.direction.x,
129
+ y: material.anisotropy.direction.y,
130
+ },
131
+ },
132
+ subSurface: {
133
+ enabled: material.subSurface.isRefractionEnabled ||
134
+ material.subSurface.isTranslucencyEnabled,
135
+ refractionEnabled: material.subSurface.isRefractionEnabled,
136
+ translucencyEnabled: material.subSurface.isTranslucencyEnabled,
137
+ indexOfRefraction: material.subSurface.indexOfRefraction,
138
+ volumeIndexOfRefraction: material.subSurface.volumeIndexOfRefraction,
139
+ minimumThickness: material.subSurface.minimumThickness,
140
+ maximumThickness: material.subSurface.maximumThickness,
141
+ tintColor: toColorValue(material.subSurface.tintColor),
142
+ tintColorAtDistance: material.subSurface.tintColorAtDistance,
143
+ refractionIntensity: material.subSurface.refractionIntensity,
144
+ translucencyIntensity: material.subSurface.translucencyIntensity,
145
+ diffusionDistance: toColorValue(material.subSurface.diffusionDistance),
146
+ linkRefractionWithTransparency: material.subSurface.linkRefractionWithTransparency,
147
+ useAlbedoToTintRefraction: material.subSurface.useAlbedoToTintRefraction,
148
+ useAlbedoToTintTranslucency: material.subSurface.useAlbedoToTintTranslucency,
149
+ },
150
+ ...(Object.keys(textures).length > 0
151
+ ? {
152
+ textures: textures,
153
+ }
154
+ : {}),
155
+ };
156
+ }
157
+ dispose() {
158
+ if (this.#disposed)
159
+ return;
160
+ this.#disposed = true;
161
+ this.#revision += 1;
162
+ this.#releaseTextures();
163
+ this.#restoreOverrides();
164
+ this.#owned?.dispose();
165
+ this.#owned = null;
166
+ }
167
+ async #applyTextures(document, material, override, isCurrent) {
168
+ const entries = Object.entries(override.textures ?? {});
169
+ for (const [slot, reference] of entries) {
170
+ const asset = document.assets[reference.assetId];
171
+ if (!asset)
172
+ continue;
173
+ this.#resourceScope ??= this.resources.createScope();
174
+ const resource = await acquireCurrent(this.#resourceScope, asset, isCurrent);
175
+ if (!resource)
176
+ return;
177
+ const texture = createTexture(this.scene, resource.objectUrl, reference, `${material.name}:${slot}`);
178
+ const previous = readTextureSlot(material, slot);
179
+ assignTextureSlot(material, slot, texture);
180
+ const bindings = this.#bindings.get(material) ?? [];
181
+ bindings.push({ slot, texture, previous });
182
+ this.#bindings.set(material, bindings);
183
+ }
184
+ }
185
+ #releaseTextures() {
186
+ for (const [material, bindings] of this.#bindings) {
187
+ for (const binding of [...bindings].reverse()) {
188
+ if (readTextureSlot(material, binding.slot) === binding.texture) {
189
+ assignTextureSlot(material, binding.slot, binding.previous);
190
+ }
191
+ binding.texture.dispose();
192
+ }
193
+ }
194
+ this.#bindings.clear();
195
+ this.#resourceScope?.dispose();
196
+ this.#resourceScope = null;
197
+ }
198
+ #restoreOverrides() {
199
+ for (const [material, original] of this.#originals) {
200
+ applyPbrOverride(material, original.definition);
201
+ material.transparencyMode = original.transparencyMode;
202
+ }
203
+ this.#originals.clear();
204
+ }
205
+ #assertActive() {
206
+ if (this.#disposed) {
207
+ throw new Error("MaterialController has been disposed");
208
+ }
209
+ }
210
+ }
211
+ async function acquireCurrent(scope, asset, isCurrent) {
212
+ try {
213
+ const resource = await scope.acquire(asset);
214
+ if (isCurrent())
215
+ return resource;
216
+ scope.dispose();
217
+ return null;
218
+ }
219
+ catch (error) {
220
+ if (!isCurrent() && isAbortError(error)) {
221
+ scope.dispose();
222
+ return null;
223
+ }
224
+ throw error;
225
+ }
226
+ }
227
+ function isAbortError(error) {
228
+ return (!!error &&
229
+ typeof error === "object" &&
230
+ "name" in error &&
231
+ error.name === "AbortError");
232
+ }
233
+ //# sourceMappingURL=material-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"material-controller.js","sourceRoot":"","sources":["../../src/systems/material-controller.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAExE,OAAO,EAAE,OAAO,EAAE,MAAM,4CAA4C,CAAC;AAgBrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAOjE,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,YAAY,GACb,MAAM,gBAAgB,CAAC;AAqBxB,8EAA8E;AAC9E,MAAM,OAAO,kBAAkB;IACpB,KAAK,CAAQ;IACb,SAAS,CAAmB;IAC5B,QAAQ,CAAmB;IAC3B,QAAQ,CAA4B;IACpC,SAAS,GAAG,IAAI,GAAG,EAAiC,CAAC;IACrD,UAAU,GAAG,IAAI,GAAG,EAG1B,CAAC;IACJ,MAAM,GAAmC,IAAI,CAAC;IAC9C,cAAc,GAAyB,IAAI,CAAC;IAC5C,SAAS,GAAG,CAAC,CAAC;IAC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ACP,OAAO,KAAK,KAAK,QAAQ;QACzB,MAAM,IAAI,KAAK;QACf,KAAK,CAAC,IAAI,KAAK,YAAY,CAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
2
+ import type { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh";
3
+ /**
4
+ * Prepares the surface variant without touching active submesh draw wrappers.
5
+ * Unlike forceCompilationAsync, this owns and cancels its polling timer.
6
+ * Readiness is not a visual-quality assertion or a check of every shadow pass.
7
+ */
8
+ export declare function prepareMaterialSurface(material: PBRMaterial, mesh: AbstractMesh, slot: number, signal: AbortSignal): Promise<void>;
9
+ //# sourceMappingURL=material-preparation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"material-preparation.d.ts","sourceRoot":"","sources":["../../src/systems/material-preparation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAGxE;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,CAuDf"}
@@ -0,0 +1,51 @@
1
+ import { SubMesh } from "@babylonjs/core/Meshes/subMesh";
2
+ /**
3
+ * Prepares the surface variant without touching active submesh draw wrappers.
4
+ * Unlike forceCompilationAsync, this owns and cancels its polling timer.
5
+ * Readiness is not a visual-quality assertion or a check of every shadow pass.
6
+ */
7
+ export async function prepareMaterialSurface(material, mesh, slot, signal) {
8
+ const probe = new SubMesh(slot, 0, mesh.getTotalVertices(), 0, mesh.getTotalIndices(), mesh, undefined, false, false);
9
+ let timer;
10
+ let abort = () => undefined;
11
+ const hotSwap = material.allowShaderHotSwapping;
12
+ material.allowShaderHotSwapping = false;
13
+ try {
14
+ await new Promise((resolve, reject) => {
15
+ abort = () => reject(new DOMException("Material preparation cancelled", "AbortError"));
16
+ signal.addEventListener("abort", abort, { once: true });
17
+ const check = () => {
18
+ if (signal.aborted || mesh.isDisposed()) {
19
+ abort();
20
+ return;
21
+ }
22
+ try {
23
+ if (material.isReadyForSubMesh(mesh, probe, mesh.hasThinInstances)) {
24
+ resolve();
25
+ return;
26
+ }
27
+ if (probe.effect?.getCompilationError() &&
28
+ probe.effect.allFallbacksProcessed()) {
29
+ reject(new Error("Material program preparation failed"));
30
+ return;
31
+ }
32
+ timer = setTimeout(check, 16);
33
+ }
34
+ catch {
35
+ reject(new Error("Material program preparation failed"));
36
+ }
37
+ };
38
+ check();
39
+ });
40
+ }
41
+ finally {
42
+ if (timer !== undefined)
43
+ clearTimeout(timer);
44
+ signal.removeEventListener("abort", abort);
45
+ material.allowShaderHotSwapping = hotSwap;
46
+ // The probe was not inserted in mesh.subMeshes. SubMesh.dispose() would
47
+ // splice index -1 in Babylon 9, removing a real submesh; release only its cache.
48
+ probe.resetDrawCache();
49
+ }
50
+ }
51
+ //# sourceMappingURL=material-preparation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"material-preparation.js","sourceRoot":"","sources":["../../src/systems/material-preparation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,QAAqB,EACrB,IAAkB,EAClB,IAAY,EACZ,MAAmB;IAEnB,MAAM,KAAK,GAAG,IAAI,OAAO,CACvB,IAAI,EACJ,CAAC,EACD,IAAI,CAAC,gBAAgB,EAAE,EACvB,CAAC,EACD,IAAI,CAAC,eAAe,EAAE,EACtB,IAAI,EACJ,SAAS,EACT,KAAK,EACL,KAAK,CACN,CAAC;IACF,IAAI,KAAgD,CAAC;IACrD,IAAI,KAAK,GAAe,GAAG,EAAE,CAA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AC,CAAC;QAC7C,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC3C,QAAQ,CAAC,sBAAsB,GAAG,OAAO,CAAC;QAC1C,wEAAwE;QACxE,iFAAiF;QACjF,KAAK,CAAC,cAAc,EAAE,CAAC;IACzB,CAAC;AACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Material } from "@babylonjs/core/Materials/material";
2
+ import type { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh";
3
+ import type { Scene } from "@babylonjs/core/scene";
4
+ import type { MaterialBindingRecord, MaterialDiagnostic, MaterialSlotDescriptor } from "@skenora/contracts";
5
+ export declare class MaterialProjectionError extends Error {
6
+ readonly diagnostic: Readonly<MaterialDiagnostic>;
7
+ constructor(diagnostic: MaterialDiagnostic);
8
+ }
9
+ export interface MaterialSlot {
10
+ readonly mesh: AbstractMesh;
11
+ readonly slot: number;
12
+ readonly original: Material | null;
13
+ readonly material: Material | null;
14
+ readonly descriptor: MaterialSlotDescriptor;
15
+ }
16
+ export declare function listMaterialSlots(scene: Scene, entityId: string, readOriginal?: (mesh: AbstractMesh) => Material | null): readonly MaterialSlot[];
17
+ export declare function resolveMaterialSlot(scene: Scene, binding: Readonly<MaterialBindingRecord>, readOriginal?: (mesh: AbstractMesh) => Material | null): MaterialSlot;
18
+ //# sourceMappingURL=material-slots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"material-slots.d.ts","sourceRoot":"","sources":["../../src/systems/material-slots.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC;gBACtC,UAAU,EAAE,kBAAkB;CAK3C;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,sBAAsB,CAAC;CAC7C;AAcD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,EAChB,YAAY,GAAE,CAAC,IAAI,EAAE,YAAY,KAAK,QAAQ,GAAG,IAClC,GACd,SAAS,YAAY,EAAE,CA4BzB;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,EACxC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,QAAQ,GAAG,IAAI,GACrD,YAAY,CAwCd"}
@@ -0,0 +1,78 @@
1
+ import { MultiMaterial } from "@babylonjs/core/Materials/multiMaterial";
2
+ export class MaterialProjectionError extends Error {
3
+ diagnostic;
4
+ constructor(diagnostic) {
5
+ super(diagnostic.message);
6
+ this.name = "MaterialProjectionError";
7
+ this.diagnostic = Object.freeze({ ...diagnostic });
8
+ }
9
+ }
10
+ /** Stops at the closest declared entity so parents cannot claim child entities. */
11
+ function entityOf(mesh) {
12
+ let node = mesh;
13
+ while (node) {
14
+ const id = node.metadata
15
+ ?.skenora?.entityId;
16
+ if (typeof id === "string")
17
+ return id;
18
+ node = node.parent;
19
+ }
20
+ return null;
21
+ }
22
+ export function listMaterialSlots(scene, entityId, readOriginal = (mesh) => mesh.material) {
23
+ return scene.meshes.flatMap((mesh) => {
24
+ if (mesh.isDisposed() ||
25
+ mesh.getTotalVertices() === 0 ||
26
+ entityOf(mesh) !== entityId)
27
+ return [];
28
+ const original = readOriginal(mesh);
29
+ const sourceNodeId = mesh.metadata?.skenora?.sourceNodeId;
30
+ const nodeId = typeof sourceNodeId === "string" ? sourceNodeId : mesh.id;
31
+ const materials = original instanceof MultiMaterial ? original.subMaterials : [original];
32
+ return materials.map((material, slot) => ({
33
+ mesh,
34
+ slot,
35
+ original,
36
+ material,
37
+ descriptor: {
38
+ entityId,
39
+ nodeId,
40
+ slot,
41
+ materialName: material?.name ?? null,
42
+ },
43
+ }));
44
+ });
45
+ }
46
+ export function resolveMaterialSlot(scene, binding, readOriginal) {
47
+ const matches = listMaterialSlots(scene, binding.entityId, readOriginal).filter(({ descriptor }) => (binding.target?.nodeId === undefined ||
48
+ descriptor.nodeId === binding.target.nodeId) &&
49
+ (binding.target?.slot === undefined ||
50
+ descriptor.slot === binding.target.slot));
51
+ if (matches.length !== 1) {
52
+ throw new MaterialProjectionError({
53
+ stage: "binding",
54
+ code: matches.length
55
+ ? "ambiguous-material-slot"
56
+ : "missing-material-slot",
57
+ materialId: binding.materialId,
58
+ bindingId: binding.id,
59
+ message: matches.length
60
+ ? "More than one material slot matches; specify the source node ID and slot."
61
+ : "No material slot matches this entity and selector; inspect the current asset slots.",
62
+ });
63
+ }
64
+ if (matches[0].mesh.getClassName() === "LinesMesh" ||
65
+ matches[0].mesh.isAnInstance) {
66
+ throw new MaterialProjectionError({
67
+ stage: "binding",
68
+ code: "unsupported-material-target",
69
+ materialId: binding.materialId,
70
+ bindingId: binding.id,
71
+ message: matches[0].mesh.isAnInstance
72
+ ? "This instance borrows its source mesh material. Select a directly owned mesh slot or supply a non-instanced asset."
73
+ : "Line geometry does not accept authored PBR surfaces. Select a filled surface or use a tube.",
74
+ });
75
+ }
76
+ return matches[0];
77
+ }
78
+ //# sourceMappingURL=material-slots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"material-slots.js","source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YACrB,OAAO,EAAE,OAAO,CAAC,MAAM;gBACrB,CAAC,CAAC,2EAA2E;gBAC7E,CAAC,CAAC,qFAAqF;SAC1F,CAAC,CAAC;IACL,CAAC;IACD,IACE,OAAO,CAAC,CAAC,CAAE,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,WAAW;QAC/C,OAAO,CAAC,CAAC,CAAE,CAAC,IAAI,CAAC,YAAY,EAC7B,CAAC;QACD,MAAM,IAAI,uBAAuB,CAAC;YAChC,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,6BAA6B;YACnC,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,SAAS,EAAE,OAAO,CAAC,EAAE;YACrB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAE,CAAC,IAAI,CAAC,YAAY;gBACpC,CAAC,CAAC,oHAAoH;gBACtH,CAAC,CAAC,6FAA6F;SAClG,CAAC,CAAC;IACL,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,CAAE,CAAC;AACrB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
2
+ import type { Material } from "@babylonjs/core/Materials/material";
3
+ import type { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh";
4
+ import type { Scene } from "@babylonjs/core/scene";
5
+ import { type MaterialExecutionPolicy, type MaterialPreparationEvent, type SceneDocumentData, type MaterialSurfaceEffects, type MaterialEffectRuntimeProperty, type GpuProgramPreparationReport } from "@skenora/contracts";
6
+ import type { ResourceResolver } from "@skenora/resources";
7
+ import { GpuProgramCache } from "./gpu-program-cache.js";
8
+ /** Owns only explicitly authored instances; imported resources are borrowed. */
9
+ export declare class OwnedMaterialController {
10
+ #private;
11
+ constructor(scene: Scene, resources: ResourceResolver, policy?: MaterialExecutionPolicy, onPreparation?: (event: MaterialPreparationEvent) => void, programCache?: GpuProgramCache, onGpuProgramPreparation?: (event: GpuProgramPreparationReport) => void);
12
+ /** Null means legacy/unknown; an empty array means an unbound owned definition. */
13
+ get(materialId: string): readonly PBRMaterial[] | null;
14
+ captureEffects(material: PBRMaterial): MaterialSurfaceEffects | undefined;
15
+ setEffectProperty(materialId: string, property: MaterialEffectRuntimeProperty, value: unknown): void;
16
+ readOriginal: (mesh: AbstractMesh) => Material | null;
17
+ apply(document: Readonly<SceneDocumentData>, isCurrent: () => boolean): Promise<void>;
18
+ dispose(): void;
19
+ }
20
+ //# sourceMappingURL=owned-material-controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owned-material-controller.d.ts","sourceRoot":"","sources":["../../src/systems/owned-material-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAExE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAEnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAKL,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAI7B,KAAK,iBAAiB,EAEtB,KAAK,sBAAsB,EAE3B,KAAK,6BAA6B,EAIlC,KAAK,2BAA2B,EAEjC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,oBAAoB,CAAC;AAe1E,OAAO,EAAE,eAAe,EAA2B,MAAM,qBAAqB,CAAC;AAkC/E,gFAAgF;AAChF,qBAAa,uBAAuB;;gBAiBhC,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,gBAAgB,EAC3B,MAAM,CAAC,EAAE,uBAAuB,EAChC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,IAAI,EACzD,YAAY,CAAC,EAAE,eAAe,EAC9B,uBAAuB,CAAC,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,IAAI;IA6BxE,mFAAmF;IACnF,GAAG,CAAC,UAAU,EAAE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