mirror of https://gitee.com/cf-fz/WebCAD.git
parent
d45ecf7e85
commit
ed9e0432e1
@ -1,63 +1,59 @@
|
|||||||
import { app } from '../ApplicationServices/Application';
|
import { Command } from "../Editor/CommandMachine";
|
||||||
import { Curve } from '../DatabaseServices/Curve';
|
import { Region } from "../DatabaseServices/Region";
|
||||||
import { Region } from '../DatabaseServices/Region';
|
import { app } from "../ApplicationServices/Application";
|
||||||
import { Command } from '../Editor/CommandMachine';
|
import { Vector3 } from "three";
|
||||||
import { SelectSet } from '../Editor/SelectSet';
|
import { Line } from "../DatabaseServices/Line";
|
||||||
import { Vector3 } from 'three';
|
import { Curve } from "../DatabaseServices/Curve";
|
||||||
import { RegionParse } from '../Geometry/RegionParse';
|
import { CreateRegion } from "../Geometry/RegionAlg";
|
||||||
|
import { SelectSet } from "../Editor/SelectSet";
|
||||||
|
import { Circle } from "../DatabaseServices/Circle";
|
||||||
|
import { Ellipse } from "../DatabaseServices/Ellipse";
|
||||||
|
import { Polyline } from "../DatabaseServices/Polyline";
|
||||||
|
import { Arc } from "../DatabaseServices/Arc";
|
||||||
|
import { RegionParse, Route } from '../Geometry/RegionParse';
|
||||||
|
|
||||||
export class DrawRegion implements Command
|
export class DrawRegion implements Command
|
||||||
{
|
{
|
||||||
async exec(ss: SelectSet)
|
async exec(ss: SelectSet)
|
||||||
{
|
{
|
||||||
let cus: Curve[] = [];
|
let lines: Curve[] = [];
|
||||||
for (let o of ss.SelectObjectList)
|
|
||||||
|
for (let en of ss.SelectEntityList)
|
||||||
{
|
{
|
||||||
if (o.userData && o.userData instanceof Curve)
|
if (en instanceof Circle || en instanceof Ellipse)
|
||||||
{
|
{
|
||||||
cus.push(o.userData);
|
let reg = new Region([en.Clone() as Curve]);
|
||||||
|
app.m_Database.ModelSpace.Append(reg);
|
||||||
}
|
}
|
||||||
|
else if (en instanceof Curve)
|
||||||
|
{
|
||||||
|
lines.push(en.Clone() as Curve);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
console.log(cus.length);
|
if (lines.length > 0)
|
||||||
let str = cus.map(cu =>
|
|
||||||
{
|
{
|
||||||
console.log(`new Vector3().fromArray([${cu.StartPoint.toArray()}]), new Vector3().fromArray([${cu.EndPoint.toArray()}])`);
|
let reg = new RegionParse(lines);
|
||||||
}).join("\n")
|
|
||||||
|
|
||||||
let alg = new RegionParse(cus);
|
for (let routes of reg.m_RegionsOutline)
|
||||||
for (let r of alg.m_RegionsOutline)
|
|
||||||
{
|
{
|
||||||
let re = new Region();
|
this.AddToModelSpace(routes);
|
||||||
r.forEach(route => re.reg.add(route.curve));
|
|
||||||
|
|
||||||
re.ColorIndex = 1;
|
|
||||||
|
|
||||||
app.m_Database.ModelSpace.Append(re);
|
|
||||||
}
|
}
|
||||||
|
for (let routes of reg.m_RegionsInternal)
|
||||||
for (let r of alg.m_RegionsInternal)
|
|
||||||
{
|
{
|
||||||
let re = new Region();
|
this.AddToModelSpace(routes);
|
||||||
r.forEach(route => re.reg.add(route.curve));
|
}
|
||||||
re.ColorIndex = 2;
|
app.m_Editor.UpdateScreen();
|
||||||
|
|
||||||
app.m_Database.ModelSpace.Append(re);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
// for (let r of regs[0])
|
AddToModelSpace(routeS: Set<Route>)
|
||||||
// {
|
{
|
||||||
// let reg = new Region();
|
let cus: Curve[] = [];
|
||||||
// reg.reg = r;
|
for (let r of routeS)
|
||||||
// app.m_Database.ModelSpace.Append(reg);
|
{
|
||||||
// }
|
cus.push(r.curve);
|
||||||
|
}
|
||||||
// for (let r of regs[1])
|
let reg = new Region(cus);
|
||||||
// {
|
app.m_Database.ModelSpace.Append(reg);
|
||||||
// let reg = new Region();
|
|
||||||
// reg.reg = r;
|
|
||||||
// app.m_Database.ModelSpace.Append(reg);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
import { Command } from '../Editor/CommandMachine';
|
||||||
|
import { SelectSet } from '../Editor/SelectSet';
|
||||||
|
import { Polyline } from '../DatabaseServices/Polyline';
|
||||||
|
import { app } from '../ApplicationServices/Application';
|
||||||
|
|
||||||
|
export class Command_RevPl implements Command
|
||||||
|
{
|
||||||
|
async exec(ss: SelectSet)
|
||||||
|
{
|
||||||
|
|
||||||
|
let pls: Polyline[] = [];
|
||||||
|
for (let en of ss.SelectEntityList)
|
||||||
|
{
|
||||||
|
if (en instanceof Polyline)
|
||||||
|
{
|
||||||
|
pls.push(en);
|
||||||
|
en.Reverse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.m_Editor.UpdateScreen();
|
||||||
|
}
|
||||||
|
}
|
@ -1,99 +1,152 @@
|
|||||||
import { Object3D, ShapeGeometry, Vector3 } from 'three';
|
|
||||||
import * as THREE from 'three';
|
import * as THREE from 'three';
|
||||||
|
import { Object3D, ShapeGeometry, Vector3, Vector2 } from 'three';
|
||||||
|
|
||||||
|
import { CreateBoardUtil } from '../ApplicationServices/mesh/createBoard';
|
||||||
import { RenderType } from '../GraphicsSystem/Enum';
|
import { RenderType } from '../GraphicsSystem/Enum';
|
||||||
|
import { Arc } from './Arc';
|
||||||
import { Factory } from './CADFactory';
|
import { Factory } from './CADFactory';
|
||||||
|
import { CADFile } from './CADFile';
|
||||||
import { Circle } from './Circle';
|
import { Circle } from './Circle';
|
||||||
import { Curve } from './Curve';
|
import { Curve } from './Curve';
|
||||||
|
import { Ellipse } from './Ellipse';
|
||||||
import { Entity } from './Entity';
|
import { Entity } from './Entity';
|
||||||
import { Line } from './Line';
|
import { Line } from './Line';
|
||||||
import { ColorMaterial } from '../Common/ColorPalette';
|
import { Polyline } from './Polyline';
|
||||||
|
import { begin } from 'xaop';
|
||||||
|
|
||||||
|
const fuzz = 1e-8;
|
||||||
|
|
||||||
@Factory
|
@Factory
|
||||||
export class Region extends Entity
|
export class Region extends Entity
|
||||||
{
|
{
|
||||||
reg: Set<Curve> = new Set<Curve>();
|
private m_CuList: Array<Curve> = [];
|
||||||
constructor()
|
private m_Shape: THREE.Shape;
|
||||||
|
constructor(curveList?: Array<Curve>)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
}
|
|
||||||
|
|
||||||
|
if (curveList)
|
||||||
|
this.m_CuList.push(...curveList);
|
||||||
|
}
|
||||||
Draw(renderType: RenderType): Object3D
|
Draw(renderType: RenderType): Object3D
|
||||||
{
|
{
|
||||||
if (this.reg.size === 0)
|
let obj = super.Draw(renderType);
|
||||||
return;
|
if (obj) return obj;
|
||||||
let shape = new THREE.Shape();
|
|
||||||
|
|
||||||
let begin = new Vector3();
|
this.m_Shape = new THREE.Shape();
|
||||||
let end = new Vector3();
|
|
||||||
let n = 0;
|
|
||||||
|
|
||||||
|
let begin: Vector3;
|
||||||
|
|
||||||
let lines = [];
|
if (this.m_CuList.length > 1)
|
||||||
for (let l of this.reg)
|
|
||||||
{
|
{
|
||||||
lines.push(l);
|
let firstL = this.m_CuList[0];
|
||||||
}
|
let seconL = this.m_CuList[1];
|
||||||
let firstL = lines[0];
|
|
||||||
let seconL = lines[1];
|
if (firstL.StartPoint.distanceTo(seconL.StartPoint) < fuzz
|
||||||
if (firstL.StartPoint.distanceTo(seconL.StartPoint) < 0.1
|
|| firstL.StartPoint.distanceTo(seconL.EndPoint) < fuzz
|
||||||
|| firstL.StartPoint.distanceTo(seconL.EndPoint) < 0.1
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
begin.copy(firstL.EndPoint);
|
begin = firstL.EndPoint;
|
||||||
end.copy(firstL.StartPoint);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
begin.copy(firstL.StartPoint);
|
begin = firstL.StartPoint;
|
||||||
end.copy(firstL.EndPoint);
|
}
|
||||||
|
this.m_Shape.moveTo(begin.x, begin.y);
|
||||||
}
|
}
|
||||||
for (let i = 0; i < lines.length; i++)
|
|
||||||
|
for (let cu of this.m_CuList)
|
||||||
{
|
{
|
||||||
let cu = lines[i];
|
|
||||||
if (cu instanceof Line)
|
if (cu instanceof Line)
|
||||||
{
|
{
|
||||||
if (i !== 0)
|
if (cu.StartPoint.distanceTo(begin) < fuzz)
|
||||||
|
begin = cu.EndPoint;
|
||||||
|
else
|
||||||
|
begin = cu.StartPoint;
|
||||||
|
|
||||||
|
this.m_Shape.lineTo(begin.x, begin.y);
|
||||||
|
}
|
||||||
|
else if (cu instanceof Circle)
|
||||||
{
|
{
|
||||||
if (end.distanceTo(cu.StartPoint) < 0.1)
|
this.m_Shape.absarc(cu.Center.x, cu.Center.y, cu.Radius, 0, 2 * Math.PI, true);
|
||||||
|
}
|
||||||
|
else if (cu instanceof Ellipse)
|
||||||
{
|
{
|
||||||
begin.copy(cu.StartPoint);
|
this.m_Shape.absellipse(cu.Center.x, cu.Center.y, cu.RadX, cu.RadY, 0, Math.PI * 2, true, cu.Angle);
|
||||||
end.copy(cu.EndPoint);
|
|
||||||
}
|
}
|
||||||
else
|
else if (cu instanceof Polyline)
|
||||||
|
{
|
||||||
|
if (cu.EndPoint.distanceTo(begin) < fuzz)
|
||||||
|
cu.Reverse();
|
||||||
|
|
||||||
|
let plData = cu.LineData;
|
||||||
|
let pts: Vector2[] = [];
|
||||||
|
let bul: number[] = [];
|
||||||
|
for (let d of plData)
|
||||||
{
|
{
|
||||||
begin.copy(cu.EndPoint);
|
pts.push(d.pt);
|
||||||
end.copy(cu.StartPoint);
|
bul.push(d.bul);
|
||||||
}
|
}
|
||||||
|
CreateBoardUtil.createPath(pts, bul, this.m_Shape);
|
||||||
|
|
||||||
|
begin = cu.EndPoint;
|
||||||
}
|
}
|
||||||
shape.moveTo(begin.x, begin.y);
|
else if (cu instanceof Arc)
|
||||||
shape.lineTo(end.x, end.y);
|
{
|
||||||
|
//起点和终点影响开始角度,结束角度和法向量
|
||||||
|
if (begin.distanceTo(cu.StartPoint) < 0.1)
|
||||||
|
this.m_Shape.absarc(cu.Center.x, cu.Center.y, cu.Radius, cu.StartAngle, cu.EndAngle, cu.Normal.z < 0);
|
||||||
|
else
|
||||||
|
this.m_Shape.absarc(cu.Center.x, cu.Center.y, cu.Radius, cu.EndAngle, cu.StartAngle, cu.Normal.z > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// shape.absarc(i.Center.x, i.Center.y, i.Radius, 0, 2 * Math.PI, true);
|
|
||||||
|
|
||||||
|
let geometry = new ShapeGeometry(this.m_Shape, 60);
|
||||||
|
let material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
|
||||||
|
|
||||||
let geometry = new ShapeGeometry(shape, 60);
|
let mesh = new THREE.Mesh(geometry, material);
|
||||||
let mesh = new THREE.Mesh(geometry, ColorMaterial.GetLineMaterial(this.m_Color));
|
|
||||||
this.m_DrawEntity.set(renderType, mesh);
|
this.m_DrawEntity.set(renderType, mesh);
|
||||||
mesh.userData = this;
|
mesh.userData = this;
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
// Update()
|
|
||||||
// {
|
|
||||||
// for (let [, obj] of this.m_DrawEntity)
|
|
||||||
// {
|
|
||||||
// let mesh = (<THREE.Mesh>obj);
|
|
||||||
|
|
||||||
// mesh.updateMorphTargets();
|
|
||||||
|
|
||||||
// }
|
//在移动时应用矩阵变换
|
||||||
// }
|
|
||||||
ApplyMatrix(m: THREE.Matrix4)
|
ApplyMatrix(m: THREE.Matrix4)
|
||||||
{
|
{
|
||||||
|
this.WriteAllObjectRecord();
|
||||||
|
for (let cu of this.m_CuList)
|
||||||
|
{
|
||||||
|
cu.ApplyMatrix(m);
|
||||||
|
}
|
||||||
for (let [, en] of this.m_DrawEntity)
|
for (let [, en] of this.m_DrawEntity)
|
||||||
{
|
{
|
||||||
en.applyMatrix(m);
|
en.applyMatrix(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//读写文件
|
||||||
|
ReadFile(file: CADFile)
|
||||||
|
{
|
||||||
|
super.ReadFile(file);
|
||||||
|
let ver = file.Read();//1
|
||||||
|
let cout = file.Read();
|
||||||
|
this.m_CuList.length = 0;
|
||||||
|
for (let i = 0; i < cout; i++)
|
||||||
|
{
|
||||||
|
let obj = file.ReadObject(undefined) as Curve;
|
||||||
|
this.m_CuList.push(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//对象将自身数据写入到文件.
|
||||||
|
WriteFile(file: CADFile)
|
||||||
|
{
|
||||||
|
super.WriteFile(file);
|
||||||
|
file.Write(1);//ver
|
||||||
|
file.Write(this.m_CuList.length);
|
||||||
|
for (let i of this.m_CuList)
|
||||||
|
{
|
||||||
|
file.WriteObject(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue