@tomorrowevening/hermes 0.1.35 → 0.1.37

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.
package/README.md CHANGED
@@ -10,87 +10,80 @@ This example uses [React](https://react.dev/), [ThreeJS](https://threejs.org/),
10
10
 
11
11
  ### Create an `Application`
12
12
 
13
- An application isn't required, however it's nice to maintain multiple remotes. Alternatively, Remotes can be created independently.
14
-
15
- The `ThreeEditor` is used as a multi-view editor for [ThreeJS](https://threejs.org/), and should be limited to only the Editor app.
16
-
17
- ```
18
- const IS_DEV = true;
19
- const IS_EDITOR = IS_DEV && document.location.hash.search('editor') > -1;
20
-
21
- const theatre = new RemoteTheatre(IS_DEV, IS_EDITOR);
22
- const three = new RemoteThree('Hermes Example', IS_DEV, IS_EDITOR);
13
+ Instantiate your `Application` (or a custom subclass) outside the component tree, then wrap your app with `HermesApp`. It handles `detectSettings`, the loading gate, Theatre Studio initialisation, and automatically switches between editor and app rendering based on `IS_EDITOR`.
14
+
15
+ ```tsx
16
+ import studio from '@tomorrowevening/theatre-studio';
17
+ import HermesApp from '@tomorrowevening/hermes/editor/HermesApp';
18
+ import ExampleApplication from './three/ExampleApplication';
19
+ import { loadAssets } from './three/loader';
20
+ import Scene1 from './three/scenes/Scene1';
21
+ import Scene2 from './three/scenes/Scene2';
22
+ import MyCanvas from './components/MyCanvas';
23
+ import { IS_DEV, IS_EDITOR } from './constants';
24
+
25
+ // Register scene classes so MultiView can instantiate them in the editor
26
+ const scenes = new Map<string, any>([
27
+ ['Scene1', Scene1],
28
+ ['Scene2', Scene2],
29
+ ['RTTScene', RTTScene],
30
+ ]);
31
+
32
+ // Create once outside the component — avoids re-instantiation on re-render
33
+ const app = new ExampleApplication('My Project', IS_DEV, IS_EDITOR);
34
+ if (IS_DEV && IS_EDITOR && studio) {
35
+ studio.initialize();
36
+ app.theatre.studio = studio;
37
+ app.theatre.handleEditorApp();
38
+ }
23
39
 
24
40
  export default function AppWrapper() {
25
- const [app, setApp] = useState<Application | null>(null);
26
-
27
- useEffect(() => {
28
- const instance = new Application();
29
- instance.detectSettings(IS_DEV, IS_EDITOR).then(() => {
30
- // TheatreJS
31
- instance.addComponent('theatre', theatre);
32
-
33
- // ThreeJS
34
- instance.addComponent('three', three);
35
-
36
- // Ready
37
- setApp(instance);
38
- });
39
- }, []);
40
-
41
- // MultiView requires you identify each scene so they can be instantiated by the editor
42
- const scenes: Map<string, any> = new Map();
43
- scenes.set('Scene1', Scene1);
44
- scenes.set('Scene2', Scene2);
45
- scenes.set('RTTScene', RTTScene);
46
-
47
41
  return (
48
- <>
49
- {app !== null && (
50
- <>
51
- {IS_DEV && (
52
- <>
53
- {IS_EDITOR && (
54
- <ThreeEditor
55
- three={three}
56
- scenes={scenes}
57
- onSceneUpdate={(scene: any) => {
58
- scene.update();
59
- }}
60
- />
61
- )}
62
- </>
63
- )}
64
- </>
65
- )}
66
- </>
42
+ <HermesApp
43
+ app={app}
44
+ scenes={scenes}
45
+ onSceneAdd={(scene) => {
46
+ scene.setup(app);
47
+ scene.init();
48
+ }}
49
+ onSceneUpdate={(scene) => scene.update()}
50
+ onLoad={loadAssets}
51
+ >
52
+ {(app) => <MyCanvas app={app} />}
53
+ </HermesApp>
67
54
  );
68
55
  }
69
56
  ```
70
57
 
71
- ### Scene setup
58
+ #### `HermesApp` props
72
59
 
73
- After all object's have been added to your scene, run `hierarchyUUID(yourScene)` to update the UUIDs of every object. This helps communicate back and forth between the app and your editor.
60
+ | Prop | Type | Description |
61
+ | --- | --- | --- |
62
+ | `app` | `Application` | Application instance with RemoteTheatre + RemoteThree added as components |
63
+ | `scenes` | `Map<string, any>` | Scene name → scene class map, used by the editor's MultiView |
64
+ | `onSceneAdd` | `(scene) => void` | Called when MultiView instantiates a scene (setup + init) |
65
+ | `onSceneUpdate` | `(scene) => void` | Called every frame for the active scene in the editor |
66
+ | `onSceneResize` | `(scene, w, h) => void` | Called when MultiView resizes a scene |
67
+ | `onLoad` | `(app) => Promise<void>` | Asset loading function — `HermesApp` waits for this before rendering children |
68
+ | `renderLoading` | `ReactNode` | Shown while `detectSettings` or `onLoad` is pending |
69
+ | `children` | `(app) => ReactNode` | App content rendered after loading completes (not shown in editor mode) |
74
70
 
75
- ### Custom remote commands
71
+ ### Scene setup
76
72
 
77
- This component is added only in debug-mode to add extra support for remote-components.
73
+ After all object's have been added to your scene, run `hierarchyUUID(yourScene)` to update the UUIDs of every object. This helps communicate back and forth between the app and your editor.
78
74
 
79
- In this example it's added to add custom Remote Component support for:
75
+ ### Theatre Studio integration
80
76
 
81
- - [TheatreJS](https://theatrejs.com/) - Communicates with the `studio` instance
77
+ Theatre Studio is initialised before `HermesApp` is mounted. Wire it up on the `app` instance so `HermesApp` can hand it off to the editor automatically:
82
78
 
83
- ```
84
- type RemoteProps = {
85
- three: RemoteThree
86
- theatre: RemoteTheatre
87
- }
79
+ ```tsx
80
+ import studio from '@tomorrowevening/theatre-studio';
88
81
 
89
- export default function RemoteSetup(props: RemoteProps) {
90
- // Remote Theatre setup
91
- props.theatre.studio = studio;
92
- props.theatre.handleEditorApp();
93
- return null;
82
+ const app = new ExampleApplication('My Project', IS_DEV, IS_EDITOR);
83
+ if (IS_DEV && IS_EDITOR && studio) {
84
+ studio.initialize();
85
+ app.theatre.studio = studio;
86
+ app.theatre.handleEditorApp();
94
87
  }
95
88
  ```
96
89