|
|
|
@ -1,8 +1,11 @@
|
|
|
|
|
import { Box3, Matrix4 } from "three";
|
|
|
|
|
import Flatbush from 'flatbush';
|
|
|
|
|
import { Box3, Matrix4, Vector3 } from "three";
|
|
|
|
|
import { app } from "../ApplicationServices/Application";
|
|
|
|
|
import { Entity } from "../DatabaseServices/Entity/Entity";
|
|
|
|
|
import { Command } from "../Editor/CommandMachine";
|
|
|
|
|
import { PromptStatus } from "../Editor/PromptResult";
|
|
|
|
|
import { comparePoint } from '../Geometry/GeUtils';
|
|
|
|
|
import { HotCMD } from '../Hot/HotCommand';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class Command_M0 implements Command
|
|
|
|
@ -26,3 +29,80 @@ export class Command_M0 implements Command
|
|
|
|
|
e.ApplyMatrix(m);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@HotCMD
|
|
|
|
|
export class Command_PackageMove implements Command
|
|
|
|
|
{
|
|
|
|
|
async exec()
|
|
|
|
|
{
|
|
|
|
|
let ents = app.Database.ModelSpace.Entitys.filter(e => !e.IsErase);
|
|
|
|
|
if (ents.length === 0) return;
|
|
|
|
|
let oents = ents.concat();
|
|
|
|
|
this.PackageMove(ents, oents, 0, 1);
|
|
|
|
|
this.PackageMove(oents.concat(), oents, 1, 2, 5000, 1e10);
|
|
|
|
|
this.PackageMove(oents.concat(), oents, 2, 0, 5000, 1e10);
|
|
|
|
|
app.Viewer.ZoomAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PackageMove(ents: Entity[], oents: Entity[], i1: number, i2: number, i1d = 1000, i2d = 1000)
|
|
|
|
|
{
|
|
|
|
|
for (let i = 0; i < ents.length; i++)
|
|
|
|
|
{
|
|
|
|
|
let en = ents[i];
|
|
|
|
|
en.TempData = { i, b: en.BoundingBox, u: false };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let fb = new Flatbush(ents.length);
|
|
|
|
|
for (let en of ents)
|
|
|
|
|
{
|
|
|
|
|
let box = en.TempData.b as Box3;
|
|
|
|
|
fb.add(box.min.getComponent(i1) - 10, box.min.getComponent(i2) - 10, box.max.getComponent(i1) + 10, box.max.getComponent(i2) + 10);
|
|
|
|
|
}
|
|
|
|
|
fb.finish();
|
|
|
|
|
|
|
|
|
|
let groups: { ens: Entity[], box: Box3; }[] = [];
|
|
|
|
|
while (ents.length)
|
|
|
|
|
{
|
|
|
|
|
let arr = [ents.pop()];
|
|
|
|
|
arr[0].TempData.u = true;
|
|
|
|
|
let b = new Box3;
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < arr.length; i++)
|
|
|
|
|
{
|
|
|
|
|
let e = arr[i];
|
|
|
|
|
b.union(e.TempData.b);
|
|
|
|
|
|
|
|
|
|
let ids = fb.search(b.min.getComponent(i1) - i1d, b.min.getComponent(i2) - i2d, b.max.getComponent(i1) + i1d, b.max.getComponent(i2) + i2d, id => oents[id].TempData.u === false);
|
|
|
|
|
|
|
|
|
|
for (let id of ids)
|
|
|
|
|
{
|
|
|
|
|
let e = oents[id];
|
|
|
|
|
e.TempData.u = true;
|
|
|
|
|
arr.push(e);
|
|
|
|
|
b.union(e.TempData.b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ids.length)
|
|
|
|
|
ents = ents.filter(e => e.TempData.u === false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
groups.push({ ens: arr, box: b });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
groups.sort((g1, g2) => g1.box.min.getComponent(i1) - g2.box.min.getComponent(i1));
|
|
|
|
|
|
|
|
|
|
let movex = new Vector3;
|
|
|
|
|
let size = new Vector3;
|
|
|
|
|
let mmtz = new Matrix4;
|
|
|
|
|
for (let g of groups)
|
|
|
|
|
{
|
|
|
|
|
let b = g.box;
|
|
|
|
|
mmtz.setPosition(b.min.clone().negate().add(movex));
|
|
|
|
|
|
|
|
|
|
movex.setComponent(i1, movex.getComponent(i1) + b.getSize(size).getComponent(i1) + 1000);
|
|
|
|
|
|
|
|
|
|
for (let e of g.ens)
|
|
|
|
|
e.ApplyMatrix(mmtz);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|