@tomorrowevening/hermes 0.1.38 → 0.1.40

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 (66) hide show
  1. package/dist/{ThreeEditor-BjAFHK3t.js → ThreeEditor-CB5dBR7Q.js} +11 -11
  2. package/dist/core/Application.js +77 -0
  3. package/dist/core/remote/BaseRemote.js +33 -0
  4. package/dist/core/remote/RemoteTheatre.js +253 -0
  5. package/dist/core/remote/RemoteThree.js +442 -0
  6. package/dist/core/types.js +7 -0
  7. package/dist/editor/Editor.js +12 -0
  8. package/dist/editor/HermesApp.js +24 -0
  9. package/dist/editor/ThreeEditor.js +22 -0
  10. package/dist/editor/components/Draggable.js +40 -0
  11. package/dist/editor/components/DraggableItem.js +25 -0
  12. package/dist/editor/components/Dropdown.js +32 -0
  13. package/dist/editor/components/DropdownItem.js +50 -0
  14. package/dist/editor/components/NavButton.js +7 -0
  15. package/dist/editor/components/content.js +4 -0
  16. package/dist/editor/components/icons/CloseIcon.js +9 -0
  17. package/dist/editor/components/icons/DragIcon.js +12 -0
  18. package/dist/editor/multiView/CameraWindow.js +64 -0
  19. package/dist/editor/multiView/DepthNodeMaterial.js +12 -0
  20. package/dist/editor/multiView/InfiniteGridHelper.js +31 -0
  21. package/dist/editor/multiView/InfiniteGridHelperGPU.js +31 -0
  22. package/dist/editor/multiView/InfiniteGridMaterial.js +137 -0
  23. package/dist/editor/multiView/InfiniteGridNodeMaterial.js +63 -0
  24. package/dist/editor/multiView/MultiView.js +890 -0
  25. package/dist/editor/multiView/Toggle.js +25 -0
  26. package/dist/editor/multiView/UVMaterial.js +60 -0
  27. package/dist/editor/multiView/UVNodeMaterial.js +10 -0
  28. package/dist/editor/sidePanel/Accordion.js +56 -0
  29. package/dist/editor/sidePanel/ChildObject.js +78 -0
  30. package/dist/editor/sidePanel/ContainerObject.js +11 -0
  31. package/dist/editor/sidePanel/DebugData.js +133 -0
  32. package/dist/editor/sidePanel/SidePanel.js +91 -0
  33. package/dist/editor/sidePanel/inspector/InspectGrid3.js +82 -0
  34. package/dist/editor/sidePanel/inspector/InspectGrid4.js +58 -0
  35. package/dist/editor/sidePanel/inspector/InspectImage.js +100 -0
  36. package/dist/editor/sidePanel/inspector/InspectNumber.js +76 -0
  37. package/dist/editor/sidePanel/inspector/InspectVector2.js +154 -0
  38. package/dist/editor/sidePanel/inspector/Inspector.js +95 -0
  39. package/dist/editor/sidePanel/inspector/InspectorField.js +128 -0
  40. package/dist/editor/sidePanel/inspector/InspectorGroup.js +110 -0
  41. package/dist/editor/sidePanel/inspector/utils/DragNumber.js +27 -0
  42. package/dist/editor/sidePanel/inspector/utils/InspectAnimation.js +99 -0
  43. package/dist/editor/sidePanel/inspector/utils/InspectCamera.js +91 -0
  44. package/dist/editor/sidePanel/inspector/utils/InspectLight.js +85 -0
  45. package/dist/editor/sidePanel/inspector/utils/InspectMaterial.js +861 -0
  46. package/dist/editor/sidePanel/inspector/utils/InspectTransform.js +93 -0
  47. package/dist/editor/sidePanel/utils.js +259 -0
  48. package/dist/editor/tools/Transform.js +77 -0
  49. package/dist/editor/tools/splineEditor/Spline.js +348 -0
  50. package/dist/editor/tools/splineEditor/index.js +193 -0
  51. package/dist/editor/utils.js +27 -0
  52. package/dist/hermes.cjs.js +8 -30
  53. package/dist/{index-dfUv_VcA.js → index-DepTXu6T.js} +454 -454
  54. package/dist/index.html +1 -1
  55. package/dist/index.js +125 -0
  56. package/dist/utils/ImageSequenceCapturer.js +148 -0
  57. package/dist/utils/detectSettings.js +46 -0
  58. package/dist/utils/math.js +68 -0
  59. package/dist/utils/post.js +206 -0
  60. package/dist/utils/theatre.js +316 -0
  61. package/dist/utils/three.js +199 -0
  62. package/dist/webworkers/EventHandling.js +115 -0
  63. package/dist/webworkers/ProxyManager.js +76 -0
  64. package/package.json +13 -7
  65. package/dist/.vite/manifest.json +0 -12
  66. package/dist/hermes.es.js +0 -8266
@@ -0,0 +1,77 @@
1
+ import { detectSettings as s } from "../utils/detectSettings.js";
2
+ class n {
3
+ assets = {
4
+ audio: /* @__PURE__ */ new Map(),
5
+ image: /* @__PURE__ */ new Map(),
6
+ json: /* @__PURE__ */ new Map(),
7
+ model: /* @__PURE__ */ new Map(),
8
+ video: /* @__PURE__ */ new Map()
9
+ };
10
+ components = /* @__PURE__ */ new Map();
11
+ settings = {
12
+ dpr: 1,
13
+ fps: 30,
14
+ width: 0,
15
+ height: 0,
16
+ mobile: !1,
17
+ supportOffScreenCanvas: !1,
18
+ supportWebGPU: !1,
19
+ quality: "Low",
20
+ dev: !1,
21
+ editor: !1
22
+ };
23
+ onUpdateCallback;
24
+ // Protected
25
+ playing = !1;
26
+ rafID = -1;
27
+ constructor(t, e = !1) {
28
+ this.settings.dev = t, this.settings.editor = e;
29
+ }
30
+ dispose() {
31
+ this.pause(), this.components.forEach((t) => t.dispose()), this.components.clear();
32
+ }
33
+ detectSettings() {
34
+ return new Promise((t) => {
35
+ s(this.settings.dev, this.settings.editor).then((e) => {
36
+ this.settings = e, t();
37
+ });
38
+ });
39
+ }
40
+ // Playback
41
+ update() {
42
+ }
43
+ draw() {
44
+ }
45
+ play = () => {
46
+ this.playing || (this.playing = !0, this.onUpdate());
47
+ };
48
+ pause = () => {
49
+ this.playing && (this.playing = !1, cancelAnimationFrame(this.rafID), this.rafID = -1);
50
+ };
51
+ onUpdate = () => {
52
+ this.update(), this.isApp && this.draw(), this.onUpdateCallback && this.onUpdateCallback(), this.rafID = requestAnimationFrame(this.onUpdate);
53
+ };
54
+ // Remote Components
55
+ addComponent(t, e) {
56
+ this.components.set(t, e);
57
+ }
58
+ // Getters
59
+ get debugEnabled() {
60
+ return this.settings.dev;
61
+ }
62
+ get isApp() {
63
+ return !this.editor;
64
+ }
65
+ set isApp(t) {
66
+ this.editor = !t;
67
+ }
68
+ get editor() {
69
+ return this.settings.editor;
70
+ }
71
+ set editor(t) {
72
+ this.settings.editor = t;
73
+ }
74
+ }
75
+ export {
76
+ n as default
77
+ };
@@ -0,0 +1,33 @@
1
+ class n {
2
+ name;
3
+ debug;
4
+ editor;
5
+ broadcastChannel;
6
+ onMessageHandler;
7
+ constructor(e, s = !1, a = !1) {
8
+ this.name = e, this.debug = s, this.editor = a, s && (this.broadcastChannel = new BroadcastChannel(e), this.onMessageHandler = this.messageHandler.bind(this), this.broadcastChannel.addEventListener("message", this.onMessageHandler));
9
+ }
10
+ dispose() {
11
+ this.broadcastChannel?.removeEventListener("message", this.onMessageHandler), this.broadcastChannel?.close();
12
+ }
13
+ // Broadcast
14
+ send(e) {
15
+ if (this.editor && e.target === "app" || !this.editor && e.target === "editor")
16
+ try {
17
+ this.broadcastChannel?.postMessage(e);
18
+ } catch (a) {
19
+ console.log("Hermes - Error sending message:"), console.log(a), console.log(e);
20
+ }
21
+ }
22
+ messageHandler(e) {
23
+ const s = e.data;
24
+ s.target === "app" ? this.handleApp(s) : this.handleEditor(s);
25
+ }
26
+ handleApp(e) {
27
+ }
28
+ handleEditor(e) {
29
+ }
30
+ }
31
+ export {
32
+ n as default
33
+ };
@@ -0,0 +1,253 @@
1
+ import { getProject as _ } from "@tomorrowevening/theatre-core";
2
+ import $ from "./BaseRemote.js";
3
+ import { noop as g } from "../types.js";
4
+ import { isColor as w } from "../../editor/utils.js";
5
+ function P(n, e, t, i, h) {
6
+ const s = 1 - n;
7
+ return s * s * s * e + 3 * s * s * n * t + 3 * s * n * n * i + n * n * n * h;
8
+ }
9
+ function q(n, e, t) {
10
+ if (n.type !== "bezier" || n.handles.length !== 4)
11
+ throw new Error("Invalid keyframe data for Bézier interpolation.");
12
+ const [i, h] = n.handles, s = (t - n.position) / (e.position - n.position);
13
+ return P(
14
+ s,
15
+ n.value,
16
+ n.value + i,
17
+ e.value + h,
18
+ e.value
19
+ );
20
+ }
21
+ class E extends $ {
22
+ project;
23
+ sheets = /* @__PURE__ */ new Map();
24
+ sheetObjects = /* @__PURE__ */ new Map();
25
+ sheetObjectCBs = /* @__PURE__ */ new Map();
26
+ sheetObjectUnsubscribe = /* @__PURE__ */ new Map();
27
+ activeSheet;
28
+ studio = void 0;
29
+ constructor(e = !1, t = !1) {
30
+ super("RemoteTheatre", e, t);
31
+ }
32
+ dispose() {
33
+ this.project = void 0, this.sheets = /* @__PURE__ */ new Map(), this.sheetObjects = /* @__PURE__ */ new Map(), this.sheetObjectCBs = /* @__PURE__ */ new Map(), this.sheetObjectUnsubscribe = /* @__PURE__ */ new Map();
34
+ }
35
+ loadProject(e, t) {
36
+ return this.project = _(e, { state: t }), new Promise((i, h) => {
37
+ this.project?.ready.then(() => {
38
+ if (t) {
39
+ const s = t.sheetsById;
40
+ for (const a in s) this.sheet(a);
41
+ }
42
+ i();
43
+ }).catch(() => h());
44
+ });
45
+ }
46
+ getSheetInstance(e, t) {
47
+ return t !== void 0 ? `${e}-${t}` : e;
48
+ }
49
+ sheet(e, t) {
50
+ if (this.project === void 0) {
51
+ console.error("Theatre Project hasn't been created yet.");
52
+ return;
53
+ }
54
+ const i = this.getSheetInstance(e, t);
55
+ let h = this.sheets.get(i);
56
+ return h !== void 0 || (h = this.project?.sheet(e, t), this.sheets.set(i, h)), h;
57
+ }
58
+ playSheet(e, t, i) {
59
+ return new Promise((h) => {
60
+ this.sheet(e, i)?.sequence.play(t).then((s) => h(s)), this.send({
61
+ event: "playSheet",
62
+ target: "editor",
63
+ data: {
64
+ sheet: e,
65
+ instance: i,
66
+ value: t
67
+ }
68
+ });
69
+ });
70
+ }
71
+ pauseSheet(e, t) {
72
+ this.sheet(e, t)?.sequence.pause(), this.send({
73
+ event: "pauseSheet",
74
+ target: "editor",
75
+ data: {
76
+ sheet: e,
77
+ instance: t
78
+ }
79
+ });
80
+ }
81
+ clearSheetObjects(e) {
82
+ this.sheetObjects.forEach((t, i) => {
83
+ i.search(`${e}_`) > -1 && this.unsubscribe(t);
84
+ });
85
+ }
86
+ sheetObject(e, t, i, h, s) {
87
+ if (this.project === void 0) {
88
+ console.error("Theatre Project hasn't been created yet.");
89
+ return;
90
+ }
91
+ const a = this.sheet(e, s);
92
+ if (a === void 0) return;
93
+ const u = `${this.getSheetInstance(e, s)}_${t}`;
94
+ let b = this.sheetObjects.get(u), j = i;
95
+ b !== void 0 && (j = { ...i, ...b.value }), b = a.object(t, j, { reconfigure: !0 }), this.sheetObjects.set(u, b), this.sheetObjectCBs.set(u, h !== void 0 ? h : g);
96
+ function v(d, p, o) {
97
+ if (typeof o == "object")
98
+ if (w(o))
99
+ d[p] = {
100
+ r: o.r,
101
+ g: o.g,
102
+ b: o.b,
103
+ a: o.a
104
+ };
105
+ else
106
+ for (const r in o) {
107
+ const l = o[r];
108
+ typeof l == "object" && v(o, r, l);
109
+ }
110
+ }
111
+ const c = b.onValuesChange((d) => {
112
+ const p = this.sheetObjectCBs.get(u);
113
+ if (this.editor) {
114
+ for (const o in d) {
115
+ const r = d[o];
116
+ typeof r == "object" && v(d, o, r);
117
+ }
118
+ this.send({
119
+ event: "updateSheetObject",
120
+ target: "app",
121
+ data: {
122
+ sheet: e,
123
+ sheetObject: u,
124
+ values: d
125
+ }
126
+ }), p && p(d);
127
+ } else
128
+ p && p(d);
129
+ });
130
+ return this.sheetObjectUnsubscribe.set(u, c), b;
131
+ }
132
+ getSheetObjectKeyframes(e, t, i) {
133
+ const h = this.sheet(e);
134
+ if (h === void 0) return [];
135
+ const s = `${e}_${t}`, a = this.sheetObjects.get(s);
136
+ return a === void 0 ? [] : h.sequence.__experimental_getKeyframes(a.props[i]);
137
+ }
138
+ getSheetObjectVectors(e, t) {
139
+ const i = this.sheet(e);
140
+ if (i === void 0) return [];
141
+ const h = `${e}_${t}`, s = this.sheetObjects.get(h);
142
+ if (s === void 0) return [];
143
+ const a = [], f = i.sequence.__experimental_getKeyframes(s.props.x), u = i.sequence.__experimental_getKeyframes(s.props.y), b = i.sequence.__experimental_getKeyframes(s.props.z), j = /* @__PURE__ */ new Set();
144
+ return f.forEach((c) => j.add(c.position)), u.forEach((c) => j.add(c.position)), b.forEach((c) => j.add(c.position)), Array.from(j).sort((c, d) => c - d).forEach((c) => {
145
+ const d = (p, o) => {
146
+ const r = p.find((S, y) => S.position <= o && (p[y + 1]?.position || 1 / 0) > o), l = p.find((S) => S.position > o);
147
+ if (!r) return l?.value || 0;
148
+ if (!l || r.position === o) return r.value;
149
+ if (r.type === "bezier")
150
+ return q(r, l, o);
151
+ const O = (o - r.position) / (l.position - r.position);
152
+ return r.value + O * (l.value - r.value);
153
+ };
154
+ a.push({
155
+ position: c,
156
+ x: d(f, c),
157
+ y: d(u, c),
158
+ z: d(b, c)
159
+ });
160
+ }), a;
161
+ }
162
+ update(e) {
163
+ }
164
+ unsubscribe(e) {
165
+ if (this.project === void 0) {
166
+ console.error("Theatre Project hasn't been created yet.");
167
+ return;
168
+ }
169
+ const t = e.address.sheetId, i = e.address.objectKey;
170
+ this.sheets.get(t)?.detachObject(i);
171
+ const s = `${t}_${i}`, a = this.sheetObjectUnsubscribe.get(s);
172
+ a !== void 0 && (this.sheetObjects.delete(s), this.sheetObjectCBs.delete(s), this.sheetObjectUnsubscribe.delete(s), a());
173
+ }
174
+ handleApp(e) {
175
+ let t;
176
+ switch (e.event) {
177
+ case "setSheet":
178
+ t = this.sheets.get(e.data.sheet), t !== void 0 ? this.studio?.setSelection([t]) : console.log(`Hermes - Can't set Sheet: ${e.data.sheet}`, t);
179
+ break;
180
+ case "setSheetObject":
181
+ t = this.sheetObjects.get(`${e.data.sheet}_${e.data.key}`), t !== void 0 ? this.studio?.setSelection([t]) : console.log(`Hermes - Can't set Sheet Object: ${e.data.sheet}, ${e.data.key}: ${e.data.sheet}_${e.data.key}`, t);
182
+ break;
183
+ case "updateSheetObject":
184
+ t = this.sheets.get(e.data.sheet), t !== void 0 && t.sequence.pause(), t = this.sheetObjectCBs.get(e.data.sheetObject), t !== void 0 ? t(e.data.values) : console.log(`Hermes - Can't update Sheet Object: ${e.data.sheetObject}, ${e.data.sheet}`, t);
185
+ break;
186
+ case "updateTimeline":
187
+ t = this.sheets.get(e.data.sheet), t !== void 0 ? t.sequence.position = e.data.position : console.log(`Hermes - Can't update sheet position: ${e.data.sheet}, ${e.data.position}`);
188
+ break;
189
+ }
190
+ }
191
+ handleEditor(e) {
192
+ switch (e.event) {
193
+ case "playSheet":
194
+ this.sheet(e.data.sheet, e.data.instance)?.sequence.play(e.data.value);
195
+ break;
196
+ case "pauseSheet":
197
+ this.sheet(e.data.sheet, e.data.instance)?.sequence.pause();
198
+ break;
199
+ }
200
+ }
201
+ getSheetNames() {
202
+ const e = [];
203
+ return this.sheets.forEach((t, i) => {
204
+ e.push(i);
205
+ }), e;
206
+ }
207
+ handleEditorApp() {
208
+ if (this.editor) {
209
+ this.studio?.ui.restore(), this.studio?.onSelectionChange((h) => {
210
+ h.length < 1 || h.forEach((s) => {
211
+ let a = s.address.sheetId, f = "setSheet", u = {};
212
+ switch (s.type) {
213
+ case "Theatre_Sheet_PublicAPI":
214
+ f = "setSheet", u = {
215
+ sheet: s.address.sheetId
216
+ }, this.activeSheet = this.sheets.get(s.address.sheetId);
217
+ break;
218
+ case "Theatre_SheetObject_PublicAPI":
219
+ f = "setSheetObject", a += `_${s.address.objectKey}`, u = {
220
+ id: a,
221
+ sheet: s.address.sheetId,
222
+ key: s.address.objectKey
223
+ }, this.activeSheet = this.sheets.get(s.address.sheetId);
224
+ break;
225
+ }
226
+ this.send({ event: f, target: "app", data: u });
227
+ });
228
+ });
229
+ let e = -1;
230
+ const t = () => {
231
+ if (this.activeSheet !== void 0 && e !== this.activeSheet.sequence.position) {
232
+ e = this.activeSheet.sequence.position;
233
+ const h = this.activeSheet;
234
+ this.send({
235
+ event: "updateTimeline",
236
+ target: "app",
237
+ data: {
238
+ position: e,
239
+ sheet: h.address.sheetId
240
+ }
241
+ });
242
+ }
243
+ }, i = () => {
244
+ t(), requestAnimationFrame(i);
245
+ };
246
+ t(), i();
247
+ } else
248
+ this.studio?.ui.hide();
249
+ }
250
+ }
251
+ export {
252
+ E as default
253
+ };