From 4c95c9a68d5bae0eaa2c34a3592a6557b927072a Mon Sep 17 00:00:00 2001 From: ChenX Date: Fri, 17 Dec 2021 10:48:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD:=E7=9F=A9=E5=BD=A2=E5=85=89?= =?UTF-8?q?=E7=9A=84=E6=8B=89=E4=BC=B8=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DatabaseServices/Entity/Entity.ts | 17 ++++ src/DatabaseServices/Lights/RectAreaLight.ts | 94 ++++++++++++++++++-- src/Editor/GripDragServices.ts | 5 ++ 3 files changed, 110 insertions(+), 6 deletions(-) diff --git a/src/DatabaseServices/Entity/Entity.ts b/src/DatabaseServices/Entity/Entity.ts index bb71f5d33..e1ca480f3 100644 --- a/src/DatabaseServices/Entity/Entity.ts +++ b/src/DatabaseServices/Entity/Entity.ts @@ -7,6 +7,7 @@ import { UpdateDraw } from '../../Common/Status'; import { ObjectSnapMode } from '../../Editor/ObjectSnapMode'; import { Box3Ext } from '../../Geometry/Box'; import { equaln, equalv3, GetBox, IdentityMtx4, UpdateBoundingSphere } from '../../Geometry/GeUtils'; +import { Vec3 } from '../../Geometry/IVec3'; import { IntersectOption } from '../../GraphicsSystem/IntersectWith'; import { RenderType } from '../../GraphicsSystem/RenderType'; import { AutoRecord } from '../AutoRecord'; @@ -179,6 +180,22 @@ export class Entity extends CADObject return new Vector3().setFromMatrixPosition(this._Matrix); } + Move(v: Vec3) + { + if (equaln(v.x, 0) && equaln(v.y, 0) && equaln(v.z, 0)) return; + + this.WriteAllObjectRecord(); + + this._Matrix.elements[12] += v.x; + this._Matrix.elements[13] += v.y; + this._Matrix.elements[14] += v.z; + + this._SpaceOCS.elements[12] += v.x; + this._SpaceOCS.elements[13] += v.y; + this._SpaceOCS.elements[14] += v.z; + this.Update(UpdateDraw.Matrix); + } + set Position(pt: Vector3) { let moveX = pt.x - this._Matrix.elements[12]; diff --git a/src/DatabaseServices/Lights/RectAreaLight.ts b/src/DatabaseServices/Lights/RectAreaLight.ts index 15c237c2d..44b7f897e 100644 --- a/src/DatabaseServices/Lights/RectAreaLight.ts +++ b/src/DatabaseServices/Lights/RectAreaLight.ts @@ -10,7 +10,7 @@ import { ObjectId } from "../ObjectId"; import { Light } from "./Light"; import { RectAreaLightHelper } from "./RectAreaLightHelper"; -const TARGET_DISTANCE = -1000; +const TARGET_DISTANCE = -100; @Factory export class RectAreaLight extends Light @@ -54,10 +54,10 @@ export class RectAreaLight extends Light let pos = this.Position; let pts: Vector3[] = [ - new Vector3(-widthHalf, -heightHalf, 0).applyMatrix4(this.OCSNoClone), - new Vector3(widthHalf, -heightHalf, 0).applyMatrix4(this.OCSNoClone), - new Vector3(widthHalf, heightHalf, 0).applyMatrix4(this.OCSNoClone), - new Vector3(-widthHalf, heightHalf, 0).applyMatrix4(this.OCSNoClone), + new Vector3(-widthHalf, -heightHalf, 0).applyMatrix4(this.OCSNoClone),//左下 + new Vector3(widthHalf, -heightHalf, 0).applyMatrix4(this.OCSNoClone),//右下 + new Vector3(widthHalf, heightHalf, 0).applyMatrix4(this.OCSNoClone),//右上 + new Vector3(-widthHalf, heightHalf, 0).applyMatrix4(this.OCSNoClone),//左上 pos, pos.clone().add(this.Normal.multiplyScalar(TARGET_DISTANCE)) ]; @@ -111,12 +111,94 @@ export class RectAreaLight extends Light } else if (i === 5) { - this.Target = this.Target.add(vec); + let target = this.Position.add(this.Normal.multiplyScalar(TARGET_DISTANCE)).add(vec); + this.Target = target; this.lookAtTarget(); } } + + GetStretchPoints() + { + let heightHalf = this._Height * 0.5; + let widthHalf = this.Width * 0.5; + let pos = this.Position; + + let pts: Vector3[] = [ + new Vector3(-widthHalf, -heightHalf, 0).applyMatrix4(this.OCSNoClone),//左下 + new Vector3(widthHalf, -heightHalf, 0).applyMatrix4(this.OCSNoClone),//右下 + new Vector3(widthHalf, heightHalf, 0).applyMatrix4(this.OCSNoClone),//右上 + new Vector3(-widthHalf, heightHalf, 0).applyMatrix4(this.OCSNoClone),//左上 + pos.clone().add(this.Normal.multiplyScalar(TARGET_DISTANCE)) + ]; + return pts; + } + MoveStretchPoints(ids: number[], vec: Vector3) + { + if (ids.length === 4 || ids.length === 3) + { + this.Move(vec); + return; + } + else if (ids.length === 1) + { + let i = ids[0]; + if (i < 4) + this.MoveGripPoints(ids, vec); + else + this.MoveGripPoints([5], vec); + } + else//===2 + { + ids.sort((a1, a2) => a1 - a2); + let inv = this.OCSInv.setPosition(0, 0, 0); + vec = vec.clone().applyMatrix4(inv); + let ocs = inv.copy(this._Matrix).setPosition(0, 0, 0); + + if (ids[0] === 0) + { + if (ids[1] === 1)//下 + { + vec.x = 0; + vec.z = 0; + vec.applyMatrix4(ocs); + + this.MoveGripPoints([0], vec); + } + else if (ids[1] === 3)//左 + { + vec.y = 0; + vec.z = 0; + vec.applyMatrix4(ocs); + this.MoveGripPoints([0], vec); + } + } + else if (ids[0] === 1) + { + if (ids[1] === 2)//右 + { + vec.y = 0; + vec.z = 0; + vec.applyMatrix4(ocs); + this.MoveGripPoints([1], vec); + } + } + else if (ids[0] === 2) + { + if (ids[1] === 3)//上 + { + vec.x = 0; + vec.z = 0; + vec.applyMatrix4(ocs); + + this.MoveGripPoints([2], vec); + } + } + } + } + lookAtTarget() { + this.WriteAllObjectRecord(); this._Matrix.lookAt(this.Position, this.Target, YAxis); this.Update(UpdateDraw.Matrix); } diff --git a/src/Editor/GripDragServices.ts b/src/Editor/GripDragServices.ts index bb2f04b49..627ee4e92 100644 --- a/src/Editor/GripDragServices.ts +++ b/src/Editor/GripDragServices.ts @@ -7,6 +7,7 @@ import { MouseKey } from '../Common/KeyEnum'; import { GetEntity } from '../Common/Utils'; import { Entity } from '../DatabaseServices/Entity/Entity'; import { Line } from '../DatabaseServices/Entity/Line'; +import { RectAreaLight } from '../DatabaseServices/Lights/RectAreaLight'; import { SpotLight } from '../DatabaseServices/Lights/SpotLight'; import { BufferGeometryUtils } from '../Geometry/BufferGeometryUtils'; import { isParallelTo, isPerpendicularityTo, SnapPoint } from '../Geometry/GeUtils'; @@ -161,6 +162,10 @@ export class GripDragServices implements EditorService { baseP = snapIndexMap[0].ent.Position; } + else if (snapIndexMap[0].ent instanceof RectAreaLight && snapIndexMap[0].indexArr[0] === 5) + { + baseP = snapIndexMap[0].ent.Position; + } } //修改UCS