Add intersection calculation mode.
This commit is contained in:
parent
70497b1fb0
commit
db3f33d52f
@ -73,7 +73,7 @@ import { EmbeddedViewer, Init3DViewerFromUrlList, Init3DViewerFromFileList, Init
|
|||||||
import { MouseInteraction, TouchInteraction, ClickDetector, Navigation, NavigationType } from './viewer/navigation.js';
|
import { MouseInteraction, TouchInteraction, ClickDetector, Navigation, NavigationType } from './viewer/navigation.js';
|
||||||
import { EnvironmentSettings, ShadingModel } from './viewer/shadingmodel.js';
|
import { EnvironmentSettings, ShadingModel } from './viewer/shadingmodel.js';
|
||||||
import { CameraValidator, UpVector, Viewer, GetDefaultCamera, TraverseThreeObject, GetShadingTypeOfObject } from './viewer/viewer.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 {
|
export {
|
||||||
IsDefined,
|
IsDefined,
|
||||||
@ -350,5 +350,6 @@ export {
|
|||||||
ViewerModel,
|
ViewerModel,
|
||||||
EdgeSettings,
|
EdgeSettings,
|
||||||
ViewerMainModel,
|
ViewerMainModel,
|
||||||
SetThreeMeshPolygonOffset
|
SetThreeMeshPolygonOffset,
|
||||||
|
IntersectionMode
|
||||||
};
|
};
|
||||||
|
|||||||
@ -484,19 +484,19 @@ export class Viewer
|
|||||||
this.Render ();
|
this.Render ();
|
||||||
}
|
}
|
||||||
|
|
||||||
GetMeshUserDataUnderMouse (mouseCoords)
|
GetMeshUserDataUnderMouse (intersectionMode, mouseCoords)
|
||||||
{
|
{
|
||||||
let intersection = this.GetMeshIntersectionUnderMouse (mouseCoords);
|
let intersection = this.GetMeshIntersectionUnderMouse (intersectionMode, mouseCoords);
|
||||||
if (intersection === null) {
|
if (intersection === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return intersection.object.userData;
|
return intersection.object.userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetMeshIntersectionUnderMouse (mouseCoords)
|
GetMeshIntersectionUnderMouse (intersectionMode, mouseCoords)
|
||||||
{
|
{
|
||||||
let canvasSize = this.GetCanvasSize ();
|
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) {
|
if (intersection === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,12 @@ import { ConvertColorToThreeColor, DisposeThreeObjects } from '../threejs/threeu
|
|||||||
|
|
||||||
import * as THREE from 'three';
|
import * as THREE from 'three';
|
||||||
|
|
||||||
|
export const IntersectionMode =
|
||||||
|
{
|
||||||
|
MeshOnly : 1,
|
||||||
|
MeshAndLine : 2
|
||||||
|
};
|
||||||
|
|
||||||
export function SetThreeMeshPolygonOffset (mesh, offset)
|
export function SetThreeMeshPolygonOffset (mesh, offset)
|
||||||
{
|
{
|
||||||
function SetMaterialsPolygonOffset (materials, 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)
|
function CalculateLineThreshold (mousePos, camera, boundingBoxCenter)
|
||||||
{
|
{
|
||||||
@ -343,7 +349,13 @@ export class ViewerMainModel
|
|||||||
let iSectObjects = raycaster.intersectObject (this.mainModel.GetRootObject (), true);
|
let iSectObjects = raycaster.intersectObject (this.mainModel.GetRootObject (), true);
|
||||||
for (let i = 0; i < iSectObjects.length; i++) {
|
for (let i = 0; i < iSectObjects.length; i++) {
|
||||||
let iSectObject = iSectObjects[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;
|
return iSectObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { AddSvgIconElement, IsDarkTextNeededForColor } from './utils.js';
|
|||||||
|
|
||||||
import * as THREE from 'three';
|
import * as THREE from 'three';
|
||||||
import { ColorComponentToFloat, RGBColor } from '../engine/model/color.js';
|
import { ColorComponentToFloat, RGBColor } from '../engine/model/color.js';
|
||||||
|
import { IntersectionMode } from '../engine/viewer/viewermodel.js';
|
||||||
|
|
||||||
function GetFaceWorldNormal (intersection)
|
function GetFaceWorldNormal (intersection)
|
||||||
{
|
{
|
||||||
@ -135,8 +136,8 @@ export class MeasureTool
|
|||||||
|
|
||||||
Click (mouseCoordinates)
|
Click (mouseCoordinates)
|
||||||
{
|
{
|
||||||
let intersection = this.viewer.GetMeshIntersectionUnderMouse (mouseCoordinates);
|
let intersection = this.viewer.GetMeshIntersectionUnderMouse (IntersectionMode.MeshOnly, mouseCoordinates);
|
||||||
if (intersection === null || !intersection.object.isMesh) {
|
if (intersection === null) {
|
||||||
this.ClearMarkers ();
|
this.ClearMarkers ();
|
||||||
this.UpdatePanel ();
|
this.UpdatePanel ();
|
||||||
return;
|
return;
|
||||||
@ -152,8 +153,8 @@ export class MeasureTool
|
|||||||
|
|
||||||
MouseMove (mouseCoordinates)
|
MouseMove (mouseCoordinates)
|
||||||
{
|
{
|
||||||
let intersection = this.viewer.GetMeshIntersectionUnderMouse (mouseCoordinates);
|
let intersection = this.viewer.GetMeshIntersectionUnderMouse (IntersectionMode.MeshOnly, mouseCoordinates);
|
||||||
if (intersection === null || !intersection.object.isMesh) {
|
if (intersection === null) {
|
||||||
if (this.tempMarker !== null) {
|
if (this.tempMarker !== null) {
|
||||||
this.tempMarker.Show (false);
|
this.tempMarker.Show (false);
|
||||||
this.viewer.Render ();
|
this.viewer.Render ();
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import { CloseAllDialogs } from './dialog.js';
|
|||||||
import { CreateVerticalSplitter } from './splitter.js';
|
import { CreateVerticalSplitter } from './splitter.js';
|
||||||
import { EnumeratePlugins, PluginType } from './pluginregistry.js';
|
import { EnumeratePlugins, PluginType } from './pluginregistry.js';
|
||||||
import { EnvironmentSettings } from '../engine/viewer/shadingmodel.js';
|
import { EnvironmentSettings } from '../engine/viewer/shadingmodel.js';
|
||||||
|
import { IntersectionMode } from '../engine/viewer/viewermodel.js';
|
||||||
|
|
||||||
const WebsiteUIState =
|
const WebsiteUIState =
|
||||||
{
|
{
|
||||||
@ -316,7 +317,7 @@ export class Website
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let meshUserData = this.viewer.GetMeshUserDataUnderMouse (mouseCoordinates);
|
let meshUserData = this.viewer.GetMeshUserDataUnderMouse (IntersectionMode.MeshAndLine, mouseCoordinates);
|
||||||
if (meshUserData === null) {
|
if (meshUserData === null) {
|
||||||
this.navigator.SetSelection (null);
|
this.navigator.SetSelection (null);
|
||||||
} else {
|
} else {
|
||||||
@ -333,7 +334,7 @@ export class Website
|
|||||||
|
|
||||||
OnModelContextMenu (globalMouseCoordinates, mouseCoordinates)
|
OnModelContextMenu (globalMouseCoordinates, mouseCoordinates)
|
||||||
{
|
{
|
||||||
let meshUserData = this.viewer.GetMeshUserDataUnderMouse (mouseCoordinates);
|
let meshUserData = this.viewer.GetMeshUserDataUnderMouse (IntersectionMode.MeshAndLine, mouseCoordinates);
|
||||||
let items = [];
|
let items = [];
|
||||||
if (meshUserData === null) {
|
if (meshUserData === null) {
|
||||||
items.push ({
|
items.push ({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user