@@ -582,6 +582,76 @@ export class MeshLayer extends PerspectiveViewRenderLayer<ThreeDimensionalRender
582
582
) ;
583
583
return ready ;
584
584
}
585
+
586
+ getObjectPosition (
587
+ id : Uint64 ,
588
+ nearestTo : Float32Array ,
589
+ ) : Float32Array | undefined {
590
+ const transform = this . displayState . transform . value ;
591
+ if ( transform . error !== undefined ) return undefined ;
592
+ const chunk = this . source . chunks . get ( getObjectKey ( id ) ) ;
593
+ if ( chunk === undefined ) return undefined ;
594
+ const { rank } = transform ;
595
+ const inverseModelToRenderLayerTransform = new Float32Array (
596
+ transform . modelToRenderLayerTransform . length ,
597
+ ) ;
598
+ matrix . inverse (
599
+ inverseModelToRenderLayerTransform ,
600
+ rank + 1 ,
601
+ transform . modelToRenderLayerTransform ,
602
+ rank + 1 ,
603
+ rank + 1 ,
604
+ ) ;
605
+ const nearestPositionInModal = new Float32Array ( rank ) ;
606
+ matrix . transformPoint (
607
+ nearestPositionInModal ,
608
+ inverseModelToRenderLayerTransform ,
609
+ rank + 1 ,
610
+ nearestTo ,
611
+ rank ,
612
+ ) ;
613
+ const { fragmentIds } = chunk ;
614
+ const closestVertex = new Float32Array ( rank ) ;
615
+ let closestDistanceSq = Number . POSITIVE_INFINITY ;
616
+ for ( const fragmentId of fragmentIds ) {
617
+ const fragmentChunk = this . source . fragmentSource . chunks . get ( fragmentId ) ;
618
+ if ( fragmentChunk === undefined ) continue ;
619
+ const { state, meshData } = fragmentChunk ;
620
+ if (
621
+ state !== ChunkState . SYSTEM_MEMORY &&
622
+ state !== ChunkState . GPU_MEMORY
623
+ ) {
624
+ continue ;
625
+ }
626
+ const { vertexPositions } = meshData ;
627
+ if ( vertexPositions . length < rank ) continue ;
628
+ for ( let i = 0 ; i < vertexPositions . length ; i += rank ) {
629
+ let distanceSq = 0 ;
630
+ for ( let j = 0 ; j < rank ; j ++ ) {
631
+ distanceSq += Math . pow (
632
+ vertexPositions [ i + j ] - nearestPositionInModal [ j ] ,
633
+ 2 ,
634
+ ) ;
635
+ }
636
+ if ( distanceSq < closestDistanceSq ) {
637
+ closestDistanceSq = distanceSq ;
638
+ for ( let j = 0 ; j < rank ; j ++ ) {
639
+ closestVertex [ j ] = vertexPositions [ i + j ] ;
640
+ }
641
+ }
642
+ }
643
+ }
644
+ if ( closestDistanceSq === Number . POSITIVE_INFINITY ) return undefined ;
645
+ const layerCenter = new Float32Array ( rank ) ;
646
+ matrix . transformPoint (
647
+ layerCenter ,
648
+ transform . modelToRenderLayerTransform ,
649
+ rank + 1 ,
650
+ closestVertex ,
651
+ rank ,
652
+ ) ;
653
+ return layerCenter ;
654
+ }
585
655
}
586
656
587
657
export class ManifestChunk extends Chunk {
0 commit comments