Skip to content

Commit 193cc38

Browse files
authored
Merge pull request #16252 from Temdog007/editor/PointsUI
Editor: Added UI.Points
2 parents 4cf6228 + 16d17ab commit 193cc38

File tree

3 files changed

+261
-167
lines changed

3 files changed

+261
-167
lines changed

editor/js/Sidebar.Geometry.LatheGeometry.js

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @author rfm1201
33
*/
44

5-
Sidebar.Geometry.LatheGeometry = function( editor, object ) {
5+
Sidebar.Geometry.LatheGeometry = function ( editor, object ) {
66

77
var strings = editor.strings;
88

@@ -45,99 +45,18 @@ Sidebar.Geometry.LatheGeometry = function( editor, object ) {
4545

4646
// points
4747

48-
var lastPointIdx = 0;
49-
var pointsUI = [];
50-
5148
var pointsRow = new UI.Row();
5249
pointsRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/lathe_geometry/points' ) ).setWidth( '90px' ) );
5350

54-
var points = new UI.Span().setDisplay( 'inline-block' );
51+
var points = new UI.Points2().setValue( parameters.points ).onChange( update );
5552
pointsRow.add( points );
5653

57-
var pointsList = new UI.Div();
58-
points.add( pointsList );
59-
60-
for ( var i = 0; i < parameters.points.length; i ++ ) {
61-
62-
var point = parameters.points[ i ];
63-
pointsList.add( createPointRow( point.x, point.y ) );
64-
65-
}
66-
67-
var addPointButton = new UI.Button( '+' ).onClick( function() {
68-
69-
if( pointsUI.length === 0 ){
70-
71-
pointsList.add( createPointRow( 0, 0 ) );
72-
73-
} else {
74-
75-
var point = pointsUI[ pointsUI.length - 1 ];
76-
77-
pointsList.add( createPointRow( point.x.getValue(), point.y.getValue() ) );
78-
79-
}
80-
81-
update();
82-
83-
} );
84-
points.add( addPointButton );
85-
8654
container.add( pointsRow );
8755

88-
//
89-
90-
function createPointRow( x, y ) {
91-
92-
var pointRow = new UI.Div();
93-
var lbl = new UI.Text( lastPointIdx + 1 ).setWidth( '20px' );
94-
var txtX = new UI.Number( x ).setRange( 0, Infinity ).setWidth( '40px' ).onChange( update );
95-
var txtY = new UI.Number( y ).setWidth( '40px' ).onChange( update );
96-
var idx = lastPointIdx;
97-
var btn = new UI.Button( '-' ).onClick( function() {
98-
99-
deletePointRow( idx );
100-
101-
} );
102-
103-
pointsUI.push( { row: pointRow, lbl: lbl, x: txtX, y: txtY } );
104-
lastPointIdx ++;
105-
pointRow.add( lbl, txtX, txtY, btn );
106-
107-
return pointRow;
108-
109-
}
110-
111-
function deletePointRow( idx ) {
112-
113-
if ( ! pointsUI[ idx ] ) return;
114-
115-
pointsList.remove( pointsUI[ idx ].row );
116-
pointsUI[ idx ] = null;
117-
118-
update();
119-
120-
}
121-
12256
function update() {
12357

124-
var points = [];
125-
var count = 0;
126-
127-
for ( var i = 0; i < pointsUI.length; i ++ ) {
128-
129-
var pointUI = pointsUI[ i ];
130-
131-
if ( ! pointUI ) continue;
132-
133-
points.push( new THREE.Vector2( pointUI.x.getValue(), pointUI.y.getValue() ) );
134-
count ++;
135-
pointUI.lbl.setValue( count );
136-
137-
}
138-
13958
editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
140-
points,
59+
points.getValue(),
14160
segments.getValue(),
14261
phiStart.getValue() / 180 * Math.PI,
14362
phiLength.getValue() / 180 * Math.PI

editor/js/Sidebar.Geometry.TubeGeometry.js

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,12 @@ Sidebar.Geometry.TubeGeometry = function ( editor, object ) {
1515

1616
// points
1717

18-
var lastPointIdx = 0;
19-
var pointsUI = [];
20-
2118
var pointsRow = new UI.Row();
2219
pointsRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/path' ) ).setWidth( '90px' ) );
2320

24-
var points = new UI.Span().setDisplay( 'inline-block' );
21+
var points = new UI.Points3().setValue( parameters.path.points ).onChange( update );
2522
pointsRow.add( points );
2623

27-
var pointsList = new UI.Div();
28-
points.add( pointsList );
29-
30-
var parameterPoints = parameters.path.points;
31-
for ( var i = 0; i < parameterPoints.length; i ++ ) {
32-
33-
var point = parameterPoints[ i ];
34-
pointsList.add( createPointRow( point.x, point.y, point.z ) );
35-
36-
}
37-
38-
var addPointButton = new UI.Button( '+' ).onClick( function () {
39-
40-
if ( pointsUI.length === 0 ) {
41-
42-
pointsList.add( createPointRow( 0, 0, 0 ) );
43-
44-
} else {
45-
46-
var point = pointsUI[ pointsUI.length - 1 ];
47-
48-
pointsList.add( createPointRow( point.x.getValue(), point.y.getValue(), point.z.getValue() ) );
49-
50-
}
51-
52-
update();
53-
54-
} );
55-
points.add( addPointButton );
56-
5724
container.add( pointsRow );
5825

5926
// radius
@@ -118,25 +85,10 @@ Sidebar.Geometry.TubeGeometry = function ( editor, object ) {
11885

11986
function update() {
12087

121-
var points = [];
122-
var count = 0;
123-
124-
for ( var i = 0; i < pointsUI.length; i ++ ) {
125-
126-
var pointUI = pointsUI[ i ];
127-
128-
if ( ! pointUI ) continue;
129-
130-
points.push( new THREE.Vector3( pointUI.x.getValue(), pointUI.y.getValue(), pointUI.z.getValue() ) );
131-
count ++;
132-
pointUI.lbl.setValue( count );
133-
134-
}
135-
13688
tensionRow.setDisplay( curveType.getValue() == 'catmullrom' ? '' : 'none' );
13789

13890
editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
139-
new THREE.CatmullRomCurve3( points, closed.getValue(), curveType.getValue(), tension.getValue() ),
91+
new THREE.CatmullRomCurve3( points.getValue(), closed.getValue(), curveType.getValue(), tension.getValue() ),
14092
tubularSegments.getValue(),
14193
radius.getValue(),
14294
radialSegments.getValue(),
@@ -145,39 +97,6 @@ Sidebar.Geometry.TubeGeometry = function ( editor, object ) {
14597

14698
}
14799

148-
function createPointRow( x, y, z ) {
149-
150-
var pointRow = new UI.Div();
151-
var lbl = new UI.Text( lastPointIdx + 1 ).setWidth( '20px' );
152-
var txtX = new UI.Number( x ).setWidth( '30px' ).onChange( update );
153-
var txtY = new UI.Number( y ).setWidth( '30px' ).onChange( update );
154-
var txtZ = new UI.Number( z ).setWidth( '30px' ).onChange( update );
155-
var idx = lastPointIdx;
156-
var btn = new UI.Button( '-' ).onClick( function () {
157-
158-
deletePointRow( idx );
159-
160-
} );
161-
162-
pointsUI.push( { row: pointRow, lbl: lbl, x: txtX, y: txtY, z: txtZ } );
163-
lastPointIdx ++;
164-
pointRow.add( lbl, txtX, txtY, txtZ, btn );
165-
166-
return pointRow;
167-
168-
}
169-
170-
function deletePointRow( idx ) {
171-
172-
if ( ! pointsUI[ idx ] ) return;
173-
174-
pointsList.remove( pointsUI[ idx ].row );
175-
pointsUI[ idx ] = null;
176-
177-
update();
178-
179-
}
180-
181100
return container;
182101

183102
};

0 commit comments

Comments
 (0)