@fps-games/editor 0.1.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 (186) hide show
  1. package/dist/authoring-apply.d.ts +21 -0
  2. package/dist/authoring-apply.d.ts.map +1 -0
  3. package/dist/authoring-apply.js +45 -0
  4. package/dist/authoring-apply.js.map +1 -0
  5. package/dist/index.d.ts +85 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +539 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/local-editor-harness.d.ts +173 -0
  10. package/dist/local-editor-harness.d.ts.map +1 -0
  11. package/dist/local-editor-harness.js +969 -0
  12. package/dist/local-editor-harness.js.map +1 -0
  13. package/node_modules/@fps-games/editor-babylon/dist/camera-controller.d.ts +20 -0
  14. package/node_modules/@fps-games/editor-babylon/dist/camera-controller.d.ts.map +1 -0
  15. package/node_modules/@fps-games/editor-babylon/dist/camera-controller.js +239 -0
  16. package/node_modules/@fps-games/editor-babylon/dist/camera-controller.js.map +1 -0
  17. package/node_modules/@fps-games/editor-babylon/dist/edit-session.d.ts +30 -0
  18. package/node_modules/@fps-games/editor-babylon/dist/edit-session.d.ts.map +1 -0
  19. package/node_modules/@fps-games/editor-babylon/dist/edit-session.js +297 -0
  20. package/node_modules/@fps-games/editor-babylon/dist/edit-session.js.map +1 -0
  21. package/node_modules/@fps-games/editor-babylon/dist/editor-world.d.ts +30 -0
  22. package/node_modules/@fps-games/editor-babylon/dist/editor-world.d.ts.map +1 -0
  23. package/node_modules/@fps-games/editor-babylon/dist/editor-world.js +67 -0
  24. package/node_modules/@fps-games/editor-babylon/dist/editor-world.js.map +1 -0
  25. package/node_modules/@fps-games/editor-babylon/dist/event-guard.d.ts +13 -0
  26. package/node_modules/@fps-games/editor-babylon/dist/event-guard.d.ts.map +1 -0
  27. package/node_modules/@fps-games/editor-babylon/dist/event-guard.js +101 -0
  28. package/node_modules/@fps-games/editor-babylon/dist/event-guard.js.map +1 -0
  29. package/node_modules/@fps-games/editor-babylon/dist/index.d.ts +19 -0
  30. package/node_modules/@fps-games/editor-babylon/dist/index.d.ts.map +1 -0
  31. package/node_modules/@fps-games/editor-babylon/dist/index.js +18 -0
  32. package/node_modules/@fps-games/editor-babylon/dist/index.js.map +1 -0
  33. package/node_modules/@fps-games/editor-babylon/dist/input-controller.d.ts +3 -0
  34. package/node_modules/@fps-games/editor-babylon/dist/input-controller.d.ts.map +1 -0
  35. package/node_modules/@fps-games/editor-babylon/dist/input-controller.js +182 -0
  36. package/node_modules/@fps-games/editor-babylon/dist/input-controller.js.map +1 -0
  37. package/node_modules/@fps-games/editor-babylon/dist/inspector-adapter.d.ts +13 -0
  38. package/node_modules/@fps-games/editor-babylon/dist/inspector-adapter.d.ts.map +1 -0
  39. package/node_modules/@fps-games/editor-babylon/dist/inspector-adapter.js +94 -0
  40. package/node_modules/@fps-games/editor-babylon/dist/inspector-adapter.js.map +1 -0
  41. package/node_modules/@fps-games/editor-babylon/dist/inspector-host.d.ts +43 -0
  42. package/node_modules/@fps-games/editor-babylon/dist/inspector-host.d.ts.map +1 -0
  43. package/node_modules/@fps-games/editor-babylon/dist/inspector-host.js +510 -0
  44. package/node_modules/@fps-games/editor-babylon/dist/inspector-host.js.map +1 -0
  45. package/node_modules/@fps-games/editor-babylon/dist/legacy-runtime.d.ts +5 -0
  46. package/node_modules/@fps-games/editor-babylon/dist/legacy-runtime.d.ts.map +1 -0
  47. package/node_modules/@fps-games/editor-babylon/dist/legacy-runtime.js +5 -0
  48. package/node_modules/@fps-games/editor-babylon/dist/legacy-runtime.js.map +1 -0
  49. package/node_modules/@fps-games/editor-babylon/dist/material-property-adapter.d.ts +22 -0
  50. package/node_modules/@fps-games/editor-babylon/dist/material-property-adapter.d.ts.map +1 -0
  51. package/node_modules/@fps-games/editor-babylon/dist/material-property-adapter.js +408 -0
  52. package/node_modules/@fps-games/editor-babylon/dist/material-property-adapter.js.map +1 -0
  53. package/node_modules/@fps-games/editor-babylon/dist/monitor.d.ts +39 -0
  54. package/node_modules/@fps-games/editor-babylon/dist/monitor.d.ts.map +1 -0
  55. package/node_modules/@fps-games/editor-babylon/dist/monitor.js +780 -0
  56. package/node_modules/@fps-games/editor-babylon/dist/monitor.js.map +1 -0
  57. package/node_modules/@fps-games/editor-babylon/dist/outline-adapter.d.ts +37 -0
  58. package/node_modules/@fps-games/editor-babylon/dist/outline-adapter.d.ts.map +1 -0
  59. package/node_modules/@fps-games/editor-babylon/dist/outline-adapter.js +268 -0
  60. package/node_modules/@fps-games/editor-babylon/dist/outline-adapter.js.map +1 -0
  61. package/node_modules/@fps-games/editor-babylon/dist/projection-selection-controller.d.ts +34 -0
  62. package/node_modules/@fps-games/editor-babylon/dist/projection-selection-controller.d.ts.map +1 -0
  63. package/node_modules/@fps-games/editor-babylon/dist/projection-selection-controller.js +221 -0
  64. package/node_modules/@fps-games/editor-babylon/dist/projection-selection-controller.js.map +1 -0
  65. package/node_modules/@fps-games/editor-babylon/dist/projection.d.ts +90 -0
  66. package/node_modules/@fps-games/editor-babylon/dist/projection.d.ts.map +1 -0
  67. package/node_modules/@fps-games/editor-babylon/dist/projection.js +479 -0
  68. package/node_modules/@fps-games/editor-babylon/dist/projection.js.map +1 -0
  69. package/node_modules/@fps-games/editor-babylon/dist/runtime-globals.d.ts +3 -0
  70. package/node_modules/@fps-games/editor-babylon/dist/runtime-globals.d.ts.map +1 -0
  71. package/node_modules/@fps-games/editor-babylon/dist/runtime-globals.js +7 -0
  72. package/node_modules/@fps-games/editor-babylon/dist/runtime-globals.js.map +1 -0
  73. package/node_modules/@fps-games/editor-babylon/dist/scene-view-camera-controller.d.ts +18 -0
  74. package/node_modules/@fps-games/editor-babylon/dist/scene-view-camera-controller.d.ts.map +1 -0
  75. package/node_modules/@fps-games/editor-babylon/dist/scene-view-camera-controller.js +213 -0
  76. package/node_modules/@fps-games/editor-babylon/dist/scene-view-camera-controller.js.map +1 -0
  77. package/node_modules/@fps-games/editor-babylon/dist/scene-view-input-controller.d.ts +36 -0
  78. package/node_modules/@fps-games/editor-babylon/dist/scene-view-input-controller.d.ts.map +1 -0
  79. package/node_modules/@fps-games/editor-babylon/dist/scene-view-input-controller.js +272 -0
  80. package/node_modules/@fps-games/editor-babylon/dist/scene-view-input-controller.js.map +1 -0
  81. package/node_modules/@fps-games/editor-babylon/dist/selection-controller.d.ts +27 -0
  82. package/node_modules/@fps-games/editor-babylon/dist/selection-controller.d.ts.map +1 -0
  83. package/node_modules/@fps-games/editor-babylon/dist/selection-controller.js +308 -0
  84. package/node_modules/@fps-games/editor-babylon/dist/selection-controller.js.map +1 -0
  85. package/node_modules/@fps-games/editor-babylon/dist/tool-controller.d.ts +17 -0
  86. package/node_modules/@fps-games/editor-babylon/dist/tool-controller.d.ts.map +1 -0
  87. package/node_modules/@fps-games/editor-babylon/dist/tool-controller.js +83 -0
  88. package/node_modules/@fps-games/editor-babylon/dist/tool-controller.js.map +1 -0
  89. package/node_modules/@fps-games/editor-babylon/dist/transform-gizmo-controller.d.ts +47 -0
  90. package/node_modules/@fps-games/editor-babylon/dist/transform-gizmo-controller.d.ts.map +1 -0
  91. package/node_modules/@fps-games/editor-babylon/dist/transform-gizmo-controller.js +689 -0
  92. package/node_modules/@fps-games/editor-babylon/dist/transform-gizmo-controller.js.map +1 -0
  93. package/node_modules/@fps-games/editor-babylon/dist/types.d.ts +111 -0
  94. package/node_modules/@fps-games/editor-babylon/dist/types.d.ts.map +1 -0
  95. package/node_modules/@fps-games/editor-babylon/dist/types.js +2 -0
  96. package/node_modules/@fps-games/editor-babylon/dist/types.js.map +1 -0
  97. package/node_modules/@fps-games/editor-babylon/package.json +25 -0
  98. package/node_modules/@fps-games/editor-browser/dist/index.d.ts +28 -0
  99. package/node_modules/@fps-games/editor-browser/dist/index.d.ts.map +1 -0
  100. package/node_modules/@fps-games/editor-browser/dist/index.js +54 -0
  101. package/node_modules/@fps-games/editor-browser/dist/index.js.map +1 -0
  102. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-input-router.d.ts +12 -0
  103. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-input-router.d.ts.map +1 -0
  104. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-input-router.js +80 -0
  105. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-input-router.js.map +1 -0
  106. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panel-registry.d.ts +11 -0
  107. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panel-registry.d.ts.map +1 -0
  108. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panel-registry.js +33 -0
  109. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panel-registry.js.map +1 -0
  110. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panels.d.ts +9 -0
  111. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panels.d.ts.map +1 -0
  112. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panels.js +444 -0
  113. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panels.js.map +1 -0
  114. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-primitives.d.ts +21 -0
  115. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-primitives.d.ts.map +1 -0
  116. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-primitives.js +103 -0
  117. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-primitives.js.map +1 -0
  118. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-shared.d.ts +12 -0
  119. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-shared.d.ts.map +1 -0
  120. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-shared.js +123 -0
  121. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-shared.js.map +1 -0
  122. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-shortcuts.d.ts +2 -0
  123. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-shortcuts.d.ts.map +1 -0
  124. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-shortcuts.js +115 -0
  125. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-shortcuts.js.map +1 -0
  126. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-theme.d.ts +3 -0
  127. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-theme.d.ts.map +1 -0
  128. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-theme.js +68 -0
  129. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-theme.js.map +1 -0
  130. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-types.d.ts +183 -0
  131. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-types.d.ts.map +1 -0
  132. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-types.js +2 -0
  133. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-types.js.map +1 -0
  134. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-workbench.d.ts +58 -0
  135. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-workbench.d.ts.map +1 -0
  136. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-workbench.js +136 -0
  137. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-workbench.js.map +1 -0
  138. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui.d.ts +4 -0
  139. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui.d.ts.map +1 -0
  140. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui.js +589 -0
  141. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui.js.map +1 -0
  142. package/node_modules/@fps-games/editor-browser/package.json +16 -0
  143. package/node_modules/@fps-games/editor-core/dist/authoring-source.d.ts +211 -0
  144. package/node_modules/@fps-games/editor-core/dist/authoring-source.d.ts.map +1 -0
  145. package/node_modules/@fps-games/editor-core/dist/authoring-source.js +511 -0
  146. package/node_modules/@fps-games/editor-core/dist/authoring-source.js.map +1 -0
  147. package/node_modules/@fps-games/editor-core/dist/editor-session.d.ts +132 -0
  148. package/node_modules/@fps-games/editor-core/dist/editor-session.d.ts.map +1 -0
  149. package/node_modules/@fps-games/editor-core/dist/editor-session.js +265 -0
  150. package/node_modules/@fps-games/editor-core/dist/editor-session.js.map +1 -0
  151. package/node_modules/@fps-games/editor-core/dist/host-services.d.ts +24 -0
  152. package/node_modules/@fps-games/editor-core/dist/host-services.d.ts.map +1 -0
  153. package/node_modules/@fps-games/editor-core/dist/host-services.js +2 -0
  154. package/node_modules/@fps-games/editor-core/dist/host-services.js.map +1 -0
  155. package/node_modules/@fps-games/editor-core/dist/index.d.ts +106 -0
  156. package/node_modules/@fps-games/editor-core/dist/index.d.ts.map +1 -0
  157. package/node_modules/@fps-games/editor-core/dist/index.js +217 -0
  158. package/node_modules/@fps-games/editor-core/dist/index.js.map +1 -0
  159. package/node_modules/@fps-games/editor-core/dist/scene-graph.d.ts +44 -0
  160. package/node_modules/@fps-games/editor-core/dist/scene-graph.d.ts.map +1 -0
  161. package/node_modules/@fps-games/editor-core/dist/scene-graph.js +86 -0
  162. package/node_modules/@fps-games/editor-core/dist/scene-graph.js.map +1 -0
  163. package/node_modules/@fps-games/editor-core/dist/scene-view-input.d.ts +41 -0
  164. package/node_modules/@fps-games/editor-core/dist/scene-view-input.d.ts.map +1 -0
  165. package/node_modules/@fps-games/editor-core/dist/scene-view-input.js +2 -0
  166. package/node_modules/@fps-games/editor-core/dist/scene-view-input.js.map +1 -0
  167. package/node_modules/@fps-games/editor-core/dist/serialized-object.d.ts +53 -0
  168. package/node_modules/@fps-games/editor-core/dist/serialized-object.d.ts.map +1 -0
  169. package/node_modules/@fps-games/editor-core/dist/serialized-object.js +32 -0
  170. package/node_modules/@fps-games/editor-core/dist/serialized-object.js.map +1 -0
  171. package/node_modules/@fps-games/editor-core/dist/transform-gizmo.d.ts +48 -0
  172. package/node_modules/@fps-games/editor-core/dist/transform-gizmo.d.ts.map +1 -0
  173. package/node_modules/@fps-games/editor-core/dist/transform-gizmo.js +2 -0
  174. package/node_modules/@fps-games/editor-core/dist/transform-gizmo.js.map +1 -0
  175. package/node_modules/@fps-games/editor-core/package.json +19 -0
  176. package/node_modules/@fps-games/editor-forge-play/dist/index.d.ts +46 -0
  177. package/node_modules/@fps-games/editor-forge-play/dist/index.d.ts.map +1 -0
  178. package/node_modules/@fps-games/editor-forge-play/dist/index.js +156 -0
  179. package/node_modules/@fps-games/editor-forge-play/dist/index.js.map +1 -0
  180. package/node_modules/@fps-games/editor-forge-play/package.json +19 -0
  181. package/node_modules/@fps-games/editor-protocol/dist/index.d.ts +239 -0
  182. package/node_modules/@fps-games/editor-protocol/dist/index.d.ts.map +1 -0
  183. package/node_modules/@fps-games/editor-protocol/dist/index.js +54 -0
  184. package/node_modules/@fps-games/editor-protocol/dist/index.js.map +1 -0
  185. package/node_modules/@fps-games/editor-protocol/package.json +16 -0
  186. package/package.json +40 -0
@@ -0,0 +1,308 @@
1
+ import { createBrowserHost } from '@fps-games/editor-browser';
2
+ const PENDING_SELECTION_CONTEXT_TTL_MS = 1000;
3
+ function getNodeIdentity(node) {
4
+ if (!node || typeof node !== 'object')
5
+ return null;
6
+ if (typeof node.uniqueId === 'number' && Number.isFinite(node.uniqueId))
7
+ return `uid:${node.uniqueId}`;
8
+ if (typeof node.id === 'string' && node.id.trim())
9
+ return `id:${node.id.trim()}`;
10
+ return null;
11
+ }
12
+ function getNodeParentIdentity(node) {
13
+ const parent = node?.parent ?? null;
14
+ if (!parent)
15
+ return 'root';
16
+ if (typeof parent.uniqueId === 'number' && Number.isFinite(parent.uniqueId))
17
+ return `uid:${parent.uniqueId}`;
18
+ if (typeof parent.id === 'string' && parent.id.trim())
19
+ return `id:${parent.id.trim()}`;
20
+ if (typeof parent.name === 'string' && parent.name.trim())
21
+ return `name:${parent.name.trim()}`;
22
+ return null;
23
+ }
24
+ function collectHighlightMeshesFromNode(node) {
25
+ if (!node)
26
+ return [];
27
+ const result = [];
28
+ if ('showBoundingBox' in node)
29
+ result.push(node);
30
+ const children = typeof node.getChildMeshes === 'function' ? node.getChildMeshes(false) : [];
31
+ for (const mesh of children) {
32
+ if (mesh && 'showBoundingBox' in mesh)
33
+ result.push(mesh);
34
+ }
35
+ return result;
36
+ }
37
+ function isHostHTMLElement(target, win) {
38
+ const ElementCtor = win.HTMLElement ?? HTMLElement;
39
+ return typeof ElementCtor === 'function' && target instanceof ElementCtor;
40
+ }
41
+ export function createEditorSelectionController(options) {
42
+ const host = options.host ?? createBrowserHost();
43
+ let externalSelectionService = null;
44
+ let selectedEntity = null;
45
+ let selectedEntities = [];
46
+ let highlightedMeshes = new Map();
47
+ let normalizingSelection = false;
48
+ let selectionTrackingCtx = null;
49
+ let pendingSelectionContext = null;
50
+ let nextSelectionToken = 1;
51
+ function clearSelectionHighlight() {
52
+ for (const [mesh, state] of highlightedMeshes.entries()) {
53
+ try {
54
+ if (mesh && 'showBoundingBox' in mesh)
55
+ mesh.showBoundingBox = state.showBoundingBox;
56
+ }
57
+ catch { }
58
+ }
59
+ highlightedMeshes = new Map();
60
+ }
61
+ function syncSelectionHighlight() {
62
+ clearSelectionHighlight();
63
+ const nextMeshes = new Map();
64
+ for (const entity of selectedEntities) {
65
+ for (const mesh of collectHighlightMeshesFromNode(entity)) {
66
+ try {
67
+ const prevState = { showBoundingBox: !!mesh.showBoundingBox };
68
+ mesh.showBoundingBox = true;
69
+ nextMeshes.set(mesh, prevState);
70
+ }
71
+ catch { }
72
+ }
73
+ }
74
+ highlightedMeshes = nextMeshes;
75
+ }
76
+ function createSelectionToken() {
77
+ const token = nextSelectionToken;
78
+ nextSelectionToken += 1;
79
+ return token;
80
+ }
81
+ function setPendingSelectionContext(context) {
82
+ pendingSelectionContext = context;
83
+ }
84
+ function clearPendingSelectionContext(expectedToken) {
85
+ if (expectedToken != null && pendingSelectionContext && pendingSelectionContext.token !== expectedToken)
86
+ return;
87
+ pendingSelectionContext = null;
88
+ }
89
+ function peekPendingSelectionContext(expectedToken) {
90
+ const context = pendingSelectionContext;
91
+ if (!context)
92
+ return null;
93
+ if (expectedToken != null && context.token !== expectedToken)
94
+ return null;
95
+ if (Date.now() - context.createdAt > PENDING_SELECTION_CONTEXT_TTL_MS) {
96
+ clearPendingSelectionContext(context.token);
97
+ return null;
98
+ }
99
+ return context;
100
+ }
101
+ function consumePendingSelectionContext(expectedToken) {
102
+ const context = peekPendingSelectionContext(expectedToken);
103
+ if (!context)
104
+ return null;
105
+ pendingSelectionContext = null;
106
+ return context;
107
+ }
108
+ function commitSelection(entity, syncExternalSelection = true, selectionOptions) {
109
+ const additive = !!selectionOptions?.additive;
110
+ const toggle = selectionOptions?.toggle ?? additive;
111
+ const nextEntity = entity ?? null;
112
+ if (!additive || !nextEntity) {
113
+ selectedEntity = nextEntity;
114
+ selectedEntities = nextEntity ? [nextEntity] : [];
115
+ }
116
+ else {
117
+ const identity = getNodeIdentity(nextEntity);
118
+ if (!identity) {
119
+ selectedEntity = nextEntity;
120
+ selectedEntities = [nextEntity];
121
+ }
122
+ else {
123
+ const nextParentIdentity = getNodeParentIdentity(nextEntity);
124
+ const currentParentIdentity = selectedEntities.length > 0 ? getNodeParentIdentity(selectedEntities[0]) : null;
125
+ if (selectedEntities.length > 0
126
+ && currentParentIdentity != null
127
+ && nextParentIdentity != null
128
+ && currentParentIdentity !== nextParentIdentity) {
129
+ return;
130
+ }
131
+ const index = selectedEntities.findIndex(item => getNodeIdentity(item) === identity);
132
+ if (index >= 0 && toggle) {
133
+ const nextList = selectedEntities.slice();
134
+ nextList.splice(index, 1);
135
+ selectedEntities = nextList;
136
+ if (selectedEntities.length === 0) {
137
+ selectedEntity = null;
138
+ }
139
+ else if (getNodeIdentity(selectedEntity) === identity) {
140
+ selectedEntity = selectedEntities[selectedEntities.length - 1] ?? null;
141
+ }
142
+ }
143
+ else if (index < 0) {
144
+ selectedEntities = [...selectedEntities, nextEntity];
145
+ selectedEntity = nextEntity;
146
+ }
147
+ else {
148
+ selectedEntity = nextEntity;
149
+ }
150
+ }
151
+ }
152
+ options.onSelectionCommitted(selectedEntity ?? null);
153
+ syncSelectionHighlight();
154
+ if (!syncExternalSelection || !externalSelectionService)
155
+ return;
156
+ if (externalSelectionService.selectedEntity === (selectedEntity ?? null))
157
+ return;
158
+ if (normalizingSelection)
159
+ return;
160
+ normalizingSelection = true;
161
+ try {
162
+ externalSelectionService.selectedEntity = selectedEntity ?? null;
163
+ }
164
+ finally {
165
+ queueMicrotask(() => {
166
+ normalizingSelection = false;
167
+ });
168
+ }
169
+ }
170
+ function isWithinCanvasViewport(event, canvas) {
171
+ if (event.target === canvas)
172
+ return true;
173
+ const rect = canvas.getBoundingClientRect();
174
+ return event.clientX >= rect.left
175
+ && event.clientX <= rect.right
176
+ && event.clientY >= rect.top
177
+ && event.clientY <= rect.bottom;
178
+ }
179
+ return {
180
+ createV2SelectionBridge(v2) {
181
+ const SelectionServiceIdentity = v2?.SelectionServiceIdentity;
182
+ if (!SelectionServiceIdentity)
183
+ return null;
184
+ return {
185
+ friendlyName: 'Editor Selection Sync',
186
+ consumes: [SelectionServiceIdentity],
187
+ factory: (selectionService) => {
188
+ externalSelectionService = selectionService;
189
+ const selObs = selectionService.onSelectedEntityChanged?.add(() => {
190
+ if (normalizingSelection)
191
+ return;
192
+ if (options.getMonitor?.()?.isDragging)
193
+ return;
194
+ let entity = selectionService.selectedEntity;
195
+ const consumedContext = consumePendingSelectionContext();
196
+ if (!consumedContext) {
197
+ commitSelection(entity ?? null, false);
198
+ return;
199
+ }
200
+ const normalized = options.normalizeSelection({
201
+ source: consumedContext.kind,
202
+ rawEntity: entity,
203
+ });
204
+ if (consumedContext.kind === 'viewport' && !normalized.hasPersistentBinding)
205
+ return;
206
+ if (!normalized.normalizedEntity)
207
+ return;
208
+ entity = normalized.normalizedEntity;
209
+ commitSelection(entity ?? null, consumedContext.kind === 'viewport', {
210
+ additive: consumedContext.additive,
211
+ toggle: consumedContext.additive,
212
+ });
213
+ });
214
+ return {
215
+ dispose: () => {
216
+ if (selObs)
217
+ selectionService.onSelectedEntityChanged?.remove(selObs);
218
+ if (externalSelectionService === selectionService)
219
+ externalSelectionService = null;
220
+ if (selectedEntity === selectionService.selectedEntity)
221
+ selectedEntity = null;
222
+ clearSelectionHighlight();
223
+ selectedEntities = [];
224
+ },
225
+ };
226
+ },
227
+ };
228
+ },
229
+ bindSelectionSourceTracking() {
230
+ this.unbindSelectionSourceTracking?.();
231
+ const onPointerDown = (event) => {
232
+ const rawTarget = event.target;
233
+ const target = isHostHTMLElement(rawTarget, host.window) ? rawTarget : null;
234
+ const scene = options.getScene();
235
+ const canvas = scene?.getEngine?.()?.getRenderingCanvas?.() ?? null;
236
+ if (!target)
237
+ return;
238
+ if (canvas && isWithinCanvasViewport(event, canvas)) {
239
+ const withinExternalRoot = options.externalSelectionRootSelector
240
+ ? !!target.closest?.(options.externalSelectionRootSelector)
241
+ : false;
242
+ const isExternalInteractive = options.externalSelectionInteractiveSelector
243
+ ? !!target.closest?.(options.externalSelectionInteractiveSelector)
244
+ : false;
245
+ if (!withinExternalRoot || !isExternalInteractive) {
246
+ if (event.button !== 0 || !scene || !canvas)
247
+ return;
248
+ if (!(options.shouldHandleViewportSelection?.() ?? true))
249
+ return;
250
+ setPendingSelectionContext({
251
+ kind: 'viewport',
252
+ token: createSelectionToken(),
253
+ createdAt: Date.now(),
254
+ additive: !!event.shiftKey,
255
+ });
256
+ return;
257
+ }
258
+ }
259
+ if (options.externalSelectionRootSelector && target.closest?.(options.externalSelectionRootSelector)) {
260
+ const isExternalInteractive = options.externalSelectionInteractiveSelector
261
+ ? !!target.closest?.(options.externalSelectionInteractiveSelector)
262
+ : true;
263
+ if (isExternalInteractive) {
264
+ setPendingSelectionContext({
265
+ kind: 'tree',
266
+ token: createSelectionToken(),
267
+ createdAt: Date.now(),
268
+ additive: !!event.shiftKey,
269
+ });
270
+ return;
271
+ }
272
+ clearPendingSelectionContext();
273
+ }
274
+ };
275
+ host.document.addEventListener('pointerdown', onPointerDown, true);
276
+ selectionTrackingCtx = { onPointerDown };
277
+ },
278
+ unbindSelectionSourceTracking() {
279
+ if (!selectionTrackingCtx)
280
+ return;
281
+ host.document.removeEventListener('pointerdown', selectionTrackingCtx.onPointerDown, true);
282
+ selectionTrackingCtx = null;
283
+ pendingSelectionContext = null;
284
+ },
285
+ enablePicking() {
286
+ options.setExternalPickingState?.(true);
287
+ },
288
+ reset() {
289
+ this.unbindSelectionSourceTracking?.();
290
+ normalizingSelection = false;
291
+ externalSelectionService = null;
292
+ selectedEntity = null;
293
+ clearSelectionHighlight();
294
+ selectedEntities = [];
295
+ pendingSelectionContext = null;
296
+ },
297
+ getSelectedEntity() {
298
+ return selectedEntity;
299
+ },
300
+ getSelectedEntities() {
301
+ return [...selectedEntities];
302
+ },
303
+ selectEntity(entity, syncExternalSelection = true, selectionOptions) {
304
+ commitSelection(entity ?? null, syncExternalSelection, selectionOptions);
305
+ },
306
+ };
307
+ }
308
+ //# sourceMappingURL=selection-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection-controller.js","sourceRoot":"","sources":["../src/selection-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAoB,MAAM,2BAA2B,CAAC;AAyChF,MAAM,gCAAgC,GAAG,IAAI,CAAC;AAE9C,SAAS,eAAe,CAAC,IAAS;IAChC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACnD,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IACvG,IAAI,OAAO,IAAI,CAAC,EAAE,KAAK,QAAQ,IAAI,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,OAAO,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;IACjF,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,qBAAqB,CAAC,IAAS;IACtC,MAA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/editor-protocol';
2
+ import type { BabylonRuntimeGlobal, RuntimeScene } from './types';
3
+ export interface EditorToolControllerOptions {
4
+ getScene: () => RuntimeScene | null;
5
+ getSelectedEntity: () => unknown;
6
+ enablePicking: () => void;
7
+ babylon?: BabylonRuntimeGlobal | null;
8
+ syncExternalToolState?: (tool: EditorTool) => boolean;
9
+ }
10
+ export interface EditorToolController {
11
+ currentTool(): EditorTool;
12
+ syncSelection(entity?: unknown): boolean;
13
+ setTool(nextTool: EditorTool): boolean;
14
+ dispose(): void;
15
+ }
16
+ export declare function createEditorToolController(options: EditorToolControllerOptions): EditorToolController;
17
+ //# sourceMappingURL=tool-controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-controller.d.ts","sourceRoot":"","sources":["../src/tool-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGlE,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC;IACpC,iBAAiB,EAAE,MAAM,OAAO,CAAC;IACjC,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,OAAO,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACtC,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC;CACvD;AACD,MAAM,WAAW,oBAAoB;IACnC,WAAW,IAAI,UAAU,CAAC;IAC1B,aAAa,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IACzC,OAAO,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC;IACvC,OAAO,IAAI,IAAI,CAAC;CACjB;AAMD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,2BAA2B,GAAG,oBAAoB,CAiErG"}
@@ -0,0 +1,83 @@
1
+ import { getBabylonRuntime } from './runtime-globals';
2
+ function entityHasTransform(entity) {
3
+ return !!entity?.position && !!entity?.scaling && (!!entity?.rotation || !!entity?.rotationQuaternion);
4
+ }
5
+ export function createEditorToolController(options) {
6
+ let tool = 'pick';
7
+ let gizmoManager = null;
8
+ function ensureGizmoManager() {
9
+ if (gizmoManager)
10
+ return gizmoManager;
11
+ const scene = options.getScene();
12
+ if (!scene)
13
+ return null;
14
+ const GizmoManager = getBabylonRuntime(options.babylon)?.GizmoManager;
15
+ if (!GizmoManager)
16
+ return null;
17
+ const manager = new GizmoManager(scene);
18
+ manager.usePointerToAttachGizmos = false;
19
+ manager.clearGizmoOnEmptyPointerEvent = false;
20
+ manager.boundingBoxGizmoEnabled = false;
21
+ gizmoManager = manager;
22
+ return manager;
23
+ }
24
+ return {
25
+ currentTool() {
26
+ return tool;
27
+ },
28
+ syncSelection(entity) {
29
+ const nextEntity = entity ?? options.getSelectedEntity() ?? null;
30
+ const handledByExternalTool = options.syncExternalToolState?.(tool) ?? false;
31
+ const manager = ensureGizmoManager();
32
+ if (!manager)
33
+ return handledByExternalTool;
34
+ if (handledByExternalTool) {
35
+ manager.positionGizmoEnabled = false;
36
+ manager.rotationGizmoEnabled = false;
37
+ manager.scaleGizmoEnabled = false;
38
+ try {
39
+ manager.attachToNode?.(null);
40
+ }
41
+ catch { }
42
+ return true;
43
+ }
44
+ manager.positionGizmoEnabled = tool === 'move';
45
+ manager.rotationGizmoEnabled = tool === 'rotate';
46
+ manager.scaleGizmoEnabled = tool === 'scale';
47
+ if (tool === 'pick') {
48
+ try {
49
+ manager.attachToNode?.(null);
50
+ }
51
+ catch { }
52
+ return true;
53
+ }
54
+ const target = entityHasTransform(nextEntity) ? nextEntity : null;
55
+ try {
56
+ manager.attachToNode?.(target);
57
+ }
58
+ catch { }
59
+ return true;
60
+ },
61
+ setTool(nextTool) {
62
+ tool = nextTool;
63
+ if (nextTool === 'pick')
64
+ options.enablePicking();
65
+ return this.syncSelection();
66
+ },
67
+ dispose() {
68
+ const manager = gizmoManager;
69
+ if (!manager)
70
+ return;
71
+ try {
72
+ manager.attachToNode?.(null);
73
+ }
74
+ catch { }
75
+ try {
76
+ manager.dispose?.();
77
+ }
78
+ catch { }
79
+ gizmoManager = null;
80
+ },
81
+ };
82
+ }
83
+ //# sourceMappingURL=tool-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-controller.js","sourceRoot":"","sources":["../src/tool-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAgBtD,SAAS,kBAAkB,CAAC,MAAW;IACrC,OAAO,CAAC,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AACzG,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAoC;IAC7E,IAAI,IAAI,GAAe,MAAM,CAAC;IAC9B,IAAI,YAAY,GAAQ,IAAI,CAAC;IAE7B,SAAS,kBAAkB;QACzB,IAAI,YAAY;YAAE,OAAO,YAAY,CAAC;QACtC,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QACjC,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QACxB,MAAM,YAAY,GAAG,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC;QACtE,IAAI,CAAC,YAAY;YAAE,OAAO,IAAI,CAAC;QAC/B,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;QACxC,OAAO,CAAC,wBAAwB,GAAG,KAAK,CAAC;QACzC,OAAO,CAAC,6BAA6B,GAAG,KAAK,CAAC;QAC9C,OAAO,CAAC,uBAAuB,GAAG,KAAK,CAAC;QACxC,YAAY,GAAG,OAAO,CAAC;QACvB,OAAO,OAAO,CAAC;IACjB,CAAC;I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C;YAAC,MAAM,CAAC,CAAA,CAAC;YAChD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,CAAC,QAAoB;YAC1B,IAAI,GAAG,QAAQ,CAAC;YAChB,IAAI,QAAQ,KAAK,MAAM;gBAAE,OAAO,CAAC,aAAa,EAAE,CAAC;YACjD,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC;QAC9B,CAAC;QAED,OAAO;YACL,MAAM,OAAO,GAAG,YAAY,CAAC;YAC7B,IAAI,CAAC,OAAO;gBAAE,OAAO;YACrB,IAAI,CAAC;gBAAC,OAAO,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;YAC9C,IAAI,CAAC;gBAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;YACrC,YAAY,GAAG,IAAI,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { EditorSelectionState, EditorTransformBatchCommit, EditorTransformConstraint, EditorTransformGizmoCommit, EditorTransformGizmoState, EditorTransformPivot, EditorTransformSnapshot, EditorTransformSpace, EditorTransformTool } from '@fps-games/editor-core';
2
+ import type { BabylonRuntimeGlobal, RuntimeScene } from './types';
3
+ import type { BabylonEditorProjection } from './projection';
4
+ export interface BabylonTransformGizmoDragEvent {
5
+ nodeId: string | null;
6
+ targetIds: string[];
7
+ activeId: string | null;
8
+ tool: Exclude<EditorTransformTool, 'select'>;
9
+ space: EditorTransformSpace;
10
+ constraint: EditorTransformConstraint;
11
+ pivot: EditorTransformPivot;
12
+ before: EditorTransformSnapshot | null;
13
+ beforeTransforms: Record<string, EditorTransformSnapshot>;
14
+ }
15
+ export type BabylonTransformGizmoCommit = EditorTransformGizmoCommit | EditorTransformBatchCommit;
16
+ export interface BabylonTransformGizmoControllerOptions {
17
+ babylon: BabylonRuntimeGlobal;
18
+ scene: RuntimeScene;
19
+ projection: BabylonEditorProjection;
20
+ initialTool?: EditorTransformTool;
21
+ initialSpace?: EditorTransformSpace;
22
+ onDragStart?: (event: BabylonTransformGizmoDragEvent) => void;
23
+ onDragUpdate?: (event: BabylonTransformGizmoDragEvent & {
24
+ current: EditorTransformSnapshot;
25
+ }) => void;
26
+ onDragEnd?: (event: BabylonTransformGizmoCommit) => void;
27
+ onDragCancel?: (event: BabylonTransformGizmoDragEvent) => void;
28
+ logger?: Pick<Console, 'warn'>;
29
+ }
30
+ export interface BabylonTransformGizmoController {
31
+ getState(): EditorTransformGizmoState;
32
+ setTool(tool: EditorTransformTool): void;
33
+ setSpace(space: EditorTransformSpace): void;
34
+ setConstraint(constraint: EditorTransformConstraint): void;
35
+ setSelectedNode(nodeId: string | null): void;
36
+ setSelection(selection: EditorSelectionState): void;
37
+ refreshSelection(): void;
38
+ isGizmoDragCandidate(event: PointerEvent): boolean;
39
+ isViewPlaneMoveCandidate(event: PointerEvent): boolean;
40
+ beginViewPlaneMove(event: PointerEvent): boolean;
41
+ updateViewPlaneMove(event: PointerEvent): boolean;
42
+ endViewPlaneMove(event: PointerEvent): boolean;
43
+ cancelDrag(): void;
44
+ dispose(): void;
45
+ }
46
+ export declare function createBabylonTransformGizmoController(options: BabylonTransformGizmoControllerOptions): BabylonTransformGizmoController;
47
+ //# sourceMappingURL=transform-gizmo-controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-gizmo-controller.d.ts","sourceRoot":"","sources":["../src/transform-gizmo-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EAEpB,mBAAmB,EAEpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAA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