@@ -355,8 +355,8 @@ export class MainView extends React.Component<IProps, IStates> {
355
355
} , 100 )
356
356
) ;
357
357
358
- // Setting up the transform controls
359
- this . _transformControls = new TransformControls (
358
+ // Setting up the clip plane transform controls
359
+ this . _clipPlaneTransformControls = new TransformControls (
360
360
this . _camera ,
361
361
this . _renderer . domElement
362
362
) ;
@@ -389,12 +389,15 @@ export class MainView extends React.Component<IProps, IStates> {
389
389
this . _scene . add ( this . _clippingPlaneMeshControl ) ;
390
390
391
391
// Disable the orbit control whenever we do transformation
392
- this . _transformControls . addEventListener ( 'dragging-changed' , event => {
393
- this . _controls . enabled = ! event . value ;
394
- } ) ;
392
+ this . _clipPlaneTransformControls . addEventListener (
393
+ 'dragging-changed' ,
394
+ event => {
395
+ this . _controls . enabled = ! event . value ;
396
+ }
397
+ ) ;
395
398
396
399
// Update the clipping plane whenever the transform UI move
397
- this . _transformControls . addEventListener ( 'change' , ( ) => {
400
+ this . _clipPlaneTransformControls . addEventListener ( 'change' , ( ) => {
398
401
let normal = new THREE . Vector3 ( 0 , 0 , 1 ) ;
399
402
normal = normal . applyEuler ( this . _clippingPlaneMeshControl . rotation ) ;
400
403
@@ -415,13 +418,59 @@ export class MainView extends React.Component<IProps, IStates> {
415
418
)
416
419
) ;
417
420
} ) ;
418
- this . _transformControls . attach ( this . _clippingPlaneMeshControl ) ;
419
- this . _scene . add ( this . _transformControls ) ;
420
421
422
+ this . _clipPlaneTransformControls . attach ( this . _clippingPlaneMeshControl ) ;
423
+ this . _scene . add ( this . _clipPlaneTransformControls ) ;
424
+
425
+ this . _clipPlaneTransformControls . enabled = false ;
426
+ this . _clipPlaneTransformControls . visible = false ;
427
+
428
+ this . _transformControls = new TransformControls (
429
+ this . _camera ,
430
+ this . _renderer . domElement
431
+ ) ;
432
+ // Disable the orbit control whenever we do transformation
433
+ this . _transformControls . addEventListener ( 'dragging-changed' , event => {
434
+ this . _controls . enabled = ! event . value ;
435
+ } ) ;
436
+ // Update the currently transformed object in the shared model once finished moving
437
+ this . _transformControls . addEventListener ( 'mouseUp' , ( ) => {
438
+ const updatedObject = this . _selectedMeshes [ 0 ] ;
439
+ const objectName = updatedObject . name ;
440
+
441
+ const updatedPosition = new THREE . Vector3 ( ) ;
442
+ updatedObject . getWorldPosition ( updatedPosition ) ;
443
+
444
+ const obj = this . _model . sharedModel . getObjectByName ( objectName ) ;
445
+
446
+ if ( obj && obj . parameters && obj . parameters . Placement ) {
447
+ const positionArray = obj ?. parameters ?. Placement ?. Position ;
448
+ const newPosition = [
449
+ positionArray [ 0 ] + updatedPosition . x ,
450
+ positionArray [ 1 ] + updatedPosition . y ,
451
+ positionArray [ 2 ] + updatedPosition . z
452
+ ] ;
453
+
454
+ this . _model . sharedModel . updateObjectByName ( objectName , {
455
+ data : {
456
+ key : 'parameters' ,
457
+ value : {
458
+ ...obj . parameters ,
459
+ Placement : {
460
+ ...obj . parameters . Placement ,
461
+ Position : newPosition
462
+ }
463
+ }
464
+ }
465
+ } ) ;
466
+ }
467
+ } ) ;
468
+ this . _scene . add ( this . _transformControls ) ;
469
+ this . _transformControls . setMode ( 'translate' ) ;
421
470
this . _transformControls . enabled = false ;
422
471
this . _transformControls . visible = false ;
472
+
423
473
this . _createViewHelper ( ) ;
424
- this . _updateTransformControls ( ) ;
425
474
}
426
475
} ;
427
476
@@ -701,10 +750,10 @@ export class MainView extends React.Component<IProps, IStates> {
701
750
event . preventDefault ( ) ;
702
751
event . stopPropagation ( ) ;
703
752
704
- if ( this . _transformControls . mode === 'rotate' ) {
705
- this . _transformControls . setMode ( 'translate' ) ;
753
+ if ( this . _clipPlaneTransformControls . mode === 'rotate' ) {
754
+ this . _clipPlaneTransformControls . setMode ( 'translate' ) ;
706
755
} else {
707
- this . _transformControls . setMode ( 'rotate' ) ;
756
+ this . _clipPlaneTransformControls . setMode ( 'rotate' ) ;
708
757
}
709
758
break ;
710
759
}
@@ -1086,11 +1135,7 @@ export class MainView extends React.Component<IProps, IStates> {
1086
1135
}
1087
1136
1088
1137
// Detach TransformControls from the previous selection
1089
- if ( ! this . _clipSettings . enabled ) {
1090
- {
1091
- this . _transformControls . detach ( ) ;
1092
- }
1093
- }
1138
+ this . _transformControls . detach ( ) ;
1094
1139
}
1095
1140
1096
1141
// Set new selection
@@ -1141,7 +1186,7 @@ export class MainView extends React.Component<IProps, IStates> {
1141
1186
}
1142
1187
}
1143
1188
1144
- if ( selectedNames . length === 1 && ! this . _clipSettings . enabled ) {
1189
+ if ( selectedNames . length === 1 ) {
1145
1190
const selectedMeshName = selectedNames [ 0 ] ;
1146
1191
const matchingChild = this . _meshGroup ?. children . find ( child =>
1147
1192
child . name . startsWith ( selectedMeshName )
@@ -1162,50 +1207,12 @@ export class MainView extends React.Component<IProps, IStates> {
1162
1207
this . _transformControls . position . copy ( positionVector ) ;
1163
1208
}
1164
1209
1165
- this . _transformControls . setMode ( 'translate' ) ;
1166
1210
this . _transformControls . visible = true ;
1167
1211
this . _transformControls . enabled = true ;
1168
1212
}
1169
1213
}
1170
1214
}
1171
1215
1172
- private _updateTransformControls ( ) {
1173
- this . _transformControls . addEventListener ( 'mouseUp' , ( ) => {
1174
- if ( this . _clipSettings . enabled ) {
1175
- return ;
1176
- }
1177
- const updatedObject = this . _selectedMeshes [ 0 ] ;
1178
- const objectName = updatedObject . name ;
1179
-
1180
- const updatedPosition = new THREE . Vector3 ( ) ;
1181
- updatedObject . getWorldPosition ( updatedPosition ) ;
1182
-
1183
- const obj = this . _model . sharedModel . getObjectByName ( objectName ) ;
1184
-
1185
- if ( obj && obj . parameters && obj . parameters . Placement ) {
1186
- const positionArray = obj ?. parameters ?. Placement ?. Position ;
1187
- const newPosition = [
1188
- positionArray [ 0 ] + updatedPosition . x ,
1189
- positionArray [ 1 ] + updatedPosition . y ,
1190
- positionArray [ 2 ] + updatedPosition . z
1191
- ] ;
1192
-
1193
- this . _model . sharedModel . updateObjectByName ( objectName , {
1194
- data : {
1195
- key : 'parameters' ,
1196
- value : {
1197
- ...obj . parameters ,
1198
- Placement : {
1199
- ...obj . parameters . Placement ,
1200
- Position : newPosition
1201
- }
1202
- }
1203
- }
1204
- } ) ;
1205
- }
1206
- } ) ;
1207
- }
1208
-
1209
1216
private _onSharedMetadataChanged = (
1210
1217
_ : IJupyterCadDoc ,
1211
1218
changes : MapChange
@@ -1545,6 +1552,7 @@ export class MainView extends React.Component<IProps, IStates> {
1545
1552
this . _camera . up . copy ( up ) ;
1546
1553
1547
1554
this . _transformControls . camera = this . _camera ;
1555
+ this . _clipPlaneTransformControls . camera = this . _camera ;
1548
1556
1549
1557
const resizeEvent = new Event ( 'resize' ) ;
1550
1558
window . dispatchEvent ( resizeEvent ) ;
@@ -1553,18 +1561,20 @@ export class MainView extends React.Component<IProps, IStates> {
1553
1561
private _updateClipping ( ) {
1554
1562
if ( this . _clipSettings . enabled ) {
1555
1563
this . _renderer . localClippingEnabled = true ;
1556
- this . _transformControls . enabled = true ;
1557
- this . _transformControls . visible = true ;
1558
- this . _transformControls . attach ( this . _clippingPlaneMeshControl ) ;
1559
- this . _transformControls . position . copy ( new THREE . Vector3 ( 0 , 0 , 0 ) ) ;
1564
+ this . _clipPlaneTransformControls . enabled = true ;
1565
+ this . _clipPlaneTransformControls . visible = true ;
1566
+ this . _clipPlaneTransformControls . attach ( this . _clippingPlaneMeshControl ) ;
1567
+ this . _clipPlaneTransformControls . position . copy (
1568
+ new THREE . Vector3 ( 0 , 0 , 0 )
1569
+ ) ;
1560
1570
this . _clippingPlaneMeshControl . visible = this . _clipSettings . showClipPlane ;
1561
1571
if ( this . _clippingPlaneMesh ) {
1562
1572
this . _clippingPlaneMesh . visible = true ;
1563
1573
}
1564
1574
} else {
1565
1575
this . _renderer . localClippingEnabled = false ;
1566
- this . _transformControls . enabled = false ;
1567
- this . _transformControls . visible = false ;
1576
+ this . _clipPlaneTransformControls . enabled = false ;
1577
+ this . _clipPlaneTransformControls . visible = false ;
1568
1578
this . _clippingPlaneMeshControl . visible = false ;
1569
1579
if ( this . _clippingPlaneMesh ) {
1570
1580
this . _clippingPlaneMesh . visible = false ;
@@ -1704,7 +1714,8 @@ export class MainView extends React.Component<IProps, IStates> {
1704
1714
private _controls : OrbitControls ; // Mouse controls
1705
1715
private _hasOrbited = false ; // Whether the last orbit control run has actually orbited
1706
1716
private _disabledNextClick = false ; // We set this when we stop orbiting, to prevent the next click event
1707
- private _transformControls : TransformControls ; // Mesh position/rotation controls
1717
+ private _clipPlaneTransformControls : TransformControls ; // Clip plane position/rotation controls
1718
+ private _transformControls : TransformControls ; // Mesh position controls
1708
1719
private _pointer3D : IPointer | null = null ;
1709
1720
private _clock : THREE . Clock ;
1710
1721
private _targetPosition : THREE . Vector3 | null = null ;
0 commit comments