1
1
import { RGBColor } from '../model/color.js' ;
2
- import { ConvertColorToThreeColor , DisposeThreeObjects } from '../threejs/threeutils.js' ;
2
+ import { ConvertColorToThreeColor , DisposeThreeObjects , GetLineSegmentsProjectedDistance } from '../threejs/threeutils.js' ;
3
3
4
4
import * as THREE from 'three' ;
5
5
6
+ const LineThresholdInPixels = 10.0 ;
7
+
6
8
export const IntersectionMode =
7
9
{
8
10
MeshOnly : 1 ,
@@ -127,15 +129,13 @@ export class ViewerMainModel
127
129
this . edgeSettings = new EdgeSettings ( false , new RGBColor ( 0 , 0 , 0 ) , 1 ) ;
128
130
this . hasLines = false ;
129
131
this . hasPolygonOffset = false ;
130
- this . fullBoundingBox = null ;
131
132
}
132
133
133
134
SetMainObject ( mainObject )
134
135
{
135
136
this . mainModel . SetRootObject ( mainObject ) ;
136
137
this . hasLines = false ;
137
138
this . hasPolygonOffset = false ;
138
- this . fullBoundingBox = null ;
139
139
140
140
this . EnumerateLines ( ( line ) => {
141
141
this . hasLines = true ;
@@ -200,17 +200,6 @@ export class ViewerMainModel
200
200
this . UpdatePolygonOffset ( ) ;
201
201
}
202
202
203
- GetFullBoundingBox ( )
204
- {
205
- if ( this . fullBoundingBox !== null ) {
206
- return this . fullBoundingBox ;
207
- }
208
- this . fullBoundingBox = this . GetBoundingBox ( ( ) => {
209
- return true ;
210
- } ) ;
211
- return this . fullBoundingBox ;
212
- }
213
-
214
203
GetBoundingBox ( needToProcess )
215
204
{
216
205
let hasMesh = false ;
@@ -311,18 +300,6 @@ export class ViewerMainModel
311
300
312
301
GetMeshIntersectionUnderMouse ( intersectionMode , mouseCoords , camera , width , height )
313
302
{
314
- function CalculateLineThreshold ( mousePos , camera , boundingBoxCenter )
315
- {
316
- let thresholdInScreenCoordinates = 15.0 ;
317
- let frustumRange = camera . far - camera . near ;
318
- let cameraDistanceFromCenter = boundingBoxCenter . distanceTo ( camera . position ) ;
319
- let distanceInFrustumRatio = cameraDistanceFromCenter / frustumRange ;
320
- let zValue = - 1.0 + 2.0 * distanceInFrustumRatio ;
321
- let referencePoint1 = new THREE . Vector3 ( mousePos . x , mousePos . y , zValue ) . unproject ( camera ) ;
322
- let referencePoint2 = new THREE . Vector3 ( mousePos . x + thresholdInScreenCoordinates , mousePos . y , zValue ) . unproject ( camera ) ;
323
- return referencePoint1 . distanceTo ( referencePoint2 ) ;
324
- }
325
-
326
303
if ( this . mainModel . IsEmpty ( ) ) {
327
304
return null ;
328
305
}
@@ -336,16 +313,9 @@ export class ViewerMainModel
336
313
mousePos . y = - ( mouseCoords . y / height ) * 2 + 1 ;
337
314
338
315
let raycaster = new THREE . Raycaster ( ) ;
339
- if ( this . hasLines ) {
340
- let boundingBox = this . GetFullBoundingBox ( ) ;
341
- if ( boundingBox !== null ) {
342
- let boundingBoxCenter = new THREE . Vector3 ( 0.0 , 0.0 , 0.0 ) ;
343
- boundingBox . getCenter ( boundingBoxCenter ) ;
344
- raycaster . params . Line . threshold = CalculateLineThreshold ( mousePos , camera , boundingBoxCenter ) ;
345
- }
346
- }
347
-
348
316
raycaster . setFromCamera ( mousePos , camera ) ;
317
+ raycaster . params . Line . threshold = 10.0 ;
318
+
349
319
let iSectObjects = raycaster . intersectObject ( this . mainModel . GetRootObject ( ) , true ) ;
350
320
for ( let i = 0 ; i < iSectObjects . length ; i ++ ) {
351
321
let iSectObject = iSectObjects [ i ] ;
@@ -355,7 +325,13 @@ export class ViewerMainModel
355
325
if ( intersectionMode === IntersectionMode . MeshOnly && iSectObject . object . isLineSegments ) {
356
326
continue ;
357
327
}
358
- if ( iSectObject . object . isMesh || iSectObject . object . isLineSegments ) {
328
+ if ( iSectObject . object . isMesh ) {
329
+ return iSectObject ;
330
+ } else if ( iSectObject . object . isLineSegments ) {
331
+ let distance = GetLineSegmentsProjectedDistance ( camera , width , height , iSectObject . object , mouseCoords ) ;
332
+ if ( distance > LineThresholdInPixels ) {
333
+ continue ;
334
+ }
359
335
return iSectObject ;
360
336
}
361
337
}
0 commit comments