@tomorrowevening/hermes 0.0.1 → 0.0.3
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 +7 -0
- package/dist/hermes.js +2530 -718
- package/dist/hermes.umd.cjs +88 -11
- package/dist/images/android-chrome-192x192.png +0 -0
- package/dist/images/android-chrome-512x512.png +0 -0
- package/dist/images/apple-touch-icon.png +0 -0
- package/dist/images/favicon-16x16.png +0 -0
- package/dist/images/favicon-32x32.png +0 -0
- package/dist/images/favicon.ico +0 -0
- package/dist/images/milkyWay/dark-s_nx.jpg +0 -0
- package/dist/images/milkyWay/dark-s_ny.jpg +0 -0
- package/dist/images/milkyWay/dark-s_nz.jpg +0 -0
- package/dist/images/milkyWay/dark-s_px.jpg +0 -0
- package/dist/images/milkyWay/dark-s_py.jpg +0 -0
- package/dist/images/milkyWay/dark-s_pz.jpg +0 -0
- package/dist/images/site.webmanifest +1 -0
- package/dist/images/uv_grid_opengl.jpg +0 -0
- package/dist/index-0a798fe4.js +6862 -0
- package/dist/index-7bad599d.css +1 -0
- package/dist/index.html +18 -0
- package/dist/models/Flair.fbx +0 -0
- package/dist/models/Thriller2.fbx +0 -0
- package/dist/models/Thriller4.fbx +0 -0
- package/dist/style.css +1 -1
- package/package.json +9 -4
- package/src/core/Application.ts +28 -36
- package/src/core/RemoteController.ts +148 -98
- package/src/core/remote/BaseRemote.ts +3 -3
- package/src/core/remote/RemoteComponents.ts +5 -8
- package/src/core/remote/RemoteTheatre.ts +56 -54
- package/src/core/remote/RemoteThree.ts +77 -0
- package/src/core/remote/RemoteTweakpane.ts +71 -78
- package/src/core/types.ts +14 -4
- package/src/editor/Editor.tsx +8 -6
- package/src/editor/components/Draggable.tsx +20 -20
- package/src/editor/components/DraggableItem.tsx +6 -6
- package/src/editor/components/Dropdown.tsx +22 -14
- package/src/editor/components/DropdownItem.tsx +19 -19
- package/src/editor/components/NavButton.tsx +1 -1
- package/src/editor/components/content.ts +2 -0
- package/src/editor/components/icons/CloseIcon.tsx +1 -1
- package/src/editor/components/icons/DragIcon.tsx +1 -1
- package/src/editor/global.ts +9 -4
- package/src/editor/sceneHierarchy/Accordion.tsx +40 -0
- package/src/editor/sceneHierarchy/ChildObject.tsx +17 -17
- package/src/editor/sceneHierarchy/ContainerObject.tsx +7 -8
- package/src/editor/sceneHierarchy/SceneHierarchy.tsx +52 -49
- package/src/editor/sceneHierarchy/ToggleBtn.tsx +26 -0
- package/src/editor/sceneHierarchy/inspector/Inspector.tsx +82 -0
- package/src/editor/sceneHierarchy/inspector/InspectorField.tsx +178 -0
- package/src/editor/sceneHierarchy/inspector/InspectorGroup.tsx +55 -0
- package/src/editor/sceneHierarchy/inspector/MultiView/CameraWindow.tsx +61 -0
- package/src/editor/sceneHierarchy/inspector/MultiView/InfiniteGridHelper.ts +24 -0
- package/src/editor/sceneHierarchy/inspector/MultiView/InfiniteGridMaterial.ts +127 -0
- package/src/editor/sceneHierarchy/inspector/MultiView/MultiView.scss +93 -0
- package/src/editor/sceneHierarchy/inspector/MultiView/MultiView.tsx +450 -0
- package/src/editor/sceneHierarchy/inspector/SceneInspector.tsx +72 -0
- package/src/editor/sceneHierarchy/inspector/inspector.scss +150 -0
- package/src/editor/sceneHierarchy/inspector/utils/InspectCamera.tsx +75 -0
- package/src/editor/sceneHierarchy/inspector/utils/InspectLight.tsx +62 -0
- package/src/editor/sceneHierarchy/inspector/utils/InspectMaterial.tsx +340 -0
- package/src/editor/sceneHierarchy/inspector/utils/InspectTransform.tsx +124 -0
- package/src/editor/sceneHierarchy/types.ts +116 -5
- package/src/editor/sceneHierarchy/utils.ts +207 -11
- package/src/editor/scss/_debug.scss +9 -19
- package/src/editor/scss/_dropdown.scss +1 -0
- package/src/editor/scss/_sceneHierarchy.scss +148 -48
- package/src/editor/scss/index.scss +13 -6
- package/src/editor/utils.ts +42 -5
- package/src/example/CustomEditor.tsx +40 -0
- package/src/example/components/App.tsx +164 -0
- package/src/example/constants.ts +40 -9
- package/src/example/main.tsx +5 -45
- package/src/example/three/CustomMaterial.ts +58 -0
- package/src/example/three/ExampleScene.ts +176 -0
- package/src/example/three/FBXAnimation.ts +39 -0
- package/src/index.ts +22 -0
- package/types/core/Application.d.ts +7 -13
- package/types/core/remote/RemoteComponents.d.ts +0 -2
- package/types/core/remote/RemoteThree.d.ts +12 -0
- package/types/core/remote/RemoteTweakpane.d.ts +3 -3
- package/types/core/types.d.ts +4 -3
- package/types/editor/Editor.d.ts +2 -1
- package/types/editor/components/content.d.ts +2 -0
- package/types/editor/global.d.ts +7 -2
- package/types/editor/sceneHierarchy/Accordion.d.ts +10 -0
- package/types/editor/sceneHierarchy/SceneHierarchy.d.ts +5 -5
- package/types/editor/sceneHierarchy/ToggleBtn.d.ts +7 -0
- package/types/editor/sceneHierarchy/inspector/Inspector.d.ts +3 -0
- package/types/editor/sceneHierarchy/inspector/InspectorField.d.ts +13 -0
- package/types/editor/sceneHierarchy/inspector/InspectorGroup.d.ts +7 -0
- package/types/editor/sceneHierarchy/inspector/MultiView/CameraWindow.d.ts +16 -0
- package/types/editor/sceneHierarchy/inspector/MultiView/InfiniteGridHelper.d.ts +7 -0
- package/types/editor/sceneHierarchy/inspector/MultiView/InfiniteGridMaterial.d.ts +13 -0
- package/types/editor/sceneHierarchy/inspector/MultiView/MultiView.d.ts +11 -0
- package/types/editor/sceneHierarchy/inspector/SceneInspector.d.ts +7 -0
- package/types/editor/sceneHierarchy/inspector/utils/InspectCamera.d.ts +3 -0
- package/types/editor/sceneHierarchy/inspector/utils/InspectLight.d.ts +3 -0
- package/types/editor/sceneHierarchy/inspector/utils/InspectMaterial.d.ts +8 -0
- package/types/editor/sceneHierarchy/inspector/utils/InspectTransform.d.ts +3 -0
- package/types/editor/sceneHierarchy/types.d.ts +98 -7
- package/types/editor/sceneHierarchy/utils.d.ts +7 -1
- package/types/editor/utils.d.ts +3 -0
- package/types/example/CustomEditor.d.ts +1 -0
- package/types/example/constants.d.ts +15 -3
- package/types/example/three/CustomMaterial.d.ts +5 -0
- package/types/example/three/ExampleScene.d.ts +18 -0
- package/types/example/three/FBXAnimation.d.ts +6 -0
- package/types/{library.d.ts → index.d.ts} +5 -0
- package/src/example/App.tsx +0 -88
- package/src/library.ts +0 -16
- package/types/core/remote/RemoteDebug.d.ts +0 -23
- package/types/debug/Editor.d.ts +0 -8
- package/types/debug/components/Draggable.d.ts +0 -2
- package/types/debug/components/DraggableItem.d.ts +0 -2
- package/types/debug/components/Dropdown.d.ts +0 -2
- package/types/debug/components/DropdownItem.d.ts +0 -2
- package/types/debug/components/NavButton.d.ts +0 -5
- package/types/debug/components/icons/CloseIcon.d.ts +0 -2
- package/types/debug/components/icons/DragIcon.d.ts +0 -2
- package/types/debug/components/types.d.ts +0 -31
- package/types/debug/global.d.ts +0 -9
- package/types/debug/sceneHierarchy/ChildObject.d.ts +0 -2
- package/types/debug/sceneHierarchy/ContainerObject.d.ts +0 -2
- package/types/debug/sceneHierarchy/SceneHierarchy.d.ts +0 -13
- package/types/debug/sceneHierarchy/types.d.ts +0 -8
- package/types/debug/sceneHierarchy/utils.d.ts +0 -2
- package/types/debug/utils.d.ts +0 -4
- /package/src/example/{App.css → components/App.css} +0 -0
- /package/types/example/{App.d.ts → components/App.d.ts} +0 -0
@@ -11,17 +11,86 @@ $icon_world: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM
|
|
11
11
|
|
12
12
|
#SceneHierarchy {
|
13
13
|
background-color: #0d0d0d;
|
14
|
-
border
|
15
|
-
|
16
|
-
right: 0;
|
17
|
-
font-family: Roboto Mono, Source Code Pro, Menlo, Courier, monospace;
|
18
|
-
font-size: 10px;
|
14
|
+
border: 1px solid #111;
|
15
|
+
max-height: 100%;
|
19
16
|
min-height: $barHeight;
|
20
|
-
overflow:
|
17
|
+
overflow-y: auto;
|
21
18
|
pointer-events: visible;
|
22
19
|
position: absolute;
|
23
|
-
|
24
|
-
|
20
|
+
right: 0;
|
21
|
+
top: 0;
|
22
|
+
bottom: 0;
|
23
|
+
width: 300px;
|
24
|
+
|
25
|
+
.accordion {
|
26
|
+
border-bottom: 1px dotted #333;
|
27
|
+
background-color: #111;
|
28
|
+
line-height: 0;
|
29
|
+
resize: vertical;
|
30
|
+
overflow-y: auto;
|
31
|
+
|
32
|
+
&.hide {
|
33
|
+
resize: none;
|
34
|
+
overflow-y: hidden;
|
35
|
+
}
|
36
|
+
|
37
|
+
> div {
|
38
|
+
display: grid;
|
39
|
+
grid-template-rows: 0fr;
|
40
|
+
margin-left: 5px;
|
41
|
+
transition: 0.33s grid-template-rows cubic-bezier(0.645, 0.045, 0.355, 1);
|
42
|
+
> div {
|
43
|
+
overflow: hidden;
|
44
|
+
}
|
45
|
+
&.open {
|
46
|
+
grid-template-rows: 1fr;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
.icon {
|
51
|
+
height: $barHeight;
|
52
|
+
width: $barHeight;
|
53
|
+
button {
|
54
|
+
text-indent: -9999px;
|
55
|
+
white-space: nowrap;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
.toggle {
|
60
|
+
background-color: #333;
|
61
|
+
display: inline-block;
|
62
|
+
font-size: 12px;
|
63
|
+
font-weight: bold;
|
64
|
+
margin: 0;
|
65
|
+
padding: 0;
|
66
|
+
position: relative;
|
67
|
+
user-select: none;
|
68
|
+
width: 100%;
|
69
|
+
height: 20px;
|
70
|
+
transition: background-color 0.2s linear;
|
71
|
+
&:hover {
|
72
|
+
background-color: #444;
|
73
|
+
}
|
74
|
+
p {
|
75
|
+
margin: 0;
|
76
|
+
padding: 0;
|
77
|
+
}
|
78
|
+
.label {
|
79
|
+
display: inline;
|
80
|
+
position: absolute;
|
81
|
+
left: 25px;
|
82
|
+
top: 3px;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
input {
|
88
|
+
background-color: #222;
|
89
|
+
border: 1px dotted #333;
|
90
|
+
font-family: Roboto Mono, Source Code Pro, Menlo, Courier, monospace;
|
91
|
+
font-size: 10px;
|
92
|
+
padding: 4px;
|
93
|
+
}
|
25
94
|
|
26
95
|
button {
|
27
96
|
background-color: transparent;
|
@@ -33,52 +102,74 @@ $icon_world: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM
|
|
33
102
|
text-align: left;
|
34
103
|
}
|
35
104
|
|
36
|
-
|
37
|
-
|
38
|
-
|
105
|
+
#options {
|
106
|
+
border-bottom: 1px solid #111;
|
107
|
+
display: flex;
|
108
|
+
margin: 0;
|
109
|
+
padding: 0;
|
110
|
+
list-style-type: none;
|
111
|
+
width: 100%;
|
39
112
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
pointer-events: none;
|
113
|
+
.selected {
|
114
|
+
background-color: #222;
|
115
|
+
button {
|
116
|
+
pointer-events: none;
|
117
|
+
}
|
46
118
|
}
|
47
119
|
|
48
120
|
button {
|
49
|
-
|
50
|
-
right: 5px;
|
51
|
-
top: 50%;
|
52
|
-
width: $barHeight;
|
121
|
+
min-width: $barHeight;
|
53
122
|
height: $barHeight;
|
54
|
-
|
55
|
-
|
56
|
-
.refresh {
|
57
|
-
background-color: transparent;
|
58
|
-
background-image: $icon_refresh;
|
59
|
-
background-size: 20px 20px;
|
60
|
-
opacity: 0.7;
|
61
|
-
transform: translateY(-50%) scale(0.8);
|
62
|
-
|
123
|
+
text-align: center;
|
124
|
+
width: 100%;
|
63
125
|
&:hover {
|
64
|
-
|
126
|
+
background-color: #333;
|
65
127
|
}
|
66
128
|
}
|
67
129
|
|
68
|
-
|
69
|
-
|
70
|
-
|
130
|
+
li {
|
131
|
+
border-right: 1px solid #111;
|
132
|
+
font-size: 12px;
|
133
|
+
line-height: $barHeight;
|
134
|
+
min-height: $barHeight;
|
135
|
+
min-width: $barHeight;
|
136
|
+
text-align: center;
|
137
|
+
width: 100%;
|
138
|
+
&:first-child {
|
139
|
+
border-left: 1px solid #111;
|
140
|
+
}
|
71
141
|
}
|
72
142
|
}
|
73
143
|
|
144
|
+
.status, .refresh {
|
145
|
+
display: inline-block;
|
146
|
+
margin: 0;
|
147
|
+
padding: 0;
|
148
|
+
overflow: hidden;
|
149
|
+
width: $barHeight;
|
150
|
+
height: $barHeight;
|
151
|
+
text-indent: -9999px;
|
152
|
+
white-space: nowrap;
|
153
|
+
}
|
154
|
+
|
74
155
|
.status {
|
75
156
|
background-image: $icon_folder;
|
76
157
|
background-position-x: 2px;
|
77
158
|
background-position-y: 2px;
|
78
159
|
background-size: 32px 16px;
|
79
|
-
|
80
|
-
|
81
|
-
|
160
|
+
&.open {
|
161
|
+
background-position-x: 18px;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
.refresh {
|
166
|
+
background-color: transparent;
|
167
|
+
background-image: $icon_refresh;
|
168
|
+
background-position: 2px 2px;
|
169
|
+
background-repeat: no-repeat;
|
170
|
+
background-size: 16px 16px;
|
171
|
+
position: absolute;
|
172
|
+
right: 5px;
|
82
173
|
}
|
83
174
|
|
84
175
|
.childObject {
|
@@ -117,24 +208,33 @@ $icon_world: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM
|
|
117
208
|
.name {
|
118
209
|
background-color: transparent;
|
119
210
|
max-lines: 1;
|
211
|
+
overflow: hidden;
|
120
212
|
position: absolute;
|
121
213
|
left: 5px;
|
122
|
-
right:
|
214
|
+
right: 30px;
|
123
215
|
top: 50%;
|
124
216
|
transform: translateY(-50%);
|
125
217
|
white-space: nowrap;
|
126
218
|
}
|
127
219
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
220
|
+
> div {
|
221
|
+
display: grid;
|
222
|
+
grid-template-rows: 0fr;
|
223
|
+
transition: 0.33s grid-template-rows cubic-bezier(0.645, 0.045, 0.355, 1);
|
224
|
+
&.open {
|
225
|
+
grid-template-rows: 1fr;
|
226
|
+
}
|
227
|
+
.container {
|
228
|
+
padding-left: 5px;
|
229
|
+
height: auto;
|
230
|
+
overflow-x: hidden;
|
231
|
+
overflow-y: auto;
|
232
|
+
max-height: $maxHeight;
|
233
|
+
|
234
|
+
&.closed {
|
235
|
+
height: 0;
|
236
|
+
overflow: hidden;
|
237
|
+
}
|
138
238
|
}
|
139
239
|
}
|
140
240
|
|
@@ -3,14 +3,14 @@
|
|
3
3
|
@import 'sceneHierarchy';
|
4
4
|
|
5
5
|
.editor {
|
6
|
-
font-family:
|
6
|
+
font-family: Roboto Mono, Source Code Pro, Menlo, Courier, monospace;
|
7
|
+
font-size: 10px;
|
7
8
|
left: 0;
|
8
9
|
pointer-events: none;
|
9
10
|
position: absolute;
|
10
11
|
top: 0;
|
11
12
|
width: 100%;
|
12
13
|
height: 100%;
|
13
|
-
z-index: 101;
|
14
14
|
|
15
15
|
button {
|
16
16
|
background: none;
|
@@ -22,18 +22,25 @@
|
|
22
22
|
text-align: left;
|
23
23
|
}
|
24
24
|
|
25
|
-
|
25
|
+
header {
|
26
26
|
display: inline-block;
|
27
27
|
pointer-events: visible;
|
28
28
|
position: relative;
|
29
29
|
left: 50px;
|
30
30
|
top: 12px;
|
31
|
+
z-index: 101;
|
31
32
|
}
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
footer {
|
35
|
+
position: absolute;
|
36
|
+
right: 5px;
|
37
|
+
bottom: 0;
|
38
|
+
}
|
35
39
|
}
|
36
40
|
|
41
|
+
@import 'dropdown';
|
42
|
+
@import 'draggable';
|
43
|
+
|
37
44
|
.fsAbsolute {
|
38
45
|
position: absolute;
|
39
46
|
left: 0;
|
@@ -57,4 +64,4 @@
|
|
57
64
|
.hideText {
|
58
65
|
text-indent: -9999px;
|
59
66
|
white-space: nowrap;
|
60
|
-
}
|
67
|
+
}
|
package/src/editor/utils.ts
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
+
import { Object3D } from "three";
|
2
|
+
|
1
3
|
export function clamp(min: number, max: number, value: number) {
|
2
|
-
return Math.min(max, Math.max(min, value))
|
4
|
+
return Math.min(max, Math.max(min, value));
|
3
5
|
}
|
4
6
|
|
5
7
|
export function distance(x: number, y: number): number {
|
6
|
-
const d = x - y
|
7
|
-
return Math.sqrt(d * d)
|
8
|
+
const d = x - y;
|
9
|
+
return Math.sqrt(d * d);
|
8
10
|
}
|
9
11
|
|
10
12
|
export function randomID(): string {
|
11
|
-
return Math.round(Math.random() * 1000000).toString()
|
13
|
+
return Math.round(Math.random() * 1000000).toString();
|
12
14
|
}
|
13
15
|
|
14
16
|
export function isColor(obj: any) {
|
@@ -16,5 +18,40 @@ export function isColor(obj: any) {
|
|
16
18
|
obj.r !== undefined &&
|
17
19
|
obj.g !== undefined &&
|
18
20
|
obj.b !== undefined
|
19
|
-
)
|
21
|
+
);
|
20
22
|
}
|
23
|
+
|
24
|
+
export function colorToHex(obj: any) {
|
25
|
+
const r = Math.round(obj.r * 255);
|
26
|
+
const g = Math.round(obj.g * 255);
|
27
|
+
const b = Math.round(obj.b * 255);
|
28
|
+
|
29
|
+
const toHex = (value: number) => {
|
30
|
+
const hex = value.toString(16);
|
31
|
+
return hex.length === 1 ? '0' + hex : hex;
|
32
|
+
};
|
33
|
+
|
34
|
+
const red = toHex(r);
|
35
|
+
const green = toHex(g);
|
36
|
+
const blue = toHex(b);
|
37
|
+
|
38
|
+
return '#' + red + green + blue;
|
39
|
+
}
|
40
|
+
|
41
|
+
let totalObjects = 0;
|
42
|
+
export const hierarchyUUID = (object: Object3D): void => {
|
43
|
+
if (!object) return;
|
44
|
+
|
45
|
+
let uuid = object.name.replace(' ', '');
|
46
|
+
// fallback in case there's no name
|
47
|
+
if (uuid.length === 0) uuid = `obj_${totalObjects}`;
|
48
|
+
// inherit parent's UUID for hierarchy
|
49
|
+
if (object.parent !== null) uuid = `${object.parent.uuid}.${uuid}`;
|
50
|
+
object.uuid = uuid;
|
51
|
+
totalObjects++;
|
52
|
+
|
53
|
+
// Iterate children
|
54
|
+
object.children.forEach((child: Object3D) => {
|
55
|
+
hierarchyUUID(child);
|
56
|
+
});
|
57
|
+
};
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { app } from './constants'
|
2
|
+
import Editor from '@/editor/Editor'
|
3
|
+
import Dropdown from '@/editor/components/Dropdown'
|
4
|
+
import SceneHierarchy from '@/editor/sceneHierarchy/SceneHierarchy'
|
5
|
+
|
6
|
+
export default function CustomEditor() {
|
7
|
+
return (
|
8
|
+
<Editor
|
9
|
+
header={[
|
10
|
+
<Dropdown
|
11
|
+
title="Scenes"
|
12
|
+
key="Scenes"
|
13
|
+
options={[
|
14
|
+
{
|
15
|
+
type: 'option',
|
16
|
+
title: 'Scene 1',
|
17
|
+
value: 'scene1',
|
18
|
+
},
|
19
|
+
{
|
20
|
+
type: 'option',
|
21
|
+
title: 'Scene 2',
|
22
|
+
value: 'scene2',
|
23
|
+
},
|
24
|
+
]}
|
25
|
+
onSelect={(value: string) => {
|
26
|
+
app.send({
|
27
|
+
target: 'app',
|
28
|
+
event: 'selectComponent',
|
29
|
+
data: {
|
30
|
+
dropdown: 'Scenes',
|
31
|
+
value,
|
32
|
+
},
|
33
|
+
})
|
34
|
+
}}
|
35
|
+
/>
|
36
|
+
]}>
|
37
|
+
<SceneHierarchy key="SceneHierarchy" three={app.three} />
|
38
|
+
</Editor>
|
39
|
+
)
|
40
|
+
}
|
@@ -0,0 +1,164 @@
|
|
1
|
+
// Libs
|
2
|
+
import { useEffect, useRef, useState } from 'react'
|
3
|
+
import { types } from '@theatre/core'
|
4
|
+
import { WebGLRenderer } from 'three';
|
5
|
+
// Models
|
6
|
+
import { app, IS_DEV } from '../constants'
|
7
|
+
// Components
|
8
|
+
import './App.css'
|
9
|
+
import ExampleScene from '../three/ExampleScene';
|
10
|
+
import SceneInspector from '@/editor/sceneHierarchy/inspector/SceneInspector';
|
11
|
+
import { debugDispatcher, ToolEvents } from '../../editor/global';
|
12
|
+
import MultiView from '@/editor/sceneHierarchy/inspector/MultiView/MultiView';
|
13
|
+
|
14
|
+
let renderer: WebGLRenderer;
|
15
|
+
let exampleScene: ExampleScene;
|
16
|
+
|
17
|
+
const useTweakpane = false;
|
18
|
+
const threeCameras: any[] = [];
|
19
|
+
|
20
|
+
function App() {
|
21
|
+
const elementRef = useRef<HTMLDivElement>(null!)
|
22
|
+
const [showSceneInspector, setShowSceneInspector] = useState(false);
|
23
|
+
app.theatre?.sheet('App')
|
24
|
+
|
25
|
+
// Theatre
|
26
|
+
useEffect(() => {
|
27
|
+
const container = elementRef.current!
|
28
|
+
container.style.visibility = app.editor ? 'hidden' : 'inherit'
|
29
|
+
|
30
|
+
// Theatre Example
|
31
|
+
const sheetObj = app.theatre?.sheetObject(
|
32
|
+
'App',
|
33
|
+
'Box',
|
34
|
+
{
|
35
|
+
x: types.number(100, {range: [0, window.innerWidth]}),
|
36
|
+
y: types.number(100, {range: [0, window.innerHeight]}),
|
37
|
+
},
|
38
|
+
(values: any) => {
|
39
|
+
container.style.left = `${values.x}px`
|
40
|
+
container.style.top = `${values.y}px`
|
41
|
+
},
|
42
|
+
)
|
43
|
+
return () => {
|
44
|
+
if (sheetObj !== undefined) app.theatre?.unsubscribe(sheetObj)
|
45
|
+
app.dispose()
|
46
|
+
}
|
47
|
+
}, [])
|
48
|
+
|
49
|
+
// ThreeJS
|
50
|
+
useEffect(() => {
|
51
|
+
renderer = new WebGLRenderer({ antialias: true });
|
52
|
+
renderer.autoClear = false;
|
53
|
+
renderer.shadowMap.enabled = true;
|
54
|
+
renderer.setPixelRatio(devicePixelRatio);
|
55
|
+
renderer.setClearColor(0x000000, 1);
|
56
|
+
elementRef.current.parentElement!.appendChild(renderer.domElement);
|
57
|
+
|
58
|
+
exampleScene = new ExampleScene();
|
59
|
+
threeCameras.push(exampleScene.camera);
|
60
|
+
|
61
|
+
// Start RAF
|
62
|
+
let raf = -1;
|
63
|
+
|
64
|
+
const onResize = () => {
|
65
|
+
let width = window.innerWidth;
|
66
|
+
const height = window.innerHeight;
|
67
|
+
if (app.editor) width -= 300;
|
68
|
+
renderer.setSize(width, height);
|
69
|
+
exampleScene.resize(width, height);
|
70
|
+
};
|
71
|
+
|
72
|
+
const onUpdate = () => {
|
73
|
+
renderer.clear();
|
74
|
+
exampleScene.update();
|
75
|
+
renderer.render(exampleScene, exampleScene.camera);
|
76
|
+
raf = requestAnimationFrame(onUpdate);
|
77
|
+
};
|
78
|
+
|
79
|
+
app.three.setScene(exampleScene);
|
80
|
+
onResize();
|
81
|
+
window.addEventListener('resize', onResize);
|
82
|
+
if (!app.editor) onUpdate();
|
83
|
+
setShowSceneInspector(true);
|
84
|
+
|
85
|
+
return () => {
|
86
|
+
window.removeEventListener('resize', onResize);
|
87
|
+
renderer.dispose();
|
88
|
+
cancelAnimationFrame(raf);
|
89
|
+
raf = -1;
|
90
|
+
}
|
91
|
+
}, [])
|
92
|
+
|
93
|
+
// Debug Components
|
94
|
+
if (IS_DEV) {
|
95
|
+
useEffect(() => {
|
96
|
+
const container = elementRef.current!;
|
97
|
+
container.style.visibility = app.editor ? 'hidden' : 'inherit';
|
98
|
+
|
99
|
+
// Tweakpane Example
|
100
|
+
if (useTweakpane) {
|
101
|
+
const testFolder = app.debug.addFolder('Test Folder');
|
102
|
+
|
103
|
+
app.debug.button('Test Button', () => {
|
104
|
+
console.log('Test button works!');
|
105
|
+
}, testFolder);
|
106
|
+
|
107
|
+
const test = { opacity: 1, rotation: 0 };
|
108
|
+
app.debug.bind(test, 'opacity', {
|
109
|
+
min: 0,
|
110
|
+
max: 1,
|
111
|
+
onChange: (value: number) => {
|
112
|
+
container.style.opacity = value.toFixed(2);
|
113
|
+
}
|
114
|
+
}, testFolder);
|
115
|
+
|
116
|
+
app.debug.bind(test, 'rotation', {
|
117
|
+
min: 0,
|
118
|
+
max: 360,
|
119
|
+
onChange: (value: number) => {
|
120
|
+
container.style.transform = `rotate(${value}deg)`;
|
121
|
+
}
|
122
|
+
}, testFolder);
|
123
|
+
}
|
124
|
+
|
125
|
+
// Components Example
|
126
|
+
const onCustom = (evt: any) => {
|
127
|
+
console.log('Custom:', evt.value)
|
128
|
+
}
|
129
|
+
const selectDropdown = (evt: any) => {
|
130
|
+
console.log(`Dropdown: ${evt.value.dropdown}, value: ${evt.value.value}`)
|
131
|
+
}
|
132
|
+
debugDispatcher.addEventListener(ToolEvents.CUSTOM, onCustom)
|
133
|
+
debugDispatcher.addEventListener(ToolEvents.SELECT_DROPDOWN, selectDropdown)
|
134
|
+
return () => {
|
135
|
+
debugDispatcher.removeEventListener(ToolEvents.CUSTOM, onCustom)
|
136
|
+
debugDispatcher.removeEventListener(ToolEvents.SELECT_DROPDOWN, selectDropdown)
|
137
|
+
}
|
138
|
+
}, [])
|
139
|
+
}
|
140
|
+
|
141
|
+
return (
|
142
|
+
<>
|
143
|
+
<div id='box' ref={elementRef}>
|
144
|
+
<button onClick={() => {
|
145
|
+
app.send({
|
146
|
+
target: 'editor',
|
147
|
+
event: 'custom',
|
148
|
+
data: 'hello editor!'
|
149
|
+
});
|
150
|
+
}}>Click</button>
|
151
|
+
</div>
|
152
|
+
|
153
|
+
{IS_DEV && showSceneInspector && (
|
154
|
+
<SceneInspector scene={exampleScene} three={app.three} />
|
155
|
+
)}
|
156
|
+
|
157
|
+
{IS_DEV && showSceneInspector && app.editor && (
|
158
|
+
<MultiView scene={exampleScene} renderer={renderer} cameras={threeCameras} />
|
159
|
+
)}
|
160
|
+
</>
|
161
|
+
)
|
162
|
+
}
|
163
|
+
|
164
|
+
export default App
|
package/src/example/constants.ts
CHANGED
@@ -1,13 +1,44 @@
|
|
1
|
-
import Application from '
|
1
|
+
import Application from '@/core/Application'
|
2
|
+
import RemoteComponents from '@/core/remote/RemoteComponents'
|
3
|
+
import RemoteTheatre from '@/core/remote/RemoteTheatre'
|
4
|
+
import RemoteThree from '@/core/remote/RemoteThree'
|
5
|
+
import RemoteTweakpane from '@/core/remote/RemoteTweakpane'
|
2
6
|
|
3
|
-
export const IS_DEV =
|
4
|
-
export const
|
7
|
+
export const IS_DEV = true
|
8
|
+
// export const IS_DEV = import.meta.env.DEV
|
9
|
+
// export const app = new Application('Hermes', IS_DEV, 'editor')
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
11
|
+
class CustomApp extends Application {
|
12
|
+
constructor(name: string, debugEnabled: boolean, editorHashtag: string) {
|
13
|
+
super(name, debugEnabled, editorHashtag)
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
15
|
+
// Add components
|
16
|
+
this.addComponent('theatre', new RemoteTheatre(this, 'RemoteApp', {}))
|
17
|
+
|
18
|
+
if (IS_DEV) {
|
19
|
+
this.addComponent('components', new RemoteComponents(this))
|
20
|
+
// this.addComponent('debug', new RemoteTweakpane(this))
|
21
|
+
this.addComponent('three', new RemoteThree(this))
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
// Components
|
26
|
+
|
27
|
+
get debug(): RemoteTweakpane {
|
28
|
+
return this.components.get('debug') as RemoteTweakpane
|
29
|
+
}
|
30
|
+
|
31
|
+
get debugComponents(): RemoteComponents {
|
32
|
+
return this.components.get('components') as RemoteComponents
|
33
|
+
}
|
34
|
+
|
35
|
+
get theatre(): RemoteTheatre {
|
36
|
+
return this.components.get('theatre') as RemoteTheatre
|
37
|
+
}
|
38
|
+
|
39
|
+
get three(): RemoteThree {
|
40
|
+
return this.components.get('three') as RemoteThree
|
41
|
+
}
|
13
42
|
}
|
43
|
+
|
44
|
+
export const app = new CustomApp('Hermes', IS_DEV, 'editor')
|
package/src/example/main.tsx
CHANGED
@@ -6,13 +6,10 @@ import studio from '@theatre/studio'
|
|
6
6
|
import { app, IS_DEV } from './constants'
|
7
7
|
// Components
|
8
8
|
import './index.scss'
|
9
|
-
import App from './App'
|
10
|
-
import
|
11
|
-
import Draggable from '../editor/components/Draggable'
|
12
|
-
import Dropdown from '../editor/components/Dropdown'
|
9
|
+
import App from './components/App'
|
10
|
+
import CustomEditor from './CustomEditor'
|
13
11
|
// Tools
|
14
|
-
import RemoteController from '
|
15
|
-
import SceneHierarchy from '../editor/sceneHierarchy/SceneHierarchy'
|
12
|
+
import RemoteController from '@/core/RemoteController'
|
16
13
|
|
17
14
|
// Debug tools
|
18
15
|
if (IS_DEV) {
|
@@ -20,51 +17,14 @@ if (IS_DEV) {
|
|
20
17
|
RemoteController(app)
|
21
18
|
}
|
22
19
|
|
23
|
-
//
|
20
|
+
// React
|
24
21
|
|
25
22
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
26
23
|
<>
|
27
24
|
{IS_DEV ? (
|
28
25
|
<>
|
29
26
|
<App />
|
30
|
-
{app.editor ?
|
31
|
-
<Editor components={[
|
32
|
-
<SceneHierarchy key="SceneHierarchy" />
|
33
|
-
]}>
|
34
|
-
<Dropdown
|
35
|
-
title="Scenes"
|
36
|
-
options={[
|
37
|
-
{
|
38
|
-
type: 'option',
|
39
|
-
title: 'Option 1',
|
40
|
-
value: 'opt1',
|
41
|
-
},
|
42
|
-
{
|
43
|
-
type: 'option',
|
44
|
-
title: 'Option 2',
|
45
|
-
value: 'opt2',
|
46
|
-
},
|
47
|
-
]}
|
48
|
-
onSelect={(value: string) => {
|
49
|
-
app.components?.selectDropdown('Scenes', value)
|
50
|
-
}}
|
51
|
-
/>
|
52
|
-
|
53
|
-
<Draggable
|
54
|
-
title="Draggable Items"
|
55
|
-
options={[
|
56
|
-
'Item A',
|
57
|
-
'Item B',
|
58
|
-
'Item C',
|
59
|
-
'Item D',
|
60
|
-
'Item E',
|
61
|
-
]}
|
62
|
-
onDragComplete={(options: string[]) => {
|
63
|
-
app.components?.updateDropdown('Draggable Items', options)
|
64
|
-
}}
|
65
|
-
/>
|
66
|
-
</Editor>
|
67
|
-
) : null}
|
27
|
+
{app.editor ? <CustomEditor /> : null}
|
68
28
|
</>
|
69
29
|
) : (
|
70
30
|
<React.StrictMode>
|