@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,324 @@
1
+ import { assertSceneDocument, normalizeSceneDocument, } from "@skenora/contracts";
2
+ import { RuntimeSession, } from "../core/runtime-session.js";
3
+ import { RUNTIME_CAMERA_CAPABILITY } from "../core/runtime-capability-registry.js";
4
+ /**
5
+ * Read-only presentation facade over RuntimeSession.
6
+ *
7
+ * It intentionally does not expose the Babylon scene, nodes, document
8
+ * projection methods, extensions, or any document capture operation.
9
+ */
10
+ export class SceneRenderer {
11
+ #runtime;
12
+ #statusListeners = new Set();
13
+ #statusUnsubscribers = new Set();
14
+ #onStatusListenerError;
15
+ #modelFailures = [];
16
+ #viewerControls = {};
17
+ #captureTail = Promise.resolve();
18
+ #documentId = null;
19
+ #status = "idle";
20
+ #error = null;
21
+ #loadGeneration = 0;
22
+ #disposed = false;
23
+ constructor(canvas, options = {}) {
24
+ this.#runtime = new RuntimeSession(canvas, {
25
+ ...(options.antialias === undefined
26
+ ? {}
27
+ : { antialias: options.antialias }),
28
+ ...(options.engineOptions === undefined
29
+ ? {}
30
+ : { engineOptions: options.engineOptions }),
31
+ adaptToDeviceRatio: options.adaptToDeviceRatio ?? true,
32
+ executionMode: options.executionMode ?? "authoring",
33
+ ...(options.autoResize === undefined
34
+ ? {}
35
+ : { autoResize: options.autoResize }),
36
+ });
37
+ this.#onStatusListenerError =
38
+ options.onStatusListenerError ?? (() => undefined);
39
+ this.#runtime.events.subscribe("runtime.model.failed", ({ entityId, error }) => this.#modelFailures.push({ entityId, error }));
40
+ }
41
+ get canvas() {
42
+ return this.#runtime.canvas;
43
+ }
44
+ get rendering() {
45
+ return this.#runtime.rendering;
46
+ }
47
+ get documentId() {
48
+ return this.#documentId;
49
+ }
50
+ get status() {
51
+ return this.#status;
52
+ }
53
+ get error() {
54
+ return this.#error;
55
+ }
56
+ get modelFailures() {
57
+ return Object.freeze(this.#modelFailures.map((item) => ({ ...item })));
58
+ }
59
+ getBackendSnapshot() {
60
+ return this.#runtime.getBackendSnapshot();
61
+ }
62
+ getGpuProgramCacheSnapshot() {
63
+ return this.#runtime.getGpuProgramCacheSnapshot();
64
+ }
65
+ /** Serializes with capture so render/readback operations never overlap. */
66
+ probe() {
67
+ this.#assertActive();
68
+ const probe = this.#captureTail.then(() => this.#runtime.probe());
69
+ this.#captureTail = probe.then(() => undefined, () => undefined);
70
+ return probe;
71
+ }
72
+ subscribeStatus(listener, options = {}) {
73
+ this.#assertActive();
74
+ if (options.signal?.aborted)
75
+ return () => undefined;
76
+ this.#statusListeners.add(listener);
77
+ if (options.immediate ?? true) {
78
+ this.#notifyStatusListener(listener);
79
+ }
80
+ const unsubscribe = () => {
81
+ this.#statusListeners.delete(listener);
82
+ options.signal?.removeEventListener("abort", unsubscribe);
83
+ this.#statusUnsubscribers.delete(unsubscribe);
84
+ };
85
+ this.#statusUnsubscribers.add(unsubscribe);
86
+ options.signal?.addEventListener("abort", unsubscribe, { once: true });
87
+ return unsubscribe;
88
+ }
89
+ async load(document, resources, options = {}) {
90
+ this.#assertActive();
91
+ let ownedDocument;
92
+ try {
93
+ const candidate = normalizeSceneDocument(structuredClone(document));
94
+ assertSceneDocument(candidate);
95
+ ownedDocument = candidate;
96
+ }
97
+ catch (error) {
98
+ if (this.#status !== "ready")
99
+ this.#setStatus("error", error);
100
+ throw error;
101
+ }
102
+ const generation = ++this.#loadGeneration;
103
+ this.#modelFailures.length = 0;
104
+ const documentId = ownedDocument.id;
105
+ this.#documentId = null;
106
+ this.#setStatus("loading");
107
+ try {
108
+ await this.#captureTail;
109
+ if (generation !== this.#loadGeneration)
110
+ return;
111
+ await this.#runtime.loadDocument(ownedDocument, resources, options);
112
+ if (generation !== this.#loadGeneration)
113
+ return;
114
+ this.#documentId = documentId;
115
+ this.#setStatus("ready");
116
+ }
117
+ catch (error) {
118
+ if (generation === this.#loadGeneration) {
119
+ const aborted = isAbortError(error);
120
+ this.#setStatus(aborted ? "idle" : "error", aborted ? null : error);
121
+ }
122
+ throw error;
123
+ }
124
+ }
125
+ frame() {
126
+ this.#assertActive();
127
+ this.#runtime.capabilities.require(RUNTIME_CAMERA_CAPABILITY).frame();
128
+ this.#runtime.viewportCamera?.configureModelViewerControls(this.#viewerControls);
129
+ }
130
+ setView(view) {
131
+ this.#assertActive();
132
+ this.#runtime.viewportCamera?.setView(view);
133
+ this.#runtime.viewportCamera?.configureModelViewerControls(this.#viewerControls);
134
+ }
135
+ resetView(view = "front") {
136
+ this.#assertActive();
137
+ this.#runtime.resize();
138
+ this.#runtime.capabilities.require(RUNTIME_CAMERA_CAPABILITY).frame();
139
+ this.#runtime.viewportCamera?.setView(view);
140
+ this.#runtime.viewportCamera?.configureModelViewerControls(this.#viewerControls);
141
+ }
142
+ configureViewerControls(options = {}) {
143
+ this.#assertActive();
144
+ this.#viewerControls = { ...options };
145
+ this.#runtime.viewportCamera?.configureModelViewerControls(this.#viewerControls);
146
+ }
147
+ normalizeModelView(view = "front") {
148
+ this.#assertActive();
149
+ this.#runtime.centerImportedModelsAtOrigin();
150
+ this.resetView(view);
151
+ }
152
+ resize() {
153
+ this.#assertActive();
154
+ this.#runtime.resize();
155
+ }
156
+ pause() {
157
+ this.#assertActive();
158
+ this.#runtime.pause();
159
+ }
160
+ resume() {
161
+ this.#assertActive();
162
+ this.#runtime.resume();
163
+ }
164
+ setAutoRotate(enabled, speed = 0.15) {
165
+ this.#assertActive();
166
+ if (!Number.isFinite(speed)) {
167
+ throw new Error("Auto-rotation speed must be finite");
168
+ }
169
+ const camera = this.#runtime.viewportCamera?.camera;
170
+ if (!camera)
171
+ return;
172
+ camera.useAutoRotationBehavior = enabled;
173
+ if (!camera.autoRotationBehavior)
174
+ return;
175
+ camera.autoRotationBehavior.idleRotationSpeed = speed;
176
+ camera.autoRotationBehavior.idleRotationWaitTime = 0;
177
+ camera.autoRotationBehavior.idleRotationSpinupTime = 0;
178
+ }
179
+ capture(options = {}) {
180
+ this.#assertActive();
181
+ if (this.#status !== "ready") {
182
+ return Promise.reject(new Error("A scene document must be ready before capture"));
183
+ }
184
+ const request = structuredClone(options);
185
+ validateCaptureOptions(request);
186
+ const capture = this.#captureTail.then(() => this.#capture(request));
187
+ this.#captureTail = capture.then(() => undefined, () => undefined);
188
+ return capture;
189
+ }
190
+ dispose() {
191
+ if (this.#disposed)
192
+ return;
193
+ this.#loadGeneration += 1;
194
+ this.#documentId = null;
195
+ this.#setStatus("disposed");
196
+ this.#disposed = true;
197
+ try {
198
+ this.#runtime.dispose();
199
+ }
200
+ finally {
201
+ for (const unsubscribe of [...this.#statusUnsubscribers])
202
+ unsubscribe();
203
+ this.#statusUnsubscribers.clear();
204
+ this.#statusListeners.clear();
205
+ }
206
+ }
207
+ async #capture(options) {
208
+ this.#assertActive();
209
+ const engine = this.#runtime.engine;
210
+ const scene = this.#runtime.scene;
211
+ const previousWidth = engine.getRenderWidth();
212
+ const previousHeight = engine.getRenderHeight();
213
+ const previousClear = scene.clearColor.clone();
214
+ const previousBackground = this.#runtime.backgroundVisible;
215
+ try {
216
+ if (options.width !== undefined && options.height !== undefined) {
217
+ engine.setSize(Math.round(options.width), Math.round(options.height));
218
+ }
219
+ if (options.transparent) {
220
+ scene.clearColor.a = 0;
221
+ this.#runtime.setBackgroundVisible(false);
222
+ }
223
+ scene.render();
224
+ return options.crop
225
+ ? await captureRegion(this.canvas, options.crop, options.type ?? "image/png", options.quality)
226
+ : await canvasToBlob(this.canvas, options.type ?? "image/png", options.quality);
227
+ }
228
+ finally {
229
+ scene.clearColor.copyFrom(previousClear);
230
+ this.#runtime.setBackgroundVisible(previousBackground);
231
+ if (options.width !== undefined && options.height !== undefined) {
232
+ engine.setSize(previousWidth, previousHeight);
233
+ }
234
+ scene.render();
235
+ }
236
+ }
237
+ #assertActive() {
238
+ if (this.#disposed)
239
+ throw new Error("SceneRenderer has been disposed");
240
+ }
241
+ #setStatus(status, error = null) {
242
+ this.#status = status;
243
+ this.#error = error;
244
+ for (const listener of [...this.#statusListeners]) {
245
+ this.#notifyStatusListener(listener);
246
+ }
247
+ }
248
+ #notifyStatusListener(listener) {
249
+ try {
250
+ listener(this.#status, this.#error);
251
+ }
252
+ catch (error) {
253
+ try {
254
+ this.#onStatusListenerError(error);
255
+ }
256
+ catch {
257
+ // Status diagnostics must not interrupt renderer lifecycle changes.
258
+ }
259
+ }
260
+ }
261
+ }
262
+ function isAbortError(error) {
263
+ return error?.name === "AbortError";
264
+ }
265
+ function validateCaptureOptions(options) {
266
+ const hasWidth = options.width !== undefined;
267
+ const hasHeight = options.height !== undefined;
268
+ if (hasWidth !== hasHeight) {
269
+ throw new Error("Capture width and height must be provided together");
270
+ }
271
+ if ((hasWidth &&
272
+ (!Number.isFinite(options.width) ||
273
+ Math.round(options.width ?? 0) < 1)) ||
274
+ (hasHeight &&
275
+ (!Number.isFinite(options.height) || Math.round(options.height ?? 0) < 1))) {
276
+ throw new Error("Capture dimensions must be positive finite numbers");
277
+ }
278
+ if (options.quality !== undefined &&
279
+ (!Number.isFinite(options.quality) ||
280
+ options.quality < 0 ||
281
+ options.quality > 1)) {
282
+ throw new Error("Capture quality must be in the 0..1 range");
283
+ }
284
+ }
285
+ async function captureRegion(source, requested, type, quality) {
286
+ const region = normalizeRegion(requested, source.width, source.height);
287
+ const target = source.ownerDocument.createElement("canvas");
288
+ target.width = region.width;
289
+ target.height = region.height;
290
+ const context = target.getContext("2d");
291
+ if (!context)
292
+ throw new Error("A 2D canvas context is required for cropping");
293
+ context.drawImage(source, region.x, region.y, region.width, region.height, 0, 0, region.width, region.height);
294
+ return canvasToBlob(target, type, quality);
295
+ }
296
+ function normalizeRegion(region, width, height) {
297
+ if (!Number.isFinite(region.x) ||
298
+ !Number.isFinite(region.y) ||
299
+ !Number.isFinite(region.width) ||
300
+ !Number.isFinite(region.height) ||
301
+ region.width <= 0 ||
302
+ region.height <= 0) {
303
+ throw new Error("Capture crop must overlap the rendered canvas");
304
+ }
305
+ const x = Math.max(0, Math.floor(region.x));
306
+ const y = Math.max(0, Math.floor(region.y));
307
+ const right = Math.min(width, Math.ceil(region.x + region.width));
308
+ const bottom = Math.min(height, Math.ceil(region.y + region.height));
309
+ if (right <= x || bottom <= y) {
310
+ throw new Error("Capture crop must overlap the rendered canvas");
311
+ }
312
+ return { x, y, width: right - x, height: bottom - y };
313
+ }
314
+ function canvasToBlob(canvas, type, quality) {
315
+ return new Promise((resolve, reject) => {
316
+ canvas.toBlob((blob) => {
317
+ if (blob)
318
+ resolve(blob);
319
+ else
320
+ reject(new Error("The rendered canvas could not be captured"));
321
+ }, type, quality);
322
+ });
323
+ }
324
+ //# sourceMappingURL=scene-renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene-renderer.js","sourceRoot":"","sources":["../../src/presentation/scene-renderer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,sBAAsB,GAKvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,cAAc,GAGf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qC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QACrC,MAAM,CAAC,MAAM,CACX,CAAC,IAAI,EAAE,EAAE;YACP,IAAI,IAAI;gBAAE,OAAO,CAAC,IAAI,CAAC,CAAC;;gBACnB,MAAM,CAAC,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC,CAAC;QACtE,CAAC,EACD,IAAI,EACJ,OAAO,CACR,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Scene } from "@babylonjs/core/scene";
2
+ export type ViewportTextureChannel = "baseColor" | "reflectivity" | "microSurface" | "reflectance" | "normal" | "metallicRoughness" | "ambientOcclusion" | "emissive" | "lightmap" | "opacity" | "reflection" | "refraction" | "clearCoat" | "clearCoatRoughness" | "clearCoatNormal" | "sheen" | "sheenRoughness" | "thickness" | "subSurfaceRefraction" | "refractionIntensity";
3
+ export type ViewportMode = "normal" | "unlit" | "wireframe" | "white" | ViewportTextureChannel;
4
+ export declare class ViewportController {
5
+ #private;
6
+ readonly scene: Scene;
7
+ constructor(scene: Scene);
8
+ get mode(): ViewportMode;
9
+ listTextureChannels(): readonly ViewportTextureChannel[];
10
+ setMode(mode: ViewportMode): void;
11
+ dispose(): void;
12
+ }
13
+ //# sourceMappingURL=viewport-controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewport-controller.d.ts","sourceRoot":"","sources":["../../src/presentation/viewport-controller.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,MAAM,MAAM,sBAAsB,GAC9B,WAAW,GACX,cAAc,GACd,cAAc,GACd,aAAa,GACb,QAAQ,GACR,mBAAmB,GACnB,kBAAkB,GAClB,UAAU,GACV,UAAU,GACV,SAAS,GACT,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,oBAAoB,GACpB,iBAAiB,GACjB,OAAO,GACP,gBAAgB,GAChB,WAAW,GACX,sBAAsB,GACtB,qBAAqB,CAAC;AAE1B,MAAM,MAAM,YAAY,GACtB,QAAQ,GAAG,OAAO,GAAG,WAAW,GAAG,OAAO,GAAG,sBAAsB,CAAC;AAOtE,qBAAa,kBAAkB;;IAC7B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;gBAOV,KAAK,EAAE,KAAK;IAIxB,IAAI,IAAI,IAAI,YAAY,CAEvB;IAED,mBAAmB,IAAI,SAAS,sBAAsB,EAAE;IAgBxD,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAkDjC,OAAO,IAAI,IAAI;CAgChB"}
@@ -0,0 +1,186 @@
1
+ /** Read-only presentation helpers for viewport inspection modes. */
2
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
3
+ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial";
4
+ import { Color3 } from "@babylonjs/core/Maths/math.color";
5
+ export class ViewportController {
6
+ scene;
7
+ #states = new Map();
8
+ #meshMaterials = new Map();
9
+ #debugMaterials = new Set();
10
+ #whiteMaterial = null;
11
+ #mode = "normal";
12
+ constructor(scene) {
13
+ this.scene = scene;
14
+ }
15
+ get mode() {
16
+ return this.#mode;
17
+ }
18
+ listTextureChannels() {
19
+ const channels = [];
20
+ for (const channel of TEXTURE_CHANNELS) {
21
+ if (this.scene.materials.some((material) => material instanceof PBRMaterial &&
22
+ textureForChannel(material, channel) !== null)) {
23
+ channels.push(channel);
24
+ }
25
+ }
26
+ return channels;
27
+ }
28
+ setMode(mode) {
29
+ this.#restore();
30
+ this.#mode = mode;
31
+ if (mode === "normal")
32
+ return;
33
+ if (mode === "white") {
34
+ this.#whiteMaterial ??= this.#createWhiteMaterial();
35
+ for (const mesh of this.scene.meshes) {
36
+ if (isHelper(mesh.metadata))
37
+ continue;
38
+ this.#meshMaterials.set(mesh.uniqueId, mesh.material);
39
+ mesh.material = this.#whiteMaterial;
40
+ }
41
+ return;
42
+ }
43
+ if (isTextureChannel(mode)) {
44
+ for (const mesh of this.scene.meshes) {
45
+ if (isHelper(mesh.metadata))
46
+ continue;
47
+ const source = mesh.material;
48
+ if (!(source instanceof PBRMaterial))
49
+ continue;
50
+ this.#meshMaterials.set(mesh.uniqueId, source);
51
+ const debug = new StandardMaterial(`skenora-${mode}-${mesh.uniqueId}`, this.scene);
52
+ debug.disableLighting = true;
53
+ debug.diffuseColor = Color3.Black();
54
+ const texture = textureForChannel(source, mode);
55
+ debug.emissiveColor = texture ? Color3.White() : Color3.Black();
56
+ debug.emissiveTexture = texture;
57
+ debug.backFaceCulling = source.backFaceCulling;
58
+ mesh.material = debug;
59
+ this.#debugMaterials.add(debug);
60
+ }
61
+ return;
62
+ }
63
+ for (const material of this.scene.materials) {
64
+ const state = { wireframe: material.wireframe };
65
+ if (hasDisableLighting(material)) {
66
+ state.disableLighting = material.disableLighting;
67
+ }
68
+ this.#states.set(material, state);
69
+ if (mode === "wireframe")
70
+ material.wireframe = true;
71
+ if (mode === "unlit" && hasDisableLighting(material)) {
72
+ material.disableLighting = true;
73
+ }
74
+ }
75
+ }
76
+ dispose() {
77
+ this.#restore();
78
+ this.#whiteMaterial?.dispose();
79
+ this.#whiteMaterial = null;
80
+ }
81
+ #restore() {
82
+ for (const [material, state] of this.#states) {
83
+ if (!this.scene.materials.includes(material))
84
+ continue;
85
+ material.wireframe = state.wireframe;
86
+ if (state.disableLighting !== undefined && hasDisableLighting(material)) {
87
+ material.disableLighting = state.disableLighting;
88
+ }
89
+ }
90
+ this.#states.clear();
91
+ for (const mesh of this.scene.meshes) {
92
+ if (!this.#meshMaterials.has(mesh.uniqueId))
93
+ continue;
94
+ const material = this.#meshMaterials.get(mesh.uniqueId) ?? null;
95
+ mesh.material =
96
+ material && this.scene.materials.includes(material) ? material : null;
97
+ }
98
+ this.#meshMaterials.clear();
99
+ for (const material of this.#debugMaterials)
100
+ material.dispose();
101
+ this.#debugMaterials.clear();
102
+ }
103
+ #createWhiteMaterial() {
104
+ const material = new StandardMaterial("skenora-white-viewport", this.scene);
105
+ material.diffuseColor = new Color3(0.82, 0.82, 0.82);
106
+ material.specularColor = new Color3(0.05, 0.05, 0.05);
107
+ return material;
108
+ }
109
+ }
110
+ const TEXTURE_CHANNELS = [
111
+ "baseColor",
112
+ "reflectivity",
113
+ "microSurface",
114
+ "reflectance",
115
+ "normal",
116
+ "metallicRoughness",
117
+ "ambientOcclusion",
118
+ "emissive",
119
+ "lightmap",
120
+ "opacity",
121
+ "reflection",
122
+ "refraction",
123
+ "clearCoat",
124
+ "clearCoatRoughness",
125
+ "clearCoatNormal",
126
+ "sheen",
127
+ "sheenRoughness",
128
+ "thickness",
129
+ "subSurfaceRefraction",
130
+ "refractionIntensity",
131
+ ];
132
+ function isTextureChannel(mode) {
133
+ return TEXTURE_CHANNELS.includes(mode);
134
+ }
135
+ function textureForChannel(material, channel) {
136
+ if (channel === "baseColor")
137
+ return material.albedoTexture;
138
+ if (channel === "reflectivity")
139
+ return material.reflectivityTexture;
140
+ if (channel === "microSurface")
141
+ return material.microSurfaceTexture;
142
+ if (channel === "reflectance")
143
+ return material.reflectanceTexture;
144
+ if (channel === "normal")
145
+ return material.bumpTexture;
146
+ if (channel === "metallicRoughness")
147
+ return material.metallicTexture;
148
+ if (channel === "ambientOcclusion")
149
+ return material.ambientTexture;
150
+ if (channel === "emissive")
151
+ return material.emissiveTexture;
152
+ if (channel === "lightmap")
153
+ return material.lightmapTexture;
154
+ if (channel === "opacity")
155
+ return material.opacityTexture;
156
+ if (channel === "reflection")
157
+ return material.reflectionTexture;
158
+ if (channel === "refraction")
159
+ return material.refractionTexture;
160
+ if (channel === "clearCoat")
161
+ return material.clearCoat.texture;
162
+ if (channel === "clearCoatRoughness") {
163
+ return material.clearCoat.textureRoughness;
164
+ }
165
+ if (channel === "clearCoatNormal")
166
+ return material.clearCoat.bumpTexture;
167
+ if (channel === "sheen")
168
+ return material.sheen.texture;
169
+ if (channel === "sheenRoughness")
170
+ return material.sheen.textureRoughness;
171
+ if (channel === "thickness")
172
+ return material.subSurface.thicknessTexture;
173
+ if (channel === "subSurfaceRefraction") {
174
+ return material.subSurface.refractionTexture;
175
+ }
176
+ return material.subSurface.refractionIntensityTexture;
177
+ }
178
+ function hasDisableLighting(material) {
179
+ return "disableLighting" in material;
180
+ }
181
+ function isHelper(metadata) {
182
+ return Boolean(metadata &&
183
+ typeof metadata === "object" &&
184
+ metadata.skenora?.helper);
185
+ }
186
+ //# sourceMappingURL=viewport-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewport-controller.js","sourceRoot":"","sources":["../../src/presentation/viewport-controller.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAGxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAiC1D,MAAM,OAAO,kBAAkB;IACpB,KAAK,CAAQ;IACb,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC7C,cAAc,GAAG,IAAI,GAAG,EAA2B,CAAC;IACpD,eAAe,GAAG,IAAI,GAAG,EAAoB,CAAC;IACvD,cAAc,GAA4B,IAAI,CAAC;IAC/C,KAAK,GAAiB,QAAQ,CAAC;IAE/B,YAAY,KAAY;QACtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,mBAAmB;QACjB,MAAM,QAAQ,GAA6B,EAAE,CAAC;QAC9C,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;YACvC,IACE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CACvB,CAAC,QAAQ,EAAE,EAAE,CACX,QAAQ,YAAY,WAAW;gBAC/B,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,KAAK,IAAI,CAChD,EACD,CAAC;gBACD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;Y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DocumentData } from "@skenora/contracts";
4
+ export interface AnnotationProjection {
5
+ entityId: string;
6
+ text: string;
7
+ color: string;
8
+ x: number;
9
+ y: number;
10
+ depth: number;
11
+ distance: number;
12
+ world: {
13
+ x: number;
14
+ y: number;
15
+ z: number;
16
+ };
17
+ visible: boolean;
18
+ priority: number;
19
+ payload?: Readonly<Record<string, unknown>>;
20
+ }
21
+ export declare class AnnotationProjector {
22
+ #private;
23
+ readonly scene: Scene;
24
+ constructor(scene: Scene, resolveNode: (entityId: string) => TransformNode | null);
25
+ project(document: Readonly<SceneDocumentData>): readonly AnnotationProjection[];
26
+ }
27
+ export declare function createAnnotationEntity(scene: Scene, entity: Readonly<EntityRecord>): TransformNode;
28
+ //# sourceMappingURL=annotation-projector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotation-projector.d.ts","sourceRoot":"","sources":["../../src/projection/annotation-projector.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAEV,YAAY,EACZ,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAG5B,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC7C;AAED,qBAAa,mBAAmB;;IAC9B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;gBAIpB,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,aAAa,GAAG,IAAI;IAMzD,OAAO,CACL,QAAQ,EAAE,QAAQ,CAAC,iBAAiB,CAAC,GACpC,SAAS,oBAAoB,EAAE;CA0EnC;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAC7B,aAAa,CAQf"}