@tomorrowevening/hermes 0.0.9 → 0.0.11

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 (34) hide show
  1. package/dist/hermes.js +1068 -1038
  2. package/dist/hermes.umd.cjs +16 -16
  3. package/dist/style.css +1 -1
  4. package/package.json +1 -1
  5. package/src/core/RemoteController.ts +0 -3
  6. package/src/core/remote/RemoteThree.ts +5 -10
  7. package/src/core/types.ts +0 -1
  8. package/src/editor/global.ts +0 -1
  9. package/src/editor/{sceneHierarchy/inspector/MultiView → multiView}/MultiView.scss +6 -0
  10. package/src/editor/{sceneHierarchy/inspector/MultiView → multiView}/MultiView.tsx +103 -55
  11. package/src/editor/{sceneHierarchy/inspector/MultiView → multiView}/MultiViewData.ts +7 -15
  12. package/src/editor/sceneHierarchy/SceneHierarchy.tsx +7 -21
  13. package/src/editor/sceneHierarchy/inspector/SceneInspector.tsx +16 -11
  14. package/src/editor/sceneHierarchy/inspector/utils/InspectMaterial.tsx +1 -0
  15. package/src/editor/sceneHierarchy/inspector/utils/InspectTransform.tsx +35 -46
  16. package/src/editor/utils.ts +60 -4
  17. package/src/index.ts +3 -3
  18. package/types/core/remote/RemoteThree.d.ts +0 -1
  19. package/types/core/types.d.ts +1 -1
  20. package/types/editor/global.d.ts +0 -1
  21. package/types/editor/{sceneHierarchy/inspector/MultiView → multiView}/MultiView.d.ts +2 -4
  22. package/types/editor/{sceneHierarchy/inspector/MultiView → multiView}/MultiViewData.d.ts +4 -4
  23. package/types/editor/sceneHierarchy/SceneHierarchy.d.ts +0 -2
  24. package/types/editor/sceneHierarchy/inspector/SceneInspector.d.ts +0 -2
  25. package/types/editor/utils.d.ts +7 -1
  26. package/types/index.d.ts +3 -3
  27. /package/src/editor/{sceneHierarchy/inspector/MultiView → multiView}/CameraWindow.tsx +0 -0
  28. /package/src/editor/{sceneHierarchy/inspector/MultiView → multiView}/InfiniteGridHelper.ts +0 -0
  29. /package/src/editor/{sceneHierarchy/inspector/MultiView → multiView}/InfiniteGridMaterial.ts +0 -0
  30. /package/src/editor/{sceneHierarchy/inspector/MultiView → multiView}/UVMaterial.ts +0 -0
  31. /package/types/editor/{sceneHierarchy/inspector/MultiView → multiView}/CameraWindow.d.ts +0 -0
  32. /package/types/editor/{sceneHierarchy/inspector/MultiView → multiView}/InfiniteGridHelper.d.ts +0 -0
  33. /package/types/editor/{sceneHierarchy/inspector/MultiView → multiView}/InfiniteGridMaterial.d.ts +0 -0
  34. /package/types/editor/{sceneHierarchy/inspector/MultiView → multiView}/UVMaterial.d.ts +0 -0
@@ -1,32 +1,42 @@
1
1
  import RemoteThree from "@/core/remote/RemoteThree";
2
2
  import { ToolEvents, debugDispatcher } from "@/editor/global";
3
3
  import { useEffect } from "react";
4
- import { Scene, Texture } from "three";
4
+ import { Texture } from "three";
5
5
  import { setItemProps, textureFromSrc } from "../utils";
6
6
 
7
7
  export interface SceneInspectorProps {
8
- scene: Scene
9
8
  three: RemoteThree
10
9
  }
11
10
 
12
11
  export default function SceneInspector(props: SceneInspectorProps) {
12
+ function hasScene() {
13
+ if (props.three.scene === undefined) {
14
+ console.log('No scene:', props.three);
15
+ return false;
16
+ }
17
+ return true;
18
+ }
13
19
  const onGetObject = (evt: any) => {
14
- const child = props.scene.getObjectByProperty('uuid', evt.value);
20
+ if (!hasScene()) return;
21
+ const child = props.three.scene?.getObjectByProperty('uuid', evt.value);
15
22
  if (child !== undefined) props.three.setObject(child);
16
23
  };
17
24
 
18
25
  const setChildProps = (uuid: string, key: string, value: any) => {
19
- const child = props.scene.getObjectByProperty('uuid', uuid);
26
+ if (!hasScene()) return;
27
+ const child = props.three.scene?.getObjectByProperty('uuid', uuid);
20
28
  if (child !== undefined) setItemProps(child, key, value);
21
29
  };
22
30
 
23
31
  const onUpdateObject = (evt: any) => {
32
+ if (!hasScene()) return;
24
33
  const msg = evt.value;
25
34
  const { key, value, uuid } = msg;
26
35
  setChildProps(uuid, key, value);
27
36
  };
28
37
 
29
38
  const onCreateTexture = (evt: any) => {
39
+ if (!hasScene()) return;
30
40
  const data = evt.value;
31
41
  textureFromSrc(data.value).then((texture: Texture) => {
32
42
  setChildProps(data.uuid, data.key, texture);
@@ -34,13 +44,10 @@ export default function SceneInspector(props: SceneInspectorProps) {
34
44
  });
35
45
  };
36
46
 
37
- const onGetScene = () => {
38
- props.three.setScene(props.scene);
39
- };
40
-
41
47
  const onRequestMethod = (evt: any) => {
48
+ if (!hasScene()) return;
42
49
  const { key, uuid, value } = evt.value;
43
- const child = props.scene.getObjectByProperty('uuid', uuid);
50
+ const child = props.three.scene?.getObjectByProperty('uuid', uuid);
44
51
  if (child !== undefined) {
45
52
  try {
46
53
  child[key](value);
@@ -55,13 +62,11 @@ export default function SceneInspector(props: SceneInspectorProps) {
55
62
 
56
63
  useEffect(() => {
57
64
  debugDispatcher.addEventListener(ToolEvents.GET_OBJECT, onGetObject);
58
- debugDispatcher.addEventListener(ToolEvents.GET_SCENE, onGetScene);
59
65
  debugDispatcher.addEventListener(ToolEvents.UPDATE_OBJECT, onUpdateObject);
60
66
  debugDispatcher.addEventListener(ToolEvents.CREATE_TEXTURE, onCreateTexture);
61
67
  debugDispatcher.addEventListener(ToolEvents.REQUEST_METHOD, onRequestMethod);
62
68
  return () => {
63
69
  debugDispatcher.removeEventListener(ToolEvents.GET_OBJECT, onGetObject);
64
- debugDispatcher.removeEventListener(ToolEvents.GET_SCENE, onGetScene);
65
70
  debugDispatcher.removeEventListener(ToolEvents.UPDATE_OBJECT, onUpdateObject);
66
71
  debugDispatcher.removeEventListener(ToolEvents.CREATE_TEXTURE, onCreateTexture);
67
72
  debugDispatcher.removeEventListener(ToolEvents.REQUEST_METHOD, onRequestMethod);
@@ -339,6 +339,7 @@ export function InspectMaterial(object: RemoteObject, three: RemoteThree): any {
339
339
  items.push(
340
340
  <InspectorGroup
341
341
  title={`Material ${i}`}
342
+ key={`Material ${i}`}
342
343
  items={inspectMaterialItems(material[i], object, three)}
343
344
  />
344
345
  );
@@ -1,8 +1,10 @@
1
1
  import { Euler, Matrix4, Vector3 } from 'three';
2
+ import { degToRad, radToDeg } from 'three/src/math/MathUtils';
2
3
  import InspectorGroup from '../InspectorGroup';
3
4
  import { RemoteObject } from "../../types";
4
5
  import RemoteThree from '@/core/remote/RemoteThree';
5
6
  import { setItemProps } from '../../utils';
7
+ import { round } from '@/editor/utils';
6
8
 
7
9
  export function InspectTransform(obj: RemoteObject, three: RemoteThree) {
8
10
  const matrix = new Matrix4();
@@ -22,73 +24,67 @@ export function InspectTransform(obj: RemoteObject, three: RemoteThree) {
22
24
  if (child !== undefined) setItemProps(child, prop, value);
23
25
  };
24
26
 
25
- const items: any[] = [
26
- {
27
- title: 'Position',
28
- items: [
27
+ const updateRotation = (prop: string, value: any) => {
28
+ updateTransform(prop, degToRad(value));
29
+ };
30
+
31
+ return (
32
+ <InspectorGroup
33
+ title="Transform"
34
+ items={[
29
35
  {
30
- title: 'X',
36
+ title: 'Position X',
31
37
  prop: 'position.x',
32
38
  type: 'number',
33
39
  value: position.x,
34
40
  onChange: updateTransform,
35
41
  },
36
42
  {
37
- title: 'Y',
43
+ title: 'Position Y',
38
44
  prop: 'position.y',
39
45
  type: 'number',
40
46
  value: position.y,
41
47
  onChange: updateTransform,
42
48
  },
43
49
  {
44
- title: 'Z',
50
+ title: 'Position Z',
45
51
  prop: 'position.z',
46
52
  type: 'number',
47
53
  value: position.z,
48
54
  onChange: updateTransform,
49
55
  },
50
- ],
51
- },
52
- {
53
- title: 'Rotation',
54
- items: [
55
56
  {
56
- title: 'X',
57
+ title: 'Rotation X',
57
58
  prop: 'rotation.x',
58
59
  type: 'number',
59
- value: rotation.x,
60
- min: -Math.PI,
61
- max: Math.PI,
62
- step: 0.01,
63
- onChange: updateTransform,
60
+ value: round(radToDeg(rotation.x)),
61
+ min: -360,
62
+ max: 360,
63
+ step: 0.1,
64
+ onChange: updateRotation,
64
65
  },
65
66
  {
66
- title: 'Y',
67
+ title: 'Rotation Y',
67
68
  prop: 'rotation.y',
68
69
  type: 'number',
69
- value: rotation.y,
70
- min: -Math.PI,
71
- max: Math.PI,
72
- step: 0.01,
73
- onChange: updateTransform,
70
+ value: round(radToDeg(rotation.y)),
71
+ min: -360,
72
+ max: 360,
73
+ step: 0.1,
74
+ onChange: updateRotation,
74
75
  },
75
76
  {
76
- title: 'Z',
77
+ title: 'Rotation Z',
77
78
  prop: 'rotation.z',
78
79
  type: 'number',
79
- value: rotation.z,
80
- min: -Math.PI,
81
- max: Math.PI,
82
- step: 0.01,
83
- onChange: updateTransform,
80
+ value: round(radToDeg(rotation.z)),
81
+ min: -360,
82
+ max: 360,
83
+ step: 0.1,
84
+ onChange: updateRotation,
84
85
  },
85
- ],
86
- },
87
- {
88
- title: 'Scale',
89
- items: [
90
86
  {
91
- title: 'X',
87
+ title: 'Scale X',
92
88
  prop: 'scale.x',
93
89
  type: 'number',
94
90
  value: scale.x,
@@ -96,7 +92,7 @@ export function InspectTransform(obj: RemoteObject, three: RemoteThree) {
96
92
  onChange: updateTransform,
97
93
  },
98
94
  {
99
- title: 'Y',
95
+ title: 'Scale Y',
100
96
  prop: 'scale.y',
101
97
  type: 'number',
102
98
  value: scale.y,
@@ -104,21 +100,14 @@ export function InspectTransform(obj: RemoteObject, three: RemoteThree) {
104
100
  onChange: updateTransform,
105
101
  },
106
102
  {
107
- title: 'Z',
103
+ title: 'Scale Z',
108
104
  prop: 'scale.z',
109
105
  type: 'number',
110
106
  value: scale.z,
111
107
  step: 0.01,
112
108
  onChange: updateTransform,
113
109
  },
114
- ],
115
- },
116
- ];
117
-
118
- return (
119
- <InspectorGroup
120
- title="Transform"
121
- items={items}
110
+ ]}
122
111
  />
123
112
  );
124
113
  }
@@ -1,4 +1,4 @@
1
- import { Object3D } from "three";
1
+ import { Material, Mesh, Object3D, PositionalAudio, Texture } from "three";
2
2
 
3
3
  export function clamp(min: number, max: number, value: number) {
4
4
  return Math.min(max, Math.max(min, value));
@@ -38,20 +38,76 @@ export function colorToHex(obj: any) {
38
38
  return '#' + red + green + blue;
39
39
  }
40
40
 
41
- let totalObjects = 0;
41
+ export function round(value: number, precision: number = 1): number {
42
+ return Number(value.toFixed(precision));
43
+ }
44
+
45
+ export let totalThreeObjects = 0;
46
+ export const resetThreeObjects = () => {
47
+ totalThreeObjects = 0;
48
+ };
42
49
  export const hierarchyUUID = (object: Object3D): void => {
43
50
  if (!object) return;
44
51
 
45
52
  let uuid = object.name.replace(' ', '');
46
53
  // fallback in case there's no name
47
- if (uuid.length === 0) uuid = `obj_${totalObjects}`;
54
+ if (uuid.length === 0) {
55
+ uuid = `obj_${totalThreeObjects}`;
56
+ totalThreeObjects++;
57
+ }
48
58
  // inherit parent's UUID for hierarchy
49
59
  if (object.parent !== null) uuid = `${object.parent.uuid}.${uuid}`;
50
60
  object.uuid = uuid;
51
- totalObjects++;
52
61
 
53
62
  // Iterate children
54
63
  object.children.forEach((child: Object3D) => {
55
64
  hierarchyUUID(child);
56
65
  });
57
66
  };
67
+
68
+ // Dispose
69
+
70
+ export const disposeTexture = (texture?: Texture): void => {
71
+ texture?.dispose();
72
+ };
73
+
74
+ // Dispose material
75
+ export const disposeMaterial = (material?: Material | Material[]): void => {
76
+ if (!material) return;
77
+
78
+ if (Array.isArray(material)) {
79
+ material.forEach((mat: Material) => mat.dispose());
80
+ } else {
81
+ material.dispose();
82
+ }
83
+ };
84
+
85
+ // Dispose object
86
+ export const dispose = (object: Object3D): void => {
87
+ if (!object) return;
88
+
89
+ // Dispose children
90
+ while (object.children.length > 0) {
91
+ const child = object.children[0];
92
+ if (child instanceof PositionalAudio) {
93
+ child.pause();
94
+ if (child.parent) {
95
+ child.parent.remove(child);
96
+ }
97
+ } else {
98
+ dispose(child);
99
+ }
100
+ }
101
+
102
+ // Dispose object
103
+ if (object.parent) object.parent.remove(object);
104
+ // @ts-ignore
105
+ if (object.isMesh) {
106
+ const mesh = object as Mesh;
107
+ mesh.geometry?.dispose();
108
+ disposeMaterial(mesh.material);
109
+ }
110
+
111
+ // @ts-ignore
112
+ if (object.dispose !== undefined) object.dispose();
113
+ };
package/src/index.ts CHANGED
@@ -15,13 +15,13 @@ export { default as DropdownItem } from './editor/components/DropdownItem';
15
15
  export { default as Dropdown } from './editor/components/Dropdown';
16
16
  export { default as RemoteController } from './core/RemoteController';
17
17
  // RemoteThree
18
- export { default as InfiniteGridHelper } from './editor/sceneHierarchy/inspector/MultiView/InfiniteGridHelper';
19
- export { default as UVMaterial } from './editor/sceneHierarchy/inspector/MultiView/UVMaterial';
18
+ export { default as InfiniteGridHelper } from './editor/multiView/InfiniteGridHelper';
19
+ export { default as UVMaterial } from './editor/multiView/UVMaterial';
20
20
  export { default as SceneHierarchy } from './editor/sceneHierarchy/SceneHierarchy';
21
21
  export { default as Accordion } from './editor/sceneHierarchy/Accordion';
22
22
  export { default as ChildObject } from './editor/sceneHierarchy/ChildObject';
23
23
  export { default as ContainerObject } from './editor/sceneHierarchy/ContainerObject';
24
24
  export { default as Inspector } from './editor/sceneHierarchy/inspector/Inspector';
25
25
  export { default as SceneInspector } from './editor/sceneHierarchy/inspector/SceneInspector';
26
- export { default as MultiView } from './editor/sceneHierarchy/inspector/MultiView/MultiView';
26
+ export { default as MultiView } from './editor/multiView/MultiView';
27
27
  export { default as Editor } from './editor/Editor';
@@ -7,6 +7,5 @@ export default class RemoteThree extends BaseRemote {
7
7
  requestMethod(uuid: string, key: string, value?: any): void;
8
8
  updateObject(uuid: string, key: string, value: any): void;
9
9
  createTexture(uuid: string, key: string, value: any): void;
10
- getScene(): void;
11
10
  setScene(value: Scene): void;
12
11
  }
@@ -6,7 +6,7 @@ export interface BroadcastData {
6
6
  export type ApplicationMode = 'app' | 'editor';
7
7
  export type VoidCallback = () => void;
8
8
  export type DataUpdateCallback = (data: any) => void;
9
- export type EditorEvent = 'custom' | 'setSheet' | 'setSheetObject' | 'updateSheetObject' | 'updateTimeline' | 'getObject' | 'setObject' | 'updateObject' | 'getScene' | 'setScene' | 'createTexture' | 'requestMethod' | 'addFolder' | 'bindObject' | 'updateBind' | 'addButton' | 'clickButton' | 'selectComponent' | 'draggableListUpdate';
9
+ export type EditorEvent = 'custom' | 'setSheet' | 'setSheetObject' | 'updateSheetObject' | 'updateTimeline' | 'getObject' | 'setObject' | 'updateObject' | 'setScene' | 'createTexture' | 'requestMethod' | 'addFolder' | 'bindObject' | 'updateBind' | 'addButton' | 'clickButton' | 'selectComponent' | 'draggableListUpdate';
10
10
  export type VoidFunc = () => void;
11
11
  export type BroadcastCallback = (data: BroadcastData) => void;
12
12
  export type TheatreUpdateCallback = (data: any) => void;
@@ -4,7 +4,6 @@ export declare const ToolEvents: {
4
4
  CUSTOM: string;
5
5
  SELECT_DROPDOWN: string;
6
6
  DRAG_UPDATE: string;
7
- GET_SCENE: string;
8
7
  SET_SCENE: string;
9
8
  GET_OBJECT: string;
10
9
  SET_OBJECT: string;
@@ -1,10 +1,8 @@
1
- import { Camera, Scene, WebGLRenderer } from 'three';
2
1
  import { MultiViewMode } from './MultiViewData';
3
2
  import './MultiView.scss';
3
+ import RemoteThree from '@/core/remote/RemoteThree';
4
4
  interface MultiViewProps {
5
- scene: Scene;
6
- renderer: WebGLRenderer;
7
- cameras: Camera[];
5
+ three: RemoteThree;
8
6
  mode?: MultiViewMode;
9
7
  }
10
8
  export default function MultiView(props: MultiViewProps): import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,4 @@
1
- import { Camera, CameraHelper, MeshBasicMaterial, MeshNormalMaterial, OrthographicCamera, PerspectiveCamera, Vector3 } from 'three';
1
+ import { Camera, CameraHelper, MeshBasicMaterial, MeshDepthMaterial, MeshNormalMaterial, OrthographicCamera, PerspectiveCamera, Vector3 } from 'three';
2
2
  import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
3
3
  import UVMaterial from './UVMaterial';
4
4
  export type MultiViewMode = 'Single' | 'Side by Side' | 'Stacked' | 'Quad';
@@ -6,11 +6,11 @@ export declare const ModeOptions: MultiViewMode[];
6
6
  export declare const cameras: Map<string, Camera>;
7
7
  export declare const controls: Map<string, OrbitControls>;
8
8
  export declare const helpers: Map<string, CameraHelper>;
9
- export declare const cameraOptions: string[];
10
9
  export declare function createOrtho(name: string, position: Vector3): OrthographicCamera;
11
10
  export declare const debugCamera: PerspectiveCamera;
12
- export type RenderMode = 'Default' | 'Normals' | 'Wireframe' | 'UVs';
11
+ export type RenderMode = 'Depth' | 'Normals' | 'Renderer' | 'UVs' | 'Wireframe';
13
12
  export declare const renderOptions: RenderMode[];
13
+ export declare const depthMaterial: MeshDepthMaterial;
14
14
  export declare const normalsMaterial: MeshNormalMaterial;
15
- export declare const wireframeMaterial: MeshBasicMaterial;
16
15
  export declare const uvMaterial: UVMaterial;
16
+ export declare const wireframeMaterial: MeshBasicMaterial;
@@ -4,10 +4,8 @@ import { SceneHierarchyState } from './types';
4
4
  export default class SceneHierarchy extends Component<SceneHierarchyState> {
5
5
  private three;
6
6
  constructor(props: SceneHierarchyState);
7
- componentDidMount(): void;
8
7
  componentWillUnmount(): void;
9
8
  render(): ReactNode;
10
- private onRefresh;
11
9
  private setScene;
12
10
  get componentState(): SceneHierarchyState;
13
11
  }
@@ -1,7 +1,5 @@
1
1
  import RemoteThree from "@/core/remote/RemoteThree";
2
- import { Scene } from "three";
3
2
  export interface SceneInspectorProps {
4
- scene: Scene;
5
3
  three: RemoteThree;
6
4
  }
7
5
  export default function SceneInspector(props: SceneInspectorProps): null;
@@ -1,7 +1,13 @@
1
- import { Object3D } from "three";
1
+ import { Material, Object3D, Texture } from "three";
2
2
  export declare function clamp(min: number, max: number, value: number): number;
3
3
  export declare function distance(x: number, y: number): number;
4
4
  export declare function randomID(): string;
5
5
  export declare function isColor(obj: any): boolean;
6
6
  export declare function colorToHex(obj: any): string;
7
+ export declare function round(value: number, precision?: number): number;
8
+ export declare let totalThreeObjects: number;
9
+ export declare const resetThreeObjects: () => void;
7
10
  export declare const hierarchyUUID: (object: Object3D) => void;
11
+ export declare const disposeTexture: (texture?: Texture) => void;
12
+ export declare const disposeMaterial: (material?: Material | Material[]) => void;
13
+ export declare const dispose: (object: Object3D) => void;
package/types/index.d.ts CHANGED
@@ -12,13 +12,13 @@ export { default as Draggable } from './editor/components/Draggable';
12
12
  export { default as DropdownItem } from './editor/components/DropdownItem';
13
13
  export { default as Dropdown } from './editor/components/Dropdown';
14
14
  export { default as RemoteController } from './core/RemoteController';
15
- export { default as InfiniteGridHelper } from './editor/sceneHierarchy/inspector/MultiView/InfiniteGridHelper';
16
- export { default as UVMaterial } from './editor/sceneHierarchy/inspector/MultiView/UVMaterial';
15
+ export { default as InfiniteGridHelper } from './editor/multiView/InfiniteGridHelper';
16
+ export { default as UVMaterial } from './editor/multiView/UVMaterial';
17
17
  export { default as SceneHierarchy } from './editor/sceneHierarchy/SceneHierarchy';
18
18
  export { default as Accordion } from './editor/sceneHierarchy/Accordion';
19
19
  export { default as ChildObject } from './editor/sceneHierarchy/ChildObject';
20
20
  export { default as ContainerObject } from './editor/sceneHierarchy/ContainerObject';
21
21
  export { default as Inspector } from './editor/sceneHierarchy/inspector/Inspector';
22
22
  export { default as SceneInspector } from './editor/sceneHierarchy/inspector/SceneInspector';
23
- export { default as MultiView } from './editor/sceneHierarchy/inspector/MultiView/MultiView';
23
+ export { default as MultiView } from './editor/multiView/MultiView';
24
24
  export { default as Editor } from './editor/Editor';