diff --git a/source/engine/main.js b/source/engine/main.js index b58b3cfb..91a6deb0 100644 --- a/source/engine/main.js +++ b/source/engine/main.js @@ -73,7 +73,7 @@ import { EmbeddedViewer, Init3DViewerFromUrlList, Init3DViewerFromFileList, Init import { MouseInteraction, TouchInteraction, ClickDetector, Navigation, NavigationType } from './viewer/navigation.js'; import { EnvironmentSettings, ShadingModel } from './viewer/shadingmodel.js'; import { CameraValidator, UpVector, Viewer, GetDefaultCamera, TraverseThreeObject, GetShadingTypeOfObject } from './viewer/viewer.js'; -import { ViewerModel, EdgeSettings, ViewerMainModel, SetThreeMeshPolygonOffset } from './viewer/viewermodel.js'; +import { ViewerModel, EdgeSettings, ViewerMainModel, SetThreeMeshPolygonOffset, IntersectionMode } from './viewer/viewermodel.js'; export { IsDefined, @@ -350,5 +350,6 @@ export { ViewerModel, EdgeSettings, ViewerMainModel, - SetThreeMeshPolygonOffset + SetThreeMeshPolygonOffset, + IntersectionMode }; diff --git a/source/engine/viewer/viewer.js b/source/engine/viewer/viewer.js index 8bd7c51f..789c01d0 100644 --- a/source/engine/viewer/viewer.js +++ b/source/engine/viewer/viewer.js @@ -484,19 +484,19 @@ export class Viewer this.Render (); } - GetMeshUserDataUnderMouse (mouseCoords) + GetMeshUserDataUnderMouse (intersectionMode, mouseCoords) { - let intersection = this.GetMeshIntersectionUnderMouse (mouseCoords); + let intersection = this.GetMeshIntersectionUnderMouse (intersectionMode, mouseCoords); if (intersection === null) { return null; } return intersection.object.userData; } - GetMeshIntersectionUnderMouse (mouseCoords) + GetMeshIntersectionUnderMouse (intersectionMode, mouseCoords) { let canvasSize = this.GetCanvasSize (); - let intersection = this.mainModel.GetMeshIntersectionUnderMouse (mouseCoords, this.camera, canvasSize.width, canvasSize.height); + let intersection = this.mainModel.GetMeshIntersectionUnderMouse (intersectionMode, mouseCoords, this.camera, canvasSize.width, canvasSize.height); if (intersection === null) { return null; } diff --git a/source/engine/viewer/viewermodel.js b/source/engine/viewer/viewermodel.js index b8454cf0..0e128c57 100644 --- a/source/engine/viewer/viewermodel.js +++ b/source/engine/viewer/viewermodel.js @@ -3,6 +3,12 @@ import { ConvertColorToThreeColor, DisposeThreeObjects } from '../threejs/threeu import * as THREE from 'three'; +export const IntersectionMode = +{ + MeshOnly : 1, + MeshAndLine : 2 +}; + export function SetThreeMeshPolygonOffset (mesh, offset) { function SetMaterialsPolygonOffset (materials, offset) @@ -303,7 +309,7 @@ export class ViewerMainModel } } - GetMeshIntersectionUnderMouse (mouseCoords, camera, width, height) + GetMeshIntersectionUnderMouse (intersectionMode, mouseCoords, camera, width, height) { function CalculateLineThreshold (mousePos, camera, boundingBoxCenter) { @@ -343,7 +349,13 @@ export class ViewerMainModel let iSectObjects = raycaster.intersectObject (this.mainModel.GetRootObject (), true); for (let i = 0; i < iSectObjects.length; i++) { let iSectObject = iSectObjects[i]; - if ((iSectObject.object.isMesh || iSectObject.object.isLineSegments) && iSectObject.object.visible) { + if (!iSectObject.object.visible) { + continue; + } + if (intersectionMode === IntersectionMode.MeshOnly && iSectObject.object.isLineSegments) { + continue; + } + if (iSectObject.object.isMesh || iSectObject.object.isLineSegments) { return iSectObject; } } diff --git a/source/website/measuretool.js b/source/website/measuretool.js index f86ed78c..73426084 100644 --- a/source/website/measuretool.js +++ b/source/website/measuretool.js @@ -4,6 +4,7 @@ import { AddSvgIconElement, IsDarkTextNeededForColor } from './utils.js'; import * as THREE from 'three'; import { ColorComponentToFloat, RGBColor } from '../engine/model/color.js'; +import { IntersectionMode } from '../engine/viewer/viewermodel.js'; function GetFaceWorldNormal (intersection) { @@ -135,8 +136,8 @@ export class MeasureTool Click (mouseCoordinates) { - let intersection = this.viewer.GetMeshIntersectionUnderMouse (mouseCoordinates); - if (intersection === null || !intersection.object.isMesh) { + let intersection = this.viewer.GetMeshIntersectionUnderMouse (IntersectionMode.MeshOnly, mouseCoordinates); + if (intersection === null) { this.ClearMarkers (); this.UpdatePanel (); return; @@ -152,8 +153,8 @@ export class MeasureTool MouseMove (mouseCoordinates) { - let intersection = this.viewer.GetMeshIntersectionUnderMouse (mouseCoordinates); - if (intersection === null || !intersection.object.isMesh) { + let intersection = this.viewer.GetMeshIntersectionUnderMouse (IntersectionMode.MeshOnly, mouseCoordinates); + if (intersection === null) { if (this.tempMarker !== null) { this.tempMarker.Show (false); this.viewer.Render (); diff --git a/source/website/website.js b/source/website/website.js index 8e4729f4..c75450c4 100644 --- a/source/website/website.js +++ b/source/website/website.js @@ -27,6 +27,7 @@ import { CloseAllDialogs } from './dialog.js'; import { CreateVerticalSplitter } from './splitter.js'; import { EnumeratePlugins, PluginType } from './pluginregistry.js'; import { EnvironmentSettings } from '../engine/viewer/shadingmodel.js'; +import { IntersectionMode } from '../engine/viewer/viewermodel.js'; const WebsiteUIState = { @@ -316,7 +317,7 @@ export class Website return; } - let meshUserData = this.viewer.GetMeshUserDataUnderMouse (mouseCoordinates); + let meshUserData = this.viewer.GetMeshUserDataUnderMouse (IntersectionMode.MeshAndLine, mouseCoordinates); if (meshUserData === null) { this.navigator.SetSelection (null); } else { @@ -333,7 +334,7 @@ export class Website OnModelContextMenu (globalMouseCoordinates, mouseCoordinates) { - let meshUserData = this.viewer.GetMeshUserDataUnderMouse (mouseCoordinates); + let meshUserData = this.viewer.GetMeshUserDataUnderMouse (IntersectionMode.MeshAndLine, mouseCoordinates); let items = []; if (meshUserData === null) { items.push ({