功能:矩形光的拉伸实现

pull/1767/head
ChenX 3 years ago
parent b8f57b49a4
commit 4c95c9a68d

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

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

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

Loading…
Cancel
Save