优化Stretch和DragGrip性能,并对(板件,排钻实体)进行特殊优化. fix #IWF6X

pull/298/head
ChenX 5 years ago
parent 62c729e507
commit 3a41e564b1

@ -8,7 +8,7 @@
"url": "http://localhost:7778", "url": "http://localhost:7778",
"webRoot": "${workspaceFolder}", "webRoot": "${workspaceFolder}",
"skipFiles": [ "skipFiles": [
// "*.js" //.js,js "*.dll.js" //.js,js
] ]
}, },
//Ref: https://github.com/Microsoft/vscode-recipes/blob/master/debugging-jest-tests/.vscode/launch.json //Ref: https://github.com/Microsoft/vscode-recipes/blob/master/debugging-jest-tests/.vscode/launch.json

@ -55,10 +55,10 @@ test('循环引用', () =>
this.ref = id; this.ref = id;
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
let ver = file.Read(); let ver = file.Read();
super.ReadFile(file); super._ReadFile(file);
this.ref = file.ReadObjectId(); this.ref = file.ReadObjectId();
} }

@ -2,7 +2,6 @@
import { Line } from '../../src/DatabaseServices/Line'; import { Line } from '../../src/DatabaseServices/Line';
import { Vector3 } from 'three'; import { Vector3 } from 'three';
test('直线参数', () => test('直线参数', () =>
{ {

@ -1,10 +1,8 @@
import * as THREE from 'three'; import { Matrix4 } from 'three';
import { app } from '../ApplicationServices/Application'; import { app } from '../ApplicationServices/Application';
import { Command } from '../Editor/CommandMachine'; import { Command } from '../Editor/CommandMachine';
import { PromptStatus } from '../Editor/PromptResult';
import { MoveMatrix } from '../Geometry/GeUtils';
import { JigUtils } from '../Editor/JigUtils'; import { JigUtils } from '../Editor/JigUtils';
// import { IsEntity } from '../Common/Utils'; import { PromptStatus } from '../Editor/PromptResult';
export class Command_Move implements Command export class Command_Move implements Command
{ {
@ -23,14 +21,17 @@ export class Command_Move implements Command
let ptBase = ptRes.Point; let ptBase = ptRes.Point;
let ptLast = ptBase.clone(); let ptLast = ptBase.clone();
let moveMatrix = new Matrix4();
ptRes = await app.m_Editor.GetPoint( ptRes = await app.m_Editor.GetPoint(
{ {
Msg: "请点击移动终点:", Msg: "请点击移动终点:",
Callback: (p: THREE.Vector3) => Callback: (p: THREE.Vector3) =>
{ {
let moveMatrix = MoveMatrix(p.clone().sub(ptLast)); moveMatrix.setPosition(p.clone().sub(ptLast));
ensClone.forEach(e => e.ApplyMatrix(moveMatrix)); for (let ent of ensClone)
ent.ApplyMatrix(moveMatrix);
ptLast.copy(p); ptLast.copy(p);
// //对调试实体进行移动 // //对调试实体进行移动
// for (let obj of ssRes.SelectSet.SelectObjectList) // for (let obj of ssRes.SelectSet.SelectObjectList)
// { // {
@ -44,9 +45,9 @@ export class Command_Move implements Command
if (ptRes.Status === PromptStatus.OK) if (ptRes.Status === PromptStatus.OK)
{ {
let moveM = MoveMatrix(ptRes.Point.clone().sub(ptBase)); moveMatrix.setPosition(ptRes.Point.clone().sub(ptBase));
for (let en of ens) for (let en of ens)
en.ApplyMatrix(moveM); en.ApplyMatrix(moveMatrix);
} }
} }
} }

@ -1,20 +1,18 @@
import * as THREE from 'three'; import { Matrix4, Vector3 } from 'three';
import { app } from '../ApplicationServices/Application'; import { app } from '../ApplicationServices/Application';
import { Board } from '../DatabaseServices/Board';
import { Entity } from '../DatabaseServices/Entity'; import { Entity } from '../DatabaseServices/Entity';
import { Command } from '../Editor/CommandMachine'; import { Command } from '../Editor/CommandMachine';
import { JigUtils } from '../Editor/JigUtils'; import { Jig } from '../Editor/Jig';
import { PromptStatus } from '../Editor/PromptResult'; import { PromptStatus } from '../Editor/PromptResult';
import { SelectBox, SelectType } from '../Editor/SelectBox'; import { SelectBox, SelectType } from '../Editor/SelectBox';
import { SelectPick } from '../Editor/SelectPick'; import { SelectPick } from '../Editor/SelectPick';
import { SelectSet } from '../Editor/SelectSet'; import { SelectSet } from '../Editor/SelectSet';
import { MoveMatrix } from '../Geometry/GeUtils';
//拉伸的解析数据 //拉伸的解析数据
interface StretchData interface StretchData
{ {
moveEntityList: Entity[];//被移动的图元(所有点都被选中) moveEntityList: Entity[];//被移动的图元(所有点都被选中)
stretchEntityMap: { Ent: Entity, Indexs: Array<number> }[]; //被拉伸的图元,对照被拉伸的点索引. stretchEntityMap: { ent: Entity, indexs: Array<number> }[]; //被拉伸的图元,对照被拉伸的点索引.
} }
export class Stretch implements Command export class Stretch implements Command
@ -29,19 +27,27 @@ export class Stretch implements Command
let ss = ssRes.SelectSet; let ss = ssRes.SelectSet;
let data = this.Parse(ss); let data = this.Parse(ss);
let moveJig = new Jig();
let stretchJig = new Jig();
let dataClone: StretchData = let dataClone: StretchData =
{ {
moveEntityList: data.moveEntityList.map(e => JigUtils.Draw(e)), moveEntityList: data.moveEntityList.map(e => moveJig.Draw(e)),
stretchEntityMap: data.stretchEntityMap.map(v => stretchEntityMap: data.stretchEntityMap.map(v =>
{ {
let jigEntity = stretchJig.Draw(v.ent, true);
jigEntity.AutoUpdate = false;//避免Jig Restore时更新对象
return { return {
Ent: JigUtils.Draw(v.Ent, v.Ent instanceof Board), ent: jigEntity,
Indexs: v.Indexs indexs: v.indexs
} };
}) })
} };
let lastP = p1.Point; let lastStretchPoint = p1.Point;
let lastMovePoint = lastStretchPoint;
let moveMatrix = new Matrix4();
let p2 = await app.m_Editor.GetPoint( let p2 = await app.m_Editor.GetPoint(
{ {
BasePoint: p1.Point, BasePoint: p1.Point,
@ -49,25 +55,28 @@ export class Stretch implements Command
Msg: "指定第二个点:",//或 <使用第一个点作为位移> Msg: "指定第二个点:",//或 <使用第一个点作为位移>
Callback: (p) => Callback: (p) =>
{ {
p = p.clone(); stretchJig.Restore();
JigUtils.Restore(); let moveVector = p.clone().sub(lastMovePoint);
let v = p.sub(lastP); let stretchVector = p.clone().sub(lastStretchPoint);
this.Stretch(dataClone, v); moveMatrix.setPosition(moveVector);
this.Stretch(dataClone, stretchVector, moveMatrix);
lastMovePoint = p.clone();
} }
}); });
if (p2.Status === PromptStatus.OK) if (p2.Status === PromptStatus.OK)
this.Stretch(data, p2.Point.sub(lastP)); {
let stretchVector = p2.Point.sub(lastStretchPoint);
moveMatrix.setPosition(stretchVector);
this.Stretch(data, stretchVector, moveMatrix);
}
JigUtils.End(); moveJig.End();
stretchJig.End();
} }
/** /**
* ,,. * ,,.
*
* @param {SelectSet} ss
* @returns {StretchData}
* @memberof Stretch
*/ */
Parse(ss: SelectSet): StretchData Parse(ss: SelectSet): StretchData
{ {
@ -107,7 +116,7 @@ export class Stretch implements Command
if (indexArr.length === pts.length) if (indexArr.length === pts.length)
data.moveEntityList.push(en); data.moveEntityList.push(en);
else else
data.stretchEntityMap.push({ Ent: en, Indexs: indexArr }); data.stretchEntityMap.push({ ent: en, indexs: indexArr });
} }
} }
} }
@ -115,16 +124,14 @@ export class Stretch implements Command
} }
return data; return data;
} }
Stretch(d: StretchData, vec: THREE.Vector3) Stretch(d: StretchData, stretchVector: Vector3, moveMatrix: Matrix4)
{ {
let moveMat = MoveMatrix(vec); for (let ent of d.moveEntityList)
for (let e of d.moveEntityList) ent.ApplyMatrix(moveMatrix);
{ for (let { ent, indexs } of d.stretchEntityMap)
e.ApplyMatrix(moveMat);
}
for (let { Ent, Indexs } of d.stretchEntityMap)
{ {
Ent.MoveStretchPoints(Indexs, vec); ent.MoveStretchPoints(indexs, stretchVector);
ent.DeferUpdate();
} }
} }
} }

@ -69,9 +69,9 @@ export class Cylineder extends Solid3D
(obj.geometry as Geometry).verticesNeedUpdate = true; (obj.geometry as Geometry).verticesNeedUpdate = true;
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read();//1 let ver = file.Read();//1
this.m_Radius = file.Read(); this.m_Radius = file.Read();
this.m_Height = file.Read(); this.m_Height = file.Read();

@ -1,5 +1,8 @@
import * as THREE from 'three'; import * as THREE from 'three';
import { ExtrudeGeometry, MeshNormalMaterial, Object3D, Vector3, LineSegments, Group } from "three"; import { BufferGeometry, ExtrudeGeometry, Group, LineSegments, MeshNormalMaterial, Object3D, Vector3 } from "three";
import { ColorMaterial } from '../../Common/ColorPalette';
import { DisposeThreeObj } from '../../Common/Dispose';
import { FastDrillingEdgeGeometry } from '../../Geometry/CreateWireframe';
import { RenderType } from "../../GraphicsSystem/RenderType"; import { RenderType } from "../../GraphicsSystem/RenderType";
import { Factory } from '../CADFactory'; import { Factory } from '../CADFactory';
import { CADFiler } from '../CADFiler'; import { CADFiler } from '../CADFiler';
@ -7,9 +10,6 @@ import { Circle } from '../Circle';
import { Contour } from '../Contour'; import { Contour } from '../Contour';
import { Shape } from '../Shape'; import { Shape } from '../Shape';
import { Solid3D } from "./Solid3D"; import { Solid3D } from "./Solid3D";
import { EdgesGeometry } from '../../Geometry/EdgeGeometry';
import { ColorMaterial } from '../../Common/ColorPalette';
import { DisposeThreeObj } from '../../Common/Dispose';
export enum GangDrillType export enum GangDrillType
{ {
@ -75,14 +75,31 @@ export class GangDrill extends Solid3D
{ {
return this.BoundingBox.intersectsBox(tarDrill.BoundingBox); return this.BoundingBox.intersectsBox(tarDrill.BoundingBox);
} }
CreateGeometry(): ExtrudeGeometry
private _MeshGeometry: ExtrudeGeometry;
private get MeshGeometry()
{ {
if (this._MeshGeometry)
return this._MeshGeometry;
let extrudeSettings = { let extrudeSettings = {
bevelEnabled: false, bevelEnabled: false,
depth: this.m_Height depth: this.m_Height
}; };
return new ExtrudeGeometry(this.m_Shape.Shape, extrudeSettings) this._MeshGeometry = new ExtrudeGeometry(this.m_Shape.Shape, extrudeSettings);
return this._MeshGeometry;
}
private _EdgeGeometry: BufferGeometry;
private get EdgeGeometry()
{
if (this._EdgeGeometry)
return this._EdgeGeometry;
this._EdgeGeometry = FastDrillingEdgeGeometry(this.m_Shape.Shape, this.Height);
return this._EdgeGeometry;
} }
InitDrawObject(renderType: RenderType) InitDrawObject(renderType: RenderType)
{ {
return new Group().add(this.GetObject3DByRenderType(renderType)); return new Group().add(this.GetObject3DByRenderType(renderType));
@ -90,11 +107,9 @@ export class GangDrill extends Solid3D
private GetObject3DByRenderType(renderType: RenderType) private GetObject3DByRenderType(renderType: RenderType)
{ {
if (renderType === RenderType.Wireframe) if (renderType === RenderType.Wireframe)
{ return new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(this.ColorIndex));
return new LineSegments(new EdgesGeometry().FromGeometry(this.CreateGeometry(), 2), ColorMaterial.GetLineMaterial(this.ColorIndex));
}
else else
return new THREE.Mesh(this.CreateGeometry(), new MeshNormalMaterial()); return new THREE.Mesh(this.MeshGeometry, new MeshNormalMaterial());
} }
UpdateDrawObject(type: RenderType, obj: Object3D) UpdateDrawObject(type: RenderType, obj: Object3D)
{ {
@ -102,9 +117,9 @@ export class GangDrill extends Solid3D
obj.add(this.GetObject3DByRenderType(type)); obj.add(this.GetObject3DByRenderType(type));
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read();//1 let ver = file.Read();//1
this.m_Shape = new Shape(); this.m_Shape = new Shape();
this.m_Shape.ReadFile(file); this.m_Shape.ReadFile(file);
@ -113,7 +128,6 @@ export class GangDrill extends Solid3D
this.type = file.Read(); this.type = file.Read();
else else
this.type = GangDrillType.Drill; this.type = GangDrillType.Drill;
this.Update();
} }
WriteFile(file: CADFiler) WriteFile(file: CADFiler)
{ {

@ -173,9 +173,9 @@ export class SweepSolid extends Solid3D
this.m_PathCurve.MoveStretchPoints(indexList, vec); this.m_PathCurve.MoveStretchPoints(indexList, vec);
this.Update(); this.Update();
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read();//1 let ver = file.Read();//1
this.m_Contour = file.ReadObject() as Polyline; this.m_Contour = file.ReadObject() as Polyline;
this.m_PathCurve = file.ReadObject() as Curve; this.m_PathCurve = file.ReadObject() as Curve;

@ -743,9 +743,9 @@ export class Arc extends Curve
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
if (ver === 1) if (ver === 1)
{ {
@ -756,7 +756,6 @@ export class Arc extends Curve
this.m_StartAngle = file.Read(); this.m_StartAngle = file.Read();
this.m_EndAngle = file.Read(); this.m_EndAngle = file.Read();
this.m_Clockwise = file.Read(); this.m_Clockwise = file.Read();
this.Update();
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file: CADFiler) WriteFile(file: CADFiler)

@ -532,9 +532,9 @@ export class Board extends ExtureSolid
return boardUVGenerator2; return boardUVGenerator2;
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.m_SpecOCS.fromArray(file.Read()); this.m_SpecOCS.fromArray(file.Read());
this.m_BoardType = file.Read(); this.m_BoardType = file.Read();
@ -577,7 +577,6 @@ export class Board extends ExtureSolid
this.layerNails.push(objId); this.layerNails.push(objId);
} }
} }
this.Update();
} }
WriteFile(file: CADFiler) WriteFile(file: CADFiler)
{ {

@ -363,12 +363,11 @@ export class Circle extends Curve
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.m_Radius = file.Read(); this.m_Radius = file.Read();
this.Update();
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file: CADFiler) WriteFile(file: CADFiler)

@ -290,16 +290,15 @@ export class LineAngularDimension extends Entity
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.m_L1StartPoint.fromArray(file.Read()); this.m_L1StartPoint.fromArray(file.Read());
this.m_L1EndPoint.fromArray(file.Read()); this.m_L1EndPoint.fromArray(file.Read());
this.m_L2StartPoint.fromArray(file.Read()); this.m_L2StartPoint.fromArray(file.Read());
this.m_L2EndPoint.fromArray(file.Read()); this.m_L2EndPoint.fromArray(file.Read());
this.m_DimPoint.fromArray(file.Read()); this.m_DimPoint.fromArray(file.Read());
this.Update();
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file: CADFiler) WriteFile(file: CADFiler)

@ -260,15 +260,14 @@ export class AlignedDimension extends Entity
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.m_ArmP1.fromArray(file.Read()); this.m_ArmP1.fromArray(file.Read());
this.m_ArmP2.fromArray(file.Read()); this.m_ArmP2.fromArray(file.Read());
this.m_FootP1.fromArray(file.Read()); this.m_FootP1.fromArray(file.Read());
this.m_FootP2.fromArray(file.Read()); this.m_FootP2.fromArray(file.Read());
this.Update();
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file: CADFiler) WriteFile(file: CADFiler)

@ -187,14 +187,13 @@ export class RadiusDimension extends Entity
this.MoveGripPoints(indexList, vec); this.MoveGripPoints(indexList, vec);
} }
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.startPt.fromArray(file.Read()); this.startPt.fromArray(file.Read());
this.center.fromArray(file.Read()); this.center.fromArray(file.Read());
this.endPt.fromArray(file.Read()); this.endPt.fromArray(file.Read());
this.Update();
} }
WriteFile(file: CADFiler) WriteFile(file: CADFiler)
{ {

@ -138,9 +138,9 @@ export class Ellipse extends Curve
this.Center = p; this.Center = p;
} }
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.RadX = file.Read(); this.RadX = file.Read();
this.RadY = file.Read(); this.RadY = file.Read();

@ -141,6 +141,7 @@ export class Entity extends CADObject
let obj = this._CacheDrawObject.get(RenderType.Jig); let obj = this._CacheDrawObject.get(RenderType.Jig);
if (obj) if (obj)
{ {
this._CacheDrawObject.delete(RenderType.Jig);
DisposeThreeObj(obj); DisposeThreeObj(obj);
if (obj.parent) if (obj.parent)
obj.parent.remove(obj); obj.parent.remove(obj);
@ -199,8 +200,12 @@ export class Entity extends CADObject
if (mode === 0) return; if (mode === 0) return;
this.UpdateVisible(); this.UpdateVisible();
let isJigIng = this._CacheDrawObject.has(RenderType.Jig);
for (let [type, en] of this._CacheDrawObject) for (let [type, en] of this._CacheDrawObject)
{ {
if (isJigIng && type !== RenderType.Jig)
continue;
if (mode & UpdateDraw.Geometry) if (mode & UpdateDraw.Geometry)
this.UpdateDrawObject(type, en); this.UpdateDrawObject(type, en);
@ -410,8 +415,13 @@ export class Entity extends CADObject
this.NeedUpdateFlag = UpdateDraw.None; this.NeedUpdateFlag = UpdateDraw.None;
} }
//对象从文件中读取数据,初始化自身
ReadFile(file: CADFiler) ReadFile(file: CADFiler)
{
this._ReadFile(file);
this.Update();
}
//对象从文件中读取数据,初始化自身
protected _ReadFile(file: CADFiler)
{ {
let ver = file.Read(); let ver = file.Read();
super.ReadFile(file); super.ReadFile(file);

@ -1037,9 +1037,6 @@ export class ExtureSolid extends Entity
UpdateDrawObject(renderType: RenderType, obj: Object3D) UpdateDrawObject(renderType: RenderType, obj: Object3D)
{ {
if (this._CacheDrawObject.has(RenderType.Jig) && renderType !== RenderType.Jig)
return;
DisposeThreeObj(obj); DisposeThreeObj(obj);
this._EdgeGeometry = undefined; this._EdgeGeometry = undefined;
this._MeshGeometry = undefined; this._MeshGeometry = undefined;
@ -1157,11 +1154,10 @@ export class ExtureSolid extends Entity
} }
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
this.ReadFileOnly(file); this.ReadFileOnly(file);
this.Update();
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file: CADFiler) WriteFile(file: CADFiler)

@ -24,10 +24,10 @@ export class FaceEntity extends Entity
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
let ver = file.Read(); let ver = file.Read();
super.ReadFile(file); super._ReadFile(file);
this.p1.fromArray(file.Read()); this.p1.fromArray(file.Read());
this.p2.fromArray(file.Read()); this.p2.fromArray(file.Read());

@ -93,12 +93,11 @@ export class DirectionalLight extends Light
} }
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.m_Target.fromArray(file.Read()); this.m_Target.fromArray(file.Read());
this.Update();
} }
WriteFile(file: CADFiler) WriteFile(file: CADFiler)
{ {

@ -32,12 +32,11 @@ export class HemisphereLight extends Light
let lg = en as THREE.HemisphereLight; let lg = en as THREE.HemisphereLight;
lg.groundColor = this.m_GroundColor; lg.groundColor = this.m_GroundColor;
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.m_GroundColor.fromArray(file.Read()); this.m_GroundColor.fromArray(file.Read());
this.Update();
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file: CADFiler) WriteFile(file: CADFiler)

@ -96,14 +96,13 @@ export class Light extends Entity
this.m_Intensity = v; this.m_Intensity = v;
this.Update(); this.Update();
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.m_LightColor = new Color(file.Read()); this.m_LightColor = new Color(file.Read());
this.m_Intensity = file.Read(); this.m_Intensity = file.Read();
this.m_ShowHelper = file.Read(); this.m_ShowHelper = file.Read();
this.Update();
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file: CADFiler) WriteFile(file: CADFiler)

@ -71,13 +71,12 @@ export class PointLight extends Light
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.m_Distance = file.Read(); this.m_Distance = file.Read();
this.m_Decay = file.Read(); this.m_Decay = file.Read();
this.Update();
} }
WriteFile(file: CADFiler) WriteFile(file: CADFiler)
{ {

@ -117,14 +117,13 @@ export class RectAreaLight extends Light
box.updateMatrixWorld(true); box.updateMatrixWorld(true);
} }
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.m_Height = file.Read(); this.m_Height = file.Read();
this.m_Width = file.Read(); this.m_Width = file.Read();
this.m_Target.fromArray(file.Read()); this.m_Target.fromArray(file.Read());
this.Update();
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file: CADFiler) WriteFile(file: CADFiler)

@ -201,16 +201,15 @@ export class SpotLight extends Light
helper.cone.lookAt(light.target.position); helper.cone.lookAt(light.target.position);
} }
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.m_Distance = file.Read(); this.m_Distance = file.Read();
this.m_Decay = file.Read(); this.m_Decay = file.Read();
this.m_Angle = file.Read(); this.m_Angle = file.Read();
this.m_Penumbra = file.Read(); this.m_Penumbra = file.Read();
this.m_Target.fromArray(file.Read()); this.m_Target.fromArray(file.Read());
this.Update();
} }
WriteFile(file: CADFiler) WriteFile(file: CADFiler)
{ {

@ -358,13 +358,12 @@ export class Line extends Curve
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read();//1 let ver = file.Read();//1
this.m_StartPoint.fromArray(file.Read()); this.m_StartPoint.fromArray(file.Read());
this.m_EndPoint.fromArray(file.Read()); this.m_EndPoint.fromArray(file.Read());
this.Update();
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file: CADFiler) WriteFile(file: CADFiler)

@ -1,29 +0,0 @@
import { Factory } from './CADFactory';
import { CADObject } from './CADObject';
import { CADFiler } from './CADFiler';
@Factory
export class Material extends CADObject
{
Update()
{
}
//#region -------------------------File-------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//对象从文件中读取数据,初始化自身
ReadFile(file: CADFiler)
{
super.ReadFile(file);
let ver = file.Read();
}
//对象将自身数据写入到文件.
WriteFile(file: CADFiler)
{
super.WriteFile(file);
file.Write(1);
}
//#endregion
}

@ -1321,9 +1321,9 @@ export class Polyline extends Curve
} }
this.Update(); this.Update();
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this.m_LineData.length = 0; this.m_LineData.length = 0;
let cout = file.Read(); let cout = file.Read();
@ -1336,7 +1336,6 @@ export class Polyline extends Curve
} }
if (ver > 1) if (ver > 1)
this.m_ClosedMark = file.Read(); this.m_ClosedMark = file.Read();
this.Update();
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file: CADFiler) WriteFile(file: CADFiler)

@ -207,13 +207,12 @@ export class Region extends Entity
} }
} }
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read();//1 let ver = file.Read();//1
this.m_ShapeManager.Clear(); this.m_ShapeManager.Clear();
this.m_ShapeManager.ReadFile(file); this.m_ShapeManager.ReadFile(file);
this.Update();
} }
WriteFile(file: CADFiler) WriteFile(file: CADFiler)
{ {

@ -107,9 +107,9 @@ export class Spline extends Curve
spl.geometry = BufferGeometryUtils.CreateFromPts(pts); spl.geometry = BufferGeometryUtils.CreateFromPts(pts);
} }
} }
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read();//1 let ver = file.Read();//1
let count = file.Read(); let count = file.Read();
this.m_PointList.length = 0; this.m_PointList.length = 0;

@ -178,9 +178,9 @@ export class Text extends Entity
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFiler) protected _ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super._ReadFile(file);
let ver = file.Read();//1 let ver = file.Read();//1
this.m_TextString = file.Read(); this.m_TextString = file.Read();
this.Height = file.Read(); this.Height = file.Read();

@ -14,7 +14,6 @@ import { Editor, EditorService } from './Editor';
import { JigUtils } from './JigUtils'; import { JigUtils } from './JigUtils';
import { MouseControls } from './MouseControls'; import { MouseControls } from './MouseControls';
import { PromptStatus } from './PromptResult'; import { PromptStatus } from './PromptResult';
import { Board } from '../DatabaseServices/Board';
/** /**
* *
@ -83,16 +82,22 @@ export class GripDragServices implements EditorService
} }
let snapIndexMapClone = snapIndexMap.map(v => let snapIndexMapClone = snapIndexMap.map(v =>
{ {
return { ent: JigUtils.Draw(v.ent, v.ent instanceof Board), indexArr: v.indexArr }; let jigEnt = JigUtils.Draw(v.ent, true);
jigEnt.AutoUpdate = false;
return { ent: jigEnt, indexArr: v.indexArr };
}); });
const DragTo = (p: Vector3, snapIndexMap = snapIndexMapClone) => const DragTo = (p: Vector3, snapIndexMap = snapIndexMapClone, isJig = false) =>
{ {
if (isJig)
JigUtils.Restore(); JigUtils.Restore();
for (let data of snapIndexMap) for (let data of snapIndexMap)
{ {
let entDrawP = data.ent.GetGripPoints()[data.indexArr[0]]; let entDrawP = data.ent.GetGripPoints()[data.indexArr[0]];
let vec = p.clone().sub(entDrawP); let vec = p.clone().sub(entDrawP);
data.ent.MoveGripPoints(data.indexArr, vec); data.ent.MoveGripPoints(data.indexArr, vec);
if (isJig)
data.ent.DeferUpdate();
} }
} }
@ -115,7 +120,7 @@ export class GripDragServices implements EditorService
Msg: "指定下一个点:", Msg: "指定下一个点:",
BasePoint: baseP, BasePoint: baseP,
AllowDrawRubberBand: true, AllowDrawRubberBand: true,
Callback: DragTo Callback: (p) => { DragTo(p, snapIndexMapClone, true) }
}); });
app.m_Editor.UCSMatrix = oldUcs; app.m_Editor.UCSMatrix = oldUcs;
if (ptRes.Status === PromptStatus.OK) if (ptRes.Status === PromptStatus.OK)

@ -41,7 +41,7 @@ export class Jig
else else
enNew = enOrg; enNew = enOrg;
this.m_JigEnts.push(enNew); this.m_JigEnts.push(enNew);
let obj = fast ? enNew.JigObject : enNew.DrawObject; let obj = (fast && enNew.JigObject) || enNew.DrawObject;
app.m_Viewer.Scene.add(obj); app.m_Viewer.Scene.add(obj);
return enNew; return enNew;
} }
@ -51,23 +51,23 @@ export class Jig
*/ */
Restore() Restore()
{ {
this.EntityCacheData.forEach((v) => for (let d of this.EntityCacheData)
{ {
v.File.Reset(); d.File.Reset();
v.Ent.ReadFile(v.File); d.Ent.ReadFile(d.File);
}); }
} }
/** /**
* ,,. * ,,.
*/ */
Destroy() Destroy()
{ {
this.m_JigEnts.forEach(e => for (let ent of this.m_JigEnts)
{ {
e.DestroyJigObject(); ent.DestroyJigObject();
if (!e.Id) if (!ent.Id)
e.GoodBye(); ent.GoodBye();
}); }
this.m_JigEnts.length = 0; this.m_JigEnts.length = 0;
app.m_Editor.UpdateScreen(); app.m_Editor.UpdateScreen();
} }

@ -1,5 +1,6 @@
import { BufferGeometry, Geometry, Line, LineBasicMaterial, Object3D, Vector3, Float32BufferAttribute, LineSegments } from "three"; import { BufferGeometry, Float32BufferAttribute, Geometry, Line, LineBasicMaterial, LineSegments, Object3D, Shape as TShape, Vector3 } from "three";
import { ColorMaterial } from "../Common/ColorPalette"; import { ColorMaterial } from "../Common/ColorPalette";
import { FixIndex } from "../Common/Utils";
import { Board } from "../DatabaseServices/Board"; import { Board } from "../DatabaseServices/Board";
import { Contour } from "../DatabaseServices/Contour"; import { Contour } from "../DatabaseServices/Contour";
import { Curve } from "../DatabaseServices/Curve"; import { Curve } from "../DatabaseServices/Curve";
@ -140,3 +141,21 @@ export function FastWireframe(br: ExtureSolid, color = 0)
return result; return result;
} }
export function FastDrillingEdgeGeometry(shape: TShape, height: number): BufferGeometry
{
let pts = shape.getPoints(6);
let geo = new BufferGeometry();
let coords: number[] = [];
for (let i = 0; i < pts.length; i++)
{
let p = pts[i];
let np = pts[FixIndex(i + 1, pts.length)];
coords.push(p.x, p.y, 0, np.x, np.y, 0);//bottom
coords.push(p.x, p.y, height, np.x, np.y, height);//top
coords.push(p.x, p.y, 0, p.x, p.y, height);//edge
}
geo.addAttribute('position', new Float32BufferAttribute(coords, 3));
return geo;
}

@ -5,7 +5,6 @@ import { GetEntity } from '../Common/Utils';
import { Database } from '../DatabaseServices/Database'; import { Database } from '../DatabaseServices/Database';
import { Entity } from '../DatabaseServices/Entity'; import { Entity } from '../DatabaseServices/Entity';
import { GenerateRaycaster } from '../Editor/PointPick'; import { GenerateRaycaster } from '../Editor/PointPick';
import { CheckFilter } from '../Editor/SelectFilter';
import { userConfig } from '../Editor/UserConfig'; import { userConfig } from '../Editor/UserConfig';
import { cZeroVec, GetBox, GetBoxArr, isPerpendicularityTo } from '../Geometry/GeUtils'; import { cZeroVec, GetBox, GetBoxArr, isPerpendicularityTo } from '../Geometry/GeUtils';
import { PlaneExt } from '../Geometry/Plane'; import { PlaneExt } from '../Geometry/Plane';

@ -21,5 +21,8 @@
}, },
"include": [ "include": [
"./src/**/*", "./src/**/*",
"./utils/**/*",
"./__test__/**/*",
"./config/**/*",
] ]
} }

@ -1,14 +1,12 @@
import { getFiles } from "./getFiles";
import path = require("path"); import path = require("path");
import fs = require("fs"); import fs = require("fs");
import { getFiles } from "./utils";
let dist = path.resolve("./dist"); let dist = path.resolve("./dist");
let files = getFiles(dist, []); let files = getFiles(dist, []);
files.forEach(f => for (let f of files)
{ {
if (f.indexOf("main.js") !== -1) if (f.indexOf("main.js") !== -1)
fs.unlink(f, e => fs.unlink(f, e => { });
{ }
});
})

@ -1,15 +0,0 @@
import fs = require("fs");
export function getFiles(dir: string, files_: string[])
{
files_ = files_ || [];
let files = fs.readdirSync(dir);
for (let i in files)
{
let name = dir + '/' + files[i];
if (fs.statSync(name).isDirectory())
getFiles(name, files_);
else
files_.push(name);
}
return files_;
}

@ -1,7 +1,7 @@
import fs = require("fs"); import fs = require("fs");
import rq = require("request-promise-native"); import rq = require("request-promise-native");
import path = require("path"); import path = require("path");
import { getFiles } from "./getFiles"; import { getFiles } from "./utils";
var GitRevisionPlugin = require('git-revision-webpack-plugin'); var GitRevisionPlugin = require('git-revision-webpack-plugin');
var gitRevisionPlugin = new GitRevisionPlugin(); var gitRevisionPlugin = new GitRevisionPlugin();

@ -4,9 +4,6 @@ import * as fs from "fs";
/** /**
* *
*
* @param {string} url
* @param {string} filePath
*/ */
export function downLoadFile(url: string, filePath: string) export function downLoadFile(url: string, filePath: string)
{ {
@ -67,3 +64,20 @@ export function copyFolderRecursiveSync(source, target)
}); });
} }
} }
/**
* ()
*/
export function getFiles(path: string, resultFiles: string[] = [])
{
let files = fs.readdirSync(path);
for (let file of files)
{
let name = path + '/' + file;
if (fs.statSync(name).isDirectory())
getFiles(name, resultFiles);
else
resultFiles.push(name);
}
return resultFiles;
}

Loading…
Cancel
Save