@@ -245,85 +245,82 @@ export default class ThreeDEngine {
245245 / this . renderer . domElement . width
246246 ) * 2 - 1 ;
247247
248- if ( event . button === 0 ) {
249- // only for left click
250- if ( this . pickingEnabled ) {
251- const intersects = this . getIntersectedObjects ( ) ;
252-
253- if ( intersects . length > 0 ) {
254- // sort intersects
255- const compare = function ( a , b ) {
256- if ( a . distance < b . distance ) {
257- return - 1 ;
258- }
259- if ( a . distance > b . distance ) {
260- return 1 ;
261- }
262- return 0 ;
248+ if ( this . pickingEnabled ) {
249+ const intersects = this . getIntersectedObjects ( ) ;
250+
251+ if ( intersects . length > 0 ) {
252+ // sort intersects
253+ const compare = function ( a , b ) {
254+ if ( a . distance < b . distance ) {
255+ return - 1 ;
263256 }
264- intersects . sort ( compare ) ;
257+ if ( a . distance > b . distance ) {
258+ return 1 ;
259+ }
260+ return 0 ;
265261 }
262+ intersects . sort ( compare ) ;
263+ }
266264
267- let selectedMap = { } ;
268- // Iterate and get the first visible item (they are now ordered by proximity)
269- for ( let i = 0 ; i < intersects . length ; i ++ ) {
270- // figure out if the entity is visible
271- let instancePath = '' ;
272- let externalMeshId = null ;
273- let geometryIdentifier = '' ;
274- if (
275- Object . prototype . hasOwnProperty . call (
276- intersects [ i ] . object ,
277- 'instancePath'
278- )
279- ) {
280- instancePath = intersects [ i ] . object . instancePath ;
281- geometryIdentifier
282- = intersects [ i ] . object . geometryIdentifier ;
283- } else if ( Object . prototype . hasOwnProperty . call (
284- intersects [ i ] . object . parent ,
285- 'instancePath'
286- ) ) {
287- instancePath = intersects [ i ] . object . parent . instancePath ;
288- geometryIdentifier
289- = intersects [ i ] . object . parent . geometryIdentifier ;
290- }
291- else {
292- externalMeshId = intersects [ i ] . object . uuid
293- geometryIdentifier = null
294- }
265+ let selectedMap = { } ;
266+ // Iterate and get the first visible item (they are now ordered by proximity)
267+ for ( let i = 0 ; i < intersects . length ; i ++ ) {
268+ // figure out if the entity is visible
269+ let instancePath = '' ;
270+ let externalMeshId = null ;
271+ let geometryIdentifier = '' ;
272+ if (
273+ Object . prototype . hasOwnProperty . call (
274+ intersects [ i ] . object ,
275+ 'instancePath'
276+ )
277+ ) {
278+ instancePath = intersects [ i ] . object . instancePath ;
279+ geometryIdentifier
280+ = intersects [ i ] . object . geometryIdentifier ;
281+ } else if ( Object . prototype . hasOwnProperty . call (
282+ intersects [ i ] . object . parent ,
283+ 'instancePath'
284+ ) ) {
285+ instancePath = intersects [ i ] . object . parent . instancePath ;
286+ geometryIdentifier
287+ = intersects [ i ] . object . parent . geometryIdentifier ;
288+ }
289+ else {
290+ externalMeshId = intersects [ i ] . object . uuid
291+ geometryIdentifier = null
292+ }
295293
296- if (
297- ( instancePath != null
298- && Object . prototype . hasOwnProperty . call (
299- this . meshFactory . meshes ,
300- instancePath
301- ) )
302- || Object . prototype . hasOwnProperty . call (
303- this . meshFactory . splitMeshes ,
304- instancePath
305- )
306- ) {
307- if ( ! ( instancePath in selectedMap ) ) {
308- selectedMap [ instancePath ] = {
309- ...intersects [ i ] ,
310- geometryIdentifier : geometryIdentifier ,
311- distanceIndex : i ,
312- } ;
313- }
294+ if (
295+ ( instancePath != null
296+ && Object . prototype . hasOwnProperty . call (
297+ this . meshFactory . meshes ,
298+ instancePath
299+ ) )
300+ || Object . prototype . hasOwnProperty . call (
301+ this . meshFactory . splitMeshes ,
302+ instancePath
303+ )
304+ ) {
305+ if ( ! ( instancePath in selectedMap ) ) {
306+ selectedMap [ instancePath ] = {
307+ ...intersects [ i ] ,
308+ geometryIdentifier : geometryIdentifier ,
309+ distanceIndex : i ,
310+ } ;
314311 }
315- if ( externalMeshId != null ) {
316- if ( ! ( externalMeshId in selectedMap ) ) {
317- selectedMap [ externalMeshId ] = {
318- ... intersects [ i ] ,
319- distanceIndex : i ,
320- } ;
321- }
312+ }
313+ if ( externalMeshId != null ) {
314+ if ( ! ( externalMeshId in selectedMap ) ) {
315+ selectedMap [ externalMeshId ] = {
316+ ... intersects [ i ] ,
317+ distanceIndex : i ,
318+ } ;
322319 }
323320 }
324- this . requestFrame ( ) ;
325- this . onSelection ( this . selectionStrategy ( selectedMap ) )
326321 }
322+ this . requestFrame ( ) ;
323+ this . onSelection ( this . selectionStrategy ( selectedMap ) , event )
327324 }
328325 }
329326 }
0 commit comments