diff --git a/src/Add-on/OpenCabinet/OpenCabinet.ts b/src/Add-on/OpenCabinet/OpenCabinet.ts index 248a2e56e..9911d9619 100644 --- a/src/Add-on/OpenCabinet/OpenCabinet.ts +++ b/src/Add-on/OpenCabinet/OpenCabinet.ts @@ -15,7 +15,7 @@ import { Command } from "../../Editor/CommandMachine"; import { PromptStatus } from "../../Editor/PromptResult"; import { userConfig } from "../../Editor/UserConfig"; import { Box3Ext } from "../../Geometry/Box"; -import { XAxis, ZAxis } from "../../Geometry/GeUtils"; +import { XAxis, YAxis, ZAxis } from "../../Geometry/GeUtils"; import { AppToaster } from "../../UI/Components/Toaster"; import { BoardOpenDir } from "../../UI/Store/BoardInterface"; import { IsDoor, IsDrawer, IsHandle, IsLattice } from "../HideSelect/HideSelectUtils"; @@ -24,8 +24,8 @@ const MOVECOUNT = 150; export class Command_OpenCabinet implements Command { - private _MoveDrawerObjs: [Entity[], Matrix4, number][] = []; - private _MoveDoorObjs: [Entity[], Vector3, number, Matrix4][] = []; + private _MoveDrawerObjs: [Entity[], Matrix4, number][] = [];//ents ro_mtx move_dist + private _MoveDoorObjs: [Entity[], Vector3, BoardOpenDir, Vector3][] = [];//ents pos dir rotate(axis) private _Timer: NodeJS.Timeout; private _Count = 0; @@ -128,10 +128,9 @@ export class Command_OpenCabinet implements Command { for (let [box, ens] of boxDrawerMap) { - let roMtx = new Matrix4(); let drawers: Entity[] = ens; let size = box.getSize(new Vector3); - roMtx.extractRotation(ens[0].SpaceOCS); //获得抽屉的旋转分量 + let roMtx = new Matrix4().extractRotation(ens[0].SpaceOCS); //获得抽屉的旋转分量 this._MoveDrawerObjs.push([drawers, roMtx, size.y * 0.8]); } } @@ -218,7 +217,7 @@ export class Command_OpenCabinet implements Command if (en instanceof Dimension) continue; //跳过模板内的标注与其他实体的判断 还有其他情况? - let ocsInv = doorTemp.Entitys[0].SpaceOCSInv; + let ocsInv = doorTemp.Entitys[0].OCSInv; let enBox = en.GetBoundingBoxInMtx(ocsInv); //排钻跟随门板 arrayRemoveIf(holes, (hole) => IsEntityBelongToDoor(enBox, ocsInv, doorGroup, hole)); @@ -270,12 +269,11 @@ export class Command_OpenCabinet implements Command } //门板旋转 - for (let [ents, vector, openDir, rotate] of this._MoveDoorObjs) + for (let [ents, rotatePos, openDir, rotateAxis] of this._MoveDoorObjs) { - let axis = openDir > 2 ? XAxis : ZAxis; - let moveMat = new Matrix4().setPosition(vector); + let moveMat = new Matrix4().setPosition(rotatePos); let moveMatInv = new Matrix4().getInverse(moveMat); - let roMat = new Matrix4().makeRotationAxis(axis.clone().applyMatrix4(new Matrix4().setPosition(0, 0, 0)).applyMatrix4(rotate), MathUtils.degToRad((openDir % 2 === 1) ? -0.6 * dis : 0.6 * dis)); + let roMat = new Matrix4().makeRotationAxis(rotateAxis, MathUtils.degToRad((openDir % 2 === 1) ? -0.6 * dis : 0.6 * dis)); let mtx = moveMat.multiply(roMat).multiply(moveMatInv); for (let en of ents) { @@ -316,7 +314,7 @@ export class Command_OpenCabinet implements Command { for (let i = 0; i < doorGroups.length; i++) { - let osc = (doorGroups[i][0] as Entity).SpaceOCSInv; + let osc = (doorGroups[i][0] as Entity).OCSInv; let brBox = new Box3; for (let en of doorGroups[i]) { @@ -329,25 +327,14 @@ export class Command_OpenCabinet implements Command for (let [box, brs] of boxDoorMap) { - let x = 0; - let y = 0; - let z = 0; - let door: Entity; - - for (let br of brs) - { - if ((br instanceof Board || br instanceof HardwareCompositeEntity) && IsDoor(br)) - { - door = br; - break; - } - } + let door: Entity = brs.find(br => (br instanceof Board || br instanceof HardwareCompositeEntity) && IsDoor(br)); if (!door) continue; - let rotate = new Matrix4().extractRotation(door.SpaceOCS); - let size = box.getCenter(new Vector3()).multiplyScalar(2); + let rotatePos = new Vector3(); + let rotateAxis = XAxis; + let size = box.getSize(new Vector3()); - let openDir = 1; + let openDir = BoardOpenDir.Left; //判断门板开门方向 设置旋转点 if (door instanceof Board) { @@ -355,20 +342,25 @@ export class Command_OpenCabinet implements Command switch (openDir) { case BoardOpenDir.Left: - x = -size.y / 3; - y = size.y * 0.75; + rotatePos.x = size.z / 3; + rotatePos.z = size.z * 0.75; + rotateAxis = YAxis; break; case BoardOpenDir.Right: - x = size.x + size.y / 3; - y = size.y * 0.75; + rotatePos.x = size.x - size.z / 3; + rotatePos.z = size.z * 0.75; + rotateAxis = YAxis; + break; case BoardOpenDir.Up: - z = size.z + size.y * 0.75; - y = size.y * 0.75; + rotatePos.y = size.y - size.z * 0.75; + rotatePos.z = size.z * 0.75; + rotateAxis = XAxis; break; case BoardOpenDir.Down: - z = -size.y * 0.75; - y = size.y * 0.75; + rotatePos.y = size.z * 0.75; + rotatePos.z = size.z * 0.75; + rotateAxis = XAxis; break; default: continue; @@ -379,29 +371,36 @@ export class Command_OpenCabinet implements Command switch (door.HardwareOption.model) { case "左开门板": - x = -size.y / 3; - y = size.y * 0.75; + rotatePos.x = -size.y / 3; + rotatePos.y = size.y * 0.75; + rotateAxis = ZAxis; break; case "右开门板": - x = size.x + size.y / 3; - y = size.y * 0.75; + rotatePos.x = size.x + size.y / 3; + rotatePos.y = size.y * 0.75; openDir = BoardOpenDir.Right; + rotateAxis = ZAxis; break; case "上开门板": - y = size.y * 0.75; - z = size.z + size.y / 3; + rotatePos.y = size.y * 0.75; + rotatePos.z = size.z + size.y / 3; openDir = BoardOpenDir.Up; + rotateAxis = XAxis; break; case "下开门板": - z = -size.y * 0.75; - y = size.y * 0.75; + rotatePos.y = size.y * 0.75; + rotatePos.z = -size.y * 0.75; openDir = BoardOpenDir.Down; + rotateAxis = XAxis; break; default: continue; } } - this._MoveDoorObjs.push([brs, new Vector3(x, y, z).applyMatrix4(door.SpaceOCS), openDir, rotate]); + + rotateAxis = rotateAxis.clone().applyMatrix4(new Matrix4().extractRotation(door.OCSNoClone)); + rotatePos.applyMatrix4(door.OCSNoClone); + this._MoveDoorObjs.push([brs, rotatePos, openDir, rotateAxis]); } } }