diff --git a/src/Editor/GetRectServices.ts b/src/Editor/GetRectServices.ts index e73401262..4bfca7538 100644 --- a/src/Editor/GetRectServices.ts +++ b/src/Editor/GetRectServices.ts @@ -58,6 +58,7 @@ export class GetRectPointServices let ucsInv = app.m_Editor.UCSMatrixInv; let basePointUCS = basePoint.clone().applyMatrix4(ucsInv); + basePointUCS.z = 0; let signX = 1; let signY = 1; @@ -116,6 +117,7 @@ export class GetRectPointServices p2UCS.x = basePointUCS.x + this.dynPrompt.Width * signX; p2UCS.y = basePointUCS.y + this.dynPrompt.Height * signY; + p2UCS.z = 0; this.UpdateDynPrompt(basePointUCS, p2UCS); } @@ -131,6 +133,7 @@ export class GetRectPointServices signY = Math.sign(res.Point2UCS.y - res.Point1UCS.y); res.Point2UCS.x = res.Point1UCS.x + signX * this.dynPrompt.Width; res.Point2UCS.y = res.Point1UCS.y + signY * this.dynPrompt.Height; + res.Point2UCS.z = 0; res.Point1WCS = basePoint; res.Point2WCS = res.Point2UCS.clone().applyMatrix4(app.m_Editor.UCSMatrix); diff --git a/src/Geometry/GeUtils.ts b/src/Geometry/GeUtils.ts index 2763a30c3..44f3654f2 100644 --- a/src/Geometry/GeUtils.ts +++ b/src/Geometry/GeUtils.ts @@ -1,4 +1,4 @@ -import { Box3, BufferGeometry, Geometry, Matrix4, Object3D, Vector, Vector2, Vector3, Line, Mesh } from 'three'; +import { Box3, BufferGeometry, Geometry, Line, Matrix4, Mesh, Object3D, Vector, Vector2, Vector3 } from 'three'; import { ToFixed } from '../Common/Utils'; import { Matrix2 } from './Matrix2'; @@ -138,6 +138,12 @@ export function isParallelTo(v1: Vector3, v2: Vector3): boolean return v1.clone().cross(v2).lengthSq() < 1e-8; } +//垂直向量 +export function isPerpendicularityTo(v1: Vector3, v2: Vector3) +{ + return equaln(v1.dot(v2), 0, 1e-8); +} + export function ptToString(v: Vector3, fractionDigits: number = 3): string { return v.toArray().map(o => ToFixed(o, fractionDigits)).join(","); diff --git a/src/GraphicsSystem/Viewer.ts b/src/GraphicsSystem/Viewer.ts index f218f6911..073add795 100644 --- a/src/GraphicsSystem/Viewer.ts +++ b/src/GraphicsSystem/Viewer.ts @@ -1,4 +1,4 @@ -import { EffectComposer, Matrix4, Object3D, OutlinePass, RenderPass, Scene, Vector2, Vector3, WebGLRenderer, SMAAPass } from 'three'; +import { EffectComposer, Matrix4, Object3D, OutlinePass, RenderPass, Scene, SMAAPass, Vector2, Vector3, WebGLRenderer } from 'three'; import * as xaop from 'xaop'; import { end } from 'xaop'; import { app } from '../ApplicationServices/Application'; @@ -7,12 +7,12 @@ import { Database } from '../DatabaseServices/Database'; import { Entity } from '../DatabaseServices/Entity'; import { GenerateRaycaster } from '../Editor/PointPick'; import { CheckFilter } from '../Editor/SelectFilter'; -import { cZeroVec, GetBox, GetBoxArr } from '../Geometry/GeUtils'; +import { userConfig } from '../Editor/UserConfig'; +import { cZeroVec, GetBox, GetBoxArr, isPerpendicularityTo } from '../Geometry/GeUtils'; import { PlaneExt } from '../Geometry/Plane'; import { CameraUpdate } from './CameraUpdate'; import { GripScene } from './GripScene'; import { PreViewer } from './PreViewer'; -import { userConfig } from '../Editor/UserConfig'; //导入其他js模块 require("three-CopyShader"); @@ -186,13 +186,18 @@ export class Viewer this.m_Render.render(this.Scene, this.Camera); } - ScreenToWorld(pt: Vector3, planNormal?: Vector3, constant?: number | Vector3) + ScreenToWorld(pt: Vector3, planNormal?: Vector3, constant?: Vector3) { + if (!constant) + constant = new Vector3().setFromMatrixColumn(app.m_Editor.UCSMatrix, 3); + if (!planNormal) + planNormal = new Vector3().setFromMatrixColumn(app.m_Editor.UCSMatrix, 2); + + if (isPerpendicularityTo(this.m_CameraCtrl.Direction, planNormal)) + planNormal = this.m_CameraCtrl.Direction; + //变换和求交点 - let plan = new PlaneExt( - (planNormal === undefined) ? new Vector3().setFromMatrixColumn(app.m_Editor.UCSMatrix, 2) : planNormal, - (constant === undefined) ? new Vector3().setFromMatrixColumn(app.m_Editor.UCSMatrix, 3) : constant - ); + let plan = new PlaneExt(planNormal, constant); let raycaster = GenerateRaycaster(pt, this); plan.intersectRay(raycaster.ray, pt, true); return pt;