From 3a41e564b16fb04fa27b53969595c55df466ea38 Mon Sep 17 00:00:00 2001 From: ChenX Date: Wed, 15 May 2019 15:29:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Stretch=E5=92=8CDragGrip?= =?UTF-8?q?=E6=80=A7=E8=83=BD,=E5=B9=B6=E5=AF=B9(=E6=9D=BF=E4=BB=B6,?= =?UTF-8?q?=E6=8E=92=E9=92=BB=E5=AE=9E=E4=BD=93)=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E4=BC=98=E5=8C=96.=20fix=20#IWF6X?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 2 +- __test__/FileSystem/wblockClone.test.ts | 4 +- __test__/Line/line.test.ts | 1 - src/Add-on/Move.ts | 17 ++--- src/Add-on/Stretch.ts | 67 ++++++++++--------- src/DatabaseServices/3DSolid/Cylineder.ts | 4 +- src/DatabaseServices/3DSolid/GangDrill.ts | 40 +++++++---- src/DatabaseServices/3DSolid/SweepSolid.ts | 4 +- src/DatabaseServices/Arc.ts | 5 +- src/DatabaseServices/Board.ts | 5 +- src/DatabaseServices/Circle.ts | 5 +- .../Dimension/2LineAngularDimension.ts | 5 +- .../Dimension/AlignedDimension.ts | 5 +- .../Dimension/RadiusDimension.ts | 5 +- src/DatabaseServices/Ellipse.ts | 4 +- src/DatabaseServices/Entity.ts | 12 +++- src/DatabaseServices/Extrude.ts | 8 +-- src/DatabaseServices/FaceEntity.ts | 4 +- .../Lights/DirectionalLight.ts | 5 +- .../Lights/HemisphereLight.ts | 5 +- src/DatabaseServices/Lights/Light.ts | 5 +- src/DatabaseServices/Lights/PointLight.ts | 5 +- src/DatabaseServices/Lights/RectAreaLight.ts | 5 +- src/DatabaseServices/Lights/SpotLight.ts | 5 +- src/DatabaseServices/Line.ts | 5 +- src/DatabaseServices/Material.ts | 29 -------- src/DatabaseServices/Polyline.ts | 5 +- src/DatabaseServices/Region.ts | 5 +- src/DatabaseServices/Spline.ts | 4 +- src/DatabaseServices/Text/Text.ts | 4 +- src/Editor/GripDragServices.ts | 15 +++-- src/Editor/Jig.ts | 20 +++--- src/Geometry/CreateWireframe.ts | 21 +++++- src/GraphicsSystem/Viewer.ts | 1 - tsconfig.json | 3 + utils/clear.ts | 10 ++- utils/getFiles.ts | 15 ----- utils/publish.ts | 2 +- utils/utils.ts | 20 +++++- 39 files changed, 196 insertions(+), 190 deletions(-) delete mode 100644 src/DatabaseServices/Material.ts delete mode 100644 utils/getFiles.ts diff --git a/.vscode/launch.json b/.vscode/launch.json index d8f56306f..e2bd5851e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "url": "http://localhost:7778", "webRoot": "${workspaceFolder}", "skipFiles": [ - // "*.js" //跳过.js文件的调试,避免调试堆栈进入js文件 + "*.dll.js" //跳过.js文件的调试,避免调试堆栈进入js文件 ] }, //Ref: https://github.com/Microsoft/vscode-recipes/blob/master/debugging-jest-tests/.vscode/launch.json diff --git a/__test__/FileSystem/wblockClone.test.ts b/__test__/FileSystem/wblockClone.test.ts index 19e66f456..75e5cdfd8 100644 --- a/__test__/FileSystem/wblockClone.test.ts +++ b/__test__/FileSystem/wblockClone.test.ts @@ -55,10 +55,10 @@ test('循环引用', () => this.ref = id; } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { let ver = file.Read(); - super.ReadFile(file); + super._ReadFile(file); this.ref = file.ReadObjectId(); } diff --git a/__test__/Line/line.test.ts b/__test__/Line/line.test.ts index c62a080b8..09e4a1b5a 100644 --- a/__test__/Line/line.test.ts +++ b/__test__/Line/line.test.ts @@ -2,7 +2,6 @@ import { Line } from '../../src/DatabaseServices/Line'; import { Vector3 } from 'three'; - test('直线参数', () => { diff --git a/src/Add-on/Move.ts b/src/Add-on/Move.ts index 77b69cea2..99cf82a7f 100644 --- a/src/Add-on/Move.ts +++ b/src/Add-on/Move.ts @@ -1,10 +1,8 @@ -import * as THREE from 'three'; +import { Matrix4 } from 'three'; import { app } from '../ApplicationServices/Application'; import { Command } from '../Editor/CommandMachine'; -import { PromptStatus } from '../Editor/PromptResult'; -import { MoveMatrix } from '../Geometry/GeUtils'; import { JigUtils } from '../Editor/JigUtils'; -// import { IsEntity } from '../Common/Utils'; +import { PromptStatus } from '../Editor/PromptResult'; export class Command_Move implements Command { @@ -23,14 +21,17 @@ export class Command_Move implements Command let ptBase = ptRes.Point; let ptLast = ptBase.clone(); + let moveMatrix = new Matrix4(); ptRes = await app.m_Editor.GetPoint( { Msg: "请点击移动终点:", Callback: (p: THREE.Vector3) => { - let moveMatrix = MoveMatrix(p.clone().sub(ptLast)); - ensClone.forEach(e => e.ApplyMatrix(moveMatrix)); + moveMatrix.setPosition(p.clone().sub(ptLast)); + for (let ent of ensClone) + ent.ApplyMatrix(moveMatrix); ptLast.copy(p); + // //对调试实体进行移动 // for (let obj of ssRes.SelectSet.SelectObjectList) // { @@ -44,9 +45,9 @@ export class Command_Move implements Command 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) - en.ApplyMatrix(moveM); + en.ApplyMatrix(moveMatrix); } } } diff --git a/src/Add-on/Stretch.ts b/src/Add-on/Stretch.ts index de879f06f..e7dbf9c54 100644 --- a/src/Add-on/Stretch.ts +++ b/src/Add-on/Stretch.ts @@ -1,20 +1,18 @@ -import * as THREE from 'three'; +import { Matrix4, Vector3 } from 'three'; import { app } from '../ApplicationServices/Application'; -import { Board } from '../DatabaseServices/Board'; import { Entity } from '../DatabaseServices/Entity'; import { Command } from '../Editor/CommandMachine'; -import { JigUtils } from '../Editor/JigUtils'; +import { Jig } from '../Editor/Jig'; import { PromptStatus } from '../Editor/PromptResult'; import { SelectBox, SelectType } from '../Editor/SelectBox'; import { SelectPick } from '../Editor/SelectPick'; import { SelectSet } from '../Editor/SelectSet'; -import { MoveMatrix } from '../Geometry/GeUtils'; //拉伸的解析数据 interface StretchData { moveEntityList: Entity[];//被移动的图元(所有点都被选中) - stretchEntityMap: { Ent: Entity, Indexs: Array }[]; //被拉伸的图元,对照被拉伸的点索引. + stretchEntityMap: { ent: Entity, indexs: Array }[]; //被拉伸的图元,对照被拉伸的点索引. } export class Stretch implements Command @@ -29,19 +27,27 @@ export class Stretch implements Command let ss = ssRes.SelectSet; let data = this.Parse(ss); + + let moveJig = new Jig(); + let stretchJig = new Jig(); + let dataClone: StretchData = { - moveEntityList: data.moveEntityList.map(e => JigUtils.Draw(e)), + moveEntityList: data.moveEntityList.map(e => moveJig.Draw(e)), stretchEntityMap: data.stretchEntityMap.map(v => { + let jigEntity = stretchJig.Draw(v.ent, true); + jigEntity.AutoUpdate = false;//避免Jig Restore时更新对象 return { - Ent: JigUtils.Draw(v.Ent, v.Ent instanceof Board), - Indexs: v.Indexs - } + ent: jigEntity, + 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( { BasePoint: p1.Point, @@ -49,25 +55,28 @@ export class Stretch implements Command Msg: "指定第二个点:",//或 <使用第一个点作为位移> Callback: (p) => { - p = p.clone(); - JigUtils.Restore(); - let v = p.sub(lastP); - this.Stretch(dataClone, v); + stretchJig.Restore(); + let moveVector = p.clone().sub(lastMovePoint); + let stretchVector = p.clone().sub(lastStretchPoint); + moveMatrix.setPosition(moveVector); + this.Stretch(dataClone, stretchVector, moveMatrix); + lastMovePoint = p.clone(); } }); 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 { @@ -107,7 +116,7 @@ export class Stretch implements Command if (indexArr.length === pts.length) data.moveEntityList.push(en); 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; } - Stretch(d: StretchData, vec: THREE.Vector3) + Stretch(d: StretchData, stretchVector: Vector3, moveMatrix: Matrix4) { - let moveMat = MoveMatrix(vec); - for (let e of d.moveEntityList) - { - e.ApplyMatrix(moveMat); - } - for (let { Ent, Indexs } of d.stretchEntityMap) + for (let ent of d.moveEntityList) + ent.ApplyMatrix(moveMatrix); + for (let { ent, indexs } of d.stretchEntityMap) { - Ent.MoveStretchPoints(Indexs, vec); + ent.MoveStretchPoints(indexs, stretchVector); + ent.DeferUpdate(); } } } diff --git a/src/DatabaseServices/3DSolid/Cylineder.ts b/src/DatabaseServices/3DSolid/Cylineder.ts index 09ef6e3ab..dad5e86fc 100644 --- a/src/DatabaseServices/3DSolid/Cylineder.ts +++ b/src/DatabaseServices/3DSolid/Cylineder.ts @@ -69,9 +69,9 @@ export class Cylineder extends Solid3D (obj.geometry as Geometry).verticesNeedUpdate = true; } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read();//1 this.m_Radius = file.Read(); this.m_Height = file.Read(); diff --git a/src/DatabaseServices/3DSolid/GangDrill.ts b/src/DatabaseServices/3DSolid/GangDrill.ts index 4deb95205..92cdce4db 100644 --- a/src/DatabaseServices/3DSolid/GangDrill.ts +++ b/src/DatabaseServices/3DSolid/GangDrill.ts @@ -1,5 +1,8 @@ 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 { Factory } from '../CADFactory'; import { CADFiler } from '../CADFiler'; @@ -7,9 +10,6 @@ import { Circle } from '../Circle'; import { Contour } from '../Contour'; import { Shape } from '../Shape'; import { Solid3D } from "./Solid3D"; -import { EdgesGeometry } from '../../Geometry/EdgeGeometry'; -import { ColorMaterial } from '../../Common/ColorPalette'; -import { DisposeThreeObj } from '../../Common/Dispose'; export enum GangDrillType { @@ -75,14 +75,31 @@ export class GangDrill extends Solid3D { return this.BoundingBox.intersectsBox(tarDrill.BoundingBox); } - CreateGeometry(): ExtrudeGeometry + + private _MeshGeometry: ExtrudeGeometry; + private get MeshGeometry() { + if (this._MeshGeometry) + return this._MeshGeometry; + let extrudeSettings = { bevelEnabled: false, 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) { return new Group().add(this.GetObject3DByRenderType(renderType)); @@ -90,11 +107,9 @@ export class GangDrill extends Solid3D private GetObject3DByRenderType(renderType: RenderType) { if (renderType === RenderType.Wireframe) - { - return new LineSegments(new EdgesGeometry().FromGeometry(this.CreateGeometry(), 2), ColorMaterial.GetLineMaterial(this.ColorIndex)); - } + return new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(this.ColorIndex)); else - return new THREE.Mesh(this.CreateGeometry(), new MeshNormalMaterial()); + return new THREE.Mesh(this.MeshGeometry, new MeshNormalMaterial()); } UpdateDrawObject(type: RenderType, obj: Object3D) { @@ -102,9 +117,9 @@ export class GangDrill extends Solid3D obj.add(this.GetObject3DByRenderType(type)); } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read();//1 this.m_Shape = new Shape(); this.m_Shape.ReadFile(file); @@ -113,7 +128,6 @@ export class GangDrill extends Solid3D this.type = file.Read(); else this.type = GangDrillType.Drill; - this.Update(); } WriteFile(file: CADFiler) { diff --git a/src/DatabaseServices/3DSolid/SweepSolid.ts b/src/DatabaseServices/3DSolid/SweepSolid.ts index 1e8c188a0..479d0b9ff 100644 --- a/src/DatabaseServices/3DSolid/SweepSolid.ts +++ b/src/DatabaseServices/3DSolid/SweepSolid.ts @@ -173,9 +173,9 @@ export class SweepSolid extends Solid3D this.m_PathCurve.MoveStretchPoints(indexList, vec); this.Update(); } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read();//1 this.m_Contour = file.ReadObject() as Polyline; this.m_PathCurve = file.ReadObject() as Curve; diff --git a/src/DatabaseServices/Arc.ts b/src/DatabaseServices/Arc.ts index e2c926397..54437851e 100644 --- a/src/DatabaseServices/Arc.ts +++ b/src/DatabaseServices/Arc.ts @@ -743,9 +743,9 @@ export class Arc extends Curve //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象从文件中读取数据,初始化自身 - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); if (ver === 1) { @@ -756,7 +756,6 @@ export class Arc extends Curve this.m_StartAngle = file.Read(); this.m_EndAngle = file.Read(); this.m_Clockwise = file.Read(); - this.Update(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) diff --git a/src/DatabaseServices/Board.ts b/src/DatabaseServices/Board.ts index 6557bc16d..223207114 100644 --- a/src/DatabaseServices/Board.ts +++ b/src/DatabaseServices/Board.ts @@ -532,9 +532,9 @@ export class Board extends ExtureSolid return boardUVGenerator2; } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); this.m_SpecOCS.fromArray(file.Read()); this.m_BoardType = file.Read(); @@ -577,7 +577,6 @@ export class Board extends ExtureSolid this.layerNails.push(objId); } } - this.Update(); } WriteFile(file: CADFiler) { diff --git a/src/DatabaseServices/Circle.ts b/src/DatabaseServices/Circle.ts index 96092fc53..705cd206f 100644 --- a/src/DatabaseServices/Circle.ts +++ b/src/DatabaseServices/Circle.ts @@ -363,12 +363,11 @@ export class Circle extends Curve //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象从文件中读取数据,初始化自身 - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); this.m_Radius = file.Read(); - this.Update(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) diff --git a/src/DatabaseServices/Dimension/2LineAngularDimension.ts b/src/DatabaseServices/Dimension/2LineAngularDimension.ts index 16cd4282a..c798e9614 100644 --- a/src/DatabaseServices/Dimension/2LineAngularDimension.ts +++ b/src/DatabaseServices/Dimension/2LineAngularDimension.ts @@ -290,16 +290,15 @@ export class LineAngularDimension extends Entity //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象从文件中读取数据,初始化自身 - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); this.m_L1StartPoint.fromArray(file.Read()); this.m_L1EndPoint.fromArray(file.Read()); this.m_L2StartPoint.fromArray(file.Read()); this.m_L2EndPoint.fromArray(file.Read()); this.m_DimPoint.fromArray(file.Read()); - this.Update(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) diff --git a/src/DatabaseServices/Dimension/AlignedDimension.ts b/src/DatabaseServices/Dimension/AlignedDimension.ts index d56b0dbab..5ddb657da 100644 --- a/src/DatabaseServices/Dimension/AlignedDimension.ts +++ b/src/DatabaseServices/Dimension/AlignedDimension.ts @@ -260,15 +260,14 @@ export class AlignedDimension extends Entity //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象从文件中读取数据,初始化自身 - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); this.m_ArmP1.fromArray(file.Read()); this.m_ArmP2.fromArray(file.Read()); this.m_FootP1.fromArray(file.Read()); this.m_FootP2.fromArray(file.Read()); - this.Update(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) diff --git a/src/DatabaseServices/Dimension/RadiusDimension.ts b/src/DatabaseServices/Dimension/RadiusDimension.ts index 76260575f..90a5eb6ab 100644 --- a/src/DatabaseServices/Dimension/RadiusDimension.ts +++ b/src/DatabaseServices/Dimension/RadiusDimension.ts @@ -187,14 +187,13 @@ export class RadiusDimension extends Entity this.MoveGripPoints(indexList, vec); } } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); this.startPt.fromArray(file.Read()); this.center.fromArray(file.Read()); this.endPt.fromArray(file.Read()); - this.Update(); } WriteFile(file: CADFiler) { diff --git a/src/DatabaseServices/Ellipse.ts b/src/DatabaseServices/Ellipse.ts index 4312b61a5..5a233159a 100644 --- a/src/DatabaseServices/Ellipse.ts +++ b/src/DatabaseServices/Ellipse.ts @@ -138,9 +138,9 @@ export class Ellipse extends Curve this.Center = p; } } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); this.RadX = file.Read(); this.RadY = file.Read(); diff --git a/src/DatabaseServices/Entity.ts b/src/DatabaseServices/Entity.ts index 168bc6ce6..01ab72eb4 100644 --- a/src/DatabaseServices/Entity.ts +++ b/src/DatabaseServices/Entity.ts @@ -141,6 +141,7 @@ export class Entity extends CADObject let obj = this._CacheDrawObject.get(RenderType.Jig); if (obj) { + this._CacheDrawObject.delete(RenderType.Jig); DisposeThreeObj(obj); if (obj.parent) obj.parent.remove(obj); @@ -199,8 +200,12 @@ export class Entity extends CADObject if (mode === 0) return; this.UpdateVisible(); + + let isJigIng = this._CacheDrawObject.has(RenderType.Jig); for (let [type, en] of this._CacheDrawObject) { + if (isJigIng && type !== RenderType.Jig) + continue; if (mode & UpdateDraw.Geometry) this.UpdateDrawObject(type, en); @@ -410,8 +415,13 @@ export class Entity extends CADObject this.NeedUpdateFlag = UpdateDraw.None; } - //对象从文件中读取数据,初始化自身 ReadFile(file: CADFiler) + { + this._ReadFile(file); + this.Update(); + } + //对象从文件中读取数据,初始化自身 + protected _ReadFile(file: CADFiler) { let ver = file.Read(); super.ReadFile(file); diff --git a/src/DatabaseServices/Extrude.ts b/src/DatabaseServices/Extrude.ts index 7e855bf91..02662ff5c 100644 --- a/src/DatabaseServices/Extrude.ts +++ b/src/DatabaseServices/Extrude.ts @@ -1037,9 +1037,6 @@ export class ExtureSolid extends Entity UpdateDrawObject(renderType: RenderType, obj: Object3D) { - if (this._CacheDrawObject.has(RenderType.Jig) && renderType !== RenderType.Jig) - return; - DisposeThreeObj(obj); this._EdgeGeometry = 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.Update(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) diff --git a/src/DatabaseServices/FaceEntity.ts b/src/DatabaseServices/FaceEntity.ts index 7445b7d49..14464d5da 100644 --- a/src/DatabaseServices/FaceEntity.ts +++ b/src/DatabaseServices/FaceEntity.ts @@ -24,10 +24,10 @@ export class FaceEntity extends Entity //对象从文件中读取数据,初始化自身 - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { let ver = file.Read(); - super.ReadFile(file); + super._ReadFile(file); this.p1.fromArray(file.Read()); this.p2.fromArray(file.Read()); diff --git a/src/DatabaseServices/Lights/DirectionalLight.ts b/src/DatabaseServices/Lights/DirectionalLight.ts index 1d5de64e6..ad6536304 100644 --- a/src/DatabaseServices/Lights/DirectionalLight.ts +++ b/src/DatabaseServices/Lights/DirectionalLight.ts @@ -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(); this.m_Target.fromArray(file.Read()); - this.Update(); } WriteFile(file: CADFiler) { diff --git a/src/DatabaseServices/Lights/HemisphereLight.ts b/src/DatabaseServices/Lights/HemisphereLight.ts index d89e66fe2..8aaf1469d 100644 --- a/src/DatabaseServices/Lights/HemisphereLight.ts +++ b/src/DatabaseServices/Lights/HemisphereLight.ts @@ -32,12 +32,11 @@ export class HemisphereLight extends Light let lg = en as THREE.HemisphereLight; lg.groundColor = this.m_GroundColor; } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); this.m_GroundColor.fromArray(file.Read()); - this.Update(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) diff --git a/src/DatabaseServices/Lights/Light.ts b/src/DatabaseServices/Lights/Light.ts index 0777b4642..b8a96dffc 100644 --- a/src/DatabaseServices/Lights/Light.ts +++ b/src/DatabaseServices/Lights/Light.ts @@ -96,14 +96,13 @@ export class Light extends Entity this.m_Intensity = v; this.Update(); } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); this.m_LightColor = new Color(file.Read()); this.m_Intensity = file.Read(); this.m_ShowHelper = file.Read(); - this.Update(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) diff --git a/src/DatabaseServices/Lights/PointLight.ts b/src/DatabaseServices/Lights/PointLight.ts index 7260aa6c7..b034654e2 100644 --- a/src/DatabaseServices/Lights/PointLight.ts +++ b/src/DatabaseServices/Lights/PointLight.ts @@ -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(); this.m_Distance = file.Read(); this.m_Decay = file.Read(); - this.Update(); } WriteFile(file: CADFiler) { diff --git a/src/DatabaseServices/Lights/RectAreaLight.ts b/src/DatabaseServices/Lights/RectAreaLight.ts index 6836b5573..f81e7c782 100644 --- a/src/DatabaseServices/Lights/RectAreaLight.ts +++ b/src/DatabaseServices/Lights/RectAreaLight.ts @@ -117,14 +117,13 @@ export class RectAreaLight extends Light box.updateMatrixWorld(true); } } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); this.m_Height = file.Read(); this.m_Width = file.Read(); this.m_Target.fromArray(file.Read()); - this.Update(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) diff --git a/src/DatabaseServices/Lights/SpotLight.ts b/src/DatabaseServices/Lights/SpotLight.ts index 3acb2a245..d4bdd5fc5 100644 --- a/src/DatabaseServices/Lights/SpotLight.ts +++ b/src/DatabaseServices/Lights/SpotLight.ts @@ -201,16 +201,15 @@ export class SpotLight extends Light helper.cone.lookAt(light.target.position); } } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); this.m_Distance = file.Read(); this.m_Decay = file.Read(); this.m_Angle = file.Read(); this.m_Penumbra = file.Read(); this.m_Target.fromArray(file.Read()); - this.Update(); } WriteFile(file: CADFiler) { diff --git a/src/DatabaseServices/Line.ts b/src/DatabaseServices/Line.ts index 2f024243f..6709b277d 100644 --- a/src/DatabaseServices/Line.ts +++ b/src/DatabaseServices/Line.ts @@ -358,13 +358,12 @@ export class Line extends Curve //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象从文件中读取数据,初始化自身 - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read();//1 this.m_StartPoint.fromArray(file.Read()); this.m_EndPoint.fromArray(file.Read()); - this.Update(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) diff --git a/src/DatabaseServices/Material.ts b/src/DatabaseServices/Material.ts deleted file mode 100644 index 819b1dd9d..000000000 --- a/src/DatabaseServices/Material.ts +++ /dev/null @@ -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 -} diff --git a/src/DatabaseServices/Polyline.ts b/src/DatabaseServices/Polyline.ts index a52435d09..136ea0467 100644 --- a/src/DatabaseServices/Polyline.ts +++ b/src/DatabaseServices/Polyline.ts @@ -1321,9 +1321,9 @@ export class Polyline extends Curve } this.Update(); } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read(); this.m_LineData.length = 0; let cout = file.Read(); @@ -1336,7 +1336,6 @@ export class Polyline extends Curve } if (ver > 1) this.m_ClosedMark = file.Read(); - this.Update(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) diff --git a/src/DatabaseServices/Region.ts b/src/DatabaseServices/Region.ts index 9ebf915ce..d8368601d 100644 --- a/src/DatabaseServices/Region.ts +++ b/src/DatabaseServices/Region.ts @@ -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 this.m_ShapeManager.Clear(); this.m_ShapeManager.ReadFile(file); - this.Update(); } WriteFile(file: CADFiler) { diff --git a/src/DatabaseServices/Spline.ts b/src/DatabaseServices/Spline.ts index 232570230..136a6ef23 100644 --- a/src/DatabaseServices/Spline.ts +++ b/src/DatabaseServices/Spline.ts @@ -107,9 +107,9 @@ export class Spline extends Curve spl.geometry = BufferGeometryUtils.CreateFromPts(pts); } } - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read();//1 let count = file.Read(); this.m_PointList.length = 0; diff --git a/src/DatabaseServices/Text/Text.ts b/src/DatabaseServices/Text/Text.ts index 18d4328fb..5e8ba67ac 100644 --- a/src/DatabaseServices/Text/Text.ts +++ b/src/DatabaseServices/Text/Text.ts @@ -178,9 +178,9 @@ export class Text extends Entity //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象从文件中读取数据,初始化自身 - ReadFile(file: CADFiler) + protected _ReadFile(file: CADFiler) { - super.ReadFile(file); + super._ReadFile(file); let ver = file.Read();//1 this.m_TextString = file.Read(); this.Height = file.Read(); diff --git a/src/Editor/GripDragServices.ts b/src/Editor/GripDragServices.ts index 8aadf4fa6..c9d622232 100644 --- a/src/Editor/GripDragServices.ts +++ b/src/Editor/GripDragServices.ts @@ -14,7 +14,6 @@ import { Editor, EditorService } from './Editor'; import { JigUtils } from './JigUtils'; import { MouseControls } from './MouseControls'; import { PromptStatus } from './PromptResult'; -import { Board } from '../DatabaseServices/Board'; /** * 夹点拽拖服务 @@ -83,16 +82,22 @@ export class GripDragServices implements EditorService } 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) => { - JigUtils.Restore(); + if (isJig) + JigUtils.Restore(); for (let data of snapIndexMap) { let entDrawP = data.ent.GetGripPoints()[data.indexArr[0]]; let vec = p.clone().sub(entDrawP); data.ent.MoveGripPoints(data.indexArr, vec); + + if (isJig) + data.ent.DeferUpdate(); } } @@ -115,7 +120,7 @@ export class GripDragServices implements EditorService Msg: "指定下一个点:", BasePoint: baseP, AllowDrawRubberBand: true, - Callback: DragTo + Callback: (p) => { DragTo(p, snapIndexMapClone, true) } }); app.m_Editor.UCSMatrix = oldUcs; if (ptRes.Status === PromptStatus.OK) diff --git a/src/Editor/Jig.ts b/src/Editor/Jig.ts index 7254e7f85..eb6d97c13 100644 --- a/src/Editor/Jig.ts +++ b/src/Editor/Jig.ts @@ -41,7 +41,7 @@ export class Jig else enNew = enOrg; 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); return enNew; } @@ -51,23 +51,23 @@ export class Jig */ Restore() { - this.EntityCacheData.forEach((v) => + for (let d of this.EntityCacheData) { - v.File.Reset(); - v.Ent.ReadFile(v.File); - }); + d.File.Reset(); + d.Ent.ReadFile(d.File); + } } /** * 销毁临时对象,如果临时对象被加入到图纸,那么将不会被销毁. */ Destroy() { - this.m_JigEnts.forEach(e => + for (let ent of this.m_JigEnts) { - e.DestroyJigObject(); - if (!e.Id) - e.GoodBye(); - }); + ent.DestroyJigObject(); + if (!ent.Id) + ent.GoodBye(); + } this.m_JigEnts.length = 0; app.m_Editor.UpdateScreen(); } diff --git a/src/Geometry/CreateWireframe.ts b/src/Geometry/CreateWireframe.ts index 70524b93b..98889dd69 100644 --- a/src/Geometry/CreateWireframe.ts +++ b/src/Geometry/CreateWireframe.ts @@ -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 { FixIndex } from "../Common/Utils"; import { Board } from "../DatabaseServices/Board"; import { Contour } from "../DatabaseServices/Contour"; import { Curve } from "../DatabaseServices/Curve"; @@ -140,3 +141,21 @@ export function FastWireframe(br: ExtureSolid, color = 0) 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; +} diff --git a/src/GraphicsSystem/Viewer.ts b/src/GraphicsSystem/Viewer.ts index 6f451a84a..3b9be8da1 100644 --- a/src/GraphicsSystem/Viewer.ts +++ b/src/GraphicsSystem/Viewer.ts @@ -5,7 +5,6 @@ import { GetEntity } from '../Common/Utils'; import { Database } from '../DatabaseServices/Database'; import { Entity } from '../DatabaseServices/Entity'; import { GenerateRaycaster } from '../Editor/PointPick'; -import { CheckFilter } from '../Editor/SelectFilter'; import { userConfig } from '../Editor/UserConfig'; import { cZeroVec, GetBox, GetBoxArr, isPerpendicularityTo } from '../Geometry/GeUtils'; import { PlaneExt } from '../Geometry/Plane'; diff --git a/tsconfig.json b/tsconfig.json index 9fbcb73ef..c7f3caa6e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,5 +21,8 @@ }, "include": [ "./src/**/*", + "./utils/**/*", + "./__test__/**/*", + "./config/**/*", ] } diff --git a/utils/clear.ts b/utils/clear.ts index 91e987157..6d941b3e9 100644 --- a/utils/clear.ts +++ b/utils/clear.ts @@ -1,14 +1,12 @@ -import { getFiles } from "./getFiles"; import path = require("path"); import fs = require("fs"); +import { getFiles } from "./utils"; let dist = path.resolve("./dist"); let files = getFiles(dist, []); -files.forEach(f => +for (let f of files) { if (f.indexOf("main.js") !== -1) - fs.unlink(f, e => - { - }); -}) + fs.unlink(f, e => { }); +} diff --git a/utils/getFiles.ts b/utils/getFiles.ts deleted file mode 100644 index a1a6097f2..000000000 --- a/utils/getFiles.ts +++ /dev/null @@ -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_; -} diff --git a/utils/publish.ts b/utils/publish.ts index fe76f0b77..3597e573a 100644 --- a/utils/publish.ts +++ b/utils/publish.ts @@ -1,7 +1,7 @@ import fs = require("fs"); import rq = require("request-promise-native"); import path = require("path"); -import { getFiles } from "./getFiles"; +import { getFiles } from "./utils"; var GitRevisionPlugin = require('git-revision-webpack-plugin'); var gitRevisionPlugin = new GitRevisionPlugin(); diff --git a/utils/utils.ts b/utils/utils.ts index 1b6080e87..dc4cfcdd2 100644 --- a/utils/utils.ts +++ b/utils/utils.ts @@ -4,9 +4,6 @@ import * as fs from "fs"; /** * 下载文件到指定的文件地址 - * - * @param {string} url - * @param {string} filePath */ 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; +}