forked from Orillusion/orillusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUIShape3D.ts
156 lines (132 loc) · 6.36 KB
/
GUIShape3D.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { GUIHelp } from "@orillusion/debug/GUIHelp";
import { CircleShape3D, CurveShape3D, EllipseShape3D, QuadraticCurveShape3D, RoundRectShape3D, LineShape3D, Shape3D, CircleArcType, Path2DShape3D, Path3DShape3D } from "@orillusion/graphic";
import { LineJoin } from "@orillusion/graphic";
import { GUIUtil } from "./GUIUtil";
export class GUIShape3D {
public static renderRoundRect(shape: RoundRectShape3D, maxSize: number, open: boolean = true, name?: string) {
name ||= 'Rect3D_' + shape.shapeIndex;
GUIHelp.addFolder(name);
GUIHelp.add(shape, 'width', 0, maxSize, 0.1);
GUIHelp.add(shape, 'height', 0, maxSize, 0.1);
GUIHelp.add(shape, 'radius', 0, maxSize, 0.1);
GUIHelp.add(shape, 'cornerSegment', 0, 10, 1);
this.renderCommonShape3D(shape, maxSize);
open && GUIHelp.open();
GUIHelp.endFolder();
}
public static renderCircle(shape: CircleShape3D, maxSize: number, open: boolean = true, name?: string) {
name ||= 'Circle3D_' + shape.shapeIndex;
GUIHelp.addFolder(name);
GUIHelp.add(shape, 'radius', 0, maxSize, 0.1);
GUIHelp.add(shape, 'segment', 0, 100, 1);
GUIHelp.add(shape, 'startAngle', 0, 360, 1);
GUIHelp.add(shape, 'endAngle', 0, 360, 1);
let arcType = {}
arcType['sector'] = CircleArcType.Sector;
arcType['moon'] = CircleArcType.Moon;
GUIHelp.add({ arcType: shape.arcType }, 'arcType', arcType).onChange((v) => {
shape.arcType = Number.parseInt(v);
});
this.renderCommonShape3D(shape, maxSize);
open && GUIHelp.open();
GUIHelp.endFolder();
}
public static renderLine(shape: LineShape3D, maxSize: number, open: boolean = true, name?: string) {
name ||= 'Line3D_' + shape.shapeIndex;
GUIHelp.addFolder(name);
GUIHelp.add(shape, 'corner', 0, 50, 1);
let lineJoin = {}
lineJoin['miter'] = LineJoin.miter;
lineJoin['bevel'] = LineJoin.bevel;
lineJoin['round'] = LineJoin.round;
GUIHelp.add({ lineJoin: shape.lineJoin }, 'lineJoin', lineJoin).onChange((v) => {
shape.lineJoin = Number.parseInt(v);
});
this.renderCommonShape3D(shape, maxSize);
if (!(shape instanceof Path3DShape3D) && !(shape instanceof Path2DShape3D)) {
for (let i = 0; i < shape.points3D.length; i++) {
let point = shape.points3D[i];
GUIHelp.add(point, 'x', -10, 10, 0.01).onChange(
(v) => { shape.points3D = shape.points3D; }
);
GUIHelp.add(point, 'y', -10, 10, 0.01).onChange(
(v) => { shape.points3D = shape.points3D; }
);
}
}
open && GUIHelp.open();
GUIHelp.endFolder();
}
public static renderQuadraticCurve(shape: QuadraticCurveShape3D, maxSize: number, open: boolean = true, name?: string) {
name ||= 'QuadraticCurve_' + shape.shapeIndex;
GUIHelp.addFolder(name);
GUIHelp.add(shape, 'segment', 1, 100, 1);
GUIHelp.add(shape, 'corner', 0, 50, 1);
let lineJoin = {}
lineJoin['miter'] = LineJoin.miter;
lineJoin['bevel'] = LineJoin.bevel;
lineJoin['round'] = LineJoin.round;
GUIHelp.add({ lineJoin: shape.lineJoin }, 'lineJoin', lineJoin).onChange((v) => {
shape.lineJoin = Number.parseInt(v);
});
this.renderCommonShape3D(shape, maxSize);
GUIUtil.RenderVector2('Start.', shape, 'start', -10, 10, 0.01);
GUIUtil.RenderVector2('End2.', shape, 'end', -10, 10, 0.01);
GUIUtil.RenderVector2('CP.', shape, 'cp', -10, 10, 0.01);
open && GUIHelp.open();
GUIHelp.endFolder();
}
public static renderCurve(shape: CurveShape3D, maxSize: number, open: boolean = true, name?: string) {
name ||= 'Curve_' + shape.shapeIndex;
GUIHelp.addFolder(name);
GUIHelp.add(shape, 'segment', 1, 100, 1);
GUIHelp.add(shape, 'corner', 0, 50, 1);
let lineJoin = {}
lineJoin['miter'] = LineJoin.miter;
lineJoin['bevel'] = LineJoin.bevel;
lineJoin['round'] = LineJoin.round;
GUIHelp.add({ lineJoin: shape.lineJoin }, 'lineJoin', lineJoin).onChange((v) => {
shape.lineJoin = Number.parseInt(v);
});
this.renderCommonShape3D(shape, maxSize);
GUIUtil.RenderVector2('Start.', shape, 'start', -10, 10, 0.01);
GUIUtil.RenderVector2('End2.', shape, 'end', -10, 10, 0.01);
GUIUtil.RenderVector2('CP1.', shape, 'cp1', -10, 10, 0.01);
GUIUtil.RenderVector2('CP2.', shape, 'cp2', -10, 10, 0.01);
open && GUIHelp.open();
GUIHelp.endFolder();
}
public static renderEllipse(shape: EllipseShape3D, maxSize: number, open: boolean = true, name?: string) {
name ||= 'Ellipse3D_' + shape.shapeIndex;
GUIHelp.addFolder(name);
GUIHelp.add(shape, 'rx', 0, maxSize, 0.01);
GUIHelp.add(shape, 'ry', 0, maxSize, 0.01);
GUIHelp.add(shape, 'segment', 0, 100, 1);
GUIHelp.add(shape, 'rotation', -Math.PI, Math.PI, 0.01);
GUIHelp.add(shape, 'startAngle', 0, 360, 1);
GUIHelp.add(shape, 'endAngle', 0, 360, 1);
let arcType = {}
arcType['sector'] = CircleArcType.Sector;
arcType['moon'] = CircleArcType.Moon;
GUIHelp.add({ arcType: shape.arcType }, 'arcType', arcType).onChange((v) => {
shape.arcType = Number.parseInt(v);
});
this.renderCommonShape3D(shape, maxSize);
open && GUIHelp.open();
GUIHelp.endFolder();
}
private static renderCommonShape3D(shape: Shape3D, maxSize: number, uvMin: number = 0.01, uvMax: number = 1.0) {
GUIHelp.add(shape, 'line');
GUIHelp.add(shape, 'fill');
GUIHelp.add(shape, 'isClosed');
GUIHelp.add(shape, 'lineWidth', 0, maxSize, 0.01);
GUIHelp.add(shape, 'fillRotation', -Math.PI, Math.PI, 0.01);
GUIUtil.RenderVector4('FillUVRect.', shape, 'fillUVRect', 0, 10, 0.01);
GUIUtil.RenderVector4('LineUVRect.', shape, 'lineUVRect', 0, 10, 0.01);
GUIUtil.RenderVector4('UVSpeed.', shape, 'uvSpeed', -0.01, 0.01, 0.0001);
GUIUtil.RenderColor(shape, 'lineColor');
GUIUtil.RenderColor(shape, 'fillColor');
GUIHelp.add(shape, 'lineTextureID', 0, 9, 1);
GUIHelp.add(shape, 'fillTextureID', 0, 9, 1);
}
}