Skip to content

Commit

Permalink
Add intersection calculation mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacsv committed Dec 26, 2023
1 parent 70497b1 commit db3f33d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
5 changes: 3 additions & 2 deletions source/engine/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -350,5 +350,6 @@ export {
ViewerModel,
EdgeSettings,
ViewerMainModel,
SetThreeMeshPolygonOffset
SetThreeMeshPolygonOffset,
IntersectionMode
};
8 changes: 4 additions & 4 deletions source/engine/viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 14 additions & 2 deletions source/engine/viewer/viewermodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -303,7 +309,7 @@ export class ViewerMainModel
}
}

GetMeshIntersectionUnderMouse (mouseCoords, camera, width, height)
GetMeshIntersectionUnderMouse (intersectionMode, mouseCoords, camera, width, height)
{
function CalculateLineThreshold (mousePos, camera, boundingBoxCenter)
{
Expand Down Expand Up @@ -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;
}
}
Expand Down
9 changes: 5 additions & 4 deletions source/website/measuretool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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 ();
Expand Down
5 changes: 3 additions & 2 deletions source/website/website.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
{
Expand Down Expand Up @@ -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 {
Expand All @@ -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 ({
Expand Down

0 comments on commit db3f33d

Please sign in to comment.