@@ -306,6 +306,13 @@ export const MeasurementMixin = (superclass) =>
306
306
307
307
if ( intersectItem . type === "Mesh" ) {
308
308
const isAlreadySelected = intersectItem . userData . selected ;
309
+
310
+ // Get atom position and draw coordinates if enabled
311
+ const position = new THREE . Vector3 ( ) . setFromMatrixPosition (
312
+ intersectItem . matrixWorld ,
313
+ ) ;
314
+ this . drawCoordinateText ( position , intersectItem ) ;
315
+
309
316
if ( this . measurementSettings . isDistanceShown )
310
317
this . addIfLastNotSame ( intersectItem ) ;
311
318
if ( this . measurementSettings . isAnglesShown )
@@ -347,7 +354,17 @@ export const MeasurementMixin = (superclass) =>
347
354
getIntersectedObjects ( event ) {
348
355
this . checkMouseCoordinates ( event ) ;
349
356
const atomGroup = this . getAtomGroups ( ) ;
350
- const searchedIntersects = [ ...atomGroup ] ;
357
+ const searchedIntersects = [ ] ;
358
+
359
+ // Always include atoms if any measurement type is enabled
360
+ if (
361
+ this . measurementSettings . isDistanceShown ||
362
+ this . measurementSettings . isAnglesShown ||
363
+ this . measurementSettings . isCoordinatesShown
364
+ ) {
365
+ searchedIntersects . push ( ...atomGroup ) ;
366
+ }
367
+
351
368
if ( this . measurementSettings . isDistanceShown ) {
352
369
searchedIntersects . push ( ...this . atomConnections . children ) ;
353
370
}
@@ -544,6 +561,13 @@ export const MeasurementMixin = (superclass) =>
544
561
atom . userData . selected = false ;
545
562
this . selectedAtoms . pop ( ) ;
546
563
atom . material . emissive . setHex ( atom . currentHex ) ;
564
+
565
+ // Remove coordinate label if it exists
566
+ if ( atom . userData . coordinateLabel ) {
567
+ this . measurementLabels . remove ( atom . userData . coordinateLabel ) ;
568
+ atom . userData . coordinateLabel = null ;
569
+ }
570
+
547
571
this . render ( ) ;
548
572
}
549
573
}
@@ -627,11 +651,16 @@ export const MeasurementMixin = (superclass) =>
627
651
this . deleteConnection ( ) ;
628
652
} ) ;
629
653
}
630
-
631
654
if ( this . selectedAtoms . length ) {
632
655
this . selectedAtoms . forEach ( ( atom ) => {
633
656
atom . userData . selected = false ;
634
657
atom . material . emissive . setHex ( atom . currentHex ) ;
658
+
659
+ // Remove coordinate labels
660
+ if ( atom . userData . coordinateLabel ) {
661
+ this . measurementLabels . remove ( atom . userData . coordinateLabel ) ;
662
+ atom . userData . coordinateLabel = null ;
663
+ }
635
664
} ) ;
636
665
this . selectedAtoms = [ ] ;
637
666
}
@@ -683,4 +712,43 @@ export const MeasurementMixin = (superclass) =>
683
712
684
713
return this . radiansToDegrees ( Math . acos ( angle ) ) . toFixed ( 2 ) ;
685
714
}
715
+
716
+ /**
717
+ * Function that draws coordinate text.
718
+ * @param {THREE.Vector3 } position - position of the atom
719
+ * @param {Object } atom - the atom object
720
+ */
721
+ drawCoordinateText ( position , atom ) {
722
+ // Remove existing coordinate label if it exists
723
+ if ( atom . userData . coordinateLabel ) {
724
+ this . measurementLabels . remove ( atom . userData . coordinateLabel ) ;
725
+ }
726
+
727
+ // Only show coordinates if coordinate measurement is enabled
728
+ if ( ! this . measurementSettings . isCoordinatesShown ) {
729
+ return ;
730
+ }
731
+
732
+ const label = this . createLabelSprite (
733
+ `(${ position . x . toFixed ( 3 ) } , ${ position . y . toFixed ( 3 ) } , ${ position . z . toFixed ( 3 ) } )` ,
734
+ `coordinates-for-${ atom . uuid } ` ,
735
+ ) ;
736
+
737
+ // Position the label up and to the right of the atom
738
+ const labelPosition = position . clone ( ) ;
739
+ labelPosition . y += 0.0 ;
740
+ labelPosition . x += 0.0 ;
741
+
742
+ label . position . copy ( labelPosition ) ;
743
+ label . visible = true ;
744
+ label . scale . set ( 1.0 , 1.0 , 1.0 ) ;
745
+ label . lookAt ( this . camera . position ) ;
746
+
747
+ // Store reference to label in atom's userData
748
+ atom . userData . coordinateLabel = label ;
749
+
750
+ this . measurementLabels . add ( label ) ;
751
+ this . scene . add ( this . measurementLabels ) ;
752
+ this . render ( ) ;
753
+ }
686
754
} ;
0 commit comments