Add intersection calculation mode.

This commit is contained in:
kovacsv 2023-12-26 13:11:55 +01:00
parent 70497b1fb0
commit db3f33d52f
5 changed files with 29 additions and 14 deletions

View File

@ -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
};

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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 ();

View File

@ -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 ({