|
1 | | -import { Component, ReactNode } from "react"; |
| 1 | +import { Mesh } from "babylonjs"; |
2 | 2 |
|
3 | | -import { CreateBoxVertexData, CreateSphereVertexData, CreateGroundVertexData, Mesh } from "babylonjs"; |
| 3 | +import { Editor } from "../../../main"; |
4 | 4 |
|
5 | | -import { EditorInspectorListField } from "../fields/list"; |
6 | | -import { EditorInspectorNumberField } from "../fields/number"; |
7 | | -import { EditorInspectorSectionField } from "../fields/section"; |
| 5 | +import { BoxMeshGeometryInspector } from "./geometry/box"; |
| 6 | +import { GroundMeshGeometryInspector } from "./geometry/ground"; |
| 7 | +import { SphereMeshGeometryInspector } from "./geometry/sphere"; |
8 | 8 |
|
9 | 9 | export interface IMeshGeometryInspectorProps { |
10 | 10 | object: Mesh; |
| 11 | + editor: Editor; |
11 | 12 | } |
12 | 13 |
|
13 | | -export class MeshGeometryInspector extends Component<IMeshGeometryInspectorProps> { |
14 | | - public render(): ReactNode { |
15 | | - if (this.props.object.metadata?.type === "Box") { |
16 | | - return this._getBoxInspectorComponent(); |
17 | | - } |
18 | | - |
19 | | - if (this.props.object.metadata?.type === "Sphere") { |
20 | | - return this._getSphereInspectorComponent(); |
21 | | - } |
22 | | - |
23 | | - if (this.props.object.metadata?.type === "Ground") { |
24 | | - return this._getGroundInspectorComponent(); |
25 | | - } |
26 | | - |
27 | | - return null; |
| 14 | +export function MeshGeometryInspector(props: IMeshGeometryInspectorProps) { |
| 15 | + if (props.object.metadata?.type === "Box") { |
| 16 | + return <BoxMeshGeometryInspector {...props} />; |
28 | 17 | } |
29 | 18 |
|
30 | | - private _getBoxInspectorComponent(): ReactNode { |
31 | | - const proxy = this._getProxy(() => { |
32 | | - this.props.object.geometry?.setAllVerticesData( |
33 | | - CreateBoxVertexData({ |
34 | | - width: this.props.object.metadata.width, |
35 | | - height: this.props.object.metadata.height, |
36 | | - depth: this.props.object.metadata.depth, |
37 | | - sideOrientation: this.props.object.metadata.sideOrientation, |
38 | | - }), |
39 | | - false |
40 | | - ); |
41 | | - }); |
42 | | - |
43 | | - return ( |
44 | | - <EditorInspectorSectionField title="Box"> |
45 | | - <EditorInspectorNumberField object={proxy} property="width" label="Width" step={0.1} /> |
46 | | - <EditorInspectorNumberField object={proxy} property="height" label="Height" step={0.1} /> |
47 | | - <EditorInspectorNumberField object={proxy} property="depth" label="Depth" step={0.1} /> |
48 | | - <EditorInspectorListField |
49 | | - object={proxy} |
50 | | - property="sideOrientation" |
51 | | - label="Side Orientation" |
52 | | - items={[ |
53 | | - { text: "Front", value: Mesh.FRONTSIDE }, |
54 | | - { text: "Back", value: Mesh.BACKSIDE }, |
55 | | - ]} |
56 | | - /> |
57 | | - </EditorInspectorSectionField> |
58 | | - ); |
| 19 | + if (props.object.metadata?.type === "Sphere") { |
| 20 | + return <SphereMeshGeometryInspector {...props} />; |
59 | 21 | } |
60 | 22 |
|
61 | | - private _getSphereInspectorComponent(): ReactNode { |
62 | | - const proxy = this._getProxy(() => { |
63 | | - this.props.object.geometry?.setAllVerticesData( |
64 | | - CreateSphereVertexData({ |
65 | | - diameter: this.props.object.metadata.diameter, |
66 | | - segments: this.props.object.metadata.segments, |
67 | | - sideOrientation: this.props.object.metadata.sideOrientation, |
68 | | - }), |
69 | | - false |
70 | | - ); |
71 | | - }); |
72 | | - |
73 | | - return ( |
74 | | - <EditorInspectorSectionField title="Sphere"> |
75 | | - <EditorInspectorNumberField object={proxy} property="diameter" label="Diameter" step={0.1} min={0.01} /> |
76 | | - <EditorInspectorNumberField object={proxy} property="segments" label="Segments" step={0.1} min={2} /> |
77 | | - <EditorInspectorListField |
78 | | - object={proxy} |
79 | | - property="sideOrientation" |
80 | | - label="Side Orientation" |
81 | | - items={[ |
82 | | - { text: "Front", value: Mesh.FRONTSIDE }, |
83 | | - { text: "Back", value: Mesh.BACKSIDE }, |
84 | | - ]} |
85 | | - /> |
86 | | - </EditorInspectorSectionField> |
87 | | - ); |
| 23 | + if (props.object.metadata?.type === "Ground") { |
| 24 | + return <GroundMeshGeometryInspector {...props} />; |
88 | 25 | } |
89 | 26 |
|
90 | | - private _getGroundInspectorComponent(): ReactNode { |
91 | | - const proxy = this._getProxy(() => { |
92 | | - this.props.object.geometry?.setAllVerticesData( |
93 | | - CreateGroundVertexData({ |
94 | | - width: this.props.object.metadata.width, |
95 | | - height: this.props.object.metadata.height, |
96 | | - subdivisions: this.props.object.metadata.subdivisions >> 0, |
97 | | - }), |
98 | | - false |
99 | | - ); |
100 | | - }); |
101 | | - |
102 | | - return ( |
103 | | - <EditorInspectorSectionField title="Ground"> |
104 | | - <EditorInspectorNumberField object={proxy} property="width" label="Width" step={0.1} /> |
105 | | - <EditorInspectorNumberField object={proxy} property="height" label="Height" step={0.1} /> |
106 | | - <EditorInspectorNumberField object={proxy} property="subdivisions" label="Subdivisions" step={1} min={1} /> |
107 | | - </EditorInspectorSectionField> |
108 | | - ); |
109 | | - } |
110 | | - |
111 | | - private _getProxy<T>(onChange: () => void): T { |
112 | | - return new Proxy(this.props.object.metadata, { |
113 | | - get(target, prop) { |
114 | | - return target[prop]; |
115 | | - }, |
116 | | - set(obj, prop, value) { |
117 | | - obj[prop] = value; |
118 | | - onChange(); |
119 | | - return true; |
120 | | - }, |
121 | | - }); |
122 | | - } |
| 27 | + return null; |
123 | 28 | } |
0 commit comments