From 6af53cc797f7c6829fd0f31f7383cf921ed21bc3 Mon Sep 17 00:00:00 2001 From: ChenX <908666218@qq.com> Date: Mon, 1 Feb 2021 16:34:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91:=E6=9B=B4=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=BB=A5=E4=BE=BF=E6=94=AF=E6=8C=81ue4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.esm.js | 5235 ++++++++++++---------- types/Geometry/ExtrudeEdgeGeometry2.d.ts | 36 +- 2 files changed, 2838 insertions(+), 2433 deletions(-) diff --git a/api.esm.js b/api.esm.js index 12efe99..ff00e48 100644 --- a/api.esm.js +++ b/api.esm.js @@ -21,7 +21,8 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ -function __decorate(decorators, target, key, desc) { +function __decorate(decorators, target, key, desc) +{ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; @@ -33,7 +34,8 @@ function __decorate(decorators, target, key, desc) { * @param {Array} arr 需要操作的数组 * @param {*} el 需要移除的元素 */ -function arrayRemoveOnce(arr, el) { +function arrayRemoveOnce(arr, el) +{ let index = arr.indexOf(el); if (index !== -1) arr.splice(index, 1); @@ -43,7 +45,8 @@ function arrayRemoveOnce(arr, el) { * 删除通过函数校验的元素 * @param {(e: T) => boolean} checkFuntion 校验函数 */ -function arrayRemoveIf(arr, checkFuntion) { +function arrayRemoveIf(arr, checkFuntion) +{ let j = 0; for (let i = 0, l = arr.length; i < l; i++) { if (!checkFuntion(arr[i])) { @@ -53,7 +56,8 @@ function arrayRemoveIf(arr, checkFuntion) { arr.length = j; return arr; } -function arrayLast(arr) { +function arrayLast(arr) +{ return arr[arr.length - 1]; } /** @@ -61,7 +65,8 @@ function arrayLast(arr) { * @param {Array} arr * @returns {Array} 返回自身 */ -function arraySortByNumber(arr) { +function arraySortByNumber(arr) +{ arr.sort(sortNumberCompart); return arr; } @@ -70,7 +75,8 @@ function arraySortByNumber(arr) { * @param {(e1, e2) => boolean} [checkFuction] 校验对象相等函数 * @returns {Array} 返回自身 */ -function arrayRemoveDuplicateBySort(arr, checkFuction = checkEqual) { +function arrayRemoveDuplicateBySort(arr, checkFuction = checkEqual) +{ if (arr.length < 2) return arr; let j = 1; @@ -80,10 +86,12 @@ function arrayRemoveDuplicateBySort(arr, checkFuction = checkEqual) { arr.length = j; return arr; } -function sortNumberCompart(e1, e2) { +function sortNumberCompart(e1, e2) +{ return e1 - e2; } -function checkEqual(e1, e2) { +function checkEqual(e1, e2) +{ return e1 === e2; } /** @@ -91,11 +99,13 @@ function checkEqual(e1, e2) { * @param arr 需要改变初始值位置的数组 * @param index //将index位置以后的值放到起始位置 */ -function changeArrayStartIndex(arr, index) { +function changeArrayStartIndex(arr, index) +{ arr.unshift(...arr.splice(index)); return arr; } -function equalArray(a, b, checkF = checkEqual) { +function equalArray(a, b, checkF = checkEqual) +{ if (a === b) return true; if (a.length !== b.length) @@ -105,17 +115,20 @@ function equalArray(a, b, checkF = checkEqual) { return false; return true; } -function arrayClone(arr) { +function arrayClone(arr) +{ return arr.slice(); } -function arraySum(arr) { +function arraySum(arr) +{ let sum = 0; for (let n of arr) sum += n; return sum; } -function GetGoodShaderSimple(color = new Vector3) { +function GetGoodShaderSimple(color = new Vector3) +{ return { uniforms: { "SurfaceColor": { value: color } @@ -394,30 +407,35 @@ const ColorPalette = [ ]; const LINE_WIDTH = 2; //颜色材质,对于二维图像来说可能有用,应该不对三维对象使用该材质 -class ColorMaterial { +class ColorMaterial +{ constructor() { } - static GetLineMaterial(color) { + static GetLineMaterial(color) + { if (this._LineMaterialMap.has(color)) return this._LineMaterialMap.get(color); let mat = new LineBasicMaterial({ color: this.GetColor(color) }); this._LineMaterialMap.set(color, mat); return mat; } - static GetBasicMaterial(color) { + static GetBasicMaterial(color) + { if (this._BasicMaterialMap.has(color)) return this._BasicMaterialMap.get(color); let mtl = new MeshBasicMaterial({ color: this.GetColor(color) }); this._BasicMaterialMap.set(color, mtl); return mtl; } - static GetBasicMaterialDoubleSide(color) { + static GetBasicMaterialDoubleSide(color) + { if (this._BasicDoubleSideMaterialMap.has(color)) return this._BasicDoubleSideMaterialMap.get(color); let mtl = new MeshBasicMaterial({ color: this.GetColor(color), side: DoubleSide }); this._BasicDoubleSideMaterialMap.set(color, mtl); return mtl; } - static GetConceptualMaterial(color) { + static GetConceptualMaterial(color) + { if (this._ConceptualMaterial.has(color)) return this._ConceptualMaterial.get(color); let shaderParams = GetGoodShaderSimple(new Vector3().fromArray(this.GetColor(color).toArray())); @@ -425,7 +443,8 @@ class ColorMaterial { this._ConceptualMaterial.set(color, mtl); return mtl; } - static GetPrintConceptualMaterial() { + static GetPrintConceptualMaterial() + { if (!this._printConceptualMaterial) { this._printConceptualMaterial = new ShaderMaterial({ uniforms: { @@ -440,7 +459,8 @@ class ColorMaterial { } return this._printConceptualMaterial; } - static GetBasicMaterialTransparent(color, opacity) { + static GetBasicMaterialTransparent(color, opacity) + { let key = `${color},${opacity}`; let mat = this._BasicTransparentMaterialMap.get(key); if (mat) @@ -449,7 +469,8 @@ class ColorMaterial { this._BasicTransparentMaterialMap.set(key, mat); return mat; } - static GetBasicMaterialTransparent2(color, opacity) { + static GetBasicMaterialTransparent2(color, opacity) + { let key = `${color},${opacity}`; let mat = this._BasicTransparentMaterialMap2.get(key); if (mat) @@ -458,7 +479,8 @@ class ColorMaterial { this._BasicTransparentMaterialMap2.set(key, mat); return mat; } - static GetColor(color) { + static GetColor(color) + { let rgb = ColorPalette[color]; if (rgb) return new Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255); @@ -507,14 +529,17 @@ ColorMaterial.TransparentLineMaterial = new MeshBasicMaterial({ /** * 坐标系运算. */ -class CoordinateSystem { - constructor(postion, xAxis, yAxis, zAxis) { +class CoordinateSystem +{ + constructor(postion, xAxis, yAxis, zAxis) + { this.Postion = postion || new Vector3(0, 0, 0); this.XAxis = xAxis || new Vector3(1, 0, 0); this.YAxis = yAxis || new Vector3(0, 1, 0); this.ZAxis = zAxis || new Vector3(0, 0, 1); } - applyMatrix4(mat4) { + applyMatrix4(mat4) + { this.Postion.applyMatrix4(mat4); let roMat = mat4.clone().setPosition(new Vector3()); this.XAxis.applyMatrix4(roMat); @@ -522,30 +547,35 @@ class CoordinateSystem { this.ZAxis.applyMatrix4(roMat); return this; } - getMatrix4() { + getMatrix4() + { let m = new Matrix4(); m.makeBasis(this.XAxis, this.YAxis, this.ZAxis); m.setPosition(this.Postion); return m; } - CopyForm(mat4) { + CopyForm(mat4) + { this.Postion.setFromMatrixPosition(mat4); mat4.extractBasis(this.XAxis, this.YAxis, this.ZAxis); return this; } - extractBasis(xAxisA, yAxisA, zAxisA) { + extractBasis(xAxisA, yAxisA, zAxisA) + { xAxisA.copy(this.XAxis); yAxisA.copy(this.YAxis); zAxisA.copy(this.ZAxis); } - copy(cs) { + copy(cs) + { this.Postion.copy(cs.Postion); this.XAxis.copy(cs.XAxis); this.YAxis.copy(cs.YAxis); this.ZAxis.copy(cs.ZAxis); return this; } - clone() { + clone() + { let r = new CoordinateSystem(); r.Postion = this.Postion.clone(); r.XAxis = this.XAxis.clone(); @@ -560,7 +590,8 @@ let HostApplicationServices = { ShowHistoryLog: true }; /** * 销毁Object对象的Geometry,并不会销毁材质(新版本销毁材质,好像问题不大?) */ -function DisposeThreeObj(obj) { +function DisposeThreeObj(obj) +{ for (let o of obj.children) { let oany = o; //文字的geometry缓存保留下来 @@ -583,7 +614,8 @@ function DisposeThreeObj(obj) { // obj.children.length = 0; return obj; } -function Object3DRemoveAll(obj) { +function Object3DRemoveAll(obj) +{ for (let o of obj.children) { o.parent = null; o.dispatchEvent({ type: "removed" }); @@ -593,7 +625,8 @@ function Object3DRemoveAll(obj) { } var Status; -(function (Status) { +(function (Status) +{ Status[Status["False"] = 0] = "False"; Status[Status["True"] = 1] = "True"; Status[Status["Canel"] = -1] = "Canel"; @@ -601,7 +634,8 @@ var Status; Status[Status["DuplicateRecordName"] = 102] = "DuplicateRecordName"; })(Status || (Status = {})); var UpdateDraw; -(function (UpdateDraw) { +(function (UpdateDraw) +{ UpdateDraw[UpdateDraw["None"] = 0] = "None"; UpdateDraw[UpdateDraw["Matrix"] = 1] = "Matrix"; UpdateDraw[UpdateDraw["Geometry"] = 2] = "Geometry"; @@ -612,7 +646,8 @@ var UpdateDraw; * WblockClne时,遇到重复记录的操作方式 */ var DuplicateRecordCloning; -(function (DuplicateRecordCloning) { +(function (DuplicateRecordCloning) +{ DuplicateRecordCloning[DuplicateRecordCloning["Ignore"] = 1] = "Ignore"; DuplicateRecordCloning[DuplicateRecordCloning["Replace"] = 2] = "Replace"; DuplicateRecordCloning[DuplicateRecordCloning["Rename"] = 3] = "Rename"; @@ -622,7 +657,8 @@ var DuplicateRecordCloning; * 场景的渲染类型. */ var RenderType; -(function (RenderType) { +(function (RenderType) +{ /** * 线框模式 */ @@ -660,7 +696,8 @@ var RenderType; })(RenderType || (RenderType = {})); var StoreageKeys; -(function (StoreageKeys) { +(function (StoreageKeys) +{ StoreageKeys["IsLogin"] = "isLogin"; StoreageKeys["PlatSession"] = "platSession"; StoreageKeys["PlatToken"] = "platToken"; @@ -680,12 +717,14 @@ var StoreageKeys; })(StoreageKeys || (StoreageKeys = {})); var AAType; -(function (AAType) { +(function (AAType) +{ AAType[AAType["FXAA"] = 0] = "FXAA"; AAType[AAType["SMAA"] = 1] = "SMAA"; })(AAType || (AAType = {})); var ViewDirType; -(function (ViewDirType) { +(function (ViewDirType) +{ ViewDirType[ViewDirType["FS"] = 0] = "FS"; ViewDirType[ViewDirType["YAS"] = 1] = "YAS"; ViewDirType[ViewDirType["ZS"] = 2] = "ZS"; @@ -695,8 +734,10 @@ var ViewDirType; ViewDirType[ViewDirType["XN"] = 6] = "XN"; })(ViewDirType || (ViewDirType = {})); -class UserConfig { - constructor() { +class UserConfig +{ + constructor() + { this._version = 13; this._renderType = RenderType.Wireframe; this.maxSize = { @@ -764,12 +805,11 @@ class UserConfig { this.configsNames = []; this.Init(); } - Init() { - let type = Number(localStorage.getItem(StoreageKeys.RenderType)); - if (type && type !== RenderType.Edge) - this._renderType = type; + Init() + { } - set RenderType(t) { + set RenderType(t) + { if (t !== this._renderType) { this._renderType = t; this.checkSealing = t === RenderType.Edge; @@ -779,15 +819,18 @@ class UserConfig { } get RenderType() { return this._renderType; } SetRenderTypeEvent() { } - get DrillConfigs() { + get DrillConfigs() + { return this._drillConfigs || new Map(); } - set DrillConfigs(config) { + set DrillConfigs(config) + { observable(this._drillConfigs).replace(config); this.SetDrillConfigsEvent(); } SetDrillConfigsEvent() { } - InitOption() { + InitOption() + { this.openDrillingReactor = true; this.openAutoCuttingReactor = true; Object.assign(this.maxSize, { @@ -809,7 +852,8 @@ class UserConfig { }); this.dimTextHeight = 60; } - SaveConfig() { + SaveConfig() + { return { option: { version: this._version, @@ -835,7 +879,8 @@ class UserConfig { } }; } - UpdateOption(config) { + UpdateOption(config) + { this.openDrillingReactor = config.option.openDrillingReactor; this.openAutoCuttingReactor = config.option.openAutoCuttingReactor; Object.assign(this.maxSize, config.option.maxSize); @@ -945,7 +990,8 @@ const userConfig = new UserConfig(); * 盒子的切割类型 */ var SplitType; -(function (SplitType) { +(function (SplitType) +{ SplitType[SplitType["X"] = 0] = "X"; SplitType[SplitType["Y"] = 1] = "Y"; SplitType[SplitType["Z"] = 2] = "Z"; @@ -953,16 +999,20 @@ var SplitType; /** * 扩展Box3,添加切割方法,体积等 */ -class Box3Ext extends Box3 { - get Volume() { +class Box3Ext extends Box3 +{ + get Volume() + { let size = this.getSize(new Vector3()); return size.x * size.y * size.z; } //每个轴的大小必须大于最小的size - isSolid(minSize = 1) { + isSolid(minSize = 1) + { return this.getSize(new Vector3()).toArray().every(x => x > minSize); } - substract(b, spaceType) { + substract(b, spaceType) + { let interBox = this.clone().intersect(b); if (interBox.isEmpty() || !interBox.isSolid()) return [this]; @@ -975,7 +1025,8 @@ class Box3Ext extends Box3 { new Box3Ext(p3, p4) ].filter(b => b.isSolid()); } - clampSpace(b2, splitType) { + clampSpace(b2, splitType) + { let interBox = this.clone(); interBox.min.max(b2.min); interBox.max.min(b2.max); @@ -983,17 +1034,20 @@ class Box3Ext extends Box3 { interBox.max.setComponent(splitType, Math.max(this.min.getComponent(splitType), b2.min.getComponent(splitType))); return interBox; } - intersectsBox(box, fuzz = 1e-8) { + intersectsBox(box, fuzz = 1e-8) + { return IntersectsBox(this, box, fuzz); } } -function IntersectsBox(box1, box2, fuzz = 1e-6) { +function IntersectsBox(box1, box2, fuzz = 1e-6) +{ return box2.max.x < box1.min.x - fuzz || box2.min.x > box1.max.x + fuzz || box2.max.y < box1.min.y - fuzz || box2.min.y > box1.max.y + fuzz || box2.max.z < box1.min.z - fuzz || box2.min.z > box1.max.z + fuzz ? false : true; } /**盒子二维面是否相交 */ -function IntersectBox2(box1, box2, fuzz = 1e-3) { +function IntersectBox2(box1, box2, fuzz = 1e-3) +{ return box2.max.x < box1.min.x - fuzz || box2.min.x > box1.max.x + fuzz || box2.max.y < box1.min.y - fuzz || box2.min.y > box1.max.y + fuzz ? false : true; } @@ -1008,22 +1062,26 @@ const ISPROXYKEY = "_isProxy"; * @param property * @param [descriptor] */ -function AutoRecord(target, property, descriptor) { +function AutoRecord(target, property, descriptor) +{ let privateKey = '__' + property; Object.defineProperty(target, property, { - set: function (value) { + set: function (value) + { if (value instanceof Array) { if (!this[privateKey]) { if (value[ISPROXYKEY]) this[privateKey] = value; else this[privateKey] = new Proxy(value, { - set: (target, key, value, receiver) => { + set: (target, key, value, receiver) => + { if (Reflect.get(target, key, receiver) !== value) this.WriteAllObjectRecord(); return Reflect.set(target, key, value, receiver); }, - get: (target, key, receiver) => { + get: (target, key, receiver) => + { if (key === ISPROXYKEY) return true; //实体先被删除后在触发length = xxx @@ -1047,7 +1105,8 @@ function AutoRecord(target, property, descriptor) { } } }, - get: function () { + get: function () + { return this[privateKey]; }, enumerable: true, @@ -1058,17 +1117,22 @@ function AutoRecord(target, property, descriptor) { /** * CAD对象工厂,通过注册 和暴露的创建方法,动态创建对象 */ -class CADFactory { - constructor() { +class CADFactory +{ + constructor() + { this.objectNameMap = new Map(); } - static RegisterObject(C) { + static RegisterObject(C) + { this.factory.objectNameMap.set(C.name, C); } - static RegisterObjectAlias(C, name) { + static RegisterObjectAlias(C, name) + { this.factory.objectNameMap.set(name, C); } - static CreateObject(name) { + static CreateObject(name) + { let C = this.factory.objectNameMap.get(name); if (C) return new C(); @@ -1076,12 +1140,14 @@ class CADFactory { } CADFactory.factory = new CADFactory(); //可以通过添加装饰器 在类前面(@Factory),自动注册工厂的序列化 -function Factory(target) { +function Factory(target) +{ CADFactory.RegisterObject(target); } var RelevancyType; -(function (RelevancyType) { +(function (RelevancyType) +{ RelevancyType[RelevancyType["General"] = 0] = "General"; RelevancyType[RelevancyType["Soft"] = 1] = "Soft"; RelevancyType[RelevancyType["Hard"] = 2] = "Hard"; @@ -1093,25 +1159,32 @@ CADObject对象拥有Id属性,用来记录引用关系. ObjectId必须使用 Database分配(db里面会存id的列表,以便同时更新id指向实体) */ -class ObjectId { - constructor(index = 0, obj) { +class ObjectId +{ + constructor(index = 0, obj) + { this.index = index; this.obj = obj; this._RelevancyType = RelevancyType.General; } - get IsErase() { + get IsErase() + { return !this.obj || this.obj.IsErase; } - set Object(obj) { + set Object(obj) + { this.obj = obj; } - get Object() { + get Object() + { return this.obj; } - get Index() { + get Index() + { return this.index; } - set Index(index) { + set Index(index) + { this.index = index; } } @@ -1119,38 +1192,48 @@ class ObjectId { /** * CAD文件数据 */ -class CADFiler { - constructor(_datas = []) { +class CADFiler +{ + constructor(_datas = []) + { this._datas = _datas; this.readIndex = 0; } - Destroy() { + Destroy() + { delete this._datas; delete this.readIndex; } - get Data() { + get Data() + { return this._datas; } - set Data(data) { + set Data(data) + { this._datas = data; this.Reset(); } - Clear() { + Clear() + { this._datas.length = 0; return this.Reset(); } - Reset() { + Reset() + { this.readIndex = 0; return this; } - WriteString(str) { + WriteString(str) + { this._datas.push(str); return this; } - ReadString() { + ReadString() + { return this._datas[this.readIndex++]; } - WriteObject(obj) { + WriteObject(obj) + { if (!obj) { this.Write(""); return; @@ -1159,7 +1242,8 @@ class CADFiler { obj.WriteFile(this); return this; } - ReadObject(obj) { + ReadObject(obj) + { let className = this.ReadString(); if (className) { if (obj === undefined) { @@ -1171,7 +1255,8 @@ class CADFiler { return obj; } } - CloneObjects(objects, clonedObjects = []) { + CloneObjects(objects, clonedObjects = []) + { for (let o of objects) this.WriteObject(o); let count = objects.length; @@ -1183,17 +1268,20 @@ class CADFiler { } return clonedObjects; } - Write(data) { + Write(data) + { if (data instanceof ObjectId) this._datas.push(data.Index); else this._datas.push(data); return this; } - Read() { + Read() + { return this._datas[this.readIndex++]; } - ReadArray(count) { + ReadArray(count) + { let arr = this._datas.slice(this.readIndex, this.readIndex + count); this.readIndex += count; return arr; @@ -1206,37 +1294,45 @@ class CADFiler { 3.硬关联 :对象被拷贝时,被关联的对象必须也被拷贝. */ //-------1.普通关联 - WriteObjectId(id) { + WriteObjectId(id) + { if (id) this.Write(id.Index); else this.Write(0); return this; } - ReadObjectId() { + ReadObjectId() + { let index = this.Read(); if (this.database) return this.database.GetObjectId(index, true); } //-------2.软关联 - WriteSoftObjectId(id) { + WriteSoftObjectId(id) + { return this.WriteObjectId(id); } - ReadSoftObjectId() { + ReadSoftObjectId() + { return this.ReadObjectId(); } //-------3.硬关联 - WriteHardObjectId(id) { + WriteHardObjectId(id) + { return this.WriteObjectId(id); } - ReadHardObjectId() { + ReadHardObjectId() + { return this.ReadObjectId(); } //序列化 - ToString() { + ToString() + { return JSON.stringify(this._datas); } - FromString(str) { + FromString(str) + { this._datas = JSON.parse(str); } } @@ -1244,8 +1340,10 @@ class CADFiler { /** * 保存对象创建或者修改时的所有数据记录 */ -let AllObjectData = class AllObjectData { - constructor(obj) { +let AllObjectData = class AllObjectData +{ + constructor(obj) + { this.file = new CADFiler(); if (obj) obj.WriteFile(this.file); @@ -1253,14 +1351,16 @@ let AllObjectData = class AllObjectData { //#region -------------------------File------------------------- //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象从文件中读取数据,初始化自身 - ReadFile(file) { + ReadFile(file) + { let ver = file.Read(); let data = file.Read(); this.file.Data = data; return this; } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { file.Write(1); file.Write(this.file.Data); return this; @@ -1270,15 +1370,19 @@ AllObjectData = __decorate([ Factory ], AllObjectData); -let EraseEntityData = class EraseEntityData { - constructor(isErase = true) { +let EraseEntityData = class EraseEntityData +{ + constructor(isErase = true) + { this.isErase = isErase; } - ReadFile(file) { + ReadFile(file) + { this.isErase = file.Read(); return this; } - WriteFile(file) { + WriteFile(file) + { file.Write(this.isErase); return this; } @@ -1287,25 +1391,31 @@ EraseEntityData = __decorate([ Factory ], EraseEntityData); -class CADObject { - constructor() { +class CADObject +{ + constructor() + { //-------------------------DB End------------------------- // -------------------------isErase------------------------- this._isErase = false; } - set Owner(owner) { + set Owner(owner) + { this._Owner = owner; } - get Owner() { + get Owner() + { return this._Owner; } - Destroy() { + Destroy() + { //在效果图同步反应器中,需要知道被删除的实体的id,所以不删除这个属性 // this.objectId = undefined; this._db = undefined; } //对象被彻底遗弃 - GoodBye() { + GoodBye() + { this.Destroy(); this.Erase(true); } @@ -1313,13 +1423,16 @@ class CADObject { * 当实体异步更新绘制实体完成后触发这个函数. * Application通过注入的方式得知这个事件,刷新视图显示. */ - AsyncUpdated() { + AsyncUpdated() + { } - get Db() { + get Db() + { return this._db; } //对象在加入数据库时,必须指定一个源数据库,否则无法读取引用id. - SetDefaultDb(db) { + SetDefaultDb(db) + { if (!this._db) this._db = db; else @@ -1329,7 +1442,8 @@ class CADObject { //private 私有的方法,暴露给Db的添加对象,方法使用. //只用对象加入到db中,我们才初始化ObjectId. //从db池中分配id给自身使用. 除非你创建对象往db里面加,否则不要调用该方法 - SetOwnerDatabase(db) { + SetOwnerDatabase(db) + { if (!this._db) { this._db = db; this.objectId = db.AllocateId(); @@ -1342,13 +1456,16 @@ class CADObject { /** * WblockClone 的时候,id是db分配的,此刻我们只需要设置它的db */ - SetDatabase(db) { + SetDatabase(db) + { this._db = db; } - get IsErase() { + get IsErase() + { return this._isErase; } - Erase(isErase = true) { + Erase(isErase = true) + { if (isErase === this._isErase) return; let undoData = this.UndoRecord(); @@ -1356,19 +1473,21 @@ class CADObject { undoData.CreateEraseHistory(this, isErase); this._isErase = isErase; } - get Id() { + get Id() + { return this.objectId; } // -------------------------id End------------------------- // -------------------------File------------------------- //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象从文件中读取数据,初始化自身 - ReadFile(file) { + ReadFile(file) + { let ver = file.Read(); //write Id; let id = file.ReadObjectId(); if (!this.objectId && id) //避免CopyFrom时错误的修改自身Id - { + { this.objectId = id; id.Object = this; } @@ -1377,14 +1496,16 @@ class CADObject { this.Owner = file.ReadObjectId(); } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { file.Write(2); file.WriteObjectId(this.objectId); file.Write(this._isErase); file.WriteObjectId(this.Owner); } //局部撤销 - ApplyPartialUndo(undoData) { + ApplyPartialUndo(undoData) + { if (undoData instanceof AllObjectData) { undoData.file.database = this._db; undoData.file.Reset(); @@ -1395,12 +1516,14 @@ class CADObject { } } //撤销所保存的位置 - UndoRecord() { + UndoRecord() + { if (this._db && this.objectId) return this._db.hm.UndoData; } //写入所有的对象数据 以便还原对象 - WriteAllObjectRecord() { + WriteAllObjectRecord() + { let undoData = this.UndoRecord(); if (undoData) { undoData.WriteObjectSnapshoot(this); @@ -1409,7 +1532,8 @@ class CADObject { return false; } //复制出一个实体,如果存在关联,则指向原关联实体 - Clone() { + Clone() + { let newObject = CADFactory.CreateObject(this.constructor.name); //备份 let bakId = this.objectId; @@ -1424,11 +1548,13 @@ class CADObject { this.objectId = bakId; return newObject; } - DeepClone(ownerObject, cloneObejct, idMaping = undefined, isPrimary = true) { + DeepClone(ownerObject, cloneObejct, idMaping = undefined, isPrimary = true) + { return this; } //从一个实体拷贝数据,实体类型必须相同. - CopyFrom(obj) { + CopyFrom(obj) + { let idBak = this.objectId; let ownerBak = this._Owner; this.WriteAllObjectRecord(); @@ -1447,16 +1573,19 @@ class CADObject { * 实体删除行为暂时无法监听 * @param setCallback 设置新的实体到数组时的回调函数 */ - CreateProxyArray(setCallback) { + CreateProxyArray(setCallback) + { return new Proxy([], { - set: (target, key, value, receiver) => { + set: (target, key, value, receiver) => + { if (Reflect.get(target, key, receiver) !== value) { this.WriteAllObjectRecord(); setCallback(value); } return Reflect.set(target, key, value, receiver); }, - get: (target, key, receiver) => { + get: (target, key, receiver) => + { if (key === ISPROXYKEY) return true; //实体先被删除后在触发length = xxx @@ -1469,16 +1598,15 @@ class CADObject { }); } } -__decorate([ - iaop -], CADObject.prototype, "AsyncUpdated", null); var Entity_1; /** * Entity 是所有图元的基类,绘制的实体都集成该类. */ -let Entity = Entity_1 = class Entity extends CADObject { - constructor() { +let Entity = Entity_1 = class Entity extends CADObject +{ + constructor() + { super(...arguments); this.IsEmbedEntity = false; /** @@ -1504,32 +1632,39 @@ let Entity = Entity_1 = class Entity extends CADObject { this.__UpdateVersion__ = 0; //#endregion } - get SpaceOCS() { + get SpaceOCS() + { return this._SpaceOCS.clone(); } - get SpaceOCSInv() { + get SpaceOCSInv() + { return new Matrix4().getInverse(this._SpaceOCS); } - set SpaceOCS(m) { + set SpaceOCS(m) + { this.WriteAllObjectRecord(); this._SpaceOCS.copy(m); } - set Material(materialId) { + set Material(materialId) + { this.WriteAllObjectRecord(); this.materialId = materialId; this.Update(); } - get Material() { + get Material() + { return this.materialId; } - set ColorIndex(color) { + set ColorIndex(color) + { if (color !== this._Color) { this.WriteAllObjectRecord(); this._Color = color; this.Update(UpdateDraw.Material); } } - get ColorIndex() { + get ColorIndex() + { return this._Color; } /** @@ -1539,42 +1674,52 @@ let Entity = Entity_1 = class Entity extends CADObject { /** * 返回对象的包围框. */ - get BoundingBox() { + get BoundingBox() + { return new Box3(); } /** * 返回对象在自身坐标系下的Box */ - get BoundingBoxInOCS() { + get BoundingBoxInOCS() + { let mtxBak = this._Matrix; this._Matrix = IdentityMtx4; let box = this.BoundingBox; this._Matrix = mtxBak; return new Box3Ext().copy(box); } - GetBoundingBoxInMtx(mtx) { + GetBoundingBoxInMtx(mtx) + { return this.BoundingBoxInOCS.applyMatrix4(this.OCS.premultiply(mtx)); } - get BoundingBoxInSpaceCS() { + get BoundingBoxInSpaceCS() + { return this.GetBoundingBoxInMtx(this.SpaceOCSInv); } - get OCS() { + get OCS() + { return this._Matrix.clone(); } - get OCSNoClone() { + get OCSNoClone() + { return this._Matrix; } //直接设置实体的矩阵,谨慎使用该函数,没有更新实体. - set OCS(mat4) { + set OCS(mat4) + { this._Matrix.copy(mat4); } - get Normal() { + get Normal() + { return new Vector3().setFromMatrixColumn(this._Matrix, 2); } - get Position() { + get Position() + { return new Vector3().setFromMatrixPosition(this._Matrix); } - set Position(pt) { + set Position(pt) + { let moveX = pt.x - this._Matrix.elements[12]; let moveY = pt.y - this._Matrix.elements[13]; let moveZ = pt.z - this._Matrix.elements[14]; @@ -1588,7 +1733,8 @@ let Entity = Entity_1 = class Entity extends CADObject { this.Update(UpdateDraw.Matrix); } //Z轴归0 - Z0() { + Z0() + { if (this._Matrix.elements[14] === 0) return this; this.WriteAllObjectRecord(); @@ -1597,7 +1743,8 @@ let Entity = Entity_1 = class Entity extends CADObject { return this; } //坐标系二维化 - MatrixPlanarizere() { + MatrixPlanarizere() + { let z = this._Matrix.elements[10]; if (equaln(Math.abs(z), 1, 1e-4)) { this.WriteAllObjectRecord(); @@ -1605,25 +1752,29 @@ let Entity = Entity_1 = class Entity extends CADObject { } return this; } - get OCSInv() { + get OCSInv() + { return new Matrix4().getInverse(this._Matrix); } /** * 与指定实体是否共面. */ - IsCoplaneTo(e) { + IsCoplaneTo(e) + { return matrixIsCoplane(this._Matrix, e.OCS, 1e-4); } /** * 测试两个实体的包围盒是否相交. */ - BoundingBoxIntersectWith(en) { + BoundingBoxIntersectWith(en) + { let box = this.BoundingBox; let box2 = en.BoundingBox; return box && box2 && box.intersectsBox(box2); } //#region Draw - ClearDraw() { + ClearDraw() + { if (this._drawObject) { DisposeThreeObj(this._drawObject); this._drawObject = undefined; @@ -1633,7 +1784,8 @@ let Entity = Entity_1 = class Entity extends CADObject { this._CacheDrawObject.clear(); return this; } - ClearDrawOfJig() { + ClearDrawOfJig() + { let jig = this._CacheDrawObject.get(RenderType.Jig); if (jig) this._CacheDrawObject.delete(RenderType.Jig); @@ -1643,10 +1795,12 @@ let Entity = Entity_1 = class Entity extends CADObject { if (jig) this._CacheDrawObject.set(RenderType.Jig, jig); } - get IsOnlyRender() { + get IsOnlyRender() + { return this.OnlyRenderType; } - get DrawObject() { + get DrawObject() + { if (this._drawObject) return this._drawObject; this._drawObject = new Object3D(); @@ -1662,13 +1816,15 @@ let Entity = Entity_1 = class Entity extends CADObject { this._drawObject.visible = false; return this._drawObject; } - get JigObject() { + get JigObject() + { let obj = this.GetDrawObjectFromRenderType(RenderType.Jig); if (obj && !this.IsEmbedEntity) obj.userData.Entity = this; return obj; } - DestroyJigObject() { + DestroyJigObject() + { let obj = this._CacheDrawObject.get(RenderType.Jig); if (obj) { this._CacheDrawObject.delete(RenderType.Jig); @@ -1677,7 +1833,8 @@ let Entity = Entity_1 = class Entity extends CADObject { obj.parent.remove(obj); } } - UpdateRenderType(type) { + UpdateRenderType(type) + { if (this._CurRenderType !== type || this.DrawObject.children.length === 0) { this._CurRenderType = type; if ((this.OnlyRenderType && this.DrawObject.children.length > 0) || !this.Visible) @@ -1688,7 +1845,8 @@ let Entity = Entity_1 = class Entity extends CADObject { this.DrawObject.add(obj); } } - GetDrawObjectFromRenderType(renderType = RenderType.Wireframe) { + GetDrawObjectFromRenderType(renderType = RenderType.Wireframe) + { if (this.OnlyRenderType) { if (renderType === RenderType.Jig) return; @@ -1721,13 +1879,15 @@ let Entity = Entity_1 = class Entity extends CADObject { /** * 初始化绘制的threejs实体,子类型重载该函数初始化绘制实体. */ - InitDrawObject(renderType = RenderType.Wireframe) { + InitDrawObject(renderType = RenderType.Wireframe) + { return undefined; } /** * 当实体数据改变时,绘制的实体必须做出改变.供框架调用 */ - Update(mode = UpdateDraw.All) { + Update(mode = UpdateDraw.All) + { this.__UpdateVersion__++; this.NeedUpdateFlag |= mode; if (this.AutoUpdate) @@ -1736,7 +1896,8 @@ let Entity = Entity_1 = class Entity extends CADObject { //三维实体总是一起生成线框实体和网格实体,这个通知更新,然后统一更新就好了 //避免重复更新 UpdateDrawGeometry() { } - DeferUpdate() { + DeferUpdate() + { let mode = this.NeedUpdateFlag; if (mode === 0) return; @@ -1775,14 +1936,17 @@ let Entity = Entity_1 = class Entity extends CADObject { /** * 当实体需要更新时,需要重载该方法,实现实体更新 */ - UpdateDrawObject(type, en) { + UpdateDrawObject(type, en) + { } /** * 当实体需要被更新时,更新实体材质 */ - UpdateDrawObjectMaterial(type, obj, material) { + UpdateDrawObjectMaterial(type, obj, material) + { } - get MeshMaterial() { + get MeshMaterial() + { if (this.materialId && this.materialId.Object) return this.materialId.Object.Material; return HostApplicationServices.DefaultMeshMaterial; @@ -1790,26 +1954,32 @@ let Entity = Entity_1 = class Entity extends CADObject { /** * 更新实体Jig状态时的材质 */ - UpdateJigMaterial(color = 8) { + UpdateJigMaterial(color = 8) + { } - RestoreJigMaterial() { + RestoreJigMaterial() + { for (let [type, en] of this._CacheDrawObject) this.UpdateDrawObjectMaterial(type, en); } - get Visible() { + get Visible() + { return this._Visible; } - set Visible(v) { + set Visible(v) + { if (v !== this._Visible) { this.WriteAllObjectRecord(); this._Visible = v; this.UpdateVisible(); } } - get IsVisible() { + get IsVisible() + { return !this._isErase && this._Visible; } - UpdateVisible() { + UpdateVisible() + { if (this._drawObject) { this._drawObject.visible = this.IsVisible; if (this.IsVisible) @@ -1817,13 +1987,15 @@ let Entity = Entity_1 = class Entity extends CADObject { } } //#endregion - GoodBye() { + GoodBye() + { super.GoodBye(); if (this._drawObject && this._drawObject.parent) this._drawObject.parent.remove(this._drawObject); this.ClearDraw(); } - Erase(isErase = true) { + Erase(isErase = true) + { if (isErase === this._isErase) return; this.__UpdateVersion__++; @@ -1831,13 +2003,15 @@ let Entity = Entity_1 = class Entity extends CADObject { this.UpdateVisible(); this.EraseEvent(isErase); } - EraseEvent(isErase) { + EraseEvent(isErase) + { } /** * 使用统一的方法设置对象的矩阵. * 需要对缩放矩形进行重载.避免对象矩阵不是单位矩阵 */ - ApplyMatrix(m) { + ApplyMatrix(m) + { this.WriteAllObjectRecord(); if (equaln(m.getMaxScaleOnAxis(), 1)) { let xA = new Vector3(); @@ -1856,16 +2030,20 @@ let Entity = Entity_1 = class Entity extends CADObject { } return this; } - ApplyScaleMatrix(m) { + ApplyScaleMatrix(m) + { return this; } - ApplyMirrorMatrix(m) { + ApplyMirrorMatrix(m) + { return this; } - GetGripPoints() { + GetGripPoints() + { return []; } - MoveGripPoints(indexList, vec) { + MoveGripPoints(indexList, vec) + { } /** * @@ -1875,10 +2053,12 @@ let Entity = Entity_1 = class Entity extends CADObject { * @param viewXform const 最近点捕捉需要这个变量 * @returns object snap points */ - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { return []; } - GetStretchPoints() { + GetStretchPoints() + { return []; } /** @@ -1888,18 +2068,21 @@ let Entity = Entity_1 = class Entity extends CADObject { * @param {Vector3} vec 移动向量 * @memberof Entity */ - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { } IntersectWith(curve, intType) { return; } //#region -------------------------File------------------------- - Clone() { + Clone() + { let ent = super.Clone(); ent._CurRenderType = this._CurRenderType; ent.Template = undefined; ent.CloneDrawObject(this); return ent; } - CloneDrawObject(from) { + CloneDrawObject(from) + { for (let [type, obj] of from._CacheDrawObject) { let oldUserDaata = obj.userData; obj.traverse(o => o.userData = {}); @@ -1913,20 +2096,23 @@ let Entity = Entity_1 = class Entity extends CADObject { } this.NeedUpdateFlag = UpdateDraw.None; } - get ReadFileIng() { + get ReadFileIng() + { return this.__ReadFileIng__ || Entity_1.__ReadFileIng__; } /** * 从文件读取,序列化自身,如果需要,重载_ReadFile */ - ReadFile(file) { + ReadFile(file) + { this.__ReadFileIng__ = true; this._ReadFile(file); this.Update(); this.__ReadFileIng__ = false; } //对象从文件中读取数据,初始化自身 - _ReadFile(file) { + _ReadFile(file) + { let ver = file.Read(); super.ReadFile(file); this._Color = file.Read(); @@ -1950,7 +2136,8 @@ let Entity = Entity_1 = class Entity extends CADObject { } } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { file.Write(8); super.WriteFile(file); file.Write(this._Color); @@ -1965,10 +2152,12 @@ let Entity = Entity_1 = class Entity extends CADObject { file.WriteHardObjectId(id); } //局部撤销 - ApplyPartialUndo(undoData) { + ApplyPartialUndo(undoData) + { super.ApplyPartialUndo(undoData); } - CopyFrom(obj) { + CopyFrom(obj) + { let templateIdBak = this.Template; super.CopyFrom(obj); this.Update(); @@ -1984,12 +2173,6 @@ __decorate([ __decorate([ AutoRecord ], Entity.prototype, "ProcessingGroupList", void 0); -__decorate([ - iaop -], Entity.prototype, "Update", null); -__decorate([ - iaop -], Entity.prototype, "EraseEvent", null); Entity = Entity_1 = __decorate([ Factory ], Entity); @@ -2002,7 +2185,8 @@ let OPERATORS = new Set(["+", "-", "*", "/"]); * @param [defaultParam] 当输入 +10 这样的表达式时,设置默认的操作变量 * @returns 计算结果 */ -function eval2(expr, params, defaultParam) { +function eval2(expr, params, defaultParam) +{ let code = ""; if (params) for (let name in params) @@ -2018,7 +2202,8 @@ function eval2(expr, params, defaultParam) { return result(); return Number(result); //防止bigint乱入 } -function safeEval(expr, params, defaultParam) { +function safeEval(expr, params, defaultParam) +{ try { return eval2(expr, params); } @@ -2028,7 +2213,8 @@ function safeEval(expr, params, defaultParam) { } const Reg_Expr = /\{[^\}]+\}/g; /**解析大括号内的 */ -function ParseExpr(expr, params) { +function ParseExpr(expr, params) +{ let strs = expr.match(Reg_Expr); if (!strs) return expr; @@ -2039,10 +2225,12 @@ function ParseExpr(expr, params) { /**扣除封边是否相连和连接共用精度 */ const LINK_FUZZ = 1e-3; -function clamp(value, min, max) { +function clamp(value, min, max) +{ return Math.max(min, Math.min(max, value)); } -function FixIndex(index, arr) { +function FixIndex(index, arr) +{ let count = (arr instanceof Array) ? arr.length : arr; if (index < 0) return count + index; @@ -2052,7 +2240,8 @@ function FixIndex(index, arr) { return index; } //使用定点表示法来格式化一个数,小数点后面不尾随0. 如 FixedNotZero(1.1 , 3) => 1.1 -function FixedNotZero(v, fractionDigits = 0) { +function FixedNotZero(v, fractionDigits = 0) +{ if (typeof v === "string") v = parseFloat(v); if (isNaN(v)) @@ -2084,7 +2273,8 @@ function FixedNotZero(v, fractionDigits = 0) { * @param [fractionDigits] * @returns */ -function ToFixed(v, fractionDigits = 5) { +function ToFixed(v, fractionDigits = 5) +{ if (equaln(v, 0, Math.pow(0.1, fractionDigits))) return "0"; return v.toFixed(fractionDigits); @@ -2097,19 +2287,23 @@ const XAxisN = new Vector3(-1, 0, 0); const YAxis = new Vector3(0, 1, 0); const YAxisN = new Vector3(0, -1, 0); const ZAxis = new Vector3(0, 0, 1); -function AsVector2(p) { +function AsVector2(p) +{ return new Vector2(p.x, p.y); } -function AsVector3(p) { +function AsVector3(p) +{ return new Vector3(p.x, p.y, p.z); } /** * 判断一维线段a和b是否存在交集 */ -function isIntersect(amin, amax, bmin, bmax, eps = 0) { +function isIntersect(amin, amax, bmin, bmax, eps = 0) +{ return Math.max(amin, bmin) < Math.min(amax, bmax) + eps; } -function isIntersect2(a1, a2, b1, b2, eps = 0) { +function isIntersect2(a1, a2, b1, b2, eps = 0) +{ if (a1 > a2) [a1, a2] = [a2, a1]; if (b1 > b2) @@ -2122,7 +2316,8 @@ function isIntersect2(a1, a2, b1, b2, eps = 0) { * @param {number} a 角度. * @returns {Vector3} 返回pt不拷贝. */ -function rotatePoint(p, a) { +function rotatePoint(p, a) +{ let s = Math.sin(a); let c = Math.cos(a); let x = p.x * c - p.y * s; @@ -2131,13 +2326,16 @@ function rotatePoint(p, a) { p.y = y; return p; } -function equaln(v1, v2, fuzz = 1e-5) { +function equaln(v1, v2, fuzz = 1e-5) +{ return Math.abs(v1 - v2) <= fuzz; } -function equalv3(v1, v2, fuzz = 1e-8) { +function equalv3(v1, v2, fuzz = 1e-8) +{ return equaln(v1.x, v2.x, fuzz) && equaln(v1.y, v2.y, fuzz) && equaln(v1.z, v2.z, fuzz); } -function equalv2(v1, v2, fuzz = 1e-8) { +function equalv2(v1, v2, fuzz = 1e-8) +{ return equaln(v1.x, v2.x, fuzz) && equaln(v1.y, v2.y, fuzz); } /** @@ -2150,12 +2348,14 @@ function equalv2(v1, v2, fuzz = 1e-8) { * @param {number} dis 距离 * @returns {T} */ -function polar(v, an, dis) { +function polar(v, an, dis) +{ v.x += Math.cos(an) * dis; v.y += Math.sin(an) * dis; return v; } -function angle(v) { +function angle(v) +{ let angle = Math.atan2(v.y, v.x); if (equaln(angle, 0, 1e-8)) return 0; @@ -2171,7 +2371,8 @@ function angle(v) { * @param {Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1 * @returns */ -function angleTo(v1, v2, ref = ZAxis) { +function angleTo(v1, v2, ref = ZAxis) +{ if (v1.equals(ZeroVec) || v2.equals(ZeroVec)) return 0; v1 = v1.clone(); @@ -2198,7 +2399,8 @@ function angleTo(v1, v2, ref = ZAxis) { cv.normalize(); return equaln(cv.z, 0) ? v1.angleTo(v2) : v1.angleTo(v2) * cv.z; } -function getLoocAtUpVec(dir) { +function getLoocAtUpVec(dir) +{ if (dir.equals(ZeroVec)) { throw ("zero vector"); } @@ -2220,37 +2422,44 @@ function getLoocAtUpVec(dir) { /** * 判断2个向量是不是平行,尽量传入单位向量,才能保证计算精度 */ -function isParallelTo(v1, v2, fuzz = 1e-8) { +function isParallelTo(v1, v2, fuzz = 1e-8) +{ return v1.clone().cross(v2).lengthSq() < fuzz; } /** * 垂直向量 */ -function isPerpendicularityTo(v1, v2, fuzz = 1e-8) { +function isPerpendicularityTo(v1, v2, fuzz = 1e-8) +{ return equaln(v1.dot(v2), 0, fuzz); } -function midPoint(v1, v2) { +function midPoint(v1, v2) +{ return v1.clone().add(v2).multiplyScalar(0.5); } -function MoveMatrix(v) { +function MoveMatrix(v) +{ return new Matrix4().setPosition(v); } /** * 将角度调整为0-2pi之间 */ -function clampRad(an) { +function clampRad(an) +{ an = an % (Math.PI * 2); if (an < 0) an += Math.PI * 2; return an; } -function updateGeometry(l, geometry) { +function updateGeometry(l, geometry) +{ let geo = l.geometry; geo.dispose(); l.geometry = geometry; geometry.computeBoundingSphere(); } -function UpdateBoundingSphere(obj) { +function UpdateBoundingSphere(obj) +{ //@ts-ignore let geo = obj.geometry; if (geo) @@ -2273,7 +2482,8 @@ const comparePointCache = new Map(); * @param {string} sortKey * @returns {compareVectorFn} */ -function comparePoint(sortKey) { +function comparePoint(sortKey) +{ if (comparePointCache.has(sortKey)) return comparePointCache.get(sortKey); let sortIndex = []; @@ -2284,7 +2494,8 @@ function comparePoint(sortKey) { let ci = Math.floor(i2); sortIndex.push([ci, i2 > ci ? 1 : -1]); } - let compareFunction = (v1, v2) => { + let compareFunction = (v1, v2) => + { if (!v1) return -1; if (!v2) @@ -2304,7 +2515,8 @@ function comparePoint(sortKey) { comparePointCache.set(sortKey, compareFunction); return compareFunction; } -function SelectNearP(pts, refPt) { +function SelectNearP(pts, refPt) +{ if (pts.length > 1) { let dist1 = refPt.distanceToSquared(pts[0]); let dist2 = refPt.distanceToSquared(pts[1]); @@ -2313,11 +2525,13 @@ function SelectNearP(pts, refPt) { return pts[0]; } /**n是否在AB之间,fuzz 若为负的,允许相等 */ -function IsBetweenA2B(n, A, B, fuzz = -1e-8) { +function IsBetweenA2B(n, A, B, fuzz = -1e-8) +{ return n > A + fuzz && n < B - fuzz; } /** 矩阵是世界坐标系 */ -function MatrixIsIdentityCS(mtx) { +function MatrixIsIdentityCS(mtx) +{ return mtx.elements[0] === 1 && mtx.elements[5] === 1 && mtx.elements[10] === 1 && mtx.elements[12] === 0 && mtx.elements[13] === 0 && mtx.elements[14] === 0; } @@ -2327,7 +2541,8 @@ function MatrixIsIdentityCS(mtx) { * @param {number} col 列索引,0x 1y 2z 3org * @param {Vector3} v 向量或点 */ -function matrixSetVector(mat, col, v) { +function matrixSetVector(mat, col, v) +{ let index = col * 4; mat.elements[index] = v.x; mat.elements[index + 1] = v.y; @@ -2339,7 +2554,8 @@ function matrixSetVector(mat, col, v) { * Y轴坐标轴以及Z轴坐标系统之间的坐标系统坐标系统的原点坐标系和原点坐标系统坐标轴的坐标系分别设置为XAxis,YAxis和ZAxis * @returns {Matrix4} 返回新的矩阵 */ -function matrixAlignCoordSys(matrixFrom, matrixTo) { +function matrixAlignCoordSys(matrixFrom, matrixTo) +{ return new Matrix4().getInverse(matrixTo).multiply(matrixFrom); } /** @@ -2348,7 +2564,8 @@ function matrixAlignCoordSys(matrixFrom, matrixTo) { * @param {Matrix4} matrixTo * @returns {boolean} 2个矩阵共面 */ -function matrixIsCoplane(matrixFrom, matrixTo, fuzz = 1e-5) { +function matrixIsCoplane(matrixFrom, matrixTo, fuzz = 1e-5) +{ let nor1 = new Vector3().setFromMatrixColumn(matrixFrom, 2); let nor2 = new Vector3().setFromMatrixColumn(matrixTo, 2); //法线共面 @@ -2363,14 +2580,16 @@ function matrixIsCoplane(matrixFrom, matrixTo, fuzz = 1e-5) { /** * 修正镜像后矩阵 */ -function reviseMirrorMatrix(mtx) { +function reviseMirrorMatrix(mtx) +{ let cs = new CoordinateSystem().applyMatrix4(mtx); cs.YAxis.negate(); mtx.copy(cs.getMatrix4()); return mtx; } let cacheVec; -function Vector2ApplyMatrix4(mtx, vec) { +function Vector2ApplyMatrix4(mtx, vec) +{ if (!cacheVec) cacheVec = new Vector3(); cacheVec.x = vec.x; @@ -2379,7 +2598,8 @@ function Vector2ApplyMatrix4(mtx, vec) { vec.x = cacheVec.x; vec.y = cacheVec.y; } -function GetMirrorMat(v) { +function GetMirrorMat(v) +{ let mirrorMat = new Matrix4(); let xAxis = new Vector3(1 - 2 * v.x ** 2, -2 * v.x * v.y, -2 * v.x * v.z); let yAxis = new Vector3(-2 * v.x * v.y, 1 - 2 * v.y ** 2, -2 * v.y * v.z); @@ -2390,7 +2610,8 @@ function GetMirrorMat(v) { /** * 把变换矩阵展平成2d矩阵,避免出现三维坐标. */ -function MatrixPlanarizere(mtx, z0 = true) { +function MatrixPlanarizere(mtx, z0 = true) +{ mtx.elements[2] = 0; mtx.elements[6] = 0; mtx.elements[8] = 0; @@ -2407,7 +2628,8 @@ const ZMirrorMatrix = GetMirrorMat(new Vector3(0, 0, 1)); * OSMODE */ var ObjectSnapMode; -(function (ObjectSnapMode) { +(function (ObjectSnapMode) +{ ObjectSnapMode[ObjectSnapMode["None"] = 0] = "None"; ObjectSnapMode[ObjectSnapMode["End"] = 1] = "End"; ObjectSnapMode[ObjectSnapMode["Mid"] = 2] = "Mid"; @@ -2431,8 +2653,10 @@ const BufferGeometry2GeometryCacheMap = new WeakMap(); globalThis.fuck = BufferGeometry2GeometryCacheMap; var BufferGeometryUtils; -(function (BufferGeometryUtils) { - function CreateFromPts(pts) { +(function (BufferGeometryUtils) +{ + function CreateFromPts(pts) + { return new BufferGeometry().setFromPoints(pts); } BufferGeometryUtils.CreateFromPts = CreateFromPts; @@ -2442,7 +2666,8 @@ var BufferGeometryUtils; * @param pts * @returns 当成功时返回true,更新失败时返回false */ - function UpdatePts(geo, pts) { + function UpdatePts(geo, pts) + { let bf = geo.getAttribute("position"); if (bf === undefined) geo.setFromPoints(pts); @@ -2458,7 +2683,8 @@ var BufferGeometryUtils; } BufferGeometryUtils.UpdatePts = UpdatePts; let arrowGeometry; - function ArrowGeometry() { + function ArrowGeometry() + { if (arrowGeometry) return arrowGeometry; else { @@ -2471,7 +2697,8 @@ var BufferGeometryUtils; } } BufferGeometryUtils.ArrowGeometry = ArrowGeometry; - function MergeBufferGeometries(geometries, useGroups = false) { + function MergeBufferGeometries(geometries, useGroups = false) + { if (geometries.length === 0) return new BufferGeometry(); let isIndexed = geometries[0].index !== null; @@ -2564,7 +2791,8 @@ var BufferGeometryUtils; return mergedGeometry; } BufferGeometryUtils.MergeBufferGeometries = MergeBufferGeometries; - function MergeBufferAttributes(attributes) { + function MergeBufferAttributes(attributes) + { let TypedArray; let itemSize; let normalized; @@ -2596,8 +2824,10 @@ var BufferGeometryUtils; BufferGeometryUtils.MergeBufferAttributes = MergeBufferAttributes; })(BufferGeometryUtils || (BufferGeometryUtils = {})); -class Shape2 extends Shape$1 { - getPoints(divisions = 12) { +class Shape2 extends Shape$1 +{ + getPoints(divisions = 12) + { divisions = divisions || 12; let points = [], last; for (let i = 0, curves = this.curves; i < curves.length; i++) { @@ -2627,7 +2857,8 @@ class Shape2 extends Shape$1 { } return points; } - absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) { + absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) + { let curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation); /* if (this.curves.length > 0) @@ -2647,18 +2878,22 @@ class Shape2 extends Shape$1 { } } -class Matrix2 { - constructor() { +class Matrix2 +{ + constructor() + { //column-major this.el = [1, 0, 0, 1]; //ix iy jx jy [a c b d] } - set(ix, iy, jx, jy) { + set(ix, iy, jx, jy) + { this.el[0] = ix; this.el[1] = iy; this.el[2] = jx; this.el[3] = jy; } - applyVector(vec) { + applyVector(vec) + { let x = vec.x; let y = vec.y; let e = this.el; @@ -2666,17 +2901,20 @@ class Matrix2 { vec.y = e[1] * x + e[3] * y; return this; } - fromMatrix4(mtx4) { + fromMatrix4(mtx4) + { this.set(mtx4.elements[0], mtx4.elements[1], mtx4.elements[3], mtx4.elements[4]); } - setRotate(theta) { + setRotate(theta) + { let c = Math.cos(theta); let s = Math.sin(theta); this.set(c, s, -s, c); return this; } //自我求逆矩阵,返回自身 - invert() { + invert() + { //ref:https://www.mathsisfun.com/algebra/matrix-inverse.html let [a, c, b, d] = this.el; let det = 1 / (a * d - b * c); @@ -2686,7 +2924,8 @@ class Matrix2 { } let r = new Matrix2(); -function RotateUVs(geo) { +function RotateUVs(geo) +{ r.set(0, -1, 1, 0); for (let uvs of geo.faceVertexUvs) { for (let uv of uvs) { @@ -2698,10 +2937,13 @@ function RotateUVs(geo) { } var CreateBoardUtil; -(function (CreateBoardUtil) { +(function (CreateBoardUtil) +{ //解析二维圆弧 - class Arc2d { - constructor(p1, p2, bul) { + class Arc2d + { + constructor(p1, p2, bul) + { this._StartPoint = p1.clone(); this._EndPoint = p2.clone(); let vec = p2.clone().sub(p1); @@ -2725,7 +2967,8 @@ var CreateBoardUtil; } CreateBoardUtil.Arc2d = Arc2d; //创建轮廓 通过点表和凸度 - function CreatePath(pts, buls) { + function CreatePath(pts, buls) + { let shape = new Shape2(); if (pts.length === 0) return shape; @@ -2750,7 +2993,8 @@ var CreateBoardUtil; } CreateBoardUtil.CreatePath = CreatePath; //创建板件 暂时这么写 - function createBoard(boardData) { + function createBoard(boardData) + { var pts = new Array(); var buls = new Array(); var boardPts = boardData["Pts"]; @@ -2796,8 +3040,10 @@ var CreateBoardUtil; * 曲线连接图 * 所有的顶点和边的关系 */ -class CurveMap { - constructor(numdimensions = 4, _RemoveSortLine = false, multiplier = 10 ** numdimensions) { +class CurveMap +{ + constructor(numdimensions = 4, _RemoveSortLine = false, multiplier = 10 ** numdimensions) + { this.numdimensions = numdimensions; this._RemoveSortLine = _RemoveSortLine; this.multiplier = multiplier; @@ -2813,7 +3059,8 @@ class CurveMap { /** * 得到节点图的所有站点列表 */ - get Stands() { + get Stands() + { return this._Vertices; } /** @@ -2822,7 +3069,8 @@ class CurveMap { * @param [removeDuplicate=false] * @returns 加入成功? */ - AddCurveToMap(curve, isArc = curve instanceof Arc, removeDuplicate = false, parseAngle = false) { + AddCurveToMap(curve, isArc = curve instanceof Arc, removeDuplicate = false, parseAngle = false) + { let sp = curve.StartPoint; let ep = curve.EndPoint; let startS = this.GetOnlyVertice(sp); @@ -2831,8 +3079,9 @@ class CurveMap { if (this._RemoveSortLine && startS === endS) return false; if (removeDuplicate) //删除重复 - { - let index = startS.routes.findIndex(r => { + { + let index = startS.routes.findIndex(r => + { if (r.to === endS && r.curve.constructor.name === curve.constructor.name) { if (isArc) return equalv3(curve.GetPointAtParam(0.5), r.curve.GetPointAtParam(0.5)); @@ -2858,7 +3107,8 @@ class CurveMap { /** * 获得唯一的顶点 */ - GetOnlyVertice(p) { + GetOnlyVertice(p) + { let gp = this.GenerateP(p); if (this._VerticeMap.has(gp)) return this._VerticeMap.get(gp); @@ -2870,7 +3120,8 @@ class CurveMap { /** * 生成一个唯一的向量. */ - GenerateP(p) { + GenerateP(p) + { let key = ""; let els = p.toArray(); for (let n of els) { @@ -2879,7 +3130,8 @@ class CurveMap { } if (key in this._LookupTable) return this._LookupTable[key]; - let hashparts = els.map((el) => { + let hashparts = els.map((el) => + { let q0 = Math.floor(el * this.multiplier); let q1 = q0 + 1; return ['' + q0 + '/', '' + q1 + '/']; @@ -2889,7 +3141,8 @@ class CurveMap { for (let hashmask = 0; hashmask < numhashes; ++hashmask) { let hashmaskShifted = hashmask; key = ''; - hashparts.forEach(function (hashpart) { + hashparts.forEach(function (hashpart) + { key += hashpart[hashmaskShifted & 1]; hashmaskShifted >>= 1; }); @@ -2906,13 +3159,15 @@ class CurveMap { 算法只实现去重模式,业务场景应该没有非去重模式。 如果需要非去重模式,那么应该获取到多个CurveMap,然后对多个CurveMap进行面域分析,得出多个重叠的面域。 */ -class RegionParse { +class RegionParse +{ /** * @param cuList 请不要传递圆和椭圆. * @param [numDimensions=3] 精度:小数点后个数 * @param [removeDuplicate=true] 删除重复(现在必须是true,请不要修改它) */ - constructor(cuList, numDimensions = 3, removeDuplicate = true) { + constructor(cuList, numDimensions = 3, removeDuplicate = true) + { this.numDimensions = numDimensions; this.removeDuplicate = removeDuplicate; //区域列表 通常是外轮廓 @@ -2944,7 +3199,7 @@ class RegionParse { if (maxWalk.length > 1) { this.RegionsOutline.push(maxWalk); if (minWalk.length === maxWalk.length && minWalk.every((w1, index) => w1 === maxWalk[index])) //大小重叠 - { + { //直接remove,不用计算引用个数 for (let w of minWalk) { this.RemoveEdge(w); @@ -2958,7 +3213,7 @@ class RegionParse { w.curve.TempData = 1; } if (minWalk.length > 1) // && minWalk.every(w => (w.curve.TempData) < 2) 没有重复线应该不会被用2次 - { + { this.RegionsInternal.push(minWalk); for (let w of minWalk) { w.curve.TempData++; @@ -2971,7 +3226,8 @@ class RegionParse { } } } - RemoveFilamentAt(v, vertices) { + RemoveFilamentAt(v, vertices) + { let current = v; while (current && current.routes.length < 2) { vertices = arrayRemoveOnce(vertices, current); @@ -2984,7 +3240,8 @@ class RegionParse { current = undefined; } } - RemoveEdge(r) { + RemoveEdge(r) + { let index = r.from.routes.findIndex(rr => rr.curve === r.curve); if (index !== -1) r.from.routes.splice(index, 1); @@ -2995,8 +3252,10 @@ class RegionParse { /** * 找到最下方并且最左边的站 yx */ - FindLowerLeftStand(vertices) { - return vertices.reduce((m, v) => { + FindLowerLeftStand(vertices) + { + return vertices.reduce((m, v) => + { let dy = v.position.y - m.position.y; if (dy < 0) return v; @@ -3009,16 +3268,19 @@ class RegionParse { * 构造路线图. 每个节点对应下一个路口的路线表. 路口表使用逆时针排序,起始角度使用正x轴. * @returns 所有的顶点 */ - GenerateVerticeMap(curveList) { + GenerateVerticeMap(curveList) + { let curveMap = new CurveMap(this.numDimensions, true); //将多段线炸开 let plcus = []; - arrayRemoveIf(curveList, c => { + arrayRemoveIf(curveList, c => + { if (c instanceof Polyline) { let cus = c.Explode(); //如果为圆弧,提前打断 let arcs = []; - arrayRemoveIf(cus, c => { + arrayRemoveIf(cus, c => + { if (c.Length < 1e-5) return true; if (c instanceof Arc) { @@ -3065,7 +3327,8 @@ class RegionParse { } return curveMap.Stands; } - BreakArc(arc) { + BreakArc(arc) + { let underPt = arc.Center.add(new Vector3(0, -arc.Radius)); let param = arc.GetParamAtPoint(underPt); if (param > 0.01 && param < 0.99) @@ -3076,7 +3339,8 @@ class RegionParse { /** * 曲线是否已经被算法使用 */ - GetCueveUsed(cu) { + GetCueveUsed(cu) + { if (this.ExpLineMap.has(cu)) { let use = this.ExpLineMap.get(cu).some(c => c.TempData > 0); if (!use) @@ -3087,7 +3351,8 @@ class RegionParse { return cu.TempData > 0; } } -function CalcRouteAngle(r, length) { +function CalcRouteAngle(r, length) +{ if (r.an !== undefined) return; let cu = r.curve; @@ -3097,11 +3362,13 @@ function CalcRouteAngle(r, length) { r.an = angle(p.sub(r.from.position)); } var WalkType; -(function (WalkType) { +(function (WalkType) +{ WalkType[WalkType["Min"] = 1] = "Min"; WalkType[WalkType["Max"] = -1] = "Max"; })(WalkType || (WalkType = {})); -function ClosedWalkFrom(startVertice, maxRoute, type = WalkType.Min) { +function ClosedWalkFrom(startVertice, maxRoute, type = WalkType.Min) +{ let walk = []; let curVertice = startVertice; let preRoute; @@ -3121,7 +3388,8 @@ function ClosedWalkFrom(startVertice, maxRoute, type = WalkType.Min) { /** * 删除中途回路 */ -function ReduceWalk(w) { +function ReduceWalk(w) +{ if (w.length === 0) return w; //未构成回路,直接回家 @@ -3142,7 +3410,8 @@ function ReduceWalk(w) { } return w; } -function GetNextRoute(v, prev, type = WalkType.Min) { +function GetNextRoute(v, prev, type = WalkType.Min) +{ if (!prev) return arrayLast(v.routes); //顺时针 cw \|/ 从左往右 //逆时针 ccw 往左 @@ -3152,7 +3421,8 @@ function GetNextRoute(v, prev, type = WalkType.Min) { } var BoolOpeartionType; -(function (BoolOpeartionType) { +(function (BoolOpeartionType) +{ BoolOpeartionType[BoolOpeartionType["Intersection"] = 0] = "Intersection"; BoolOpeartionType[BoolOpeartionType["Union"] = 1] = "Union"; BoolOpeartionType[BoolOpeartionType["Subtract"] = 2] = "Subtract"; @@ -3160,7 +3430,8 @@ var BoolOpeartionType; const fuzz = 1e-3; let fuzzV3 = new Vector3(fuzz, fuzz, fuzz); //判断曲线是否在源封闭曲线内 -function isTargetCurInOrOnSourceCur(sourceCur, targetCur) { +function isTargetCurInOrOnSourceCur(sourceCur, targetCur) +{ if (!sourceCur.BoundingBox.expandByVector(fuzzV3).containsBox(targetCur.BoundingBox)) return false; let cus = []; @@ -3168,7 +3439,8 @@ function isTargetCurInOrOnSourceCur(sourceCur, targetCur) { cus = targetCur.Explode(); else cus = [targetCur]; - return cus.every(c => { + return cus.every(c => + { let pts = getIntPtContextPts(sourceCur, c); if (pts.length <= 1) pts.push(c.StartPoint, c.EndPoint); @@ -3176,7 +3448,8 @@ function isTargetCurInOrOnSourceCur(sourceCur, targetCur) { }); } //获取交点处上下距0.01par的点 -function getIntPtContextPts(sourceCur, cu, pts = []) { +function getIntPtContextPts(sourceCur, cu, pts = []) +{ let interPts = cu.IntersectWith(sourceCur, IntersectOption.OnBothOperands); if (interPts.length > 0) { let pars = interPts.map(pt => cu.GetParamAtPoint(pt)); @@ -3190,15 +3463,18 @@ function getIntPtContextPts(sourceCur, cu, pts = []) { return pts; } //判断点点是否全部都在封闭区域内或者在曲线上 -function IsPtsAllInOrOnReg(sourceReg, pts) { - return pts.every(pt => { +function IsPtsAllInOrOnReg(sourceReg, pts) +{ + return pts.every(pt => + { //是否点在封闭曲线内 return sourceReg.PtOnCurve(pt) || sourceReg.PtInCurve(pt); }); } var ExtendType; -(function (ExtendType) { +(function (ExtendType) +{ /** * 前后都不延伸 */ @@ -3219,14 +3495,17 @@ var ExtendType; /** * 曲线的基类,子类请实现以下方法. */ -let Curve = class Curve extends Entity { - constructor() { +let Curve = class Curve extends Entity +{ + constructor() + { super(); //------------------绘制相关------------------ //重载 this.OnlyRenderType = true; } - get Is2D() { + get Is2D() + { return equaln(this._Matrix.elements[14], 0); } get StartPoint() { return; } @@ -3235,10 +3514,12 @@ let Curve = class Curve extends Entity { get EndPoint() { return; } set EndPoint(v) { return; } /** 曲线中点 */ - get Midpoint() { + get Midpoint() + { return this.GetPointAtParam(this.MidParam); } - get MidParam() { + get MidParam() + { if (this.EndParam === 1) return 0.5; else @@ -3269,7 +3550,8 @@ let Curve = class Curve extends Entity { * @memberof Curve */ GetFistDeriv(param) { return; } - GetFistDerivAngle(param) { + GetFistDerivAngle(param) + { let d = this.GetFistDeriv(param); return Math.atan2(d.y, d.x); } @@ -3281,12 +3563,14 @@ let Curve = class Curve extends Entity { GetSplitCurves(param) { return; } //未完善 GetCurveAtParamRange(startParam, EndParam) { return; } - GetSplitCurvesByPts(pt) { + GetSplitCurvesByPts(pt) + { let pts = Array.isArray(pt) ? pt : [pt]; let pars = pts.map(p => this.GetParamAtPoint(p)); return this.GetSplitCurves(pars); } - SplitParamSort(param) { + SplitParamSort(param) + { if (Array.isArray(param)) { param = param.filter(p => this.ParamOnCurve(p)); if (param.length === 0) @@ -3312,15 +3596,18 @@ let Curve = class Curve extends Entity { //翻转曲线.首尾调换. Reverse() { return this; } //点在曲线上 - PtOnCurve(pt, fuzz = 1e-6) { + PtOnCurve(pt, fuzz = 1e-6) + { return equalv3(this.StartPoint, pt, fuzz) || equalv3(this.EndPoint, pt, fuzz) || this.ParamOnCurve(this.GetParamAtPoint(pt)); } //点在曲线中,不在起点或者终点. - PtOnCurve2(pt) { + PtOnCurve2(pt) + { return !(equalv3(this.StartPoint, pt, 1e-6) || equalv3(this.EndPoint, pt, 1e-6)) && this.ParamOnCurve(this.GetParamAtPoint(pt), 0); } //点在曲线上,已经确定点在曲线的延伸线上 - PtOnCurve3(p, fuzz = 1e-6) { + PtOnCurve3(p, fuzz = 1e-6) + { return this.PtOnCurve(p, fuzz); } //参数在曲线上 容差,1e-6 @@ -3330,7 +3617,8 @@ let Curve = class Curve extends Entity { /** * 曲线相交点 */ - IntersectWith(curve, intType, tolerance = 1e-6) { + IntersectWith(curve, intType, tolerance = 1e-6) + { return this.IntersectWith2(curve, intType, tolerance).map(r => r.pt); } /** @@ -3344,14 +3632,16 @@ let Curve = class Curve extends Entity { /** * 重载:更新实体材质 */ - UpdateDrawObjectMaterial(type, obj, material) { - if (type === RenderType.WireframePrint) ; + UpdateDrawObjectMaterial(type, obj, material) + { + if (type === RenderType.WireframePrint); else { let m = obj; m.material = material || ColorMaterial.GetLineMaterial(this._Color); } } - UpdateJigMaterial(color = 8) { + UpdateJigMaterial(color = 8) + { for (let [type, obj] of this._CacheDrawObject) { this.UpdateDrawObjectMaterial(type, obj, ColorMaterial.GetLineMaterial(color)); } @@ -3363,8 +3653,10 @@ Curve = __decorate([ let cache = new WeakMap(); const COMBINE_FUZZ = 1e-2; -class Contour { - SetCurve(cu) { +class Contour +{ + SetCurve(cu) + { if (cu instanceof Polyline) { if (cu.Area2 < 0) cu.Reverse(); @@ -3372,7 +3664,8 @@ class Contour { this._Curve = cu; } /**会将传入的闭合轮廓改为逆时针 */ - static CreateContour(cus, needLink = true) { + static CreateContour(cus, needLink = true) + { if (cus instanceof Curve) { if (cus.IsClose) { let c = new Contour(); @@ -3392,13 +3685,16 @@ class Contour { return c; } } - get Curve() { + get Curve() + { return this._Curve; } - get Area() { + get Area() + { return this._Curve.Area; } - get BoundingBox() { + get BoundingBox() + { return this._Curve.BoundingBox; } /** @@ -3407,7 +3703,8 @@ class Contour { * @param {number} dist 缩放距离 * @param {string} dir x y z */ - UnEqualProportionScale(ref, dist, dir) { + UnEqualProportionScale(ref, dist, dir) + { let cu = this._Curve; if (cu instanceof Polyline) { let lineData = cu.LineData; @@ -3425,18 +3722,21 @@ class Contour { } return false; } - Clone() { + Clone() + { return Contour.CreateContour([this._Curve.Clone()]); } //交集:结果数组为空则失败 - IntersectionBoolOperation(target) { + IntersectionBoolOperation(target) + { if (!IntersectBox2(this.BoundingBox, target.BoundingBox)) return []; let resultCus = this.GetIntersetAndUnionList(target); return Contour.GetAllContour(resultCus.intersectionList); } //并集:结果轮廓数组长度大于2,则失败.等于1则成功. - UnionBoolOperation(target) { + UnionBoolOperation(target) + { let resultCus = this.GetIntersetAndUnionList(target); //快速 if (resultCus.unionList.every(c => c.IsClose)) @@ -3490,7 +3790,8 @@ class Contour { } } //差集:等于0完全被减去 - SubstactBoolOperation(target) { + SubstactBoolOperation(target) + { let subtractList = this.GetSubtractList(target); //纯网洞 if (subtractList.every(c => c.IsClose)) @@ -3498,7 +3799,8 @@ class Contour { let regParse = new RegionParse(subtractList, 2); let contours = []; //分析封闭包围区域 - const parseRoute = (routeSet) => { + const parseRoute = (routeSet) => + { for (let routes of routeSet) { let cs = routes.map(r => r.curve); let c = Contour.CreateContour(cs, false); @@ -3516,7 +3818,8 @@ class Contour { /** * 计算与目标轮廓布尔运算后的结果曲线. */ - GetIntersetAndUnionList(target) { + GetIntersetAndUnionList(target) + { let intersectionList = []; let unionList = []; let sourceOutline = this._Curve; @@ -3538,21 +3841,21 @@ class Contour { } //包含.相交.分离(三种状态) if (sourceContainerTarget) //源包含目标 - { + { intersectionList.push(targetOutline); unionList.push(sourceOutline); } else if (targetContainerSource) //目标包含源 - { + { unionList.push(targetOutline); intersectionList.push(sourceOutline); } else if (interPts.length <= 1) //分离 - { + { unionList.push(sourceOutline, targetOutline); } else //相交 interPts.length > 0 - { + { let pars1 = interPts.map(r => r.thisParam); let pars2 = interPts.map(r => r.argParam); let sourceCus = sourceOutline.GetSplitCurves(pars1); @@ -3593,7 +3896,8 @@ class Contour { } return { intersectionList, unionList }; } - GetSubtractList(target) { + GetSubtractList(target) + { let sourceOutline = this._Curve; let targetOutline = target.Curve; let isEqualNormal = equalv3(sourceOutline.Normal, targetOutline.Normal, 1e-3); @@ -3637,7 +3941,8 @@ class Contour { return [sourceOutline]; return subtractList; } - GetSubtractListByMoreTargets(targets) { + GetSubtractListByMoreTargets(targets) + { let { holes, subtractList } = this.GetSubListWithCus(targets); //纯网洞 if (subtractList.every(c => c.IsClose)) @@ -3648,7 +3953,8 @@ class Contour { let regParse = new RegionParse(subtractList, 2); let contours = []; //分析封闭包围区域 - const parseRoute = (routeSet) => { + const parseRoute = (routeSet) => + { for (let routes of routeSet) { let cs = routes.map(r => r.curve); let c = Contour.CreateContour(cs, false); @@ -3666,7 +3972,8 @@ class Contour { outlines: contours }; } - GetSubListWithCus(targets) { + GetSubListWithCus(targets) + { let sourceOutline = this._Curve; let subtractList = []; let holes = []; @@ -3732,7 +4039,8 @@ class Contour { * 获得全部闭合曲线 * @若传入二维曲线数据,将默认子数组为闭合曲线段 */ - static GetAllContour(cus) { + static GetAllContour(cus) + { if (cus.length === 0) return []; let cuGroups; @@ -3751,7 +4059,8 @@ class Contour { * @param [needLink=true] 需要解析成首尾连接状态 * @returns 单一曲线,如果返回超过1个,其他的将被遗弃. */ - static Combine(cus, needLink = true, tolerance = 1e-3) { + static Combine(cus, needLink = true, tolerance = 1e-3) + { if (cus.length === 0) return undefined; let groups = needLink ? curveLinkGroup(cus) : [cus]; @@ -3771,20 +4080,24 @@ class Contour { } } } - get Shape() { + get Shape() + { return this._Curve.Shape; } - CuInOutline(targetCur) { + CuInOutline(targetCur) + { return isTargetCurInOrOnSourceCur(this._Curve, targetCur); } - Equal(tar) { + Equal(tar) + { return equalCurve(this._Curve, tar._Curve); } } /** * 对于轮廓切割后的曲线判断相同,使用这个函数进行快速判断 */ -function fastEqualCurve(c1, c2, tolerance = 1e-3) { +function fastEqualCurve(c1, c2, tolerance = 1e-3) +{ let sp1 = c1.StartPoint; let ep1 = c1.EndPoint; let sp2 = c2.StartPoint; @@ -3796,23 +4109,28 @@ function fastEqualCurve(c1, c2, tolerance = 1e-3) { } //对于双多段线互相切割后的结果,快速判断曲线是否在另一条曲线内部 //也许有一天这个中点算法需要改一下, 使用 src\Geometry\ExtrudeEdgeGeometry2.ts->CenterPoint 会比较稳妥 -function fastCurveInCurve(sourceCu, targetCu) { +function fastCurveInCurve(sourceCu, targetCu) +{ return sourceCu.PtInCurve(targetCu.GetPointAtParam(targetCu.EndParam * 0.5)); } -function fastCurveInCurve2(sourceCu, targetCu) { +function fastCurveInCurve2(sourceCu, targetCu) +{ return sourceCu.PtInCurve(targetCu.StartPoint) && sourceCu.PtInCurve(targetCu.GetPointAtParam(targetCu.EndParam * 0.5)); } -class PlaneExt extends Plane$1 { - constructor(normal = new Vector3(0, 0, 1), constant) { +class PlaneExt extends Plane$1 +{ + constructor(normal = new Vector3(0, 0, 1), constant) + { super(normal); if (typeof constant === "number") this.constant = constant; else if (constant) this.constant = -this.normal.dot(constant); } - intersectLine(line, optionalTarget = new Vector3(), extendLine = false) { + intersectLine(line, optionalTarget = new Vector3(), extendLine = false) + { let v1 = new Vector3(); let direction = line.delta(v1); let denominator = this.normal.dot(direction); @@ -3831,7 +4149,8 @@ class PlaneExt extends Plane$1 { } return optionalTarget.copy(direction).multiplyScalar(t).add(line.start); } - intersectRay(ray, optionalTarget, extendLine) { + intersectRay(ray, optionalTarget, extendLine) + { // 从射线初始位置 let line = new Line3(ray.origin.clone(), ray.origin.clone().add(ray.direction)); return this.intersectLine(line, optionalTarget, extendLine); @@ -3839,8 +4158,10 @@ class PlaneExt extends Plane$1 { } var Ellipse_1; -let Ellipse = Ellipse_1 = class Ellipse extends Curve { - constructor(center, radX = 1e-3, radY = 1e-3, angle = 0) { +let Ellipse = Ellipse_1 = class Ellipse extends Curve +{ + constructor(center, radX = 1e-3, radY = 1e-3, angle = 0) + { super(); this._startAngle = 0; this._endAngle = Math.PI * 2; @@ -3849,80 +4170,100 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { this._radY = radY; this._rotate = angle; } - get StartParam() { + get StartParam() + { return 0; } - get EndParam() { + get EndParam() + { return 1; } - get StartPoint() { + get StartPoint() + { return this.GetPointAtParam(0); } - get EndPoint() { + get EndPoint() + { return this.GetPointAtParam(1); } - get Shape() { + get Shape() + { let sp = new Shape$1(); sp.ellipse(0, 0, this._radX, this._radY, this._startAngle, this._endAngle, false, this._rotate); return sp; } - get IsClose() { + get IsClose() + { return equaln(this.TotalAngle, Math.PI * 2); } - get Center() { + get Center() + { return new Vector3().setFromMatrixPosition(this._Matrix); } - set Center(v) { + set Center(v) + { this.WriteAllObjectRecord(); this._Matrix.setPosition(v); this.Update(); } - get RadX() { + get RadX() + { return this._radX; } - set RadX(v) { + set RadX(v) + { this.WriteAllObjectRecord(); this._radX = v; this.Update(); } - get RadY() { + get RadY() + { return this._radY; } - set RadY(v) { + set RadY(v) + { this.WriteAllObjectRecord(); this._radY = v; this.Update(); } - get Rotation() { + get Rotation() + { return this._rotate; } - set Rotation(v) { + set Rotation(v) + { this.WriteAllObjectRecord(); this._rotate = v; this.Update(); } - get StartAngle() { + get StartAngle() + { return this._startAngle; } - get EndAngle() { + get EndAngle() + { return this._startAngle; } - set StartAngle(v) { + set StartAngle(v) + { this.WriteAllObjectRecord(); this._startAngle = v; this.Update(); } - set EndAngle(v) { + set EndAngle(v) + { this.WriteAllObjectRecord(); this._endAngle = v; this.Update(); } - get Length() { + get Length() + { let a = this._radX; let b = this._radY; return Math.PI * Math.abs(3 * (a + b) - Math.sqrt((3 * a + b) * (a + 3 * b))) * this.TotalAngle / Math.PI * 0.5; } - get Area() { + get Area() + { let area = Math.PI * this._radX * this._radY; let an = this._endAngle - this._startAngle; if (an < 0) @@ -3935,31 +4276,37 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { area += area2; return area; } - get TotalAngle() { + get TotalAngle() + { let totolAngle = this._endAngle - this._startAngle; if (totolAngle < 0) totolAngle = Math.PI * 2 + totolAngle; return totolAngle; } - get BoundingBox() { + get BoundingBox() + { return new Box3().setFromPoints(this.GetGripPoints()); } - PtInCurve(pt) { + PtInCurve(pt) + { let p = rotatePoint(pt.clone().sub(this.Center), -this.Rotation); return p.x ** 2 / this.RadX ** 2 + p.y ** 2 / this.RadY ** 2 < 1; } - PtOnCurve(pt) { + PtOnCurve(pt) + { if (this.PtOnEllipse(pt)) { let a = this.GetCircleAngleAtPoint(pt); return a <= this.TotalAngle + 1e-6; } return false; } - PtOnEllipse(pt) { + PtOnEllipse(pt) + { let p = rotatePoint(pt.clone().applyMatrix4(this.OCSInv), -this.Rotation); return equaln(p.x ** 2 / this.RadX ** 2 + p.y ** 2 / this.RadY ** 2, 1, 1e-3); } - GetPointAtParam(param) { + GetPointAtParam(param) + { let an = this.TotalAngle * param + this._startAngle; if (an > Math.PI) an -= 2 * Math.PI; @@ -3969,7 +4316,8 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { pt.applyMatrix4(new Matrix4().makeRotationZ(this._rotate)); return pt.applyMatrix4(this.OCS); } - GetParamAtPoint(pt) { + GetParamAtPoint(pt) + { if (!this.PtOnEllipse(pt)) { return NaN; } @@ -3985,25 +4333,31 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { return par - 1 - diffPar; } } - GetPointAtDistance(distance) { + GetPointAtDistance(distance) + { let param = distance / this.Length; return this.GetPointAtParam(param); } - GetDistAtParam(param) { + GetDistAtParam(param) + { return this.Length * param; } - GetDistAtPoint(pt) { + GetDistAtPoint(pt) + { let param = this.GetParamAtPoint(pt); return this.GetDistAtParam(param); } - GetParamAtDist(d) { + GetParamAtDist(d) + { return d / this.Length; } - GetAngleAtParam(par) { + GetAngleAtParam(par) + { let pt = this.GetPointAtParam(par).applyMatrix4(this.OCSInv).applyMatrix4(new Matrix4().makeRotationZ(-this.Rotation)); return angle(pt) + this._startAngle; } - GetCircleAngleAtPoint(pt) { + GetCircleAngleAtPoint(pt) + { pt = pt.clone().applyMatrix4(this.OCSInv); let an = angle(pt) - this._rotate; if (an < 0) @@ -4023,7 +4377,8 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { an = Math.PI * 2 + an; return an; } - GetFistDeriv(pt) { + GetFistDeriv(pt) + { if (typeof pt === "number") pt = this.GetPointAtParam(pt); else @@ -4047,7 +4402,8 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { vec.applyMatrix4(new Matrix4().makeRotationZ(this._rotate)); return vec.applyMatrix4(new Matrix4().extractRotation(this.OCS)); } - GetClosestPointTo(p, extend) { + GetClosestPointTo(p, extend) + { //参考:https://wet-robots.ghost.io/simple-method-for-distance-to-ellipse/ let ro = new Matrix4().makeRotationZ(this._rotate); let roInv = new Matrix4().getInverse(ro); @@ -4086,7 +4442,8 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { return d1 < d2 ? this.StartPoint : this.EndPoint; } } - GetOffsetCurves(offsetDist) { + GetOffsetCurves(offsetDist) + { if ((offsetDist + Math.min(this._radX, this._radY)) > 0) { let el = this.Clone(); el.RadX = this._radX + offsetDist; @@ -4095,7 +4452,8 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { } return []; } - GetSplitCurves(param) { + GetSplitCurves(param) + { let params; if (param instanceof Array) { params = param.filter(p => this.ParamOnCurve(p)); @@ -4125,7 +4483,8 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { } return elllist; } - Join(el) { + Join(el) + { if (this.IsClose || el.IsClose || !this.IsCoplaneTo(el) || !equalv3(el.Center, this.Center)) return Status.False; let status = Status.False; @@ -4143,7 +4502,8 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { } return status; } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { switch (snapMode) { case ObjectSnapMode.End: { @@ -4173,7 +4533,8 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { return []; } } - IntersectWith2(curve, intType) { + IntersectWith2(curve, intType) + { //TODO:优化椭圆和椭圆,椭圆和圆相交 if (curve instanceof Line) { return SwapParam(IntersectEllipseAndLine(curve, this, reverseIntersectOption(intType))); @@ -4190,27 +4551,32 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { else return []; } - InitDrawObject(renderType = RenderType.Wireframe) { + InitDrawObject(renderType = RenderType.Wireframe) + { let line = new Line$1(this.UpdateGeometry(), ColorMaterial.GetLineMaterial(this._Color)); this.UpdateDrawObject(renderType, line); return line; } - UpdateDrawObject(type, obj) { + UpdateDrawObject(type, obj) + { let geo = obj.geometry; this.UpdateGeometry(geo); } //更新Geometry - UpdateGeometry(geo) { + UpdateGeometry(geo) + { if (!geo) geo = new BufferGeometry(); let curve = this.Shape; geo.setFromPoints(curve.getPoints(60)); return geo; } - GetStretchPoints() { + GetStretchPoints() + { return this.GetGripPoints(); } - GetGripPoints() { + GetGripPoints() + { let tmpMat4 = new Matrix4().makeRotationZ(this.Rotation); let pts = [ new Vector3(this._radX, 0), @@ -4225,10 +4591,12 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { pts.push(this.Center); return pts; } - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { this.ApplyMatrix(MoveMatrix(vec)); } - MoveGripPoints(indexList, vec) { + MoveGripPoints(indexList, vec) + { let pts = this.GetStretchPoints(); if (indexList.length > 0) { let p = pts[indexList[0]].clone(); @@ -4257,7 +4625,8 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { } } } - Convert2Polyline(count = 0) { + Convert2Polyline(count = 0) + { const MIN_LEN = 80; const par = this.TotalAngle / Math.PI * 0.5; if (!count) { @@ -4276,7 +4645,8 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { pl.CloseMark = true; return pl; } - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let ver = file.Read(); this._radX = file.Read(); @@ -4287,7 +4657,8 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve { this.Update(); } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(1); file.Write(this.RadX); @@ -4302,31 +4673,38 @@ Ellipse = Ellipse_1 = __decorate([ ], Ellipse); var Line_1; -let Line = Line_1 = class Line extends Curve { - constructor(_StartPoint = new Vector3, _EndPoint = new Vector3) { +let Line = Line_1 = class Line extends Curve +{ + constructor(_StartPoint = new Vector3, _EndPoint = new Vector3) + { super(); this._StartPoint = _StartPoint; this._EndPoint = _EndPoint; } - get Is2D() { + get Is2D() + { return super.Is2D && equaln(this._StartPoint.z, 0) && equaln(this._EndPoint.z, 0); } - get Shape() { + get Shape() + { return new Shape$1([AsVector2(this._StartPoint), AsVector2(this._EndPoint)]); } - Z0() { + Z0() + { this.WriteAllObjectRecord(); this.StartPoint = this.StartPoint.setZ(0); this.EndPoint = this.EndPoint.setZ(0); return this; } - ApplyScaleMatrix(m) { + ApplyScaleMatrix(m) + { this.WriteAllObjectRecord(); this.StartPoint = this.StartPoint.applyMatrix4(m); this.EndPoint = this.EndPoint.applyMatrix4(m); return this; } - ApplyMirrorMatrix(m) { + ApplyMirrorMatrix(m) + { this.WriteAllObjectRecord(); let sp = this.StartPoint; let ep = this.EndPoint; @@ -4335,7 +4713,8 @@ let Line = Line_1 = class Line extends Curve { this.EndPoint = ep; return this; } - InitDrawObject(renderType = RenderType.Wireframe) { + InitDrawObject(renderType = RenderType.Wireframe) + { let geo = BufferGeometryUtils.CreateFromPts([this._StartPoint, this._EndPoint]); if (renderType === RenderType.WireframePrint) { var geometry = new LineGeometry(); @@ -4344,10 +4723,12 @@ let Line = Line_1 = class Line extends Curve { } return new Line$1(geo, ColorMaterial.GetLineMaterial(this.ColorIndex)); } - UpdateDrawObject(type, lineObj) { + UpdateDrawObject(type, lineObj) + { BufferGeometryUtils.UpdatePts(lineObj.geometry, [this._StartPoint, this._EndPoint]); } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { switch (snapMode) { case ObjectSnapMode.End: return [this.StartPoint, this.EndPoint]; @@ -4378,10 +4759,12 @@ let Line = Line_1 = class Line extends Curve { } return []; } - GetGripPoints() { + GetGripPoints() + { return [this.StartPoint, this.GetPointAtParam(0.5), this.EndPoint]; } - MoveGripPoints(indexList, vec) { + MoveGripPoints(indexList, vec) + { this.WriteAllObjectRecord(); for (let index of indexList) { if (index === 0) @@ -4394,10 +4777,12 @@ let Line = Line_1 = class Line extends Curve { } } } - GetStretchPoints() { + GetStretchPoints() + { return [this.StartPoint, this.EndPoint]; } - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { this.WriteAllObjectRecord(); for (let index of indexList) { if (index === 0) @@ -4406,10 +4791,12 @@ let Line = Line_1 = class Line extends Curve { this.EndPoint = this.EndPoint.add(vec); } } - GetFistDeriv(param) { + GetFistDeriv(param) + { return this.EndPoint.sub(this.StartPoint); } - IntersectWith2(curve, intType, tolerance = 1e-4) { + IntersectWith2(curve, intType, tolerance = 1e-4) + { if (curve instanceof Line_1) { return IntersectLineAndLine(this, curve, intType, tolerance); } @@ -4428,28 +4815,35 @@ let Line = Line_1 = class Line extends Curve { return []; } //Param - GetPointAtParam(param) { + GetPointAtParam(param) + { return this.StartPoint.add(this.GetFistDeriv(0).multiplyScalar(param)); } - GetParamAtPoint(pt) { + GetParamAtPoint(pt) + { let { closestPt, param } = this.GetClosestAtPoint(pt, true); if (!equalv3(closestPt, pt, 1e-5)) return NaN; return param; } - GetParamAtDist(d) { + GetParamAtDist(d) + { return d / this.Length; } - GetPointAtDistance(distance) { + GetPointAtDistance(distance) + { return this.GetPointAtParam(this.GetParamAtDist(distance)); } - GetDistAtParam(param) { + GetDistAtParam(param) + { return this.Length * param; } - GetDistAtPoint(pt) { + GetDistAtPoint(pt) + { return this.GetDistAtParam(this.GetParamAtPoint(pt)); } - GetSplitCurves(param) { + GetSplitCurves(param) + { let params = this.SplitParamSort(param); let pts = params.map(param => this.GetPointAtParam(param)); let ret = new Array(); @@ -4464,16 +4858,19 @@ let Line = Line_1 = class Line extends Curve { } return ret; } - GetParamAtPoint2(pt) { + GetParamAtPoint2(pt) + { let { param } = this.GetClosestAtPoint(pt, true); return param; } //点在曲线上,已经确定点在曲线的延伸线上 - PtOnCurve3(p, fuzz = 1e-6) { + PtOnCurve3(p, fuzz = 1e-6) + { let { param } = this.GetClosestAtPoint(p, true); return this.ParamOnCurve(param, fuzz); } - GetClosestAtPoint(pt, extend) { + GetClosestAtPoint(pt, extend) + { let sp = this.StartPoint; let ep = this.EndPoint; if (equalv3(pt, sp, 1e-8)) @@ -4509,10 +4906,12 @@ let Line = Line_1 = class Line extends Curve { param: param / length }; } - GetClosestPointTo(pt, extend) { + GetClosestPointTo(pt, extend) + { return this.GetClosestAtPoint(pt, extend).closestPt; } - Extend(newParam) { + Extend(newParam) + { this.WriteAllObjectRecord(); if (newParam < this.StartParam) { this.StartPoint = this.GetPointAtParam(newParam); @@ -4521,7 +4920,8 @@ let Line = Line_1 = class Line extends Curve { this.EndPoint = this.GetPointAtParam(newParam); } } - Join(cu, allowGap = false, tolerance = 1e-5) { + Join(cu, allowGap = false, tolerance = 1e-5) + { if (cu instanceof Line_1) { //平行 if (!isParallelTo(this.GetFistDeriv(0).normalize(), cu.GetFistDeriv(0).normalize())) @@ -4539,7 +4939,7 @@ let Line = Line_1 = class Line extends Curve { [sp, ep] = [ep, sp]; } if (allowGap || Math.max(0, param1) < Math.min(1, param2) + tolerance / this.Length) //这里的容差是值容差,但是我们用它来判断参数,所以进行转换 - { + { if (param1 < 0) this.StartPoint = sp; if (param2 > 1) @@ -4549,12 +4949,14 @@ let Line = Line_1 = class Line extends Curve { } return Status.False; } - Reverse() { + Reverse() + { this.WriteAllObjectRecord(); [this._StartPoint, this._EndPoint] = [this._EndPoint, this._StartPoint]; return this; } - GetOffsetCurves(offsetDist) { + GetOffsetCurves(offsetDist) + { let derv = this.GetFistDeriv(0).normalize().multiplyScalar(offsetDist); derv.applyMatrix4(new Matrix4().makeRotationAxis(this.Normal, -Math.PI / 2)); let newLine = this.Clone(); @@ -4562,13 +4964,16 @@ let Line = Line_1 = class Line extends Curve { newLine.EndPoint = this.EndPoint.add(derv); return [newLine]; } - get BoundingBox() { + get BoundingBox() + { return new Box3().setFromPoints([this.StartPoint, this.EndPoint]); } - get StartParam() { + get StartParam() + { return 0; } - get EndParam() { + get EndParam() + { return 1; } //属性 @@ -4576,14 +4981,16 @@ let Line = Line_1 = class Line extends Curve { //#region -----------------------------File----------------------------- //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象从文件中读取数据,初始化自身 - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let ver = file.Read(); //1 this._StartPoint.fromArray(file.Read()); this._EndPoint.fromArray(file.Read()); } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(1); //ver file.Write(this._StartPoint.toArray()); @@ -4591,18 +4998,22 @@ let Line = Line_1 = class Line extends Curve { } //#endregion-----------------------------File End----------------------------- //#region 属性 - set StartPoint(p) { + set StartPoint(p) + { this.WriteAllObjectRecord(); this._StartPoint.copy(p).applyMatrix4(this.OCSInv); this.Update(); } - get StartPoint() { + get StartPoint() + { return this._StartPoint.clone().applyMatrix4(this.OCS); } - get EndPoint() { + get EndPoint() + { return this._EndPoint.clone().applyMatrix4(this.OCS); } - set EndPoint(p) { + set EndPoint(p) + { this.WriteAllObjectRecord(); this._EndPoint.copy(p).applyMatrix4(this.OCSInv); this.Update(); @@ -4612,12 +5023,15 @@ Line = Line_1 = __decorate([ Factory ], Line); -class CurveTreeNode { - constructor(curve, box) { +class CurveTreeNode +{ + constructor(curve, box) + { this.curve = curve; this.box = box || curve.BoundingBox; } - TrimBy(contour, box) { + TrimBy(contour, box) + { if (IntersectsBox(box, this.box)) { if (this.children !== undefined) { for (let c of this.children) @@ -4653,7 +5067,8 @@ class CurveTreeNode { } } } - get Nodes() { + get Nodes() + { if (!this.children) return [this]; else { @@ -4664,15 +5079,18 @@ class CurveTreeNode { } } } -class OffsetPolyline { +class OffsetPolyline +{ constructor(_Polyline, _OffsetDist, _ToolPath = false, _OffsetDistSq = (_OffsetDist ** 2) * 2.1 //对直角走刀不进行圆弧过度 - ) { + ) + { this._Polyline = _Polyline; this._OffsetDist = _OffsetDist; this._ToolPath = _ToolPath; this._OffsetDistSq = _OffsetDistSq; } - Do() { + Do() + { this._OffsetDistSign = Math.sign(this._OffsetDist); this._TrimPolylineContours = []; this._TrimCircleContours = []; @@ -4697,7 +5115,8 @@ class OffsetPolyline { this.LinkResultPolyline(); return this._RetCurves; } - InitSubCurves() { + InitSubCurves() + { this._CacheOCS = this._Polyline.OCS; this._IsClose = this._Polyline.IsClose; this._Polyline.OCS = IdentityMtx4; @@ -4705,7 +5124,8 @@ class OffsetPolyline { this._Polyline.OCS = this._CacheOCS; return this; } - GeneralCirclesAndVertexs() { + GeneralCirclesAndVertexs() + { this._Vertexs = this._SubCurves.map(c => c.StartPoint); let lastCu = arrayLast(this._SubCurves); if (!equalv3(lastCu.EndPoint, this._Vertexs[0], 1e-3)) @@ -4713,7 +5133,8 @@ class OffsetPolyline { let radius = Math.abs(this._OffsetDist); this._Circles = this._Vertexs.map(p => new Circle(p, radius)); } - OffsetSubCurves() { + OffsetSubCurves() + { this._SubOffsetedCurves = []; for (let index = 0; index < this._SubCurves.length; index++) { let curveOld = this._SubCurves[index]; @@ -4727,7 +5148,8 @@ class OffsetPolyline { } } //连接(延伸)曲线,或者补(圆弧,直线) - LinkSubCurves() { + LinkSubCurves() + { let count = this._SubOffsetedCurves.length; if (!this._IsClose) count--; @@ -4771,7 +5193,7 @@ class OffsetPolyline { if (tPts.length > 0) //ipts = 1 or ipts = 2 tp = SelectNearP(iPts, refP); else //补单圆 或者尝试连接 - { + { let arc = this.CreateArc(refP, sp, ep); if (iPts.length > 0 && !this._ToolPath && this.IsSharpCorner(curveResNow, curveResNext, refP)) { //设置新的连接点,并且备份旧点 @@ -4839,7 +5261,7 @@ class OffsetPolyline { } else { let padCirs = []; - for (let s = FixIndex(curveResNow.index + 1, this._Circles);; s = FixIndex(s + 1, this._Circles)) { + for (let s = FixIndex(curveResNow.index + 1, this._Circles); ; s = FixIndex(s + 1, this._Circles)) { let c = this._Circles[s]; this._TrimCircleContours.push(c); padCirs.push(c); @@ -4850,7 +5272,8 @@ class OffsetPolyline { } } } - IsSharpCorner(curveResNow, curveResNext, refP) { + IsSharpCorner(curveResNow, curveResNext, refP) + { let v1 = this._SubCurves[curveResNow.index].GetPointAtParam(0.9); let v2 = this._SubCurves[curveResNext.index].GetPointAtParam(0.1); v1.subVectors(refP, v1); @@ -4858,7 +5281,8 @@ class OffsetPolyline { v1.cross(v2); return Math.sign(v1.z) === this._OffsetDistSign; } - GeneralTrimContours() { + GeneralTrimContours() + { for (let d of this._SubOffsetedCurves) { let cu2 = d.curve; if (d.sp && d.ep) { @@ -4875,7 +5299,7 @@ class OffsetPolyline { //因为精度的问题,这种0圆心角的圆弧会被当成全圆,但是偏移算法中,应该不可能出现全圆弧的圆弧,所以我们压扁它 if (cu2 instanceof Arc && equaln(cu2.StartAngle, cu2.EndAngle, 1e-6) - // && !equaln((this._SubCurves[d.index]).AllAngle, Math.PI * 2, 1e-3) 应该不会出现 + // && !equaln((this._SubCurves[d.index]).AllAngle, Math.PI * 2, 1e-3) 应该不会出现 ) { if (cu2.IsClockWise) cu2.StartAngle = cu2.EndAngle + 1e-6; @@ -4990,7 +5414,8 @@ class OffsetPolyline { this._TrimPolylineContours.push(...this._TrimCircleContours.map(c => Contour.CreateContour(c, false)), ...this._TrimArcContours); } // 通过构建的轮廓对偏移曲线进行裁剪 - TrimByContours() { + TrimByContours() + { for (let d of this._SubOffsetedCurves) { let c = d.curve; if (CurveIsFine(c)) @@ -5006,7 +5431,8 @@ class OffsetPolyline { } } //过滤方向相反和0长度线 - FilterInvalidCurve() { + FilterInvalidCurve() + { this._CurveTrimedTreeNodes = []; for (let n of this._CurveTreeNodes) { let ns = n.Nodes; @@ -5017,7 +5443,8 @@ class OffsetPolyline { } } //合并共线 - JoinCollinear() { + JoinCollinear() + { for (let i = 0; i < this._CurveTrimedTreeNodes.length; i++) { let n = this._CurveTrimedTreeNodes[i]; if (n.used) @@ -5048,7 +5475,8 @@ class OffsetPolyline { } } //连接结果曲线,返回最终多段线 - LinkResultPolyline() { + LinkResultPolyline() + { let used = new Set(); let cuMap = new CurveMap(1); for (let n of this._CurveTrimedTreeNodes) { @@ -5056,7 +5484,8 @@ class OffsetPolyline { cuMap.AddCurveToMap(n.curve); } let preP; - let searchNext = (s, pl) => { + let searchNext = (s, pl) => + { let minDist = Infinity; let minR; for (let r of s.routes) { @@ -5104,10 +5533,12 @@ class OffsetPolyline { } } } - CheckPointDir(pt) { + CheckPointDir(pt) + { return this.GetPointAtCurveDir(pt) === this._OffsetDistSign; } - GetPointAtCurveDir(pt) { + GetPointAtCurveDir(pt) + { let minIndex = Infinity; let minDist = Infinity; let minCp; @@ -5175,24 +5606,28 @@ class OffsetPolyline { let cross = dri.cross(pt.clone().sub(minCp)); return -Math.sign(cross.z); } - CreateArc(center, startP, endP) { + CreateArc(center, startP, endP) + { let sa = angle(startP.clone().sub(center)); let ea = endP ? angle(endP.clone().sub(center)) : sa; let arc = new Arc(center, Math.abs(this._OffsetDist), sa, ea, this._OffsetDist < 0); return arc; } } -function EntityEncode(c) { +function EntityEncode(c) +{ if (c instanceof Line) return 1; else return 2; } -function EntityEncode2(c1, c2) { +function EntityEncode2(c1, c2) +{ return EntityEncode(c1) & EntityEncode(c2); } //表示这个是一个正常的曲线,不是0长度的线,也不是0长度的圆弧 -function CurveIsFine(curve) { +function CurveIsFine(curve) +{ if (curve instanceof Arc && curve.AllAngle < 2e-6) return false; return curve.Length > 5e-5; @@ -5204,12 +5639,13 @@ function CurveIsFine(curve) { * @param pt 点 * @returns 点在多段线内部 */ -function IsPointInPolyLine(pl, pt) { +function IsPointInPolyLine(pl, pt) +{ let crossings = 0; let insLine = new Line(pt, pt.clone().add(new Vector3(0, 10, 0))); for (let i = 0; i < pl.EndParam; i++) { if (equaln(pl.GetBuilgeAt(i), 0, 5e-6)) //直线 - { + { let sp = pl.GetPointAtParam(i); let ep = pl.GetPointAtParam(i + 1); //点位于线上面 @@ -5241,7 +5677,7 @@ function IsPointInPolyLine(pl, pt) { } } else //圆弧 - { + { let arc = pl.GetCurveAtIndex(i); let sp = arc.StartPoint; let ep = arc.EndPoint; @@ -5281,19 +5717,23 @@ function IsPointInPolyLine(pl, pt) { } var DragPointType; -(function (DragPointType) { +(function (DragPointType) +{ DragPointType[DragPointType["Grip"] = 0] = "Grip"; DragPointType[DragPointType["Stretch"] = 1] = "Stretch"; })(DragPointType || (DragPointType = {})); var Polyline_1; -let Polyline = Polyline_1 = class Polyline extends Curve { - constructor(_LineData = []) { +let Polyline = Polyline_1 = class Polyline extends Curve +{ + constructor(_LineData = []) + { super(); this._LineData = _LineData; this._ClosedMark = false; } - UpdateMatrixTo(m) { + UpdateMatrixTo(m) + { this.WriteAllObjectRecord(); let p = new Vector3().setFromMatrixPosition(m); p.applyMatrix4(this.OCSInv); @@ -5315,7 +5755,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { /** * 原地翻转,仅改变法向量 */ - Flip() { + Flip() + { this.WriteAllObjectRecord(); let x = new Vector3(); let y = new Vector3(); @@ -5333,7 +5774,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { return this; } //翻转曲线,首尾调换 - Reverse() { + Reverse() + { if (this._LineData.length === 0) return this; this.WriteAllObjectRecord(); @@ -5358,15 +5800,18 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return this; } - set LineData(data) { + set LineData(data) + { this.WriteAllObjectRecord(); this._LineData = data; this.Update(); } - get LineData() { + get LineData() + { return this._LineData; } - get NumberOfVertices() { + get NumberOfVertices() + { return this._LineData.length; } /** @@ -5379,11 +5824,13 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * @returns {this} * @memberof Polyline */ - AddVertexAt(index, pt) { + AddVertexAt(index, pt) + { this.WriteAllObjectRecord(); let pts; if (Array.isArray(pt)) { - pts = pt.map(p => { + pts = pt.map(p => + { return { pt: p.clone(), bul: 0 @@ -5396,7 +5843,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { this.Update(); return this; } - RemoveVertexAt(index) { + RemoveVertexAt(index) + { if (index < this._LineData.length) { this.WriteAllObjectRecord(); this._LineData.splice(index, 1); @@ -5404,7 +5852,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return this; } - RemoveVertexIn(from, to) { + RemoveVertexIn(from, to) + { if (from + 1 < this._LineData.length && to > from) { this.WriteAllObjectRecord(); this._LineData.splice(from + 1, to - from - 1); @@ -5416,7 +5865,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * 重设闭合多段线的起点 * @param index 起始index,如果index非整数,将用最接近的整数作为起始索引 */ - ResetStartPoint(index) { + ResetStartPoint(index) + { if (!this.IsClose || index >= this.EndParam) return false; if (equalv2(this._LineData[0].pt, arrayLast(this._LineData).pt)) @@ -5428,7 +5878,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { }); return true; } - GetPoint2dAt(index) { + GetPoint2dAt(index) + { if (index >= 0 && this._LineData.length > index) return this._LineData[index].pt.clone(); } @@ -5439,7 +5890,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * @param {Vector2} pt * @memberof Polyline */ - SetPointAt(index, pt) { + SetPointAt(index, pt) + { let d = this._LineData[index]; if (d) { this.WriteAllObjectRecord(); @@ -5448,7 +5900,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return this; } - ApplyScaleMatrix(m) { + ApplyScaleMatrix(m) + { this.WriteAllObjectRecord(); for (let i = 0; i <= this.EndParam; i++) { let p = this.GetPointAtParam(i); @@ -5457,7 +5910,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return this; } - ApplyMirrorMatrix(m) { + ApplyMirrorMatrix(m) + { this.WriteAllObjectRecord(); let oldPts = this.GetStretchPoints(); reviseMirrorMatrix(this._Matrix); @@ -5470,7 +5924,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { this.Reverse(); return this; } - SetBulgeAt(index, bul) { + SetBulgeAt(index, bul) + { let d = this._LineData[index]; if (d) { this.WriteAllObjectRecord(); @@ -5479,10 +5934,12 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return this; } - GetBuilgeAt(index) { + GetBuilgeAt(index) + { return this._LineData[index].bul; } - Rectangle(length, height) { + Rectangle(length, height) + { this.LineData = [ { pt: new Vector2(), bul: 0 }, { pt: new Vector2(length), bul: 0 }, @@ -5492,7 +5949,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { this.CloseMark = true; return this; } - RectangleFrom2Pt(p1, p2) { + RectangleFrom2Pt(p1, p2) + { let box = new Box3(); box.setFromPoints([p2, p1].map((p) => p.clone().applyMatrix4(this.OCSInv))); let px1 = AsVector2(box.min); @@ -5509,12 +5967,14 @@ let Polyline = Polyline_1 = class Polyline extends Curve { return this; } //多段线起点 - get StartPoint() { + get StartPoint() + { if (this._LineData.length > 0) return AsVector3(this._LineData[0].pt).applyMatrix4(this.OCS); return new Vector3(); } - set StartPoint(p) { + set StartPoint(p) + { this.WriteAllObjectRecord(); p = p.clone().applyMatrix4(this.OCSInv); if (this._LineData.length === 0) @@ -5532,14 +5992,16 @@ let Polyline = Polyline_1 = class Polyline extends Curve { this.SetPointAt(0, AsVector2(p)); } } - get EndPoint() { + get EndPoint() + { if (this._ClosedMark) return this.StartPoint; if (this._LineData.length > 0) return AsVector3(this._LineData[this.EndParam].pt).applyMatrix4(this.OCS); return new Vector3(); } - set EndPoint(p) { + set EndPoint(p) + { if (this._LineData.length < 2 || this.CloseMark) return; this.WriteAllObjectRecord(); @@ -5554,16 +6016,19 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } this.SetPointAt(this.EndParam, AsVector2(p)); } - get CurveCount() { + get CurveCount() + { return this.EndParam; } - get StartParam() { + get StartParam() + { return 0; } /** * 表示最后一条曲线的终止参数,使用该参数可以直接遍历到多段线的所有子线段. for(i 1 && (equalv3(this.StartPoint, this.EndPoint, 1e-4))); } - set CloseMark(v) { + set CloseMark(v) + { this.WriteAllObjectRecord(); this._ClosedMark = v; this.Update(); } - DigestionCloseMark() { + DigestionCloseMark() + { if (this._ClosedMark && this._LineData.length > 1) { this.WriteAllObjectRecord(); this._ClosedMark = false; @@ -5618,7 +6089,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { this._LineData.push({ pt: AsVector2(this._LineData[0].pt), bul: 0 }); } } - get Length() { + get Length() + { return this.Explode().reduce((l, cu) => l + cu.Length, 0); } /** @@ -5630,7 +6102,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * @returns {Vector3} 三维点,可为空 * @memberof Polyline */ - GetPointAtParam(param) { + GetPointAtParam(param) + { if (param === Math.floor(param) && this.ParamOnCurve(param)) return AsVector3(this.GetPoint2dAt(FixIndex(param, this.NumberOfVertices))).applyMatrix4(this.OCS); let cu = this.GetCurveAtParam(param); @@ -5638,7 +6111,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { return cu.GetPointAtParam(this.GetCurveParamAtParam(param)); return undefined; } - GetDistAtParam(param) { + GetDistAtParam(param) + { if (this._ClosedMark && !this.ParamOnCurve(param)) return NaN; //参数 整数 @@ -5660,7 +6134,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return dist; } - GetPointAtDistance(dist) { + GetPointAtDistance(dist) + { let param = this.GetParamAtDist(dist); return this.GetPointAtParam(param); } @@ -5671,7 +6146,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * @returns {number} * @memberof Polyline */ - GetParamAtPoint(pt) { + GetParamAtPoint(pt) + { let cus = this.Explode(); if (cus.length === 0) return NaN; @@ -5707,7 +6183,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return NaN; } - GetParamAtDist(dist) { + GetParamAtDist(dist) + { let cus = this.Explode(); for (let i = 0; i < cus.length; i++) { let cu = cus[i]; @@ -5722,7 +6199,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { return cus.length + cus[cus.length - 1].GetParamAtDist(dist); return NaN; } - GetDistAtPoint(pt) { + GetDistAtPoint(pt) + { let param = this.GetParamAtPoint(pt); if (!this.ParamOnCurve(param)) return NaN; @@ -5737,7 +6215,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * @returns {Vector3} * @memberof Polyline */ - GetFistDeriv(param) { + GetFistDeriv(param) + { if (param instanceof Vector3) param = this.GetParamAtPoint(param); if (isNaN(param)) @@ -5747,7 +6226,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { return undefined; return cu.GetFistDeriv(this.GetCurveParamAtParam(param)); } - GetSplitCurves(param) { + GetSplitCurves(param) + { //参数需要转化为参数数组 let params; if (typeof param == "number") @@ -5757,15 +6237,16 @@ let Polyline = Polyline_1 = class Polyline extends Curve { //校验参数在曲线中,修正参数 let endParam = this.EndParam; params = params.filter(p => this.ParamOnCurve(p) && p > -1e-6) - .map(a => { - if (a < 0) - return 0; - if (a > endParam) - return endParam; - if (equaln(a, Math.floor(a + 0.5), 1e-8)) - return Math.floor(a + 0.5); - return a; - }); + .map(a => + { + if (a < 0) + return 0; + if (a > endParam) + return endParam; + if (equaln(a, Math.floor(a + 0.5), 1e-8)) + return Math.floor(a + 0.5); + return a; + }); //排序 params.sort((a, b) => a - b); let hasEndParam = arrayLast(params) === this.EndParam; @@ -5803,11 +6284,11 @@ let Polyline = Polyline_1 = class Polyline extends Curve { buls.shift(); } if (equaln(pa, pafloor, 1e-8)) //如果pa在点上 - { + { plData.push({ pt: pts[0].clone(), bul: buls[0] }); } else //在曲线上 - { + { let bul = buls[0]; if (!equaln(bul, 0, 1e-6)) bul = Math.tan((pa - pafloor - (0 === pafloor ? prePa : 0)) * Math.atan(buls[0])); //->凸度 @@ -5836,7 +6317,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { return pls; } //未完善 - GetCurveAtParamRange(startParam, endParam) { + GetCurveAtParamRange(startParam, endParam) + { let sfloor = Math.floor(startParam + 0.5); if (equaln(sfloor, startParam, 1e-8)) startParam = sfloor; @@ -5847,7 +6329,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { endParam = efloor; else efloor = Math.floor(efloor); - const GetCurve = (index) => { + const GetCurve = (index) => + { let d = this._LineData[index]; let next = this._LineData[index + 1]; if (!equaln(d.bul, 0, 1e-8)) @@ -5890,7 +6373,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { pl.OCS = this.OCSNoClone; return; } - Extend(newParam) { + Extend(newParam) + { if (this.CloseMark || this.ParamOnCurve(newParam)) return; this.WriteAllObjectRecord(); @@ -5913,7 +6397,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { this.Update(); } //const this - MatrixAlignTo2(toMatrix) { + MatrixAlignTo2(toMatrix) + { if (!matrixIsCoplane(this._Matrix, toMatrix, 1e-4)) return this.PtsBuls; let m = matrixAlignCoordSys(this._Matrix, toMatrix); @@ -5929,7 +6414,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return { pts, buls }; } - Join(cu, allowGap = false, tolerance = 1e-4) { + Join(cu, allowGap = false, tolerance = 1e-4) + { this.WriteAllObjectRecord(); if (this._ClosedMark) return Status.False; @@ -5955,7 +6441,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } else { let LinkType; - (function (LinkType) { + (function (LinkType) + { LinkType[LinkType["None"] = 0] = "None"; LinkType[LinkType["SpSp"] = 1] = "SpSp"; LinkType[LinkType["SpEp"] = 2] = "SpEp"; @@ -6067,7 +6554,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * @param curves 已经使用CurveLinked的数组,总是首尾相连 * @returns */ - static Combine(curves, tolerance = 1e-5) { + static Combine(curves, tolerance = 1e-5) + { if (!curves || curves.length === 0) return; let pl = new Polyline_1; @@ -6083,7 +6571,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { return pl; } /**首尾相连的曲线直接连接 */ - static FastCombine(curves, tolerance = 1e-5) { + static FastCombine(curves, tolerance = 1e-5) + { if (!curves || curves.length === 0) return; let pl = new Polyline_1; @@ -6114,7 +6603,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { pl.LineData = lineData; return pl; } - PtOnCurve(pt) { + PtOnCurve(pt) + { for (let i = 0; i < this.EndParam; i++) { let c = this.GetCurveAtIndex(i); if (c.PtOnCurve(pt)) @@ -6123,7 +6613,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { return false; } //点在曲线上,已经确定点在曲线的延伸线上 - PtOnCurve3(p, fuzz = 1e-6) { + PtOnCurve3(p, fuzz = 1e-6) + { for (let i = 0; i < this.EndParam; i++) { let c = this.GetCurveAtIndex(i); if (c.PtOnCurve3(p, fuzz)) @@ -6131,13 +6622,16 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return false; } - PtInCurve(pt) { + PtInCurve(pt) + { return this.IsClose && IsPointInPolyLine(this, pt); } - GetClosestPointTo(pt, extend) { + GetClosestPointTo(pt, extend) + { return this.GetClosestPointTo2(pt, extend ? ExtendType.Both : ExtendType.None); } - GetClosestPointTo2(pt, extType) { + GetClosestPointTo2(pt, extType) + { //当曲线空时,返回空 if (this.EndParam < 1) return undefined; @@ -6181,7 +6675,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { return ptC; } //偏移 - GetOffsetCurves(offsetDist) { + GetOffsetCurves(offsetDist) + { if (equaln(offsetDist, 0)) return []; let polyOffestUtil = new OffsetPolyline(this, offsetDist); @@ -6190,7 +6685,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { cu.ColorIndex = this.ColorIndex; return curves; } - GetFeedingToolPath(offsetDist, offsetDistSq = (offsetDist ** 2) * 2.1) { + GetFeedingToolPath(offsetDist, offsetDistSq = (offsetDist ** 2) * 2.1) + { if (equaln(offsetDist, 0)) return []; let polyOffestUtil = new OffsetPolyline(this, offsetDist, true, offsetDistSq); @@ -6199,7 +6695,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { /** * 分解 */ - Explode() { + Explode() + { let exportCus = []; for (let i = 0; i < this.EndParam; i++) { exportCus.push(this.GetCurveAtIndex(i)); @@ -6215,7 +6712,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * @returns {Curve} 曲线(直线或者圆弧) 或空 * @memberof Polyline */ - GetCurveAtParam(param) { + GetCurveAtParam(param) + { if (this._ClosedMark && !this.ParamOnCurve(param)) return undefined; if (param < 0) @@ -6232,7 +6730,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * @returns {number} 参数在子曲线中表示 * @memberof Polyline */ - GetCurveParamAtParam(param) { + GetCurveParamAtParam(param) + { if (param >= this.EndParam) param -= this.EndParam - 1; else if (param > 0) @@ -6243,7 +6742,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * 获得曲线,来自索引位置. * @param {number} i 索引位置 整数 */ - GetCurveAtIndex(i) { + GetCurveAtIndex(i) + { if (i >= this._LineData.length) return undefined; if (!this.ParamOnCurve(i)) @@ -6260,11 +6760,13 @@ let Polyline = Polyline_1 = class Polyline extends Curve { curve.ColorIndex = this._Color; return curve; } - IntersectWith2(curve, intType, tolerance = 1e-5) { + IntersectWith2(curve, intType, tolerance = 1e-5) + { return IntersectPolylineAndCurve(this, curve, intType, tolerance); } //计算自交点. - IntersectSelf() { + IntersectSelf() + { let cus = this.Explode(); if (cus.length === 0) return []; @@ -6282,7 +6784,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return intParams; } - IsIntersectSelf() { + IsIntersectSelf() + { let cus = this.Explode().filter(c => !equaln(c.Length, 0, 1e-3)); for (let i = 0; i < cus.length - 1; i++) { let c1 = cus[i]; @@ -6326,7 +6829,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return false; } - get BoundingBox() { + get BoundingBox() + { let box = new Box3Ext(); for (let i = 0; i < this.EndParam; i++) { let cu = this.GetCurveAtIndex(i); @@ -6337,7 +6841,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { /** * 得到曲线有用的点表和凸度(闭合曲线首尾重复) */ - get PtsBuls() { + get PtsBuls() + { let pts = []; let buls = []; if (this._LineData.length === 0) @@ -6354,7 +6859,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return { pts, buls }; } - get IsBulge() { + get IsBulge() + { if (!this.IsClose) return false; let refDir = Math.sign(this.Area2); @@ -6393,12 +6899,14 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return true; } - get Shape() { + get Shape() + { let { pts, buls } = this.PtsBuls; let curve = CreateBoardUtil.CreatePath(pts, buls); return curve; } - get SVG() { + get SVG() + { let sp = this.StartPoint; let str = `M${sp.x} ${sp.y} `; for (let i = 1; i <= this.EndParam; i++) { @@ -6413,7 +6921,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return str; } - InitDrawObject(renderType = RenderType.Wireframe) { + InitDrawObject(renderType = RenderType.Wireframe) + { let shape = this.Shape; let geo = BufferGeometryUtils.CreateFromPts(shape.getPoints(50).map(AsVector3)); if (renderType === RenderType.WireframePrint) { @@ -6423,7 +6932,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { let obj = new Line$1(geo, ColorMaterial.GetLineMaterial(this._Color)); return obj; } - UpdateDrawObject(type, en) { + UpdateDrawObject(type, en) + { let shape = this.Shape; let pts = shape.getPoints(50).map(AsVector3); let plObj = en; @@ -6432,7 +6942,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { updateGeometry(plObj, BufferGeometryUtils.CreateFromPts(pts)); } } - GetDragPointCount(drag) { + GetDragPointCount(drag) + { if (drag === DragPointType.Grip) { let count = this.EndParam * 2 + 1; if (this.CloseMark) @@ -6443,7 +6954,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { return this._LineData.length; } } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { switch (snapMode) { case ObjectSnapMode.End: return this.GetStretchPoints(); @@ -6510,7 +7022,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return []; } - GetGripPoints() { + GetGripPoints() + { let ptList = []; if (this._LineData.length < 2) return ptList; @@ -6523,7 +7036,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } return ptList; } - MoveGripPoints(indexList, moveVec) { + MoveGripPoints(indexList, moveVec) + { this.WriteAllObjectRecord(); let moveVLoc = AsVector2(moveVec.clone().applyMatrix4(new Matrix4().extractRotation(this.OCSInv))); let calcIndexList = indexList; @@ -6568,7 +7082,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } this.Update(); } - GetStretchPoints() { + GetStretchPoints() + { let iswcs = MatrixIsIdentityCS(this._Matrix); let pts = []; for (let data of this._LineData) { @@ -6586,7 +7101,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * @param {Array} indexList * @param {Vector3} vec */ - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { this.WriteAllObjectRecord(); //本地坐标系移动向量 let moveVLoc = vec.clone().applyMatrix4(new Matrix4().extractRotation(this.OCSInv)); @@ -6607,7 +7123,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { * @param {number} bulIndex 需要修改凸度位置的索引 * @returns */ - const ChangeBul = (nextIndex, bulIndex) => { + const ChangeBul = (nextIndex, bulIndex) => + { //需要修改的点的数据 let d = this._LineData[bulIndex]; if (d === undefined || d.bul == 0) @@ -6632,7 +7149,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { } this.Update(); } - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let ver = file.Read(); this._LineData.length = 0; @@ -6646,7 +7164,8 @@ let Polyline = Polyline_1 = class Polyline extends Curve { this._ClosedMark = file.Read(); } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(2); file.Write(this._LineData.length); @@ -6669,7 +7188,8 @@ const TempPolyline = new Polyline(); * @enum {number} */ var IntersectOption; -(function (IntersectOption) { +(function (IntersectOption) +{ /** * 两者都不延伸 */ @@ -6688,7 +7208,8 @@ var IntersectOption; IntersectOption[IntersectOption["ExtendBoth"] = 3] = "ExtendBoth"; })(IntersectOption || (IntersectOption = {})); //延伸自身还是参数反转 -function reverseIntersectOption(intType) { +function reverseIntersectOption(intType) +{ if (intType === IntersectOption.ExtendThis) intType = IntersectOption.ExtendArg; else if (intType === IntersectOption.ExtendArg) @@ -6705,8 +7226,10 @@ function reverseIntersectOption(intType) { * @param {Intersect} extType 延伸选项. * @returns {Array} 校验完成后的点表 */ -function CheckPointOnCurve(intRes, c1, c2, extType, tolerance = 1e-6) { - return intRes.filter(r => { +function CheckPointOnCurve(intRes, c1, c2, extType, tolerance = 1e-6) +{ + return intRes.filter(r => + { if (!(extType & IntersectOption.ExtendThis)) if (!c1.ParamOnCurve(r.thisParam, tolerance / c1.Length)) return false; @@ -6716,7 +7239,8 @@ function CheckPointOnCurve(intRes, c1, c2, extType, tolerance = 1e-6) { return true; }); } -function IntersectCircleAndCircle(cu1, cu2) { +function IntersectCircleAndCircle(cu1, cu2) +{ if (!cu1.IsCoplaneTo(cu2)) return []; let c1OcsInv = cu1.OCSInv; @@ -6771,7 +7295,8 @@ function IntersectCircleAndCircle(cu1, cu2) { * @param {IntersectOption} extType 延伸选项 * @returns 交点集合 */ -function IntersectCircleAndArc(circle, arc, extType, tolerance = 1e-6) { +function IntersectCircleAndArc(circle, arc, extType, tolerance = 1e-6) +{ let pts = IntersectCircleAndCircle(circle, arc); return CheckPointOnCurve(pts, circle, arc, extType | IntersectOption.ExtendThis, tolerance); } @@ -6784,11 +7309,13 @@ function IntersectCircleAndArc(circle, arc, extType, tolerance = 1e-6) { * @param {IntersectOption} extType 延伸选项 * @returns 交点集合 */ -function IntersectArcAndArc(arc1, arc2, extType, tolerance = 1e-5) { +function IntersectArcAndArc(arc1, arc2, extType, tolerance = 1e-5) +{ let pts = IntersectCircleAndCircle(arc1, arc2); return CheckPointOnCurve(pts, arc1, arc2, extType, tolerance); } -function IntersectEllipseAndLine(l, el, extType, tolerance = 1e-6) { +function IntersectEllipseAndLine(l, el, extType, tolerance = 1e-6) +{ let pts = IntersectLineAndEllipseFor2D(l, el); return CheckPointOnCurve(pts, l, el, extType, tolerance); } @@ -6800,7 +7327,8 @@ function IntersectEllipseAndLine(l, el, extType, tolerance = 1e-6) { * @param {(Circle | Arc)} circle 圆或圆弧 * @returns 交点集合 */ -function IntersectLineAndCircleOrArc(line, circle) { +function IntersectLineAndCircleOrArc(line, circle) +{ let lineOrg = line.StartPoint; let lineDirection = line.EndPoint.sub(lineOrg); let dirLen = lineDirection.length(); @@ -6814,10 +7342,10 @@ function IntersectLineAndCircleOrArc(line, circle) { if (equaln(discr, 0, 1e-7)) { let pt = lineOrg.add(lineDirection.multiplyScalar(-a1)); return [{ - pt, - thisParam: -a1 / dirLen, - argParam: circle.GetParamAtPoint(pt) - }]; + pt, + thisParam: -a1 / dirLen, + argParam: circle.GetParamAtPoint(pt) + }]; } else if (discr > 0) { let root = Math.sqrt(discr); @@ -6838,16 +7366,19 @@ function IntersectLineAndCircleOrArc(line, circle) { return []; } //直线和圆 -function IntersectLineAndCircle(line, circle, extType, tolerance = 1e-6) { +function IntersectLineAndCircle(line, circle, extType, tolerance = 1e-6) +{ let ptArr = IntersectLineAndCircleOrArc(line, circle); return CheckPointOnCurve(ptArr, line, circle, extType | IntersectOption.ExtendArg); } //直线和圆弧 -function IntersectLineAndArc(line, arc, extType, tolerance = 1e-6) { +function IntersectLineAndArc(line, arc, extType, tolerance = 1e-6) +{ let ptArr = IntersectLineAndCircleOrArc(line, arc); return CheckPointOnCurve(ptArr, line, arc, extType, tolerance); } -function IntersectLAndLFor2D2(p1, p2, p3, p4) { +function IntersectLAndLFor2D2(p1, p2, p3, p4) +{ let dx1 = p1.x - p2.x; let dx2 = p3.x - p4.x; let dx3 = p4.x - p2.x; @@ -6879,7 +7410,8 @@ function IntersectLAndLFor2D2(p1, p2, p3, p4) { * @param {Vector3} p4 l2.end * @returns 交点集合 */ -function ShortestLine3AndLine3(p1, p2, p3, p4, epsilon = 1e-6) { +function ShortestLine3AndLine3(p1, p2, p3, p4, epsilon = 1e-6) +{ let p43 = p4.clone().sub(p3); if (p43.lengthSq() < epsilon) return; @@ -6909,7 +7441,8 @@ function ShortestLine3AndLine3(p1, p2, p3, p4, epsilon = 1e-6) { return [resultSegmentPoint1, resultSegmentPoint2]; } //直线和直线 -function IntersectLineAndLine(l1, l2, extType, fuzz = 1e-4) { +function IntersectLineAndLine(l1, l2, extType, fuzz = 1e-4) +{ let [pt1, pt2, pt3, pt4] = [l1.StartPoint, l1.EndPoint, l2.StartPoint, l2.EndPoint]; let ipts; if (equaln(pt1.z, 0, fuzz) && equaln(pt2.z, 0, fuzz) && equaln(pt3.z, 0, fuzz) && equaln(pt4.z, 0, fuzz)) { @@ -6942,7 +7475,8 @@ function IntersectLineAndLine(l1, l2, extType, fuzz = 1e-4) { } return ints; } -function IntersectPolylineAndCurve(pl, cu, extType, tolerance = 1e-6) { +function IntersectPolylineAndCurve(pl, cu, extType, tolerance = 1e-6) +{ let cus = pl.Explode(); let cus2; if (cu instanceof Polyline) @@ -6968,7 +7502,7 @@ function IntersectPolylineAndCurve(pl, cu, extType, tolerance = 1e-6) { //校验延伸 if (IntersectOption.ExtendThis & ext) { //如果曲线是起始又是结束,那么不校验. - if (isStart && isEnd) ; + if (isStart && isEnd); else if (isStart) { ptPars = ptPars.filter(res => res.thisParam <= 1); } @@ -6978,7 +7512,7 @@ function IntersectPolylineAndCurve(pl, cu, extType, tolerance = 1e-6) { } if (IntersectOption.ExtendArg & ext) { //如果曲线是起始又是结束,那么不校验. - if (isStart2 && isEnd2) ; + if (isStart2 && isEnd2); else if (isStart2) { ptPars = ptPars.filter(res => res.argParam + j <= cu2.EndParam); } @@ -6986,7 +7520,8 @@ function IntersectPolylineAndCurve(pl, cu, extType, tolerance = 1e-6) { ptPars = ptPars.filter(res => res.argParam + j >= 0); } } - intRes.push(...ptPars.map(r => { + intRes.push(...ptPars.map(r => + { return { pt: r.pt, thisParam: i + r.thisParam, @@ -6997,7 +7532,8 @@ function IntersectPolylineAndCurve(pl, cu, extType, tolerance = 1e-6) { } return intRes; } -function IntersectLineAndEllipseFor2D(l, el) { +function IntersectLineAndEllipseFor2D(l, el) +{ if (!l.IsCoplaneTo(el)) return []; let mat = new Matrix4().makeRotationZ(-el.Rotation).multiply(el.OCSInv); @@ -7046,7 +7582,8 @@ function IntersectLineAndEllipseFor2D(l, el) { } } let matInv = new Matrix4().getInverse(mat); - return pts.map(p => { + return pts.map(p => + { let pt = p.applyMatrix4(matInv); return { pt, @@ -7055,7 +7592,8 @@ function IntersectLineAndEllipseFor2D(l, el) { }; }); } -function IntersectEllipseAndCircleOrArc(el, cir, type) { +function IntersectEllipseAndCircleOrArc(el, cir, type) +{ if (!el.IsCoplaneTo(cir)) return []; let a = Math.max(el.RadX, el.RadY); @@ -7097,7 +7635,8 @@ function IntersectEllipseAndCircleOrArc(el, cir, type) { ]; } let ro = new Matrix4().makeRotationZ(el.Rotation); - let res = pts.map(p => { + let res = pts.map(p => + { let pt = p.applyMatrix4(ro).applyMatrix4(el.OCS); return { pt, @@ -7109,7 +7648,8 @@ function IntersectEllipseAndCircleOrArc(el, cir, type) { } else { let pts = el.Shape.getPoints(60); - let lineData = pts.map(p => { + let lineData = pts.map(p => + { return { pt: p, bul: 0 }; }); let pl = new Polyline(lineData); @@ -7123,7 +7663,8 @@ function IntersectEllipseAndCircleOrArc(el, cir, type) { return intPts; } } -function IntersectEllipse(el1, el2, type) { +function IntersectEllipse(el1, el2, type) +{ if (!el1.IsCoplaneTo(el2)) return []; let isEqul = equalv3(el1.Center, el2.Center) @@ -7143,10 +7684,12 @@ function IntersectEllipse(el1, el2, type) { let diffMat = el1.OCSInv.multiply(el2.OCS); let pts1 = el1.Shape.getPoints(60); let pts2 = el2.Shape.getPoints(60); - let lineData1 = pts1.map(p => { + let lineData1 = pts1.map(p => + { return { pt: p, bul: 0 }; }); - let lineData2 = pts2.map(p => { + let lineData2 = pts2.map(p => + { return { pt: p, bul: 0 }; }); let pl1 = new Polyline(lineData1); @@ -7166,8 +7709,10 @@ var Arc_1; * 圆弧的绘制从起始圆弧绘制到终止圆弧. 按照时针绘制. * 参考计算圆弧的完整角度方法查看该计算方式. */ -let Arc = Arc_1 = class Arc extends Curve { - constructor(center = new Vector3(), radius = 0.1, startAngle = 0.1, endAngle = 0, clockwise = true) { +let Arc = Arc_1 = class Arc extends Curve +{ + constructor(center = new Vector3(), radius = 0.1, startAngle = 0.1, endAngle = 0, clockwise = true) + { super(); /** * 曲线为顺时针 @@ -7179,37 +7724,46 @@ let Arc = Arc_1 = class Arc extends Curve { this._EndAngle = clampRad(endAngle); this._Clockwise = clockwise; } - get Shape() { + get Shape() + { let sp = new Shape$1(); sp.absarc(0, 0, this._Radius, this._StartAngle, this._EndAngle, this._Clockwise); return sp; } - get Center() { + get Center() + { return this.Position; } - set Center(v) { + set Center(v) + { this.Position = v; } - get Normal() { + get Normal() + { return new Vector3().setFromMatrixColumn(this._Matrix, 2); } - set Normal(v) { + set Normal(v) + { this.WriteAllObjectRecord(); matrixSetVector(this._Matrix, 2, v); this.Update(); } - get Area() { + get Area() + { return 0.5 * this.AllAngle * this.Radius * this.Radius; } //获得曲线的面积,逆时针为正,顺时针为负. - get Area2() { + get Area2() + { let clockwise = this._Clockwise ? -1 : 1; return 0.5 * this.AllAngle * this.Radius * this.Radius * clockwise; } - get IsClose() { + get IsClose() + { return false; } - get BoundingBox() { + get BoundingBox() + { let pts = [this.StartPoint, this.EndPoint]; //TODO:考虑三维圆弧. let addPts = [ @@ -7218,85 +7772,105 @@ let Arc = Arc_1 = class Arc extends Curve { this.Center.add(new Vector3(-this._Radius, 0)), this.Center.add(new Vector3(0, -this._Radius)), ]; - addPts.forEach(p => { + addPts.forEach(p => + { if (this.PtOnCurve(p)) pts.push(p); }); return new Box3().setFromPoints(pts); } - get Radius() { + get Radius() + { return this._Radius; } - set Radius(v) { + set Radius(v) + { this.WriteAllObjectRecord(); this._Radius = v <= 0 ? 1e-19 : v; this.Update(); } - get IsClockWise() { + get IsClockWise() + { return this._Clockwise; } - set IsClockWise(v) { + set IsClockWise(v) + { if (v !== this._Clockwise) { this.WriteAllObjectRecord(); this._Clockwise = v; this.Update(); } } - get StartAngle() { + get StartAngle() + { return this._StartAngle; } - set StartAngle(v) { + set StartAngle(v) + { this.WriteAllObjectRecord(); this._StartAngle = v; this.Update(); } - get EndAngle() { + get EndAngle() + { return this._EndAngle; } - set EndAngle(v) { + set EndAngle(v) + { this.WriteAllObjectRecord(); this._EndAngle = v; this.Update(); } //******************** Curve function start*****************// - get StartPoint() { + get StartPoint() + { return polar(new Vector3(), this._StartAngle, this._Radius).applyMatrix4(this.OCS); } - set StartPoint(v) { + set StartPoint(v) + { let vTemp = v.clone().applyMatrix4(this.OCSInv); this.StartAngle = angle(vTemp); } - get EndPoint() { + get EndPoint() + { return polar(new Vector3(), this._EndAngle, this._Radius).applyMatrix4(this.OCS); } - set EndPoint(v) { + set EndPoint(v) + { let vTemp = v.clone().applyMatrix4(this.OCSInv); this.EndAngle = angle(vTemp); } - get StartParam() { + get StartParam() + { return 0; } - get EndParam() { + get EndParam() + { return 1; } - get Length() { + get Length() + { return this.AllAngle * this._Radius; } - GetParamAtPoint2(pt) { + GetParamAtPoint2(pt) + { return this.GetParamAtAngle(this.GetAngleAtPoint(pt)); } //点在曲线上,已经确定点在曲线的延伸线上 - PtOnCurve3(p, fuzz = 1e-6) { + PtOnCurve3(p, fuzz = 1e-6) + { let param = this.GetParamAtPoint2(p); return this.ParamOnCurve(param, fuzz); } - ApplyScaleMatrix(m) { + ApplyScaleMatrix(m) + { this.WriteAllObjectRecord(); this.Center = this.Center.applyMatrix4(m); this.Radius = this.Radius * m.getMaxScaleOnAxis(); return this; } - ApplyMirrorMatrix(m) { + ApplyMirrorMatrix(m) + { this.WriteAllObjectRecord(); let sp = this.StartPoint; let ep = this.EndPoint; @@ -7306,24 +7880,29 @@ let Arc = Arc_1 = class Arc extends Curve { this.EndPoint = ep; return this; } - GetPointAtParam(param) { + GetPointAtParam(param) + { let an = this.GetAngleAtParam(param); return polar(new Vector3(), an, this._Radius).applyMatrix4(this.OCS); } - GetPointAtDistance(distance) { + GetPointAtDistance(distance) + { let len = this.Length; if (len == 0) return; return this.GetPointAtParam(distance / len); } - GetDistAtParam(param) { + GetDistAtParam(param) + { return Math.abs(param * this.Length); } - GetDistAtPoint(pt) { + GetDistAtPoint(pt) + { let param = this.GetParamAtPoint(pt); return this.GetDistAtParam(param); } - GetParamAtPoint(pt) { + GetParamAtPoint(pt) + { if (this._Radius == 0 || this.AllAngle == 0 || !equaln(pt.distanceTo(this.Center), this._Radius, 1e-6)) @@ -7339,7 +7918,8 @@ let Arc = Arc_1 = class Arc extends Curve { * @returns * @memberof Arc */ - GetParamAtAngle(an) { + GetParamAtAngle(an) + { //如果以pt为终点,那么所有的角度为 let ptAllAn = this.ComputeAnlge(an); let allAn = this.AllAngle; @@ -7356,7 +7936,8 @@ let Arc = Arc_1 = class Arc extends Curve { * @param [isStart] true:返回负数,false 返回正数 * @returns */ - GetParamAtAngle2(an, isStart = true) { + GetParamAtAngle2(an, isStart = true) + { //如果以pt为终点,那么所有的角度为 let ptAllAn = this.ComputeAnlge(an); let allAn = this.AllAngle; @@ -7367,14 +7948,17 @@ let Arc = Arc_1 = class Arc extends Curve { else //返回正数 return ptAllAn / allAn; } - GetAngleAtPoint(pt) { + GetAngleAtPoint(pt) + { let ptTmp = pt.clone().applyMatrix4(this.OCSInv); return angle(ptTmp); } - GetAngleAtParam(param) { + GetAngleAtParam(param) + { return clampRad(this._StartAngle + param * this.AllAngle * (this._Clockwise ? -1 : 1)); } - GetSplitCurves(param) { + GetSplitCurves(param) + { let params = this.SplitParamSort(param); //角度列表 let ans = params.map(p => this.GetAngleAtParam(p)); @@ -7389,7 +7973,8 @@ let Arc = Arc_1 = class Arc extends Curve { } return arcs; } - GetOffsetCurves(offsetDist) { + GetOffsetCurves(offsetDist) + { if (this._Clockwise) offsetDist *= -1; if ((offsetDist + this._Radius) > 0) { @@ -7399,7 +7984,8 @@ let Arc = Arc_1 = class Arc extends Curve { } return []; } - Extend(newParam) { + Extend(newParam) + { this.WriteAllObjectRecord(); if (newParam < 0) { this._StartAngle = this.GetAngleAtParam(newParam); @@ -7409,7 +7995,8 @@ let Arc = Arc_1 = class Arc extends Curve { } this.Update(); } - Join(cu) { + Join(cu) + { if (cu instanceof Arc_1) { //非常小的圆弧直接结束 if (cu.AllAngle < 5e-6) @@ -7423,13 +8010,13 @@ let Arc = Arc_1 = class Arc extends Curve { let saAllan = this.ComputeAnlge(sa); let eaAllan = this.ComputeAnlge(ea); if (equaln(sa, this._StartAngle)) //this起点对起点 - { + { if (eaAllan > allAn) this.EndAngle = ea; return Status.True; } else if (equaln(sa, this._EndAngle)) //this终点对起点 - { + { if (eaAllan < allAn || equaln(ea, this._StartAngle)) return Status.ConverToCircle; else @@ -7437,7 +8024,7 @@ let Arc = Arc_1 = class Arc extends Curve { return Status.True; } else if (equaln(ea, this.StartAngle)) //this起点对终点 - { + { if (saAllan < allAn) return Status.ConverToCircle; else @@ -7445,7 +8032,7 @@ let Arc = Arc_1 = class Arc extends Curve { return Status.True; } else if (equaln(ea, this._EndAngle)) //this终点对终点 - { + { if (saAllan > allAn) this.StartAngle = sa; return Status.True; @@ -7485,13 +8072,15 @@ let Arc = Arc_1 = class Arc extends Curve { } return Status.False; } - Reverse() { + Reverse() + { this.WriteAllObjectRecord(); this._Clockwise = !this._Clockwise; [this._StartAngle, this._EndAngle] = [this._EndAngle, this._StartAngle]; return this; } - IntersectWith2(curve, intType, tolerance = 1e-4) { + IntersectWith2(curve, intType, tolerance = 1e-4) + { if (curve instanceof Arc_1) { return IntersectArcAndArc(this, curve, intType); } @@ -7514,10 +8103,12 @@ let Arc = Arc_1 = class Arc extends Curve { * @type {number} * @memberof Arc */ - get AllAngle() { + get AllAngle() + { return this.ComputeAnlge(this._EndAngle); } - get Bul() { + get Bul() + { if (equaln(this.AllAngle, Math.PI * 2)) return 1; return Math.tan(this.AllAngle * 0.25) * (this.IsClockWise ? -1 : 1); @@ -7530,7 +8121,8 @@ let Arc = Arc_1 = class Arc extends Curve { * @returns * @memberof Arc */ - ComputeAnlge(endAngle) { + ComputeAnlge(endAngle) + { //顺时针 if (this._Clockwise) { if (this._StartAngle > endAngle) @@ -7552,7 +8144,8 @@ let Arc = Arc_1 = class Arc extends Curve { * @param {Vector2} p2 * @param {number} bul 凸度,在cad中,凸度为 <(四分之一圆心角)的正切值> */ - ParseFromBul(p1, p2, bul) { + ParseFromBul(p1, p2, bul) + { if (p1 instanceof Vector2) p1 = AsVector3(p1); if (p2 instanceof Vector2) @@ -7582,7 +8175,8 @@ let Arc = Arc_1 = class Arc extends Curve { this._Clockwise = bul < 0; return this; } - FromThreePoint(pt1, pt2, pt3) { + FromThreePoint(pt1, pt2, pt3) + { if (!(pt1 && pt2 && pt3)) return; let ocsInv = this.OCSInv; @@ -7607,7 +8201,8 @@ let Arc = Arc_1 = class Arc extends Curve { * * @param {RenderType} [renderType=RenderType.Wireframe] */ - InitDrawObject(renderType = RenderType.Wireframe) { + InitDrawObject(renderType = RenderType.Wireframe) + { let geo = BufferGeometryUtils.CreateFromPts(this.Shape.getPoints(60).map(AsVector3)); if (renderType === RenderType.WireframePrint) { var geometry = new LineGeometry(); @@ -7617,7 +8212,8 @@ let Arc = Arc_1 = class Arc extends Curve { return new Line$1(geo, ColorMaterial.GetLineMaterial(this._Color)); } //更新Geometry - UpdateGeometry(geo) { + UpdateGeometry(geo) + { let pts = this.Shape.getPoints(60).map(AsVector3); BufferGeometryUtils.UpdatePts(geo, pts); } @@ -7628,11 +8224,13 @@ let Arc = Arc_1 = class Arc extends Curve { * @param {Object3D} obj * @memberof Arc */ - UpdateDrawObject(type, obj) { + UpdateDrawObject(type, obj) + { let geo = obj["geometry"]; this.UpdateGeometry(geo); } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { switch (snapMode) { case ObjectSnapMode.End: return [this.StartPoint, this.EndPoint]; @@ -7659,7 +8257,8 @@ let Arc = Arc_1 = class Arc extends Curve { } return []; } - GetGripPoints() { + GetGripPoints() + { return [ this.StartPoint, this.GetPointAtParam(0.5), @@ -7667,7 +8266,8 @@ let Arc = Arc_1 = class Arc extends Curve { this.Center.clone(), ]; } - MoveGripPoints(indexList, vec) { + MoveGripPoints(indexList, vec) + { if (indexList.length > 0) { this.WriteAllObjectRecord(); let ptsArr = this.GetGripPoints(); @@ -7683,10 +8283,12 @@ let Arc = Arc_1 = class Arc extends Curve { } } } - GetStretchPoints() { + GetStretchPoints() + { return [this.StartPoint, this.EndPoint]; } - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { if (indexList.length === 0) return; this.WriteAllObjectRecord(); @@ -7706,10 +8308,12 @@ let Arc = Arc_1 = class Arc extends Curve { this.Update(); } } - GetParamAtDist(d) { + GetParamAtDist(d) + { return d / this.Length; } - GetFistDeriv(pt) { + GetFistDeriv(pt) + { let an; if (typeof pt === "number") an = this.GetAngleAtParam(pt); @@ -7719,7 +8323,8 @@ let Arc = Arc_1 = class Arc extends Curve { let ocs = new Matrix4().extractRotation(this.OCS); return polar(new Vector3(), an, this._Radius).applyMatrix4(ocs); } - GetClosestPointTo(pt, extend) { + GetClosestPointTo(pt, extend) + { let l = new Line(this.Center, pt); let inPts = this.IntersectWith(l, extend ? IntersectOption.ExtendBoth : IntersectOption.ExtendArg); if (inPts.length < 2) @@ -7729,7 +8334,8 @@ let Arc = Arc_1 = class Arc extends Curve { //#region -------------------------File------------------------- //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象从文件中读取数据,初始化自身 - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let ver = file.Read(); if (ver === 1) { @@ -7742,7 +8348,8 @@ let Arc = Arc_1 = class Arc extends Curve { this._Clockwise = file.Read(); } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(2); file.Write(this._Radius); @@ -7763,11 +8370,14 @@ Arc = Arc_1 = __decorate([ * count.AddCount("Test", 1); * count.GetCount("Test");//现在 Test 的个数为1 */ -class Count { - constructor() { +class Count +{ + constructor() + { this.m_CountMap = new WeakMap(); } - GetCount(obj) { + GetCount(obj) + { let count = this.m_CountMap.get(obj); if (!count) { this.m_CountMap.set(obj, 0); @@ -7775,7 +8385,8 @@ class Count { } return count; } - AddCount(obj, add) { + AddCount(obj, add) + { this.m_CountMap.set(obj, this.GetCount(obj) + add); } } @@ -7784,17 +8395,21 @@ class Count { * 轨道控制的数学类,观察向量和角度的互相转换 * 当x当抬头或者低头到90度时,触发万向锁. */ -class Orbit { - constructor() { +class Orbit +{ + constructor() + { //抬头低头 正数抬头 负数低头 this.phi = 0; //Φ //身体旋转 0为正右边 逆时针旋转 this.theta = 0; //θ } - get RoX() { + get RoX() + { return this.phi; } - set RoX(v) { + set RoX(v) + { this.phi = MathUtils.clamp(v, Math.PI * -0.49, Math.PI * 0.49); } /** @@ -7802,7 +8417,8 @@ class Orbit { * @param [outDirection] 引用传入,如果传入,那么就不构造新的向量 * @returns 返回观察向量 */ - UpdateDirection(outDirection = new Vector3()) { + UpdateDirection(outDirection = new Vector3()) + { outDirection.z = Math.sin(this.phi); //归一化专用. let d = Math.abs(Math.cos(this.phi)); @@ -7814,7 +8430,8 @@ class Orbit { * 使用观察向量,计算旋转角度 * @param dir 这个向量会被修改成单位向量. */ - SetFromDirection(dir) { + SetFromDirection(dir) + { dir.normalize(); this.phi = Math.asin(dir.z); if (equaln(dir.x, 0) && equaln(dir.y, 0)) @@ -7829,7 +8446,8 @@ class Orbit { * 参考任意轴坐标系算法. * http://help.autodesk.com/view/ACD/2017/CHS/?guid=GUID-E19E5B42-0CC7-4EBA-B29F-5E1D595149EE */ - static ComputUpDirection(n, ay = new Vector3(), ax = new Vector3()) { + static ComputUpDirection(n, ay = new Vector3(), ax = new Vector3()) + { n.normalize(); if (Math.abs(n.x) < 0.015625 && Math.abs(n.y) < 0.015625) ax.crossVectors(YAxis, n); @@ -7843,7 +8461,8 @@ class Orbit { } //3点获取圆心 -function getCircleCenter(pt1, pt2, pt3) { +function getCircleCenter(pt1, pt2, pt3) +{ if (!(pt1 && pt2 && pt3)) return; let A1 = pt1.x - pt2.x; @@ -7869,7 +8488,8 @@ function getCircleCenter(pt1, pt2, pt3) { return center; } //行列式 -function getDeterminantFor2V(v1, v2) { +function getDeterminantFor2V(v1, v2) +{ return v1.x * v2.y - v1.y * v2.x; } /** @@ -7883,11 +8503,13 @@ function getDeterminantFor2V(v1, v2) { * [c1,c2,c3...], * ] */ -function curveLinkGroup(cus) { +function curveLinkGroup(cus) +{ //返回的曲线组 let groupCus = new Array(); //将封闭的曲线先提取出来 - cus = cus.filter(c => { + cus = cus.filter(c => + { let isClose = c.IsClose; if (isClose) groupCus.push([c]); @@ -7909,7 +8531,8 @@ function curveLinkGroup(cus) { * @param {boolean} isEndSeach true:从终点搜索,false:从起点搜索 * @returns {Stand} 如果站点中存在可以取得的曲线,返回下个站点,否则返回undefined */ - function linkCurve(stand, cus, isEndSeach) { + function linkCurve(stand, cus, isEndSeach) + { for (let route of stand.routes) { let cu = route.curve; if (cuCount.GetCount(cu) === 0) { @@ -7945,7 +8568,8 @@ function curveLinkGroup(cus) { } return groupCus; } -function equalCurve(cu1, cu2, tolerance = 1e-4) { +function equalCurve(cu1, cu2, tolerance = 1e-4) +{ if ((cu1 instanceof Polyline) && (cu2 instanceof Polyline)) { if (cu1.IsClose !== cu2.IsClose || !isParallelTo(cu1.Normal, cu2.Normal)) return false; @@ -8021,7 +8645,8 @@ function equalCurve(cu1, cu2, tolerance = 1e-4) { * @param {Vector3} pt * @returns {boolean} 左边为-1,右边为1 */ -function GetPointAtCurveDir(cu, pt) { +function GetPointAtCurveDir(cu, pt) +{ if (cu instanceof Circle) return cu.PtInCurve(pt) ? -1 : 1; else if (cu instanceof Polyline) { @@ -8039,7 +8664,8 @@ function GetPointAtCurveDir(cu, pt) { let cross = dri.cross(pt.clone().sub(cp)).applyMatrix4(cu.OCSInv); return -Math.sign(cross.z); } -function ConverCircleToPolyline(cir) { +function ConverCircleToPolyline(cir) +{ //该写法不支持三维坐标系 // let pl = new Polyline(); // let bul = Math.tan(Math.PI * 0.125); @@ -8058,7 +8684,8 @@ function ConverCircleToPolyline(cir) { pl.Join(arcs[1]); return pl; } -function GetTanPtsOnArcOrCircle(cu, lastPoint) { +function GetTanPtsOnArcOrCircle(cu, lastPoint) +{ if (lastPoint) { //ref:wykobi let ocsInv = cu.OCSInv; @@ -8078,7 +8705,8 @@ function GetTanPtsOnArcOrCircle(cu, lastPoint) { } } } -function getArcOrCirNearPts(cu, pickPoint, viewXform) { +function getArcOrCirNearPts(cu, pickPoint, viewXform) +{ let viewNormal = new Vector3().fromArray(viewXform.elements, 2 * 3); let plane = new PlaneExt(cu.Normal, cu.Center); let pickLocal = plane.intersectLine(new Line3(pickPoint, pickPoint.clone().add(viewNormal)), new Vector3(), true); @@ -8099,10 +8727,12 @@ function getArcOrCirNearPts(cu, pickPoint, viewXform) { return cu.IntersectWith(lz, IntersectOption.ExtendBoth); } } -function getTanPtsOnEllipse(cu, lastPoint) { +function getTanPtsOnEllipse(cu, lastPoint) +{ return []; } -function IsRect(cu) { +function IsRect(cu) +{ if (cu instanceof Polyline) { if (!cu.IsClose) return { isRect: false }; @@ -8137,7 +8767,8 @@ function IsRect(cu) { } return { isRect: false }; } -function MergeCurvelist(cus) { +function MergeCurvelist(cus) +{ for (let i = 0; i < cus.length; i++) { let c1 = cus[i]; let nextI = FixIndex(i + 1, cus); @@ -8156,12 +8787,14 @@ function MergeCurvelist(cus) { } return cus; } -function SwapParam(res) { +function SwapParam(res) +{ for (let r of res) [r.thisParam, r.argParam] = [r.argParam, r.thisParam]; return res; } -function ComputerCurvesNormalOCS(curves, allowAutoCalc = true) { +function ComputerCurvesNormalOCS(curves, allowAutoCalc = true) +{ if (!curves || curves.length === 0) return; //准备计算多段线的法向量 @@ -8208,7 +8841,8 @@ function ComputerCurvesNormalOCS(curves, allowAutoCalc = true) { } return new Matrix4().makeBasis(x, y, normal).setPosition(curves[0].StartPoint); } -function Pts2Polyline(pts, isClose) { +function Pts2Polyline(pts, isClose) +{ let pl = new Polyline(); for (let i = 0; i < pts.length; i += 2) { let p1 = AsVector3(pts[i]); @@ -8237,7 +8871,8 @@ function Pts2Polyline(pts, isClose) { } const PolylineSpliteRectFuzz = 1e-3; /**封闭多段线 分割成矩形 */ -function PolylineSpliteRect(outline) { +function PolylineSpliteRect(outline) +{ if (!outline.IsClose || IsRect(outline).isRect) return [outline]; let firstDerv = outline.GetFistDeriv(0).normalize(); @@ -8296,97 +8931,122 @@ function PolylineSpliteRect(outline) { var Circle_1; let circleGeometry; -function GetCircleGeometry() { +function GetCircleGeometry() +{ if (!circleGeometry) circleGeometry = BufferGeometryUtils.CreateFromPts(new EllipseCurve(0, 0, 1, 1, 0, 2 * Math.PI, false, 0).getPoints(360).map(AsVector3)); return circleGeometry; } -let Circle = Circle_1 = class Circle extends Curve { - constructor(center, radius = 1e-6) { +let Circle = Circle_1 = class Circle extends Curve +{ + constructor(center, radius = 1e-6) + { super(); center && this._Matrix.setPosition(center); this._Radius = radius; } - get Shape() { + get Shape() + { let sp = new Shape2(); sp.ellipse(0, 0, this._Radius, this._Radius, 0, 2 * Math.PI, false, 0); return sp; } - get Center() { + get Center() + { return new Vector3().setFromMatrixPosition(this._Matrix); } - set Center(v) { + set Center(v) + { this.WriteAllObjectRecord(); this._Matrix.setPosition(v); this.Update(); } - get Radius() { + get Radius() + { return this._Radius; } - set Radius(v) { + set Radius(v) + { this.WriteAllObjectRecord(); this._Radius = clamp(v, 1e-9, 1e19); this.Update(); } - ApplyScaleMatrix(m) { + ApplyScaleMatrix(m) + { this.WriteAllObjectRecord(); this.Center = this.Center.applyMatrix4(m); this.Radius = this.Radius * m.getMaxScaleOnAxis(); return this; } - ApplyMirrorMatrix(m) { + ApplyMirrorMatrix(m) + { this.WriteAllObjectRecord(); reviseMirrorMatrix(this._Matrix); return this; } //******************** Curve function start*****************// - get StartPoint() { + get StartPoint() + { return this.GetPointAtParam(0); } - get StartParam() { + get StartParam() + { return 0; } - get EndPoint() { + get EndPoint() + { return this.GetPointAtParam(0); } - get EndParam() { + get EndParam() + { return 1; } - PtInCurve(pt) { + PtInCurve(pt) + { return pt.distanceToSquared(this.Center) < Math.pow(this.Radius, 2); } - get Area() { + get Area() + { return Math.PI * this._Radius ** 2; } - get Area2() { + get Area2() + { return Math.PI * this._Radius ** 2; } - get Length() { + get Length() + { return Math.PI * 2 * this._Radius; } - get IsClose() { + get IsClose() + { return true; } //曲线为顺时针 get IsClockWise() { return false; } - GetPointAtParam(param) { + GetPointAtParam(param) + { return polar(new Vector3(), param * 2 * Math.PI, this._Radius).applyMatrix4(this._Matrix); } - GetPointAtDistance(distance) { + GetPointAtDistance(distance) + { let param = distance / (Math.PI * 2 * this._Radius); return this.GetPointAtParam(param); } - GetDistAtParam(param) { + GetDistAtParam(param) + { return Math.PI * 2 * this._Radius * param; } - GetDistAtPoint(pt) { + GetDistAtPoint(pt) + { let param = this.GetParamAtPoint(pt); return this.GetDistAtParam(param); } - GetParamAtDist(d) { + GetParamAtDist(d) + { return d / (Math.PI * 2 * this._Radius); } - GetSplitCurves(param) { + GetSplitCurves(param) + { let params; if (param instanceof Array) { params = param.filter(p => this.ParamOnCurve(p)); @@ -8413,15 +9073,18 @@ let Circle = Circle_1 = class Circle extends Curve { } return curvelist; } - GetParamAtPoint(pt) { + GetParamAtPoint(pt) + { if (!this.PtOnCurve(pt)) return NaN; return angle(pt.clone().applyMatrix4(this.OCSInv)) / (Math.PI * 2); } - PtOnCurve(pt) { + PtOnCurve(pt) + { return equaln(pt.distanceToSquared(this.Center), this._Radius * this._Radius, 1e-5); } - GetOffsetCurves(offsetDist) { + GetOffsetCurves(offsetDist) + { if ((offsetDist + this._Radius) > 0) { let circle = this.Clone(); circle.Radius = this._Radius + offsetDist; @@ -8429,7 +9092,8 @@ let Circle = Circle_1 = class Circle extends Curve { } return []; } - IntersectWith2(curve, intType) { + IntersectWith2(curve, intType) + { if (curve instanceof Arc) { return IntersectCircleAndArc(this, curve, intType); } @@ -8447,10 +9111,12 @@ let Circle = Circle_1 = class Circle extends Curve { return []; } //******************** Curve function end*****************// - get BoundingBox() { + get BoundingBox() + { return new Box3Ext().setFromPoints(this.GetGripPoints()); } - InitDrawObject(renderType = RenderType.Wireframe) { + InitDrawObject(renderType = RenderType.Wireframe) + { let obj = new Object3D(); let cirGeo = GetCircleGeometry(); if (renderType === RenderType.WireframePrint) { @@ -8464,25 +9130,29 @@ let Circle = Circle_1 = class Circle extends Curve { this.UpdateDrawObject(renderType, obj); return obj; } - UpdateDrawObject(type, obj) { + UpdateDrawObject(type, obj) + { obj.children[0].scale.set(this._Radius, this._Radius, this._Radius); obj.children[0].updateMatrix(); } - UpdateDrawObjectMaterial(type, obj, material) { - if (type === RenderType.WireframePrint) ; + UpdateDrawObjectMaterial(type, obj, material) + { + if (type === RenderType.WireframePrint); else { let m = obj.children[0]; m.material = material ? material : ColorMaterial.GetLineMaterial(this._Color); return obj; } } - GetDragPointCount(drag) { + GetDragPointCount(drag) + { if (drag === DragPointType.Grip) return 5; else return 1; } - GetGripPoints() { + GetGripPoints() + { let pts = [ new Vector3(), new Vector3(0, this._Radius), @@ -8494,7 +9164,8 @@ let Circle = Circle_1 = class Circle extends Curve { pts.forEach(p => p.applyMatrix4(ocs)); return pts; } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { switch (snapMode) { case ObjectSnapMode.Nea: { @@ -8522,7 +9193,8 @@ let Circle = Circle_1 = class Circle extends Curve { } return []; } - MoveGripPoints(indexList, vec) { + MoveGripPoints(indexList, vec) + { let pts = this.GetGripPoints(); if (indexList.length > 0) { let index = indexList[0]; @@ -8538,19 +9210,22 @@ let Circle = Circle_1 = class Circle extends Curve { } } } - GetStretchPoints() { + GetStretchPoints() + { let pts = [new Vector3()]; let ocs = this.OCS; pts.forEach(p => p.applyMatrix4(ocs)); return pts; } - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { if (indexList.length > 0) { let mat = MoveMatrix(vec); this.ApplyMatrix(mat); } } - GetFistDeriv(pt) { + GetFistDeriv(pt) + { if (typeof pt === "number") pt = this.GetPointAtParam(pt); else @@ -8559,13 +9234,15 @@ let Circle = Circle_1 = class Circle extends Curve { let an = angle(pt) + Math.PI * 0.5; return polar(new Vector3(), an, 1).applyMatrix4(new Matrix4().extractRotation(this.OCS)); } - GetClosestPointTo(pt, extend) { + GetClosestPointTo(pt, extend) + { pt = pt.clone().applyMatrix4(this.OCSInv).setZ(0).applyMatrix4(this.OCS); if (equaln(pt.distanceToSquared(this.Center), 0, 1e-10)) return this.GetPointAtParam(0); let l = new Line(this.Center, pt); let pts = l.IntersectWith(this, IntersectOption.ExtendBoth); - pts.sort((p1, p2) => { + pts.sort((p1, p2) => + { return p1.distanceToSquared(pt) - p2.distanceToSquared(pt); }); return pts[0]; @@ -8573,13 +9250,15 @@ let Circle = Circle_1 = class Circle extends Curve { //#region -------------------------File------------------------- //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象从文件中读取数据,初始化自身 - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let ver = file.Read(); this._Radius = file.Read(); } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(1); file.Write(this._Radius); @@ -8590,7 +9269,8 @@ Circle = Circle_1 = __decorate([ ], Circle); const _LogInjectFunctions = []; -function Log(message, ...optionalParams) { +function Log(message, ...optionalParams) +{ for (let f of _LogInjectFunctions) f(message, ...optionalParams); } @@ -8598,7 +9278,8 @@ function Log(message, ...optionalParams) { let x = new Vector3(); let y = new Vector3(); let z = new Vector3(); -function IsMirror(mtx) { +function IsMirror(mtx) +{ mtx.extractBasis(x, y, z); // for a true orthogonal, non-mirrored base, u.cross(v) == w // If they have an opposite direction then we are mirroring @@ -8618,12 +9299,15 @@ const getTag = () => staticTag++; /** Class Vector3D * Represents a 3D vector with X, Y, Z coordinates. */ -class Vector3D extends Vector3 { - clone() { +class Vector3D extends Vector3 +{ + clone() + { return new Vector3D(this.x, this.y, this.z); } // find a vector that is somewhat perpendicular to this one - randomNonParallelVector() { + randomNonParallelVector() + { let x = Math.abs(this.x); let y = Math.abs(this.y); let z = Math.abs(this.z); @@ -8634,7 +9318,8 @@ class Vector3D extends Vector3 { else return new Vector3D(0, 0, 1); } - toString() { + toString() + { return ("(" + this.x.toFixed(5) + ", " + @@ -8645,19 +9330,24 @@ class Vector3D extends Vector3 { } } -class Vector2D extends Vector2 { +class Vector2D extends Vector2 +{ // extend to a 3D vector by adding a z coordinate: - toVector3D(z) { + toVector3D(z) + { return new Vector3D(this.x, this.y, z); } - clone() { + clone() + { return new Vector2D(this.x, this.y); } // returns the vector rotated by 90 degrees clockwise - normal() { + normal() + { return new Vector2D(this.y, -this.x); } - cross(a) { + cross(a) + { return this.x * a.y - this.y * a.x; } } @@ -8669,20 +9359,25 @@ class Vector2D extends Vector2 { // `flipped()`, and `interpolate()` methods that behave analogous to the ones // FIXME: And a lot MORE (see plane.fromVector3Ds for ex) ! This is fragile code // defined by `Vertex`. -class Vertex3D { - constructor(pos, uv = new Vector2D()) { +class Vertex3D +{ + constructor(pos, uv = new Vector2D()) + { this.pos = pos; this.uv = uv; } - clone() { + clone() + { return new Vertex3D(this.pos.clone(), this.uv.clone()); } // Return a vertex with all orientation-specific data (e.g. vertex normal) flipped. Called when the // orientation of a polygon is flipped. - flipped() { + flipped() + { return this; } - getTag() { + getTag() + { let result = this.tag; if (!result) { result = getTag(); @@ -8693,13 +9388,15 @@ class Vertex3D { // Create a new vertex between this vertex and `other` by linearly // interpolating all properties using a parameter of `t`. Subclasses should // override this to interpolate additional properties. - interpolate(other, t) { + interpolate(other, t) + { let pos = this.pos.clone().lerp(other.pos, t); let uv = this.uv.clone().lerp(other.uv, t); return new Vertex3D(pos, uv); } // Affine transformation of vertex. Returns a new Vertex - transform(matrix4x4) { + transform(matrix4x4) + { const newpos = this.pos.clone().applyMatrix4(matrix4x4); return new Vertex3D(newpos, this.uv); } @@ -8707,23 +9404,29 @@ class Vertex3D { // # class Plane // Represents a plane in 3D space. -class Plane { - constructor(normal, w) { +class Plane +{ + constructor(normal, w) + { this.normal = normal; this.w = w; } - flipped() { + flipped() + { return new Plane(this.normal.clone().negate(), -this.w); } - getTag() { + getTag() + { if (!this.tag) this.tag = getTag(); return this.tag; } - coplanarTo(plane) { + coplanarTo(plane) + { return equalv3(this.normal, plane.normal, 1e-4) && equaln(this.w, plane.w, 1e-4); } - transform(matrix4x4) { + transform(matrix4x4) + { // get two vectors in the plane: let r = this.normal.randomNonParallelVector(); let u = this.normal.clone().cross(r); @@ -8745,7 +9448,8 @@ class Plane { } return newplane; } - splitLineBetweenPoints(p1, p2) { + splitLineBetweenPoints(p1, p2) + { let direction = p2.pos.clone().sub(p1.pos); let labda = (this.w - this.normal.dot(p1.pos)) / this.normal.dot(direction); if (isNaN(labda)) @@ -8758,7 +9462,8 @@ class Plane { let uv = p1.uv.clone().lerp(p2.uv, labda); return new Vertex3D(pos, uv); } - static fromVector3Ds(a, b, c) { + static fromVector3Ds(a, b, c) + { let n = b.clone() .sub(a) .cross(c.clone().sub(a)) @@ -8768,7 +9473,8 @@ class Plane { } var Type; -(function (Type) { +(function (Type) +{ Type[Type["CoplanarFront"] = 0] = "CoplanarFront"; Type[Type["CoplanarBack"] = 1] = "CoplanarBack"; Type[Type["Front"] = 2] = "Front"; @@ -8792,19 +9498,23 @@ var Type; *多边形是彼此克隆或从同一多边形分割的多边形。 *这可用于定义每个多边形属性(例如表面颜色)。 */ -class Polygon { - constructor(vertices, plane) { +class Polygon +{ + constructor(vertices, plane) + { this.vertices = vertices; this.plane = plane; if (!plane) this.plane = Plane.fromVector3Ds(vertices[0].pos, vertices[1].pos, vertices[2].pos); } /** Check whether the polygon is convex. (it should be, otherwise we will get unexpected results)*/ - checkIfConvex() { + checkIfConvex() + { return Polygon.verticesConvex(this.vertices, this.plane.normal); } // returns an array with a Vector3D (center point) and a radius - boundingSphere() { + boundingSphere() + { if (!this.cachedBoundingSphere) { let box = this.boundingBox(); let middle = box[0].clone().add(box[1]).multiplyScalar(0.5); @@ -8815,7 +9525,8 @@ class Polygon { return this.cachedBoundingSphere; } // returns an array of two Vector3Ds (minimum coordinates and maximum coordinates) - boundingBox() { + boundingBox() + { if (!this.cachedBoundingBox) { let minpoint; let maxpoint; @@ -8835,14 +9546,16 @@ class Polygon { } return this.cachedBoundingBox; } - flipped() { + flipped() + { let newvertices = this.vertices.map(v => v.flipped()); newvertices.reverse(); let newplane = this.plane.flipped(); return new Polygon(newvertices, newplane); } // Affine transformation of polygon. Returns a new Polygon - transform(matrix4x4) { + transform(matrix4x4) + { let newvertices = this.vertices.map(v => v.transform(matrix4x4)); let newplane = this.plane.transform(matrix4x4); if (IsMirror(matrix4x4)) { @@ -8852,7 +9565,8 @@ class Polygon { } return new Polygon(newvertices, newplane); } - splitByPlane(plane) { + splitByPlane(plane) + { let result = { type: null, front: null, back: null }; // cache in local lets (speedup): let planeNormal = plane.normal; @@ -8920,10 +9634,12 @@ class Polygon { } // for vertexindex // remove duplicate vertices: let EPS_SQUARED = EPS * EPS; - arrayRemoveDuplicateBySort(backVertices, (v1, v2) => { + arrayRemoveDuplicateBySort(backVertices, (v1, v2) => + { return v1.pos.distanceToSquared(v2.pos) < EPS_SQUARED; }); - arrayRemoveDuplicateBySort(frontVertices, (v1, v2) => { + arrayRemoveDuplicateBySort(frontVertices, (v1, v2) => + { return v1.pos.distanceToSquared(v2.pos) < EPS_SQUARED; }); if (frontVertices.length >= 3) @@ -8934,7 +9650,8 @@ class Polygon { } return result; } - static verticesConvex(vertices, planenormal) { + static verticesConvex(vertices, planenormal) + { let count = vertices.length; if (count < 3) return false; @@ -8950,7 +9667,8 @@ class Polygon { return true; } // 计算3点是否凸角 - static isConvexPoint(prevpoint, point, nextpoint, normal) { + static isConvexPoint(prevpoint, point, nextpoint, normal) + { let crossproduct = point.clone().sub(prevpoint).cross(nextpoint.clone().sub(point)); let crossdotnormal = crossproduct.dot(normal); return crossdotnormal >= 0; @@ -8982,15 +9700,18 @@ class Polygon { // remove()从树中删除多边形。 删除多边形后,父多边形将失效 //因为它们不再完好无损 //构造函数创建根节点: -class PolygonTreeNode { - constructor(polygon) { +class PolygonTreeNode +{ + constructor(polygon) + { this.children = []; this.removed = false; this.polygon = polygon; } // fill the tree with polygons. Should be called on the root node only; child nodes must // always be a derivate (split) of the parent node. - addPolygons(polygons) { + addPolygons(polygons) + { // new polygons can only be added to root node; children can only be splitted polygons if (!this.isRootNode()) throw new Error("Assertion failed"); @@ -9000,7 +9721,8 @@ class PolygonTreeNode { // remove a node // - the siblings become toplevel nodes // - the parent is removed recursively - remove() { + remove() + { if (this.removed) return; this.removed = true; @@ -9013,24 +9735,29 @@ class PolygonTreeNode { // invalidate the parent's polygon, and of all parents above it: this.parent.recursivelyInvalidatePolygon(); } - isRemoved() { + isRemoved() + { return this.removed; } - isRootNode() { + isRootNode() + { return !this.parent; } // invert all polygons in the tree. Call on the root node - invert() { + invert() + { if (!this.isRootNode()) throw new Error("Assertion failed"); // can only call this on the root node this.invertSub(); } - getPolygon() { + getPolygon() + { if (!this.polygon) throw new Error("Assertion failed"); // doesn't have a polygon, which means that it has been broken down return this.polygon; } - getPolygons(outPolygons = []) { + getPolygons(outPolygons = []) + { let children = [this]; let queue = [children]; for (let i = 0; i < queue.length; ++i) { @@ -9051,7 +9778,8 @@ class PolygonTreeNode { // If the plane doesn't intersect the polygon, the 'this' object is added to one of the arrays // If the plane does intersect the polygon, two new child nodes are created for the front and back fragments, // and added to both arrays. - splitByPlane(plane, coplanarFrontNodes, coplanarBackNodes, frontNodes, backNodes) { + splitByPlane(plane, coplanarFrontNodes, coplanarBackNodes, frontNodes, backNodes) + { if (this.children.length) { let queue = [this.children]; for (let i = 0; i < queue.length; i++) { @@ -9075,7 +9803,8 @@ class PolygonTreeNode { } // only to be called for nodes with no children // 仅用于没有子节点的节点 - splitByPlaneNotChildren(plane, coplanarFrontNodes, coplanarBackNodes, frontNodes, backNodes) { + splitByPlaneNotChildren(plane, coplanarFrontNodes, coplanarBackNodes, frontNodes, backNodes) + { if (!this.polygon) return; let polygon = this.polygon; @@ -9120,13 +9849,15 @@ class PolygonTreeNode { // this should be called whenever the polygon is split // a child should be created for every fragment of the split polygon // returns the newly created child - addChild(polygon) { + addChild(polygon) + { let newchild = new PolygonTreeNode(polygon); newchild.parent = this; this.children.push(newchild); return newchild; } - invertSub() { + invertSub() + { let queue = [[this]]; for (let i = 0; i < queue.length; i++) { let children = queue[i]; @@ -9138,7 +9869,8 @@ class PolygonTreeNode { } } } - recursivelyInvalidatePolygon() { + recursivelyInvalidatePolygon() + { let node = this; while (node.polygon) { node.polygon = null; @@ -9151,13 +9883,16 @@ class PolygonTreeNode { // This is the root of a BSP tree // We are using this separate class for the root of the tree, to hold the PolygonTreeNode root // The actual tree is kept in this.rootnode -class Tree { - constructor(polygons) { +class Tree +{ + constructor(polygons) + { this.polygonTree = new PolygonTreeNode(); this.rootNode = new Node(null); this.addPolygons(polygons); } - invert() { + invert() + { this.polygonTree.invert(); this.rootNode.invert(); } @@ -9167,13 +9902,16 @@ class Tree { * @param tree 不会被修改 * @param [alsoRemovecoplanarFront=false] 同时删除共面 */ - clipTo(tree, alsoRemovecoplanarFront = false) { + clipTo(tree, alsoRemovecoplanarFront = false) + { this.rootNode.clipTo(tree, alsoRemovecoplanarFront); } - allPolygons() { + allPolygons() + { return this.polygonTree.getPolygons(); } - addPolygons(polygons) { + addPolygons(polygons) + { if (polygons.length > 1e4) return; let polygonTreeNodes = polygons.map((p) => this.polygonTree.addChild(p)); @@ -9188,13 +9926,16 @@ class Tree { // Tree.polygonTree // This is not a leafy BSP tree since there is // no distinction between internal and leaf nodes. -class Node { - constructor(parent) { +class Node +{ + constructor(parent) + { this.polygonTreeNodes = []; this.parent = parent; } // Convert solid space to empty space and empty space to solid space. - invert() { + invert() + { let queue = [this]; for (let i = 0; i < queue.length; i++) { let node = queue[i]; @@ -9213,7 +9954,8 @@ class Node { // calls remove() for all clipped PolygonTreeNodes //将polygontreenodes剪辑到我们的飞机上 //为所有剪切的PolygonTreeNodes调用remove() - clipPolygons(polygonTreeNodes, alsoRemoveCoplanarFront) { + clipPolygons(polygonTreeNodes, alsoRemoveCoplanarFront) + { let args = { node: this, polygonTreeNodes }; let stack = []; do { @@ -9246,7 +9988,8 @@ class Node { } // Remove all polygons in this BSP tree that are inside the other BSP tree // `tree`. - clipTo(tree, alsoRemovecoplanarFront) { + clipTo(tree, alsoRemovecoplanarFront) + { let node = this; let stack = []; do { @@ -9260,7 +10003,8 @@ class Node { node = stack.pop(); } while (node); } - addPolygonTreeNodes(polygonTreeNodes) { + addPolygonTreeNodes(polygonTreeNodes) + { let args = { node: this, polygontreenodes: polygonTreeNodes }; let stack = []; do { @@ -9292,7 +10036,8 @@ class Node { args = stack.pop(); } while (args); } - getParentPlaneNormals(normals, maxdepth) { + getParentPlaneNormals(normals, maxdepth) + { if (maxdepth > 0) { if (this.parent) { normals.push(this.parent.plane.normal); @@ -9314,8 +10059,10 @@ class Node { // numdimensions: the number of parameters for each object // for example for a 2D rectangle this would be 2 // tolerance: The maximum difference for each parameter allowed to be considered a match -class FuzzyFactory { - constructor(numdimensions, tolerance) { +class FuzzyFactory +{ + constructor(numdimensions, tolerance) + { this.lookuptable = {}; this.multiplier = 1.0 / tolerance; } @@ -9324,7 +10071,8 @@ class FuzzyFactory { // If found, returns the existing object // If not found, calls the supplied callback function which should create a new object with // the specified properties. This object is inserted in the lookup database. - lookupOrCreate(els, object) { + lookupOrCreate(els, object) + { let hash = ""; let multiplier = this.multiplier; for (let el of els) { @@ -9334,7 +10082,8 @@ class FuzzyFactory { if (hash in this.lookuptable) return this.lookuptable[hash]; else { - let hashparts = els.map(el => { + let hashparts = els.map(el => + { let q0 = Math.floor(el * multiplier); let q1 = q0 + 1; return ["" + q0 + "/", "" + q1 + "/"]; @@ -9344,7 +10093,8 @@ class FuzzyFactory { for (let hashmask = 0; hashmask < numhashes; ++hashmask) { let hashmaskShifted = hashmask; hash = ""; - hashparts.forEach(hashpart => { + hashparts.forEach(hashpart => + { hash += hashpart[hashmaskShifted & 1]; hashmaskShifted >>= 1; }); @@ -9355,22 +10105,27 @@ class FuzzyFactory { } } -class FuzzyCSGFactory { - constructor() { +class FuzzyCSGFactory +{ + constructor() + { this.vertexfactory = new FuzzyFactory(3, EPS); this.planefactory = new FuzzyFactory(4, EPS); } - getVertex(sourcevertex) { + getVertex(sourcevertex) + { let elements = [sourcevertex.pos.x, sourcevertex.pos.y, sourcevertex.pos.z]; let result = this.vertexfactory.lookupOrCreate(elements, sourcevertex); return result; } - getPlane(sourceplane) { + getPlane(sourceplane) + { let elements = [sourceplane.normal.x, sourceplane.normal.y, sourceplane.normal.z, sourceplane.w]; let result = this.planefactory.lookupOrCreate(elements, sourceplane); return result; } - getPolygon(sourcePolygon, outputPolygon = sourcePolygon) { + getPolygon(sourcePolygon, outputPolygon = sourcePolygon) + { let newPlane = this.getPlane(sourcePolygon.plane); let newVertices = sourcePolygon.vertices.map(vertex => this.getVertex(vertex)); // two vertices that were originally very close may now have become @@ -9401,15 +10156,18 @@ class FuzzyCSGFactory { * * 返回删除重复点的csg,重复点将被合并 */ -function canonicalizeCSG(csg) { +function canonicalizeCSG(csg) +{ const factory = new FuzzyCSGFactory(); let result = CSGFromCSGFuzzyFactory(factory, csg); result.isCanonicalized = true; result.isRetesselated = csg.isRetesselated; return result; } -function CSGFromCSGFuzzyFactory(factory, sourcecsg) { - let newpolygons = sourcecsg.polygons.filter(poly => { +function CSGFromCSGFuzzyFactory(factory, sourcecsg) +{ + let newpolygons = sourcecsg.polygons.filter(poly => + { return factory.getPolygon(poly).vertices.length >= 3; }); return new CSG(newpolygons); @@ -9422,7 +10180,8 @@ function CSGFromCSGFuzzyFactory(factory, sourcecsg) { * let bounds = A.getBounds() * let minX = bounds[0].x */ -function bounds(csg) { +function bounds(csg) +{ if (!csg.cachedBoundingBox) { let minpoint; let maxpoint; @@ -9446,10 +10205,12 @@ function bounds(csg) { return csg.cachedBoundingBox; } -function fnNumberSort(a, b) { +function fnNumberSort(a, b) +{ return a - b; } -function insertSorted(array, element, comparefunc) { +function insertSorted(array, element, comparefunc) +{ let leftbound = 0; let rightbound = array.length; while (rightbound > leftbound) { @@ -9467,7 +10228,8 @@ function insertSorted(array, element, comparefunc) { // Get the x coordinate of a point with a certain y coordinate, interpolated between two // points (CSG.Vector2D). // Interpolation is robust even if the points have the same y coordinate -function interpolateBetween2DPointsForY(point1, point2, y) { +function interpolateBetween2DPointsForY(point1, point2, y) +{ let f1 = y - point1.y; let f2 = point2.y - point1.y; if (f2 < 0) { @@ -9494,18 +10256,22 @@ function interpolateBetween2DPointsForY(point1, point2, y) { * and w. The line passes through the point .times(w). * Equation: p is on line if normal.dot(p)==w */ -class Line2D { - constructor(normal, w) { +class Line2D +{ + constructor(normal, w) + { this.normal = normal.clone(); let l = this.normal.length(); w *= l; this.normal.normalize(); this.w = w; } - direction() { + direction() + { return this.normal; } - static fromPoints(p1, p2) { + static fromPoints(p1, p2) + { let direction = p2.clone().sub(p1); let normal = direction .normal() @@ -9520,18 +10286,22 @@ class Line2D { * Reprojects points on a 3D plane onto a 2D plane * or from a 2D plane back onto the 3D plane */ -class OrthoNormalBasis { - constructor(plane, rightVector = plane.normal.randomNonParallelVector()) { +class OrthoNormalBasis +{ + constructor(plane, rightVector = plane.normal.randomNonParallelVector()) + { this.plane = plane; this.v = plane.normal.clone().cross(rightVector).normalize(); this.u = this.v.clone().cross(plane.normal); this.plane = plane; this.planeorigin = plane.normal.clone().multiplyScalar(plane.w); } - to2D(vec3) { + to2D(vec3) + { return new Vector2D(vec3.dot(this.u), vec3.dot(this.v)); } - to3D(vec2) { + to3D(vec2) + { return this.planeorigin.clone() .add(this.u.clone().multiplyScalar(vec2.x)) .add(this.v.clone().multiplyScalar(vec2.y)); @@ -9539,7 +10309,8 @@ class OrthoNormalBasis { } //一组共面多边形的Retesselation函数。 请参阅此文件顶部的介绍。 -function reTesselateCoplanarPolygons(sourcePolygons, destpolygons = []) { +function reTesselateCoplanarPolygons(sourcePolygons, destpolygons = []) +{ let numPolygons = sourcePolygons.length; if (numPolygons < 2) { destpolygons.push(...sourcePolygons); @@ -9686,7 +10457,7 @@ function reTesselateCoplanarPolygons(sourcePolygons, destpolygons = []) { activePolygons = []; } else // yindex < ycoordinates.length-1 - { + { nextYCoordinate = Number(yCoordinates[yindex + 1]); let middleYCoordinate = 0.5 * (yCoordinate + nextYCoordinate); // update activepolygons by adding any polygons that start here: @@ -9738,7 +10509,8 @@ function reTesselateCoplanarPolygons(sourcePolygons, destpolygons = []) { bottomright: vertices2d[nextrightvertexindex] }; //二分插入 - insertSorted(activePolygons, newactivepolygon, function (el1, el2) { + insertSorted(activePolygons, newactivepolygon, function (el1, el2) + { let x1 = interpolateBetween2DPointsForY(el1.topleft, el1.bottomleft, middleYCoordinate); let x2 = interpolateBetween2DPointsForY(el2.topleft, el2.bottomleft, middleYCoordinate); if (x1 > x2) @@ -9876,7 +10648,8 @@ function reTesselateCoplanarPolygons(sourcePolygons, destpolygons = []) { } // for yindex } -function reTesselate(csg) { +function reTesselate(csg) +{ if (csg.isRetesselated) return csg; let polygonsPerPlane = {}; @@ -9910,8 +10683,10 @@ function reTesselate(csg) { * be combined using the `union()`, `subtract()`, and `intersect()` methods. * @constructor */ -class CSG { - constructor(polygons = []) { +class CSG +{ + constructor(polygons = []) + { this.polygons = polygons; /** # 是否已精简重复点 */ this.isCanonicalized = false; @@ -9935,7 +10710,8 @@ class CSG { * | | | | * +-------+ +-------+ */ - union(csg) { + union(csg) + { let csgs; if (csg instanceof Array) { csgs = csg.slice(0); @@ -9950,7 +10726,8 @@ class CSG { } return csgs[i - 1].reTesselated().canonicalized(); } - unionSub(csg, retesselate = false, canonicalize = false) { + unionSub(csg, retesselate = false, canonicalize = false) + { if (!this.mayOverlap(csg)) return this.unionForNonIntersecting(csg); let a = new Tree(this.polygons); @@ -9971,7 +10748,8 @@ class CSG { } // Like union, but when we know that the two solids are not intersecting // Do not use if you are not completely sure that the solids do not intersect! - unionForNonIntersecting(csg) { + unionForNonIntersecting(csg) + { let newpolygons = [...this.polygons, ...csg.polygons]; let result = new CSG(newpolygons); result.isCanonicalized = this.isCanonicalized && csg.isCanonicalized; @@ -9994,7 +10772,8 @@ class CSG { * | | * +-------+ */ - subtract(csg) { + subtract(csg) + { let csgs; if (csg instanceof Array) csgs = csg; @@ -10007,7 +10786,8 @@ class CSG { } return result; } - subtractSub(csg, retesselate = false, canonicalize = false) { + subtractSub(csg, retesselate = false, canonicalize = false) + { let a = new Tree(this.polygons); let b = new Tree(csg.polygons); a.invert(); @@ -10035,7 +10815,8 @@ class CSG { * | | * +-------+ */ - intersect(csg) { + intersect(csg) + { let csgs; if (csg instanceof Array) csgs = csg; @@ -10048,7 +10829,8 @@ class CSG { } return result; } - intersectSub(csg, retesselate = false, canonicalize = false) { + intersectSub(csg, retesselate = false, canonicalize = false) + { let a = new Tree(this.polygons); let b = new Tree(csg.polygons); a.invert(); @@ -10067,13 +10849,16 @@ class CSG { * Return a new CSG solid with solid and empty space switched. * This solid is not modified. */ - invert() { + invert() + { let flippedpolygons = this.polygons.map(p => p.flipped()); return new CSG(flippedpolygons); } // Affine transformation of CSG object. Returns a new CSG object - transform1(matrix4x4) { - let newpolygons = this.polygons.map(p => { + transform1(matrix4x4) + { + let newpolygons = this.polygons.map(p => + { return p.transform(matrix4x4); }); let result = new CSG(newpolygons); @@ -10092,11 +10877,13 @@ class CSG { * m = m.multiply(CSG.Matrix4x4.translation([-.5, 0, 0])) * let B = A.transform(m) */ - transform(matrix4x4) { + transform(matrix4x4) + { let ismirror = IsMirror(matrix4x4); let transformedvertices = {}; let transformedplanes = {}; - let newpolygons = this.polygons.map(p => { + let newpolygons = this.polygons.map(p => + { let newplane; let plane = p.plane; let planetag = plane.getTag(); @@ -10107,7 +10894,8 @@ class CSG { newplane = plane.transform(matrix4x4); transformedplanes[planetag] = newplane; } - let newvertices = p.vertices.map(v => { + let newvertices = p.vertices.map(v => + { let newvertex; let vertextag = v.getTag(); if (vertextag in transformedvertices) { @@ -10128,18 +10916,21 @@ class CSG { result.isCanonicalized = this.isCanonicalized; return result; } - canonicalized() { + canonicalized() + { if (this.isCanonicalized) return this; return canonicalizeCSG(this); } - reTesselated() { + reTesselated() + { if (this.isRetesselated) return this; return reTesselate(this); } //如果两个实体有可能重叠,返回true - mayOverlap(csg) { + mayOverlap(csg) + { if (this.polygons.length === 0 || csg.polygons.length === 0) return false; let mybounds = bounds(this); @@ -10158,7 +10949,8 @@ class CSG { return false; return true; } - toTriangles() { + toTriangles() + { let polygons = []; for (let poly of this.polygons) { let firstVertex = poly.vertices[0]; @@ -10174,7 +10966,8 @@ class CSG { } } -function Geometry2CSG(geometry) { +function Geometry2CSG(geometry) +{ if (geometry instanceof BufferGeometry) geometry = new Geometry().fromBufferGeometry(geometry); let polygons = []; @@ -10200,15 +10993,19 @@ function Geometry2CSG(geometry) { } return new CSG(polygons); } -function Vector3ToVector3D(v) { +function Vector3ToVector3D(v) +{ return new Vector3D(v.x, v.y, v.z); } -function Vector3DToVector3(v) { +function Vector3DToVector3(v) +{ return new Vector3(v.x, v.y, v.z); } -class BoardUVGenerator { - generateTopUV(geometry, vertices, indexA, indexB, indexC) { +class BoardUVGenerator +{ + generateTopUV(geometry, vertices, indexA, indexB, indexC) + { var a_x = vertices[indexA * 3]; var a_y = vertices[indexA * 3 + 1]; var b_x = vertices[indexB * 3]; @@ -10221,7 +11018,8 @@ class BoardUVGenerator { new Vector2(c_x, c_y) ]; } - generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) { + generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) + { var a_x = vertices[indexA * 3]; var a_y = vertices[indexA * 3 + 1]; var a_z = vertices[indexA * 3 + 2]; @@ -10254,8 +11052,10 @@ class BoardUVGenerator { return pts; } } -class BoardUVGenerator2 extends BoardUVGenerator { - generateTopUV(geometry, vertices, indexA, indexB, indexC) { +class BoardUVGenerator2 extends BoardUVGenerator +{ + generateTopUV(geometry, vertices, indexA, indexB, indexC) + { var a_x = vertices[indexA * 3]; var a_y = vertices[indexA * 3 + 1]; var b_x = vertices[indexB * 3]; @@ -10281,8 +11081,10 @@ let boardUVGenerator2 = new BoardUVGenerator2(); * let topology = new BSPGroupParse(csg); * topology.parse(); */ -class BSPGroupParse { - constructor(bsp, fractionDigits = 1) { +class BSPGroupParse +{ + constructor(bsp, fractionDigits = 1) + { this.fractionDigits = fractionDigits; this.map = new Map(); this.vecMap = new Map(); @@ -10290,7 +11092,8 @@ class BSPGroupParse { for (let poly of bsp.polygons) this.Add(poly); } - Add(poly) { + Add(poly) + { let strs = poly.vertices.map(p => this.GenerateP(p.pos)); let str0 = strs[0]; let s0 = this.Get(str0); @@ -10303,7 +11106,8 @@ class BSPGroupParse { /** * 返回组合点 */ - Parse() { + Parse() + { let set = new Set([...this.map.keys()]); let res = []; while (set.size > 0) { @@ -10312,7 +11116,8 @@ class BSPGroupParse { let cset = new Set(); cset.add(fp); this.GetPts(fp, cset, set); - let pts = [...cset].map(str => { + let pts = [...cset].map(str => + { let v3 = this.vecMap.get(str); return new Vector3(v3.x, v3.y, v3.z); }); @@ -10320,7 +11125,8 @@ class BSPGroupParse { } return res; } - Get(vstr) { + Get(vstr) + { if (!this.map.has(vstr)) { let s = new Set(); this.map.set(vstr, s); @@ -10328,7 +11134,8 @@ class BSPGroupParse { } return this.map.get(vstr); } - GetPts(p, cset, oset) { + GetPts(p, cset, oset) + { let strs = this.map.get(p); for (let str of strs) { if (!cset.has(str)) { @@ -10338,14 +11145,16 @@ class BSPGroupParse { } } } - GenerateP(v) { + GenerateP(v) + { let str = [v.x, v.y, v.z].map(n => ToFixed(n, this.fractionDigits)).join(","); this.vecMap.set(str, v); return str; } } -function ScaleUV(geo, scale = 1e-3) { +function ScaleUV(geo, scale = 1e-3) +{ for (let uvsg of geo.faceVertexUvs) { for (let uvs of uvsg) { for (let uv of uvs) { @@ -10354,7 +11163,8 @@ function ScaleUV(geo, scale = 1e-3) { } } } -function ScaleUV2(geo, ocs, xScale = 1e-3, yScale = 1e-3, isInvert = false) { +function ScaleUV2(geo, ocs, xScale = 1e-3, yScale = 1e-3, isInvert = false) +{ for (let uvsg of geo.faceVertexUvs) { for (let uvs of uvsg) { for (let uv of uvs) { @@ -10374,65 +11184,80 @@ function ScaleUV2(geo, ocs, xScale = 1e-3, yScale = 1e-3, isInvert = false) { } } -class Shape { - constructor(out, hols) { +class Shape +{ + constructor(out, hols) + { this._Holes = []; this._Shape = new Shape$1(); this._Outline = out || new Contour(); hols && this._Holes.push(...hols); } - get Outline() { + get Outline() + { return this._Outline; } - get Holes() { + get Holes() + { return this._Holes; } - get Area() { + get Area() + { let outlineArea = this._Outline.Area; let holeArea = this._Holes.map(l => l.Area).reduce((a1, a2) => a1 + a2, 0); return outlineArea - holeArea; } - get BoundingBox() { + get BoundingBox() + { return this._Outline.BoundingBox; } - set Outline(cus) { + set Outline(cus) + { this._Outline = cus; this.UpdateShape(); } - set Holes(cus) { + set Holes(cus) + { this._Holes = cus; this.UpdateShape(); } - get Shape() { + get Shape() + { this.UpdateShape(); return this._Shape; } - get Position() { + get Position() + { return this._Outline.Curve.Position; } - set Position(p) { + set Position(p) + { let vec = p.clone().sub(this._Outline.Curve.Position); this._Outline.Curve.Position = p; for (let h of this._Holes) h.Curve.Position = h.Curve.Position.add(vec); } - Z0() { + Z0() + { this._Outline.Curve.Z0(); for (let h of this._Holes) h.Curve.Z0(); return this; } - MatrixPlanarizere() { + MatrixPlanarizere() + { this._Outline.Curve.MatrixPlanarizere(); for (let h of this._Holes) h.Curve.MatrixPlanarizere(); } - ApplyMatrix(m) { + ApplyMatrix(m) + { this._Outline.Curve.ApplyMatrix(m); this._Holes.forEach(h => h.Curve.ApplyMatrix(m)); return this; } - ApplyScaleMatrix(m) { + ApplyScaleMatrix(m) + { let cu = this.Outline.Curve; let cus = this._Holes.map(h => h.Curve); cus.unshift(cu); @@ -10443,7 +11268,8 @@ class Shape { } return this; } - Explode() { + Explode() + { let cus = []; let contours = [this._Outline, ...this._Holes]; for (let con of contours) { @@ -10454,17 +11280,20 @@ class Shape { } return cus; } - Clone() { + Clone() + { let shape = new Shape(); shape.Outline = this._Outline.Clone(); shape.Holes = this.Holes.map(h => h.Clone()); return shape; } - SetColor(color) { + SetColor(color) + { this._Outline.Curve.ColorIndex = color; this._Holes.forEach(h => h.Curve.ColorIndex = color); } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { switch (snapMode) { case ObjectSnapMode.End: return this.GetStretchPoints(); @@ -10488,14 +11317,16 @@ class Shape { } return []; } - GetGripPoints() { + GetGripPoints() + { let pts = this.Outline.Curve.GetGripPoints(); for (let h of this._Holes) { pts.push(...h.Curve.GetGripPoints()); } return pts; } - MoveGripPoints(indexList, vec) { + MoveGripPoints(indexList, vec) + { let i = indexList[0]; let outlineIndex = this._Outline.Curve.GetGripPoints().length; let cu = this._Outline.Curve; @@ -10512,14 +11343,16 @@ class Shape { } cu.MoveGripPoints(indexList, vec); } - GetStretchPoints() { + GetStretchPoints() + { let pts = this.Outline.Curve.GetStretchPoints(); for (let h of this._Holes) { pts.push(...h.Curve.GetStretchPoints()); } return pts; } - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { let outlen = 0; for (let cu of [this._Outline.Curve, ...this._Holes.map(h => h.Curve)]) { let count = cu.GetStretchPoints().length; @@ -10538,13 +11371,15 @@ class Shape { } } //交集 如果成功返回一个面域 失败返回0个 - IntersectionBoolOperation(targetShape) { + IntersectionBoolOperation(targetShape) + { let resOutlines = this._Outline.IntersectionBoolOperation(targetShape._Outline); let cus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeContours([...this._Holes, ...targetShape._Holes])); return Shape.pairHoleAndOutline(cus); } //并集,如果成功返回1个形状,不成功返回2个形状 - UnionBoolOperation(targetShape, checkIntersect = false) { + UnionBoolOperation(targetShape, checkIntersect = false) + { if (checkIntersect && !this.BoundingBox.intersectsBox(targetShape.BoundingBox, 1e-3)) return [this, targetShape]; let { contours, holes } = this._Outline.UnionBoolOperation(targetShape._Outline); @@ -10552,8 +11387,10 @@ class Shape { //提取出所有的孔洞, 目标线段孔洞和原线段差,如果孔洞和目标相减后有被包围轮廓,应把这个单独提取出来作为形状 let unionHoles = []; //合并运算时提取出运算后的孔洞和形状 - const pickUpHoleOrShape = (srcHoles, tarHoles, outline) => { - srcHoles.forEach(cu => { + const pickUpHoleOrShape = (srcHoles, tarHoles, outline) => + { + srcHoles.forEach(cu => + { let tmpContours = cu.SubstactBoolOperation(outline).sort((a, b) => b.Area - a.Area); let isAllContainered = tmpContours.length > 1 && tmpContours.slice(1).every((cu, index) => tmpContours[0].CuInOutline(cu.Curve)); //洞是否被最大的洞包含,是,则把被包含的洞都提取出来加入形状数组 @@ -10566,8 +11403,10 @@ class Shape { }; pickUpHoleOrShape(targetShape._Holes, this._Holes, this._Outline); pickUpHoleOrShape(this._Holes, targetShape._Holes, targetShape._Outline); - targetShape._Holes.forEach(cu => { - this._Holes.forEach(c => { + targetShape._Holes.forEach(cu => + { + this._Holes.forEach(c => + { unionHoles.push(...c.IntersectionBoolOperation(cu)); }); }); @@ -10578,7 +11417,8 @@ class Shape { * 如果完全被减掉,就返回0个.其他的返回1个或者n个 * @param targetShapes 已经是合并后的形状数组 */ - SubstactBoolOperation(targetShapes) { + SubstactBoolOperation(targetShapes) + { let originOutline = this.Outline; let targetOutlines = targetShapes.map(s => s.Outline); const { holes, outlines } = originOutline.GetSubtractListByMoreTargets(targetOutlines); @@ -10615,14 +11455,16 @@ class Shape { } return newShapes; } - Equal(targetShape) { + Equal(targetShape) + { if (this._Outline.Equal(targetShape._Outline)) { return this._Holes.length === targetShape._Holes.length && this._Holes.every(h1 => targetShape._Holes.some(h2 => h1.Equal(h2))); } return false; } - targetOutlinesSubHoles(targetShapes, holeShapes) { + targetOutlinesSubHoles(targetShapes, holeShapes) + { let resultShapes = []; for (let ts of targetShapes) { let res = ts.SubstactBoolOperation(holeShapes); @@ -10639,7 +11481,8 @@ class Shape { * @returns {Contour[]} 新的轮廓列表 * @memberof Shape */ - targetOutlineSubHoleOutline(tarContours, holes) { + targetOutlineSubHoleOutline(tarContours, holes) + { if (!holes.length) return tarContours; let resultContours = []; @@ -10649,7 +11492,8 @@ class Shape { for (let hole of holes) { //缓存差集生成的轮廓 let tmps = []; - tmpContour.forEach(r => { + tmpContour.forEach(r => + { let cus = r.SubstactBoolOperation(hole); tmps.push(...cus); }); @@ -10660,7 +11504,8 @@ class Shape { return resultContours; } //整理轮廓数组,匹配洞和外轮廓 - static pairHoleAndOutline(contours) { + static pairHoleAndOutline(contours) + { let shapes = []; contours.sort((a, b) => b.Area - a.Area); while (contours.length) { @@ -10668,7 +11513,8 @@ class Shape { let tmpHoles = []; let outline = contours.shift(); //取出包含的洞 - arrayRemoveIf(contours, (con) => { + arrayRemoveIf(contours, (con) => + { let bisIn = outline.CuInOutline(con.Curve); if (bisIn) tmpHoles.push(con); @@ -10683,7 +11529,8 @@ class Shape { * 合并洞,本质是使用(并集算法)将可以并集的洞合并在一起,减少洞的数量. * canSidewipe 用于走刀,擦边的,包含的,是否合并 */ - static mergeContours(holes, canSidewipe = true) { + static mergeContours(holes, canSidewipe = true) + { if (holes.length <= 1) return holes; let rets = []; //返回的合并轮廓 @@ -10697,7 +11544,8 @@ class Shape { } while (true) { //剩余的 不相交的形状表 remaining - let remHoles = holes.filter(ic => { + let remHoles = holes.filter(ic => + { let b2 = cache.get(ic); if (!b2) { b2 = ic.BoundingBox; @@ -10709,7 +11557,7 @@ class Shape { if (unions.holes.length > 0) console.warn("未知情况"); if (unions.contours.length === 1) //并集成功 - { + { if (!canSidewipe) { if (equaln(c.Area + ic.Area, unions.contours[0].Area, 0.1)) return true; @@ -10741,7 +11589,8 @@ class Shape { * @returns {Contour[]} 返回的洞列表都不会互相包含. * @memberof Shape */ - static removeBeContaineredHoles(tmpHoles) { + static removeBeContaineredHoles(tmpHoles) + { let holes = []; if (tmpHoles.length <= 1) return tmpHoles; @@ -10754,7 +11603,8 @@ class Shape { } return holes; } - UpdateShape() { + UpdateShape() + { this._Shape = this.Outline.Shape; for (let h of this._Holes) { if (h.Curve instanceof Polyline) @@ -10770,7 +11620,8 @@ class Shape { } } //读写文件 - ReadFile(file) { + ReadFile(file) + { let ver = file.Read(); //1 this._Outline = Contour.CreateContour([file.ReadObject()]); let count = file.Read(); @@ -10779,7 +11630,8 @@ class Shape { } } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { file.Write(1); //ver file.WriteObject(this._Outline.Curve); file.Write(this._Holes.length); @@ -10787,27 +11639,35 @@ class Shape { } } -class ShapeManager { - constructor() { +class ShapeManager +{ + constructor() + { this._ShapeList = []; } - get ShapeList() { + get ShapeList() + { return this._ShapeList.slice(); } - get ShapeCount() { + get ShapeCount() + { return this._ShapeList.length; } - get ShapeArea() { + get ShapeArea() + { return this._ShapeList.map(s => s.Area).reduce((a1, a2) => a1 + a2, 0); } - AppendShapeList(shapes) { + AppendShapeList(shapes) + { Array.isArray(shapes) ? this._ShapeList.push(...shapes) : this._ShapeList.push(shapes); return this; } - Clear() { + Clear() + { this._ShapeList.length = 0; } - BoolOper(otherMg, booltype) { + BoolOper(otherMg, booltype) + { switch (booltype) { case BoolOpeartionType.Intersection: return this.IntersectionBoolOperation(otherMg); @@ -10818,7 +11678,8 @@ class ShapeManager { } } //交集 如果成功返回一个面域 失败返回0个 - IntersectionBoolOperation(target) { + IntersectionBoolOperation(target) + { let shapes = []; for (let srcShape of this._ShapeList) { for (let tarShape of target._ShapeList) { @@ -10831,7 +11692,8 @@ class ShapeManager { return this._ShapeList.length > 0; } //并集,如果有一个形状并集成功,就成功 - UnionBoolOperation(targetMg) { + UnionBoolOperation(targetMg) + { let isSuccess = false; let srcShapes = this._ShapeList; let tarShapes = targetMg._ShapeList; @@ -10852,7 +11714,7 @@ class ShapeManager { } let unions = src.UnionBoolOperation(tar); if (unions.length === 1) //并集成功 - { + { isSuccess = true; src = unions[0]; //src设置为 合并完的形状 } @@ -10870,7 +11732,8 @@ class ShapeManager { this._ShapeList = alones.concat(tarShapes); return isSuccess; } - SubstactBoolOperation(target) { + SubstactBoolOperation(target) + { let newShapes = []; for (let s of this._ShapeList) { let ss = s.SubstactBoolOperation(target.ShapeList); @@ -10887,13 +11750,15 @@ class ShapeManager { * @param {Matrix4} mat4 * @memberof ShapeManager */ - ApplyMatrix(mat4) { + ApplyMatrix(mat4) + { for (let s of this._ShapeList) { s.Outline.Curve.ApplyMatrix(mat4); s.Holes.forEach(o => o.Curve.ApplyMatrix(mat4)); } } - ReadFile(file) { + ReadFile(file) + { let ver = file.Read(); //1 let cout = file.Read(); for (let i = 0; i < cout; i++) { @@ -10902,7 +11767,8 @@ class ShapeManager { this._ShapeList.push(obj); } } - WriteFile(file) { + WriteFile(file) + { file.Write(1); //ver file.Write(this.ShapeList.length); for (let s of this.ShapeList) { @@ -10912,12 +11778,15 @@ class ShapeManager { } var Region_1; -let Region = Region_1 = class Region extends Entity { - constructor(_ShapeManager = new ShapeManager()) { +let Region = Region_1 = class Region extends Entity +{ + constructor(_ShapeManager = new ShapeManager()) + { super(); this._ShapeManager = _ShapeManager; } - static CreateFromCurves(cus) { + static CreateFromCurves(cus) + { let shapes = Contour.GetAllContour(cus).map(out => new Shape(out)); if (shapes.length > 0) { let reg = new Region_1(); @@ -10928,26 +11797,31 @@ let Region = Region_1 = class Region extends Entity { } } //如果需要修改获取到的属性,需要Clone后进行操作,否则会对原实体进行破坏 - get ShapeManager() { + get ShapeManager() + { return this._ShapeManager; } - get Area() { + get Area() + { return this.ShapeManager.ShapeArea; } - get BoundingBox() { + get BoundingBox() + { let box = new Box3(); for (let s of this._ShapeManager.ShapeList) box.union(s.BoundingBox); return box; } - Explode() { + Explode() + { let shapeList = this._ShapeManager.ShapeList; if (shapeList.length <= 1) { return shapeList[0].Explode(); } else { let regs = []; - shapeList.forEach(s => { + shapeList.forEach(s => + { let reg = new Region_1().ApplyMatrix(this.OCS); reg.ShapeManager.AppendShapeList(s); regs.push(reg); @@ -10961,11 +11835,13 @@ let Region = Region_1 = class Region extends Entity { * @param {Matrix4} m * @memberof Region */ - ShapeApplyMatrix(m) { + ShapeApplyMatrix(m) + { this.WriteAllObjectRecord(); this._ShapeManager.ApplyMatrix(m); } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { switch (snapMode) { case ObjectSnapMode.End: return this.GetGripPoints(); @@ -10985,27 +11861,32 @@ let Region = Region_1 = class Region extends Entity { } return []; } - GetGripPoints() { + GetGripPoints() + { let pts = []; for (let s of this._ShapeManager.ShapeList) pts.push(...s.GetStretchPoints()); return pts; } - MoveGripPoints(indexList, moveVec) { + MoveGripPoints(indexList, moveVec) + { this.WriteAllObjectRecord(); let moveVLoc = moveVec.clone().applyMatrix4(new Matrix4().extractRotation(this.OCSInv)); this.ApplyMatrix(MoveMatrix(moveVLoc)); } - ApplyMatrix(m) { + ApplyMatrix(m) + { this.WriteAllObjectRecord(); //面域移动,组成面域的曲线也要移动 MarkX:曲线同面域一起移动 this._ShapeManager.ShapeList.forEach(s => s.ApplyMatrix(m)); return super.ApplyMatrix(m); } - get Position() { + get Position() + { return super.Position; } - set Position(pt) { + set Position(pt) + { this.WriteAllObjectRecord(); let moveX = pt.x - this._Matrix.elements[12]; let moveY = pt.y - this._Matrix.elements[13]; @@ -11019,7 +11900,8 @@ let Region = Region_1 = class Region extends Entity { s.ApplyMatrix(m); this.Update(UpdateDraw.Matrix); } - ApplyScaleMatrix(m) { + ApplyScaleMatrix(m) + { this.WriteAllObjectRecord(); for (let s of this._ShapeManager.ShapeList) s.ApplyScaleMatrix(m); @@ -11027,19 +11909,22 @@ let Region = Region_1 = class Region extends Entity { return this; } //Z轴归0 - Z0() { + Z0() + { super.Z0(); for (let s of this._ShapeManager.ShapeList) s.Z0(); return this; } - MatrixPlanarizere() { + MatrixPlanarizere() + { super.MatrixPlanarizere(); for (let s of this._ShapeManager.ShapeList) s.MatrixPlanarizere(); return this; } - ApplyMirrorMatrix(m) { + ApplyMirrorMatrix(m) + { return this; } /** @@ -11047,7 +11932,8 @@ let Region = Region_1 = class Region extends Entity { * @param {Region} otherRegion * @param {BoolOpeartionType} boolType */ - BooleanOper(otherRegion, boolType) { + BooleanOper(otherRegion, boolType) + { if (this.IsCoplaneTo(otherRegion)) { this.WriteAllObjectRecord(); let oldOcs = this.OCS; @@ -11061,23 +11947,27 @@ let Region = Region_1 = class Region extends Entity { } return false; } - get MeshGeometry() { + get MeshGeometry() + { if (this._MeshGeometry) return this._MeshGeometry; this.UpdateGeometry(); return this._MeshGeometry; } - get EdgeGeometry() { + get EdgeGeometry() + { if (this._EdgeGeometry) return this._EdgeGeometry; this.UpdateGeometry(); return this._EdgeGeometry; } - UpdateGeometry() { + UpdateGeometry() + { let shapeList = this._ShapeManager.ShapeList; let edgePts = []; let meshGeoms = []; - const AddEdgePts = (pts, diffMat) => { + const AddEdgePts = (pts, diffMat) => + { for (let i = 0; i < pts.length; i++) { let p = AsVector3(pts[i]); p.applyMatrix4(diffMat); @@ -11105,11 +11995,13 @@ let Region = Region_1 = class Region extends Entity { this._MeshGeometry["IsMesh"] = true; this._MeshGeometry.computeVertexNormals(); } - UpdateDrawGeometry() { + UpdateDrawGeometry() + { this._EdgeGeometry = undefined; this._MeshGeometry = undefined; } - InitDrawObject(renderType = RenderType.Wireframe) { + InitDrawObject(renderType = RenderType.Wireframe) + { if (renderType === RenderType.Wireframe) { return new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(this.ColorIndex)); } @@ -11132,7 +12024,8 @@ let Region = Region_1 = class Region extends Entity { return new Object3D().add(new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(this.ColorIndex)), mesh); } } - UpdateDrawObject(renderType, obj) { + UpdateDrawObject(renderType, obj) + { DisposeThreeObj(obj); Object3DRemoveAll(obj); if (renderType === RenderType.Wireframe) { @@ -11163,7 +12056,8 @@ let Region = Region_1 = class Region extends Entity { /** * 当实体需要被更新时,更新实体材质 */ - UpdateDrawObjectMaterial(type, obj, material) { + UpdateDrawObjectMaterial(type, obj, material) + { if (type === RenderType.Wireframe || type === RenderType.Print) { let line = obj; line.material = ColorMaterial.GetLineMaterial(this.ColorIndex); @@ -11187,13 +12081,15 @@ let Region = Region_1 = class Region extends Entity { } } } - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let ver = file.Read(); //1 this._ShapeManager.Clear(); this._ShapeManager.ReadFile(file); } - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(1); //ver this._ShapeManager.WriteFile(file); @@ -11206,7 +12102,8 @@ Region = Region_1 = __decorate([ /** * 把板件炸开成面域,0,1为正反面,其余的为边面(没有圆弧面) */ -function Board2Regions(br) { +function Board2Regions(br) +{ let ocs = br.OCS; let cu = br.ContourCurve.Clone(); if (cu instanceof Circle) @@ -11238,7 +12135,8 @@ function Board2Regions(br) { /**统一板件属性key的命名,修改值会导致无法 .xxx该属性 */ var EBoardKeyList; -(function (EBoardKeyList) { +(function (EBoardKeyList) +{ EBoardKeyList["Height"] = "height"; EBoardKeyList["Width"] = "width"; EBoardKeyList["Thick"] = "thickness"; @@ -11270,7 +12168,8 @@ var EBoardKeyList; })(EBoardKeyList || (EBoardKeyList = {})); /**序列化板件数据 */ -function serializeBoardData(file, processData) { +function serializeBoardData(file, processData) +{ file.Write(processData[EBoardKeyList.RoomName]); file.Write(processData[EBoardKeyList.CabinetName]); file.Write(processData[EBoardKeyList.BrMat]); @@ -11303,7 +12202,8 @@ function serializeBoardData(file, processData) { } } //反序列化板件数据 -function deserializationBoardData(file, processData, ver) { +function deserializationBoardData(file, processData, ver) +{ processData[EBoardKeyList.RoomName] = file.Read(); processData[EBoardKeyList.CabinetName] = file.Read(); processData[EBoardKeyList.BrMat] = file.Read(); @@ -11344,7 +12244,8 @@ function deserializationBoardData(file, processData, ver) { } } } -function SerializeBoard2DModeingData(file, modelList) { +function SerializeBoard2DModeingData(file, modelList) +{ file.Write(modelList.length); for (let data of modelList) { file.WriteObject(data.path); @@ -11360,7 +12261,8 @@ function SerializeBoard2DModeingData(file, modelList) { } } } -function SerializeBoard3DModeingData(file, modelList) { +function SerializeBoard3DModeingData(file, modelList) +{ file.Write(modelList.length); for (let item of modelList) { file.Write(item.path.length); @@ -11376,7 +12278,8 @@ function SerializeBoard3DModeingData(file, modelList) { } } //反序列化板件数据 -function DeserializationBoard2DModeingData(file, data, ver) { +function DeserializationBoard2DModeingData(file, data, ver) +{ data.length = 0; const count = file.Read(); for (let i = 0; i < count; i++) { @@ -11403,7 +12306,8 @@ function DeserializationBoard2DModeingData(file, data, ver) { } } //反序列化板件数据 -function DeserializationBoard3DModeingData(file, data, ver) { +function DeserializationBoard3DModeingData(file, data, ver) +{ data.length = 0; const count = file.Read(); for (let i = 0; i < count; i++) { @@ -11426,14 +12330,16 @@ function DeserializationBoard3DModeingData(file, data, ver) { } var BoardType; -(function (BoardType) { +(function (BoardType) +{ BoardType[BoardType["Layer"] = 0] = "Layer"; BoardType[BoardType["Vertical"] = 1] = "Vertical"; BoardType[BoardType["Behind"] = 2] = "Behind"; //背板 })(BoardType || (BoardType = {})); //排钻类型 var DrillType; -(function (DrillType) { +(function (DrillType) +{ DrillType["Yes"] = "\u6392"; DrillType["None"] = "\u4E0D\u6392"; DrillType["More"] = "**\u591A\u79CD**"; @@ -11441,13 +12347,15 @@ var DrillType; })(DrillType || (DrillType = {})); //偏心轮类型 var FaceDirection; -(function (FaceDirection) { +(function (FaceDirection) +{ FaceDirection[FaceDirection["Front"] = 0] = "Front"; FaceDirection[FaceDirection["Back"] = 1] = "Back"; })(FaceDirection || (FaceDirection = {})); //纹路类型 var LinesType; -(function (LinesType) { +(function (LinesType) +{ /** 正纹 */ LinesType[LinesType["Positive"] = 0] = "Positive"; /** 反纹 */ @@ -11457,7 +12365,8 @@ var LinesType; })(LinesType || (LinesType = {})); // 排版面 var ComposingType; -(function (ComposingType) { +(function (ComposingType) +{ ComposingType[ComposingType["Positive"] = 0] = "Positive"; ComposingType[ComposingType["Reverse"] = 1] = "Reverse"; ComposingType[ComposingType["Arbitrary"] = 2] = "Arbitrary"; @@ -11469,7 +12378,8 @@ var ComposingType; * @enum {number} */ var BehindHeightPositon; -(function (BehindHeightPositon) { +(function (BehindHeightPositon) +{ BehindHeightPositon["ForTop"] = "top"; BehindHeightPositon["ForBottom"] = "bottom"; BehindHeightPositon["AllHeight"] = "all"; //总高 @@ -11481,7 +12391,8 @@ var BehindHeightPositon; * @enum {number} */ var BrRelativePos; -(function (BrRelativePos) { +(function (BrRelativePos) +{ BrRelativePos["Front"] = "front"; BrRelativePos["Back"] = "back"; BrRelativePos["Top"] = "top"; @@ -11491,17 +12402,20 @@ var BrRelativePos; BrRelativePos["Div"] = "div"; })(BrRelativePos || (BrRelativePos = {})); var StripType; -(function (StripType) { +(function (StripType) +{ StripType["H"] = "h"; StripType["V"] = "v"; })(StripType || (StripType = {})); var CurtailType; -(function (CurtailType) { +(function (CurtailType) +{ CurtailType["PerBr"] = "0"; CurtailType["Total"] = "1"; })(CurtailType || (CurtailType = {})); var BoardOpenDir; -(function (BoardOpenDir) { +(function (BoardOpenDir) +{ BoardOpenDir[BoardOpenDir["Left"] = 1] = "Left"; BoardOpenDir[BoardOpenDir["Right"] = 2] = "Right"; BoardOpenDir[BoardOpenDir["Up"] = 3] = "Up"; @@ -11509,14 +12423,16 @@ var BoardOpenDir; BoardOpenDir[BoardOpenDir["None"] = 0] = "None"; })(BoardOpenDir || (BoardOpenDir = {})); -function GenerateExtrudeEdgeGeometry(contourPoints, height) { +function GenerateExtrudeEdgeGeometry(contourPoints, height) +{ let pts = []; for (let cs of contourPoints) pts.push(...GenerateExtrudeEdgeGeometryPoints(cs, height)); let geo = new BufferGeometry().setFromPoints(pts); return geo; } -function GenerateExtrudeEdgeGeometryPoints(contourPoints, height) { +function GenerateExtrudeEdgeGeometryPoints(contourPoints, height) +{ if (contourPoints.length < 3) return []; if (equalv3(contourPoints[0], arrayLast(contourPoints))) @@ -11537,14 +12453,17 @@ function GenerateExtrudeEdgeGeometryPoints(contourPoints, height) { //https://stackoverflow.com/questions/28499800/oriented-box-intersection-in-threejs //http://www.cnblogs.com/iamzhanglei/archive/2012/06/07/2539751.html //https://github.com/Mugen87/yume/blob/master/src/javascript/engine/etc/OBB.js -class OBB { - constructor(ocs, halfSizes) { +class OBB +{ + constructor(ocs, halfSizes) + { this.ocs = ocs; this.halfSizes = halfSizes; this._EPSILON = 1e-3; this.center = halfSizes.clone().applyMatrix4(ocs); } - intersectsOBB(obb, is2D, ucsInv) { + intersectsOBB(obb, is2D, ucsInv) + { let newCenter; let newObbCenter; let cs; @@ -11683,18 +12602,22 @@ class OBB { } } -let Hole = class Hole extends Entity { - get Height() { +let Hole = class Hole extends Entity +{ + get Height() + { return this._Height; } - set Height(v) { + set Height(v) + { if (this._Height !== v) { this.WriteAllObjectRecord(); this._Height = v; this.Update(); } } - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let ver = file.Read(); //1 if (ver <= 4) { @@ -11707,7 +12630,8 @@ let Hole = class Hole extends Entity { this.MId = file.ReadSoftObjectId(); } } - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(5); //ver file.Write(this._Height); @@ -11725,30 +12649,37 @@ Hole = __decorate([ Factory ], Hole); -let ExtrudeHole = class ExtrudeHole extends Hole { - constructor() { +let ExtrudeHole = class ExtrudeHole extends Hole +{ + constructor() + { super(...arguments); this._contourCurve = new Polyline(); this._knifeRadius = 3; this.isHole = true; this.isThrough = false; } - get KnifeRadius() { + get KnifeRadius() + { return this._knifeRadius; } - set KnifeRadius(v) { + set KnifeRadius(v) + { if (!equaln(v, this._knifeRadius)) { this.WriteAllObjectRecord(); this._knifeRadius = v; } } - Explode() { + Explode() + { return [this.ContourCurve.Clone().ApplyMatrix(this.OCS)]; } - get ContourCurve() { + get ContourCurve() + { return this._contourCurve; } - set ContourCurve(curve) { + set ContourCurve(curve) + { if (!curve.IsClose) return; if (curve instanceof Polyline) { @@ -11759,7 +12690,7 @@ let ExtrudeHole = class ExtrudeHole extends Hole { //如果曲线被旋转了,那么修正它的旋转矩阵,避免纹路错误 let ocs = curve.OCS; if (!equaln(ocs.elements[0], 1)) // || ocs.elements[9] || ocs.elements[10] - { + { for (let p of pts) Vector2ApplyMatrix4(ocs, p.pt); curve.OCS = new Matrix4(); @@ -11771,7 +12702,8 @@ let ExtrudeHole = class ExtrudeHole extends Hole { this.CheckContourCurve(); this.Update(); } - CheckContourCurve() { + CheckContourCurve() + { let box = this._contourCurve.BoundingBox; //修正轮廓基点 if (!equalv3(box.min, ZeroVec)) { @@ -11781,7 +12713,8 @@ let ExtrudeHole = class ExtrudeHole extends Hole { this._Matrix.setPosition(this.Position.add(v)); } } - ApplyScaleMatrix(m) { + ApplyScaleMatrix(m) + { this.WriteAllObjectRecord(); let cu = this.ContourCurve; cu.ApplyMatrix(this.OCS); @@ -11791,7 +12724,8 @@ let ExtrudeHole = class ExtrudeHole extends Hole { this.Update(); return this; } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { switch (snapMode) { case ObjectSnapMode.End: return this.GetStretchPoints(); @@ -11814,35 +12748,41 @@ let ExtrudeHole = class ExtrudeHole extends Hole { } return []; } - get Shape() { + get Shape() + { let contour = Contour.CreateContour(this.ContourCurve.Clone(), false); return new Shape(contour); } - get BoundingBoxInOCS() { + get BoundingBoxInOCS() + { let box = new Box3Ext().copy(this.ContourCurve.BoundingBox); box.max.add(new Vector3(0, 0, this.Height)); return box; } - get BoundingBox() { + get BoundingBox() + { let box = this.ContourCurve.BoundingBox; box.max.add(new Vector3(0, 0, this.Height)); box.applyMatrix4(this.OCS); return box; } - get EdgeGeometry() { + get EdgeGeometry() + { if (this._EdgeGeometry) return this._EdgeGeometry; let pts = [this.ContourCurve.Shape.getPoints(6).map(AsVector3)]; this._EdgeGeometry = GenerateExtrudeEdgeGeometry(pts, this.Height).applyMatrix4(this._contourCurve.OCSNoClone); return this._EdgeGeometry; } - get MeshGeometry() { + get MeshGeometry() + { if (this._MeshGeometry) return this._MeshGeometry; this._MeshGeometry = this.GeneralMeshGeometry(); return this._MeshGeometry; } - GeneralMeshGeometry() { + GeneralMeshGeometry() + { let extrudeSettings = { curveSegments: 12, steps: 1, @@ -11853,7 +12793,8 @@ let ExtrudeHole = class ExtrudeHole extends Hole { geo.applyMatrix4(this._contourCurve.OCS); return geo; } - GetGripOrStretchPoints(dragType) { + GetGripOrStretchPoints(dragType) + { let isGrip = dragType === DragPointType.Grip; let pts = isGrip ? this.ContourCurve.GetGripPoints() : this.ContourCurve.GetStretchPoints(); let v = new Vector3(0, 0, this.Height); @@ -11861,10 +12802,12 @@ let ExtrudeHole = class ExtrudeHole extends Hole { pts.forEach(p => { p.applyMatrix4(this.OCS); }); return pts; } - GetStrectchPointCountList(dragType) { + GetStrectchPointCountList(dragType) + { return this.ContourCurve.GetDragPointCount(dragType) * 2; } - MoveGripOrStretchPoints(indexList, vec, dragType) { + MoveGripOrStretchPoints(indexList, vec, dragType) + { this.WriteAllObjectRecord(); if (dragType === DragPointType.Stretch && indexList.length === this.GetStrectchPointCountList(dragType)) { this.Position = this.Position.add(vec); @@ -11875,7 +12818,8 @@ let ExtrudeHole = class ExtrudeHole extends Hole { this.CheckContourCurve(); this.Update(); } - IsStretchHeight(indexs) { + IsStretchHeight(indexs) + { let count = this.ContourCurve.GetStretchPoints().length; if (indexs.length === count) { let isF = indexs[0] < count; @@ -11883,7 +12827,8 @@ let ExtrudeHole = class ExtrudeHole extends Hole { } return false; } - MoveGripOrStretchPointsOnly(indexList, vec, dragType) { + MoveGripOrStretchPointsOnly(indexList, vec, dragType) + { let stretchCount = this.ContourCurve.GetDragPointCount(dragType); if (dragType === DragPointType.Stretch) { //Move @@ -11940,19 +12885,24 @@ let ExtrudeHole = class ExtrudeHole extends Hole { else this.ContourCurve.MoveStretchPoints(indexList, localVec); } - GetGripPoints() { + GetGripPoints() + { return this.GetGripOrStretchPoints(DragPointType.Grip); } - GetStretchPoints() { + GetStretchPoints() + { return this.GetGripOrStretchPoints(DragPointType.Stretch); } - MoveGripPoints(indexList, vec) { + MoveGripPoints(indexList, vec) + { this.MoveGripOrStretchPoints(indexList, vec, DragPointType.Grip); } - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { this.MoveGripOrStretchPoints(indexList, vec, DragPointType.Stretch); } - Convert2ExtrudeSolid() { + Convert2ExtrudeSolid() + { let g = new ExtrudeSolid(); g.KnifeRadius = this.KnifeRadius; g.SetContourCurve(this.ContourCurve); @@ -11960,7 +12910,8 @@ let ExtrudeHole = class ExtrudeHole extends Hole { g.ApplyMatrix(this.OCS); return g; } - GetPrintObject3D() { + GetPrintObject3D() + { let geometry = new LineGeometry(); let lineSegments = new Float32Array(this.EdgeGeometry.attributes.position.array); let instanceBuffer = new InstancedInterleavedBuffer(lineSegments, 6, 1); @@ -11970,7 +12921,8 @@ let ExtrudeHole = class ExtrudeHole extends Hole { let mesh = new Mesh(this.MeshGeometry, ColorMaterial.GetPrintConceptualMaterial()); return [line, mesh]; } - InitDrawObject(renderType = RenderType.Wireframe) { + InitDrawObject(renderType = RenderType.Wireframe) + { if (renderType === RenderType.Wireframe || renderType === RenderType.Edge) { return new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(this.ColorIndex)); } @@ -11984,7 +12936,8 @@ let ExtrudeHole = class ExtrudeHole extends Hole { return new Object3D().add(...this.GetPrintObject3D()); } } - UpdateDrawObject(renderType, obj) { + UpdateDrawObject(renderType, obj) + { DisposeThreeObj(obj); if (renderType !== RenderType.Wireframe) Object3DRemoveAll(obj); @@ -12006,7 +12959,8 @@ let ExtrudeHole = class ExtrudeHole extends Hole { obj.add(...FastWireframe2(this)); return obj; } - UpdateDrawObjectMaterial(renderType, obj) { + UpdateDrawObjectMaterial(renderType, obj) + { if (renderType === RenderType.Wireframe || renderType === RenderType.Edge) { let l = obj; l.material = ColorMaterial.GetLineMaterial(this.ColorIndex); @@ -12016,11 +12970,13 @@ let ExtrudeHole = class ExtrudeHole extends Hole { mesh.material = ColorMaterial.GetConceptualMaterial(this.ColorIndex); } } - get OBB() { + get OBB() + { let size = this.ContourCurve.BoundingBox.getSize(new Vector3).setZ(this.Height); return new OBB(this.OCS, size.multiplyScalar(0.5)); } - ReadFile(file) { + ReadFile(file) + { super.ReadFile(file); let ver = file.Read(); this._contourCurve = file.ReadObject(); @@ -12033,7 +12989,8 @@ let ExtrudeHole = class ExtrudeHole extends Hole { this.Update(); } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(3); file.WriteObject(this._contourCurve); @@ -12053,7 +13010,8 @@ ExtrudeHole = __decorate([ ], ExtrudeHole); //将嵌入的实体绘制对象添加到当前的绘制对象(由于内嵌的实体可能被重复引用) -function AddEntityDrawObject(obj, embedEntity, renderType = RenderType.Wireframe) { +function AddEntityDrawObject(obj, embedEntity, renderType = RenderType.Wireframe) +{ let embedObject = embedEntity.GetDrawObjectFromRenderType(renderType); if (embedObject.parent) obj.children.push(embedObject); //为了避免这个内嵌实体加入到不同的Object中(因为我们有PrintObject),这个写法能行,是因为我们会在其他地方更新它的矩阵 @@ -12062,8 +13020,10 @@ function AddEntityDrawObject(obj, embedEntity, renderType = RenderType.Wireframe } var CompositeEntity_1; -let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { - constructor() { +let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity +{ + constructor() + { super(); //如果你需要修改内部实体,则需要写入记录 this.Entitys = []; @@ -12073,14 +13033,17 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { /** * 初始化绘制的threejs实体,子类型重载该函数初始化绘制实体. */ - Explode() { - return this.Entitys.map(e => { + Explode() + { + return this.Entitys.map(e => + { let cloneE = e.Clone(); cloneE.Material = e.Material; return cloneE.ApplyMatrix(this.OCS); }); } - Traverse(callback) { + Traverse(callback) + { callback(this); for (let en of this.Entitys) { if (en instanceof CompositeEntity_1) @@ -12089,13 +13052,15 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { callback(en); } } - get BoundingBox() { + get BoundingBox() + { let box = new Box3Ext(); for (let e of this.Entitys) box.union(e.BoundingBox); return box.applyMatrix4(this.OCS); } - InitDrawObject(renderType = RenderType.Wireframe) { + InitDrawObject(renderType = RenderType.Wireframe) + { /** * 如果复合实体里面有圆,并且使用了拉伸夹点功能,在UpdateDrawObject时,会因为无法得到Jig对象而导致的错误. * 索性我们去掉Jig实体的功能. @@ -12106,7 +13071,8 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { this.UpdateDrawObject(renderType, object); return object; } - UpdateDrawObject(renderType, obj) { + UpdateDrawObject(renderType, obj) + { Object3DRemoveAll(obj); for (let e of this.Entitys) { e.IsEmbedEntity = true; @@ -12120,14 +13086,17 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { } } } - get ColorIndex() { + get ColorIndex() + { return super.ColorIndex; } - set ColorIndex(color) { + set ColorIndex(color) + { if (color !== this._Color) { this.WriteAllObjectRecord(); this._Color = color; - this.Traverse(e => { + this.Traverse(e => + { if (e === this) return; // if (e instanceof CompositeEntity) //有点奇怪 @@ -12137,18 +13106,22 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { }); } } - get Material() { + get Material() + { return super.Material; } - set Material(id) { + set Material(id) + { super.Material = id; for (let e of this.Entitys) e.Material = id; } - UpdateDrawObjectMaterial(renderType, obj) { + UpdateDrawObjectMaterial(renderType, obj) + { this.UpdateDrawObject(renderType, obj); } - RestoreJigMaterial() { + RestoreJigMaterial() + { //我们不做任何事情,避免更新材质引起的重绘,因为我们没有实现Jig材质,所以我们也不需要还原它 } //#endregion @@ -12161,21 +13134,25 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { * @param viewXform const 最近点捕捉需要这个变量 * @returns object snap points */ - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { let pts = []; for (let e of this.Entitys) { pts.push(...e.Clone().ApplyMatrix(this.OCS).GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform)); } return pts; } - GetGripPoints() { + GetGripPoints() + { return this.GetGripOrStretchPoints(DragPointType.Grip); } - MoveGripPoints(indexList, vec) { + MoveGripPoints(indexList, vec) + { this.WriteAllObjectRecord(); this.MoveGripOrStretchPoints(indexList, vec, DragPointType.Grip); } - GetStretchPoints() { + GetStretchPoints() + { return this.GetGripOrStretchPoints(DragPointType.Stretch); } /** @@ -12185,11 +13162,13 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { * @param {Vector3} vec 移动向量 * @memberof Entity */ - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { this.WriteAllObjectRecord(); this.MoveGripOrStretchPoints(indexList, vec, DragPointType.Stretch); } - GetGripOrStretchPoints(type) { + GetGripOrStretchPoints(type) + { let pts = []; for (let e of this.Entitys) pts.push(...(type === DragPointType.Grip ? e.GetGripPoints() : e.GetStretchPoints())); @@ -12197,13 +13176,16 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { p.applyMatrix4(this._Matrix); return pts; } - GetStrectchPointCountList(dragType) { - let counts = this.Entitys.map(e => { + GetStrectchPointCountList(dragType) + { + let counts = this.Entitys.map(e => + { return (dragType === DragPointType.Grip ? e.GetGripPoints() : e.GetStretchPoints()).length; }); return counts; } - MoveGripOrStretchPoints(indexList, vec, dragType) { + MoveGripOrStretchPoints(indexList, vec, dragType) + { this.WriteAllObjectRecord(); let counts = this.GetStrectchPointCountList(dragType); if (dragType === DragPointType.Stretch && indexList.length === arraySum(counts)) { @@ -12238,7 +13220,8 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { // if (this._drawObject && this._drawObject.children[0]?.userData.IsClone) this.Update(); } - CloneDrawObject(from) { + CloneDrawObject(from) + { for (let [type, obj] of from._CacheDrawObject) { let oldUserDaata = obj.userData; obj.userData = {}; @@ -12254,7 +13237,8 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { } //#endregion //#region 文件序列化 - _ReadFile(file) { + _ReadFile(file) + { let v = file.Read(); super._ReadFile(file); let count = file.Read(); @@ -12266,7 +13250,8 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity { } } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { file.Write(1); super.WriteFile(file); file.Write(this.Entitys.length); @@ -12282,32 +13267,37 @@ CompositeEntity = CompositeEntity_1 = __decorate([ ], CompositeEntity); var EWineRackType; -(function (EWineRackType) { +(function (EWineRackType) +{ EWineRackType[EWineRackType["Oblique"] = 0] = "Oblique"; EWineRackType[EWineRackType["Upright"] = 1] = "Upright"; })(EWineRackType || (EWineRackType = {})); var EWRackArrayType; -(function (EWRackArrayType) { +(function (EWRackArrayType) +{ EWRackArrayType[EWRackArrayType["ByWidth"] = 0] = "ByWidth"; EWRackArrayType[EWRackArrayType["ByCount"] = 1] = "ByCount"; EWRackArrayType[EWRackArrayType["Fixed"] = 2] = "Fixed"; })(EWRackArrayType || (EWRackArrayType = {})); /**铺满方式 */ var EFullType; -(function (EFullType) { +(function (EFullType) +{ EFullType[EFullType["ByHeight"] = 0] = "ByHeight"; EFullType[EFullType["ByWidth"] = 1] = "ByWidth"; EFullType[EFullType["Symmetry"] = 2] = "Symmetry"; })(EFullType || (EFullType = {})); /**高度优先时靠左还是靠右 */ var EFullDir; -(function (EFullDir) { +(function (EFullDir) +{ EFullDir[EFullDir["Left"] = 0] = "Left"; EFullDir[EFullDir["Right"] = 1] = "Right"; })(EFullDir || (EFullDir = {})); var EFindType; -(function (EFindType) { +(function (EFindType) +{ EFindType[EFindType["Find"] = 0] = "Find"; EFindType[EFindType["Modify"] = 1] = "Modify"; EFindType[EFindType["FindMaxSize"] = 2] = "FindMaxSize"; @@ -12320,7 +13310,8 @@ var EFindType; EFindType[EFindType["FindMinSize"] = 9] = "FindMinSize"; })(EFindType || (EFindType = {})); var ECompareType; -(function (ECompareType) { +(function (ECompareType) +{ ECompareType["Equal"] = "="; ECompareType["UnEqual"] = "!="; ECompareType["Greater"] = ">="; @@ -12328,32 +13319,37 @@ var ECompareType; })(ECompareType || (ECompareType = {})); var ELatticeArrayType; -(function (ELatticeArrayType) { +(function (ELatticeArrayType) +{ ELatticeArrayType[ELatticeArrayType["ByWidth"] = 0] = "ByWidth"; ELatticeArrayType[ELatticeArrayType["ByCount"] = 1] = "ByCount"; })(ELatticeArrayType || (ELatticeArrayType = {})); //门板位置类型 var DoorPosType; -(function (DoorPosType) { +(function (DoorPosType) +{ DoorPosType[DoorPosType["Out"] = 0] = "Out"; DoorPosType[DoorPosType["In"] = 1] = "In"; })(DoorPosType || (DoorPosType = {})); var HandleHorPos; -(function (HandleHorPos) { +(function (HandleHorPos) +{ HandleHorPos[HandleHorPos["Left"] = 0] = "Left"; HandleHorPos[HandleHorPos["Right"] = 1] = "Right"; HandleHorPos[HandleHorPos["Mid"] = 2] = "Mid"; })(HandleHorPos || (HandleHorPos = {})); var HandleVePos; -(function (HandleVePos) { +(function (HandleVePos) +{ HandleVePos[HandleVePos["Top"] = 0] = "Top"; HandleVePos[HandleVePos["Bottom"] = 1] = "Bottom"; HandleVePos[HandleVePos["Mid"] = 2] = "Mid"; })(HandleVePos || (HandleVePos = {})); //门板开门类型 var DoorOpenDir; -(function (DoorOpenDir) { +(function (DoorOpenDir) +{ DoorOpenDir["Left"] = "lf"; DoorOpenDir["Right"] = "rt"; DoorOpenDir["Top"] = "tp"; @@ -12362,7 +13358,8 @@ var DoorOpenDir; })(DoorOpenDir || (DoorOpenDir = {})); var EMetalsType; -(function (EMetalsType) { +(function (EMetalsType) +{ EMetalsType["Metals"] = "\u4E94\u91D1"; EMetalsType["Comp"] = "\u7EC4\u4EF6"; })(EMetalsType || (EMetalsType = {})); @@ -13007,14 +14004,17 @@ const DefaultR2b2Option = { Object.freeze(DefaultR2b2Option); var HardwareCompositeEntity_1; -let HardwareCompositeEntity = HardwareCompositeEntity_1 = class HardwareCompositeEntity extends CompositeEntity { - constructor() { +let HardwareCompositeEntity = HardwareCompositeEntity_1 = class HardwareCompositeEntity extends CompositeEntity +{ + constructor() + { super(); this.HardwareOption = { ...DefaultCompositeMetalsOption }; this.DataList = []; this.RelevanceBoards = []; } - GetAllEntity(isHole = false, filter) { + GetAllEntity(isHole = false, filter) + { let holes = []; for (let e of this.Entitys) { if (e instanceof HardwareCompositeEntity_1) { @@ -13029,7 +14029,8 @@ let HardwareCompositeEntity = HardwareCompositeEntity_1 = class HardwareComposit } return holes; } - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let v = file.Read(); this.HardwareOption.type = file.Read(); @@ -13068,7 +14069,8 @@ let HardwareCompositeEntity = HardwareCompositeEntity_1 = class HardwareComposit } } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(3); file.Write(this.HardwareOption.type); @@ -13112,9 +14114,11 @@ HardwareCompositeEntity = HardwareCompositeEntity_1 = __decorate([ Factory ], HardwareCompositeEntity); -class PointShapeUtils { +class PointShapeUtils +{ //方形点表 - static SquarePts(size) { + static SquarePts(size) + { return [ new Vector3(-size, -size), new Vector3(size, -size), @@ -13124,7 +14128,8 @@ class PointShapeUtils { ]; } //方形外圈十字直线点表 - static OutsideLinePts(squareSize, lineLength) { + static OutsideLinePts(squareSize, lineLength) + { return [ //-X new Vector3(-squareSize, 0), @@ -13141,7 +14146,8 @@ class PointShapeUtils { ]; } //十字直线点表 - static CrossLinePts(lineLength) { + static CrossLinePts(lineLength) + { return [ new Vector3(0, -lineLength), new Vector3(0, lineLength), @@ -13149,17 +14155,19 @@ class PointShapeUtils { new Vector3(-lineLength, 0), ]; } - static CrossLine3DPts(lineLength) { + static CrossLine3DPts(lineLength) + { return [ [new Vector3(lineLength, 0), - new Vector3(-lineLength / 2, 0)], + new Vector3(-lineLength / 2, 0)], [new Vector3(0, -lineLength / 2), - new Vector3(0, lineLength)], + new Vector3(0, lineLength)], [new Vector3(0, 0, -lineLength / 2), - new Vector3(0, 0, lineLength)], + new Vector3(0, 0, lineLength)], ]; } - static TrianglePts(size) { + static TrianglePts(size) + { return [ new Vector3(size, -size), new Vector3(0, size), @@ -13167,20 +14175,24 @@ class PointShapeUtils { new Vector3(size, -size), ]; } - static CirclePts(size) { + static CirclePts(size) + { let pts = []; let a = Math.PI * 2 / 8; for (let i = 0; i < 9; i++) pts.push(new Vector3(Math.sin(a * i) * size, Math.cos(a * i) * size)); return pts; } - static ObliqueCrossPts(size) { + static ObliqueCrossPts(size) + { return [new Vector3(-size, size), new Vector3(size, -size), new Vector3(-size, -size), new Vector3(size, size)]; } - static ObliqueCrossLinePts(size) { + static ObliqueCrossLinePts(size) + { return [new Vector3(-size, size), new Vector3(size, -size), new Vector3(), new Vector3(-size, -size), new Vector3(size, size)]; } - static SandClockPts(size) { + static SandClockPts(size) + { return [ new Vector3(size, size), new Vector3(-size, size), @@ -13189,7 +14201,8 @@ class PointShapeUtils { new Vector3(size, size), ]; } - static TangentPts(size) { + static TangentPts(size) + { let pts = [ new Vector3(-size, size), new Vector3(size, size), @@ -13200,7 +14213,8 @@ class PointShapeUtils { pts.push(new Vector3(Math.sin(a * i + Math.PI / 2) * size, Math.cos(a * i + Math.PI / 2) * size)); return pts; } - static PerPts(size) { + static PerPts(size) + { return [ new Vector3(-size, size), new Vector3(-size, -size), @@ -13210,7 +14224,8 @@ class PointShapeUtils { new Vector3(-size, 0), ]; } - static LinesDirPts(len, width, lineType) { + static LinesDirPts(len, width, lineType) + { if (lineType === LinesType.Reverse) { return [ new Vector3(-len / 2), new Vector3(-len / 2 + width / 2, width / 2), @@ -13248,7 +14263,8 @@ class PointShapeUtils { var CylinderHole_1; var GangDrillType; -(function (GangDrillType) { +(function (GangDrillType) +{ /**偏心轮 */ GangDrillType[GangDrillType["Pxl"] = 0] = "Pxl"; /**连接杆 */ @@ -13265,30 +14281,36 @@ var GangDrillType; })(GangDrillType || (GangDrillType = {})); let TempCircle1 = new Circle(); let TempCircle2 = new Circle(); -let CylinderHole = CylinderHole_1 = class CylinderHole extends Hole { - constructor() { +let CylinderHole = CylinderHole_1 = class CylinderHole extends Hole +{ + constructor() + { super(); this._Radius = 1; this.type = GangDrillType.Pxl; this._Color = 1; } - static CreateCylHole(radius, height, type) { + static CreateCylHole(radius, height, type) + { let drill = new CylinderHole_1(); drill.Height = height; drill._Radius = radius; drill.type = type; return drill; } - get Type() { + get Type() + { return this.type; } - set Type(t) { + set Type(t) + { if (this.type !== t) { this.WriteAllObjectRecord(); this.type = t; } } - set Radius(r) { + set Radius(r) + { if (r !== this._Radius) { this.WriteAllObjectRecord(); this._MeshGeometry = null; @@ -13297,42 +14319,50 @@ let CylinderHole = CylinderHole_1 = class CylinderHole extends Hole { this.Update(); } } - get Height() { + get Height() + { return super.Height; } - set Height(v) { + set Height(v) + { if (this._Height !== v) { this._MeshGeometry = null; this._EdgeGeometry = null; super.Height = v; } } - get Radius() { + get Radius() + { return this._Radius; } - get BoundingBox() { + get BoundingBox() + { let box = new Box3(new Vector3(-this._Radius, -this._Radius, 0), new Vector3(this._Radius, this._Radius, this._Height)); return box.applyMatrix4(this.OCS); } - get MeshGeometry() { + get MeshGeometry() + { if (this._MeshGeometry) return this._MeshGeometry; this._MeshGeometry = FastDrillingMeshGeometry(this.Radius, this.Height); return this._MeshGeometry; } - get EdgeGeometry() { + get EdgeGeometry() + { if (this._EdgeGeometry) return this._EdgeGeometry; this._EdgeGeometry = FastDrillingEdgeGeometry(this._Radius, this.Height); return this._EdgeGeometry; } - GetGripPoints() { + GetGripPoints() + { let cir = new Circle(new Vector3(), this._Radius); let pts = cir.GetGripPoints(); pts.push(...pts.map(p => p.clone().add(new Vector3(0, 0, this.Height)))); return pts.map(p => p.applyMatrix4(this.OCS)); } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { let pts = []; TempCircle1.Radius = this.Radius; TempCircle1.OCS = this._Matrix; @@ -13344,21 +14374,25 @@ let CylinderHole = CylinderHole_1 = class CylinderHole extends Hole { } return pts; } - InitDrawObject(renderType) { + InitDrawObject(renderType) + { return this.GetObject3DByRenderType(renderType); } - GetObject3DByRenderType(renderType) { + GetObject3DByRenderType(renderType) + { if (renderType === RenderType.Wireframe) return new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(this.ColorIndex)); else return new Mesh(this.MeshGeometry, ColorMaterial.GetConceptualMaterial(this.ColorIndex)); } - UpdateDrawObject(type, obj) { + UpdateDrawObject(type, obj) + { DisposeThreeObj(obj); Object3DRemoveAll(obj); obj.add(this.GetObject3DByRenderType(type)); } - UpdateDrawObjectMaterial(type, obj) { + UpdateDrawObjectMaterial(type, obj) + { if (type === RenderType.Wireframe) { let l = obj; l.material = ColorMaterial.GetLineMaterial(this.ColorIndex); @@ -13368,7 +14402,8 @@ let CylinderHole = CylinderHole_1 = class CylinderHole extends Hole { mesh.material = ColorMaterial.GetConceptualMaterial(this.ColorIndex); } } - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let ver = file.Read(); //1 this._Radius = file.Read(); @@ -13383,7 +14418,8 @@ let CylinderHole = CylinderHole_1 = class CylinderHole extends Hole { this.type = file.Read(); } } - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(5); //ver file.Write(this._Radius); @@ -13396,7 +14432,8 @@ CylinderHole = CylinderHole_1 = __decorate([ let cache$1 = new Map(); let ro = new Matrix4(); ro.makeRotationX(Math.PI / 2); -function FastDrillingMeshGeometry(radius, height) { +function FastDrillingMeshGeometry(radius, height) +{ let key = `${radius},${height}`; if (cache$1.has(key)) return cache$1.get(key); @@ -13407,7 +14444,8 @@ function FastDrillingMeshGeometry(radius, height) { return geo; } let cache2 = new Map(); -function FastDrillingEdgeGeometry(radius, height) { +function FastDrillingEdgeGeometry(radius, height) +{ let key = `${radius},${height}`; if (cache2.has(key)) return cache2.get(key); @@ -13430,7 +14468,8 @@ function FastDrillingEdgeGeometry(radius, height) { CADFactory.RegisterObjectAlias(CylinderHole, "GangDrill"); const SCALAR = 0.1; -function CyHoleInBoard(cys, br, ocs) { +function CyHoleInBoard(cys, br, ocs) +{ if (cys.length === 1 && cys[0].Type === GangDrillType.Ymj) return true; const outline = br.ContourCurve; @@ -13483,7 +14522,8 @@ function CyHoleInBoard(cys, br, ocs) { let plxs = [pxl]; if (pxl2) plxs.push(pxl2); - if (plxs.every(cy => { + if (plxs.every(cy => + { let center = cy.Position.applyMatrix4(ocs).setZ(0); let cir = new Circle(center, pxl.Radius - SCALAR); if (userConfig.forceFilterPxl) @@ -13536,7 +14576,8 @@ const TempRectHoleOption = { right: "", }; /**分析上下左右排钻 */ -function InitRectBoardHoleOption(br, option) { +function InitRectBoardHoleOption(br, option) +{ let dir = Math.sign(br.ContourCurve.Area2); let hightDrill = br.BoardProcessOption.highDrill; let cus = br.ContourCurve.Explode(); @@ -13555,7 +14596,8 @@ function InitRectBoardHoleOption(br, option) { } } /**上下左右排钻写入板件 */ -function SetRectHighHole(br, option) { +function SetRectHighHole(br, option) +{ let dir = Math.sign(br.ContourCurve.Area2); let highDrill = br.BoardProcessOption.highDrill; let cus = br.ContourCurve.Explode(); @@ -13581,7 +14623,8 @@ function SetRectHighHole(br, option) { } var Intent; -(function (Intent) { +(function (Intent) +{ Intent["NONE"] = "none"; Intent["PRIMARY"] = "primary"; Intent["SUCCESS"] = "success"; @@ -13589,12 +14632,14 @@ var Intent; Intent["DANGER"] = "danger"; })(Intent || (Intent = {})); const ToasterInjectFunctions = []; -function Toaster(option) { +function Toaster(option) +{ for (let f of ToasterInjectFunctions) f(option); } -function FixIndex$1(index, arr) { +function FixIndex$1(index, arr) +{ let count = (arr instanceof Array) ? arr.length : arr; if (index < 0) return count + index; @@ -13608,15 +14653,18 @@ function FixIndex$1(index, arr) { * 使用轮廓和扫描路径构建扫描几何体,实现衣柜中的顶线或者地脚线之类的实体. * 该几何体需要轮廓和路径的起始截面垂直,否则构造的实体将会错误. */ -class SweepGeometry extends Geometry { - constructor(contour, path) { +class SweepGeometry extends Geometry +{ + constructor(contour, path) + { super(); this.edgePts = []; this.AddShape(contour, path); this.computeVertexNormals(); this.computeFaceNormals(); } - AddShape(contour, path) { + AddShape(contour, path) + { //路径点表 let pathPts2d = path.Shape.getPoints(8); let pathPts = pathPts2d.map(AsVector3); @@ -13653,14 +14701,16 @@ class SweepGeometry extends Geometry { if (!isClosePath) this.BuildLid(shapePts2d, verts); } - BuildSideFaces(shapePts2d, pathPts2d, pathPts, verts) { + BuildSideFaces(shapePts2d, pathPts2d, pathPts, verts) + { let addCount = 0; //补充个数 shapePts2d[0]["_mask_"] = true; for (let p of shapePts2d) if (p["_mask_"]) addCount++; let sumCount = addCount + shapePts2d.length; //实际个数 - const f4 = (a, b, c, d, uvs) => { + const f4 = (a, b, c, d, uvs) => + { let f1 = new Face3(a, b, c); let f2 = new Face3(b, d, c); this.faces.push(f1, f2); @@ -13725,7 +14775,8 @@ class SweepGeometry extends Geometry { } } } - BuildLid(shapePts2d, verts) { + BuildLid(shapePts2d, verts) + { //轮廓三角网格索引 let faces = ShapeUtils.triangulateShape(shapePts2d, []); for (let v of shapePts2d) @@ -13765,7 +14816,8 @@ class SweepGeometry extends Geometry { * @param {Vector3} [nextP] 路径下一个点 * @returns 变换后的轮廓点表 */ -function ProjectionToPlane(contourPts, normal, curP, preP, nextP) { +function ProjectionToPlane(contourPts, normal, curP, preP, nextP) +{ let pts; if (!preP && nextP) { let mat = ContourTransfromToPath(curP, normal, nextP.clone().sub(curP)); @@ -13799,7 +14851,8 @@ function ProjectionToPlane(contourPts, normal, curP, preP, nextP) { * @param {Vector3} dir 点前进的方向. * @returns {Matrix4} */ -function ContourTransfromToPath(pt, norm, dir) { +function ContourTransfromToPath(pt, norm, dir) +{ let vy = norm; let vz = dir.normalize(); let vx = vz.clone().cross(vy); @@ -13809,75 +14862,94 @@ function ContourTransfromToPath(pt, norm, dir) { return mat; } -let Spline = class Spline extends Curve { - constructor(points) { +let Spline = class Spline extends Curve +{ + constructor(points) + { super(); this._ClosedMark = false; this._PointList = points || []; } - get Shape() { + get Shape() + { return new Shape$1(); } - get Curve3() { + get Curve3() + { return new CatmullRomCurve3(this.Points); } - get Length() { + get Length() + { return this.Curve3.getLength(); } - get Points() { + get Points() + { return this._PointList; } - set Points(v) { + set Points(v) + { this.WriteAllObjectRecord(); this._PointList = v.map(p => p.clone().applyMatrix4(this.OCSInv)); this.Update(); } //闭合标志 - get CloseMark() { + get CloseMark() + { return this._ClosedMark; } //曲线是否闭合 - get IsClose() { + get IsClose() + { return this.CloseMark || (equalv3(this.StartPoint, this.EndPoint, 1e-4)) && this.EndParam > 1; } - set CloseMark(v) { + set CloseMark(v) + { this.WriteAllObjectRecord(); this._ClosedMark = v; this.Update(); } - get StartPoint() { + get StartPoint() + { return this._PointList[0]; } - get EndPoint() { + get EndPoint() + { return arrayLast(this._PointList); } - get StartParam() { + get StartParam() + { return 0; } - get EndParam() { + get EndParam() + { return this._PointList.length - 1; } - GetGripPoints() { + GetGripPoints() + { return this._PointList.map(p => p.clone().applyMatrix4(this.OCS)); } - GetStretchPoints() { + GetStretchPoints() + { return this.GetGripPoints(); } - MoveGripPoints(indexList, vec) { + MoveGripPoints(indexList, vec) + { this.WriteAllObjectRecord(); for (let index of indexList) { this._PointList[index].add(vec); } this.Update(); } - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { this.WriteAllObjectRecord(); for (let index of indexList) { this._PointList[index].add(vec); } this.Update(); } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { switch (snapMode) { case ObjectSnapMode.End: return this.GetStretchPoints(); @@ -13890,11 +14962,13 @@ let Spline = class Spline extends Curve { } return []; } - InitDrawObject(renderType = RenderType.Wireframe) { + InitDrawObject(renderType = RenderType.Wireframe) + { let geometry = new BufferGeometry().setFromPoints(this.Curve3.getPoints(60)); return new Line$1(geometry, ColorMaterial.GetLineMaterial(this._Color)); } - UpdateDrawObject(type, en) { + UpdateDrawObject(type, en) + { let spl = en; if (this.CloseMark && !equalv3(this._PointList[0], arrayLast(this._PointList))) this._PointList.push(this._PointList[0].clone()); @@ -13905,7 +14979,8 @@ let Spline = class Spline extends Curve { spl.geometry = BufferGeometryUtils.CreateFromPts(pts); } } - Convert2Polyline(count = 0) { + Convert2Polyline(count = 0) + { let curve3 = this.Curve3; //修正个数 if (!count) @@ -13922,7 +14997,8 @@ let Spline = class Spline extends Curve { pl.ApplyMatrix(this.OCS); return pl; } - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let ver = file.Read(); //1 let count = file.Read(); @@ -13930,7 +15006,8 @@ let Spline = class Spline extends Curve { for (let i = 0; i < count; i++) this._PointList.push(new Vector3().fromArray(file.Read())); } - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(1); //ver file.Write(this._PointList.length); @@ -13942,8 +15019,10 @@ Spline = __decorate([ ], Spline); var SweepSolid_1; -let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { - constructor(contour, pathCurve) { +let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity +{ + constructor(contour, pathCurve) + { super(); this._Contour = contour; this._PathCurve = pathCurve; @@ -13956,22 +15035,27 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { this._PathCurve.ApplyMatrix(this._PathCurve.OCSInv); } } - Explode() { + Explode() + { return [this._Contour.Clone(), this._PathCurve.Clone()]; } - get Contour() { + get Contour() + { return this._Contour; } - get Path() { + get Path() + { return this._PathCurve; } - Reverse() { + Reverse() + { this.WriteAllObjectRecord(); this._PathCurve.Reverse(); this.Update(); } /**保持路径左下角在0点 */ - PathTo0() { + PathTo0() + { let min = this._PathCurve.BoundingBox.min; this._PathCurve.Position = this._PathCurve.Position.sub(min); this.OCS = this.OCS.multiply(MoveMatrix(min)); @@ -13979,7 +15063,8 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { /** * 将轮廓变换到wcs空间,当用户选定某个与扫描线起点相切的轮廓时. */ - TransfromPathToWCS() { + TransfromPathToWCS() + { if (equalv3(this._Contour.Normal, new Vector3(0, 0, 1))) return; let fDir = this._PathCurve.GetFistDeriv(0); @@ -14025,7 +15110,8 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { } Log("错误:提供的轮廓没有和路径垂直!"); } - get MeshGeometry() { + get MeshGeometry() + { if (this._MeshGeometry) return this._MeshGeometry; try { @@ -14044,20 +15130,23 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { return new BoxBufferGeometry(1000, 1000, 1000); } } - getLineGeo(pts) { + getLineGeo(pts) + { this._lineGeo = new LineGeometry(); let lineSegments = new Float32Array(pts); var instanceBuffer = new InstancedInterleavedBuffer(lineSegments, 6, 1); this._lineGeo.setAttribute('instanceStart', new InterleavedBufferAttribute(instanceBuffer, 3, 0)); this._lineGeo.setAttribute('instanceEnd', new InterleavedBufferAttribute(instanceBuffer, 3, 3)); } - get EdgeGeometry() { + get EdgeGeometry() + { if (this._EdgeGeometry) return this._EdgeGeometry; this.MeshGeometry; return this._EdgeGeometry; } - InitDrawObject(renderType) { + InitDrawObject(renderType) + { if (renderType === RenderType.Wireframe || renderType === RenderType.Edge) return new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(this.ColorIndex)); else if (renderType === RenderType.Conceptual) { @@ -14079,11 +15168,13 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { return new Object3D().add(new Mesh(this.MeshGeometry, this.MeshMaterial), new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(7))); } } - UpdateDrawGeometry() { + UpdateDrawGeometry() + { this._EdgeGeometry = undefined; this._MeshGeometry = undefined; } - UpdateDrawObject(renderType, obj) { + UpdateDrawObject(renderType, obj) + { DisposeThreeObj(obj); if (renderType === RenderType.Wireframe || renderType === RenderType.Edge) { let l = obj; @@ -14111,7 +15202,8 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { /** * 当实体需要被更新时,更新实体材质 */ - UpdateDrawObjectMaterial(type, obj) { + UpdateDrawObjectMaterial(type, obj) + { if (type === RenderType.Wireframe) { let l = obj; l.material = ColorMaterial.GetLineMaterial(this.ColorIndex); @@ -14129,17 +15221,20 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { mesh.material = this.MeshMaterial; } } - get BoundingBox() { + get BoundingBox() + { if (!this.MeshGeometry.boundingBox) this.MeshGeometry.computeBoundingBox(); return this.MeshGeometry.boundingBox.clone().applyMatrix4(this._Matrix); } - get OBB() { + get OBB() + { let box = this.BoundingBox; let size = box.getSize(new Vector3); return new OBB(MoveMatrix(box.min), size.multiplyScalar(0.5)); } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { switch (snapMode) { case ObjectSnapMode.End: return this.GetEndPoint(); @@ -14160,19 +15255,22 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { } return []; } - GetGripPoints() { + GetGripPoints() + { let pts = this._PathCurve.GetGripPoints(); for (let p of pts) p.applyMatrix4(this._Matrix); return pts; } - GetStretchPoints() { + GetStretchPoints() + { let pts = this._PathCurve.GetStretchPoints(); for (let p of pts) p.applyMatrix4(this._Matrix); return pts; } - UpdateEndMtx(dir, pos) { + UpdateEndMtx(dir, pos) + { let y = this.Normal; let roMat = new Matrix4().extractRotation(this.OCS); let z = dir.applyMatrix4(roMat); @@ -14180,7 +15278,8 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { tempMatrix1.makeBasis(x, y, z); tempMatrix1.setPosition(pos.applyMatrix4(this.OCS)); } - GetEndPoint() { + GetEndPoint() + { let conPts = this._Contour.GetStretchPoints(); let cus; if (this._PathCurve instanceof Polyline) @@ -14210,7 +15309,7 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { d1.applyMatrix4(roMat); d2.add(d1).normalize(); if (isParallelTo(d1, d2)) { - if (l1 instanceof Line && l2 instanceof Line) ; + if (l1 instanceof Line && l2 instanceof Line); else { let ps = conPts.map(p => p.clone().applyMatrix4(tempMatrix1)); pts.push(...ps); @@ -14229,7 +15328,8 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { } return pts; } - GetMidPoints() { + GetMidPoints() + { let conPts = this._Contour.GetStretchPoints(); const pts = []; for (let i = 0.5; i < this._PathCurve.EndParam; i++) { @@ -14240,27 +15340,31 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { } return pts; } - MoveGripPoints(indexList, vec) { + MoveGripPoints(indexList, vec) + { this.WriteAllObjectRecord(); this.IfPathIsLineThenZ0Vector(vec); this._PathCurve.MoveGripPoints(indexList, vec.clone().applyMatrix4(new Matrix4().extractRotation(this.OCSInv))); this.Update(); } //如果路径是直线,我们在这里避免vec传递z轴信息 - IfPathIsLineThenZ0Vector(vec) { + IfPathIsLineThenZ0Vector(vec) + { if (this._PathCurve instanceof Line) { let ocsinv = this._PathCurve.OCSInv.setPosition(0, 0, 0); vec.applyMatrix4(ocsinv).setZ(0); vec.applyMatrix4(this._PathCurve.OCSNoClone); } } - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { this.WriteAllObjectRecord(); this.IfPathIsLineThenZ0Vector(vec); this._PathCurve.MoveStretchPoints(indexList, vec.clone().applyMatrix4(new Matrix4().extractRotation(this.OCSInv))); this.Update(); } - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let ver = file.Read(); //1 this._Contour = file.ReadObject(); @@ -14270,7 +15374,8 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity { Log("放样实体是样条线生成的,自动删除它!"); } } - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(1); //ver file.WriteObject(this._Contour); @@ -14282,17 +15387,21 @@ SweepSolid = SweepSolid_1 = __decorate([ Factory ], SweepSolid); -let HardwareTopline = class HardwareTopline extends SweepSolid { - constructor() { +let HardwareTopline = class HardwareTopline extends SweepSolid +{ + constructor() + { super(...arguments); this.HardwareOption = { ...DefaultToplineMetalsOption }; this.DataList = []; this._contourRotation = 0; } - get ContourRotation() { + get ContourRotation() + { return this._contourRotation; } - get Contours() { + get Contours() + { var _a, _b; let c = this.Path; let conBox = this.Contour.BoundingBox; @@ -14326,7 +15435,8 @@ let HardwareTopline = class HardwareTopline extends SweepSolid { *延伸取最大最小轮廓每段首尾到前面线段,取最长线段作为分段长 * */ - get Segmentations() { + get Segmentations() + { const [l1, l2] = this.Contours; if (!(l1 instanceof Polyline)) return [l1]; @@ -14334,11 +15444,14 @@ let HardwareTopline = class HardwareTopline extends SweepSolid { let cus2 = l2.Explode(); [cus1, cus2] = cus1.length < cus2.length ? [cus2, cus1] : [cus1, cus2]; let sgs = []; - const AddSgs = (c1, c2) => { + const AddSgs = (c1, c2) => + { sgs.push(c1.Length > c2.Length ? c1 : c2); }; - const ExtendCurve = (c, refC, isPre) => { - let pts = c.IntersectWith2(refC, IntersectOption.ExtendBoth).filter(r => { + const ExtendCurve = (c, refC, isPre) => + { + let pts = c.IntersectWith2(refC, IntersectOption.ExtendBoth).filter(r => + { if (isPre) return r.thisParam < 0; else @@ -14355,14 +15468,16 @@ let HardwareTopline = class HardwareTopline extends SweepSolid { c.Extend(pts[0].thisParam); } }; - const IsNoRelativeCurve = (c1, c2) => { + const IsNoRelativeCurve = (c1, c2) => + { if ((c1 instanceof Line) !== (c2 instanceof Line)) return true; let midPt = c1.GetPointAtParam(0.5); let closePt = c2.GetClosestPointTo(midPt, false); return !closePt || !equaln(midPt.distanceTo(closePt), this._ContourWidth, 1e-3); }; - const HasRelativeCurveAndChange = (target, cs, isChange = false) => { + const HasRelativeCurveAndChange = (target, cs, isChange = false) => + { let index = cs.findIndex(c => !IsNoRelativeCurve(c, target)); if (index !== -1) { if (isChange && l1.IsClose) @@ -14431,10 +15546,12 @@ let HardwareTopline = class HardwareTopline extends SweepSolid { } return sgs; } - get MaxLength() { + get MaxLength() + { return this.Segmentations.reduce((len, c) => len + c.Length, 0); } - set ContourRotation(ro) { + set ContourRotation(ro) + { if (ro === this._contourRotation) return; let diffRo = ro - this._contourRotation; @@ -14443,7 +15560,8 @@ let HardwareTopline = class HardwareTopline extends SweepSolid { this.Contour.ApplyMatrix(mat); this.Update(); } - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); let ver = file.Read(); //1 this._contourRotation = file.Read(); @@ -14467,7 +15585,8 @@ let HardwareTopline = class HardwareTopline extends SweepSolid { this.DataList.push(d); } } - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); file.Write(1); //ver file.Write(this._contourRotation); @@ -14499,13 +15618,16 @@ HardwareTopline = __decorate([ Factory ], HardwareTopline); -class LookOverBoardInfosTool { - constructor() { +class LookOverBoardInfosTool +{ + constructor() + { this.drillTypeMap = new Map(); this.sealMap = new Map(); this.boardMap = new Map(); } - GetCount(brs, options = null) { + GetCount(brs, options = null) + { let drillCount = []; let sealCount = []; let hardwareCount = []; @@ -14541,10 +15663,12 @@ class LookOverBoardInfosTool { return { drillCount, hardwareCount, sealCount, areaCount }; } ; - Update(ens, options = null) { + Update(ens, options = null) + { var _a, _b, _c, _d; //计算排钻个数 - const addDrillToMap = (spiteName, d) => { + const addDrillToMap = (spiteName, d) => + { if (!this.drillTypeMap.has(spiteName)) this.drillTypeMap.set(spiteName, [d]); else { @@ -14647,14 +15771,17 @@ class LookOverBoardInfosTool { } } ; - ParseSpec(en, spec, len) { + ParseSpec(en, spec, len) + { let size = en instanceof Vector3 ? en : en.BoundingBoxInOCS.getSize(new Vector3); return ParseExpr(spec, { L: len !== null && len !== void 0 ? len : size.x, W: size.y, H: size.z }) || "[ 无 ]"; } - ParseHardwareCount(k, v, hardwareCount) { + ParseHardwareCount(k, v, hardwareCount) + { if (v.length > 0) { if (!(v[0] instanceof HardwareTopline)) { - let count2 = v.reduce((v, d) => { + let count2 = v.reduce((v, d) => + { var _a; let size = d.BoundingBoxInOCS.getSize(new Vector3); let c = (_a = safeEval(d.HardwareOption.count, { L: size.x, W: size.y, H: size.z })) !== null && _a !== void 0 ? _a : 0; @@ -14686,7 +15813,8 @@ class LookOverBoardInfosTool { } } } - UpdateBoardMap(brs) { + UpdateBoardMap(brs) + { this.boardMap.clear(); for (let b of brs) { let thickness = this.GetBoardThickness(b); @@ -14702,15 +15830,18 @@ class LookOverBoardInfosTool { list.push(b); } } - GetBoardThickness(br) { + GetBoardThickness(br) + { let size = Production.GetSpiteSize(br); if (size) return FixedNotZero(size.spliteThickness, 2); else return FixedNotZero(br.Thickness, 2); } - GetBoardsArea(brs) { - return brs.reduce((area, b) => { + GetBoardsArea(brs) + { + return brs.reduce((area, b) => + { let size = Production.GetSpiteSize(b); let ar; if (size) @@ -14732,10 +15863,12 @@ let instanceMap = new Map(); * //获得单例 * let a = A.GetInstance(); */ -class Singleton { +class Singleton +{ constructor() { } //FIXME: https://github.com/Microsoft/TypeScript/issues/5863 - static GetInstance() { + static GetInstance() + { if (instanceMap.has(this)) return instanceMap.get(this); //@ts-ignore @@ -14747,11 +15880,13 @@ class Singleton { const CanDrawHoleFuzz = 1e-2; var BoardFaceType; -(function (BoardFaceType) { +(function (BoardFaceType) +{ BoardFaceType[BoardFaceType["Side"] = 0] = "Side"; BoardFaceType[BoardFaceType["NoSide"] = 1] = "NoSide"; })(BoardFaceType || (BoardFaceType = {})); -function GetSideFaceMtx(cu, inverseZ = false) { +function GetSideFaceMtx(cu, inverseZ = false) +{ let x = cu.GetFistDeriv(0).normalize(); let y = ZAxis; let z = x.clone().cross(y); @@ -14777,7 +15912,8 @@ function GetSideFaceMtx(cu, inverseZ = false) { * @param rad 刀半径 * @returns tool path */ -function OptimizeToolPath(offsetCus, originShape, rad) { +function OptimizeToolPath(offsetCus, originShape, rad) +{ var _a; // 去掉最外轮廓 let outline = offsetCus.shift(); @@ -14813,7 +15949,8 @@ function OptimizeToolPath(offsetCus, originShape, rad) { } if (noCloseCus.length > 0) { let culist = []; - noCloseCus.forEach(c => { + noCloseCus.forEach(c => + { if (c instanceof Polyline) culist.push(...c.Explode()); else @@ -14879,7 +16016,8 @@ function OptimizeToolPath(offsetCus, originShape, rad) { * 为了统一刀路起点,最外轮廓左左点为起始点,其余轮廓以最接近最外轮廓起始点的点左起始点 * @param plList */ -function ChangePlListStartPt(plList) { +function ChangePlListStartPt(plList) +{ let firstPl = plList[0]; if (firstPl.IsClose) { let minP = undefined; @@ -14897,7 +16035,8 @@ function ChangePlListStartPt(plList) { for (let i = 1; i < plList.length; i++) { let pl = plList[i]; if (pl.IsClose) { - let pts = pl.GetStretchPoints().sort((p1, p2) => { + let pts = pl.GetStretchPoints().sort((p1, p2) => + { let dist1 = p1.distanceToSquared(firstSpt); let dist2 = p2.distanceToSquared(firstSpt); return dist1 - dist2; @@ -14918,7 +16057,8 @@ function ChangePlListStartPt(plList) { /** * 排序多段线数组,按照起点之间的距离 */ -function SortPlByStartPt(pls) { +function SortPlByStartPt(pls) +{ if (pls.length <= 1) return pls; let result = [pls[0]]; @@ -14945,7 +16085,8 @@ function SortPlByStartPt(pls) { pls.length = 0; pls.push(...result); } -function RempveEqualCurves(cus) { +function RempveEqualCurves(cus) +{ let needRemoveCurve = new Set(); for (let i = 0; i < cus.length; i++) { let cu1 = cus[i]; @@ -14963,7 +16104,8 @@ function RempveEqualCurves(cus) { arrayRemoveIf(cus, (c) => needRemoveCurve.has(c)); } /**获取内偏移的轮廓 */ -function GetOffsetCurves(cu, dist, rectInfo) { +function GetOffsetCurves(cu, dist, rectInfo) +{ if (cu instanceof Polyline) { if (rectInfo === null || rectInfo === void 0 ? void 0 : rectInfo.isRect) { let r = RectOffset(cu, rectInfo, Math.abs(dist)); @@ -14975,11 +16117,13 @@ function GetOffsetCurves(cu, dist, rectInfo) { return cu.GetOffsetCurves(dist); } /** 获得曲线内偏移方向*/ -function GetCurveToInDir(cu) { +function GetCurveToInDir(cu) +{ return cu.IsClockWise ? 1 : -1; } /**矩形偏移,正为内偏移 */ -function RectOffset(rect, res, dist) { +function RectOffset(rect, res, dist) +{ if (!res.isRect || equaln(dist, 0)) return; let box = res.box; @@ -15010,14 +16154,16 @@ function RectOffset(rect, res, dist) { /** *计算走刀工具类 */ -class FeedingToolPath extends Singleton { +class FeedingToolPath extends Singleton +{ /** * 处理形状,内偏移 * @param shape 造型Shape * @param knifRadius 刀半径/偏移距离 * @param [isOut=true] 是否是最外轮廓,如果是,洞需要外偏移一个刀半径,多段线偏移保留不闭合轮廓 */ - HandleShape(shape, knifRadius, isOut = true) { + HandleShape(shape, knifRadius, isOut = true) + { let outline = shape.Outline.Curve; if (isOut) outline = outline.Clone(); @@ -15127,14 +16273,16 @@ class FeedingToolPath extends Singleton { return offsetCus; } /**用于测试走刀路径 */ - TestCalcPath(br, isCd = false) { + TestCalcPath(br, isCd = false) + { let modelings = br.BoardModeling; let allModeling = GetModelingFromCustomDrill(br); modelings.push(...allModeling.modeling); if (isCd && userConfig.chaidanOption.useDefaultRad) modelings.forEach(m => m.knifeRadius = userConfig.chaidanOption.radius); if (isCd) - arrayRemoveIf(modelings, m => { + arrayRemoveIf(modelings, m => + { let c = m.shape.Outline.Curve; if (c instanceof Circle && c.Radius < userConfig.chaidanOption.modeling2HoleRad + 1e-6) return true; @@ -15145,14 +16293,16 @@ class FeedingToolPath extends Singleton { /** * 计算走刀路径 */ - CalcPath(modelings, br) { + CalcPath(modelings, br) + { let cus = []; for (let m of modelings) { cus.push(...this.GetModelFeedPath(br, m)); } return cus; } - GetModelFeedPath(br, m) { + GetModelFeedPath(br, m) + { const brThickness = br.Thickness; let cus = []; let { shape, thickness, knifeRadius, addLen, addWidth, addDepth } = m; @@ -15191,7 +16341,8 @@ class FeedingToolPath extends Singleton { } return cus; } - GrooveAddSize(shape, addLen, addWidth) { + GrooveAddSize(shape, addLen, addWidth) + { shape.Outline.Curve.Position = shape.Outline.Curve.Position.setZ(0); //若是矩形,应用槽加长 if (addLen > 0 || addWidth > 0) { @@ -15212,7 +16363,8 @@ class FeedingToolPath extends Singleton { } } } - GetContours(cus, retCus) { + GetContours(cus, retCus) + { let cons = []; for (let c of cus) { if (c.IsClose) { @@ -15222,7 +16374,8 @@ class FeedingToolPath extends Singleton { let expCus = c.Explode(); let regParse = new RegionParse(expCus); //分析封闭包围区域 - const parseRoute = (routeSet) => { + const parseRoute = (routeSet) => + { for (let routes of routeSet) { let cs = routes.map(r => r.curve); let c = Contour.CreateContour(cs, false); @@ -15241,7 +16394,8 @@ class FeedingToolPath extends Singleton { } return cons; } - CheckModeling(br) { + CheckModeling(br) + { let errorIndexs = []; let modelings = br.BoardModeling; for (let i = 0; i < modelings.length; i++) { @@ -15253,7 +16407,8 @@ class FeedingToolPath extends Singleton { } return errorIndexs; } - CheckCustomHole(br) { + CheckCustomHole(br) + { let { modeling, sideModeling } = GetModelingFromCustomDrill(br); let errHoles = []; for (let m of [...modeling, ...sideModeling]) { @@ -15268,7 +16423,8 @@ class FeedingToolPath extends Singleton { } return errHoles; } - HandleThoughGroove(br, shape, knifeRadius) { + HandleThoughGroove(br, shape, knifeRadius) + { let brCon = br.ContourCurve; let outline = shape.Outline.Curve; if (outline instanceof Circle) @@ -15356,7 +16512,8 @@ class FeedingToolPath extends Singleton { } } } -function GetModelingFromCustomDrill(br) { +function GetModelingFromCustomDrill(br) +{ let normal = br.Normal; let outline = GetSealedBoardContour(br, true); let modeling = []; @@ -15396,13 +16553,13 @@ function GetModelingFromCustomDrill(br) { //在板件的世界,0.01的误差应该不能被看出来,所以我们允许0.01的容差(这样应该是没问题的) //也避免了一些二维转三维出现的缝隙排钻不能被拆解的问题 if (max.z >= br.Thickness - 1e-2) //较大的容差(0.01) - { + { dir = FaceDirection.Front; shape.Position = shape.Position.setZ(min.z); thickness = br.Thickness - min.z; } else if (min.z < 1e-2) //较大的容差 - { + { dir = FaceDirection.Back; thickness = max.z; } @@ -15450,31 +16607,37 @@ function GetModelingFromCustomDrill(br) { } const ReportFunctionList = []; -function SendReport(msg) { +function SendReport(msg) +{ for (let f of ReportFunctionList) f(msg); } const ShowObjectsFunctionList = []; -function ShowSelectObjects(ens) { +function ShowSelectObjects(ens) +{ for (let f of ShowObjectsFunctionList) f(ens); } -function IsDev() { +function IsDev() +{ return window.location.hostname === "localhost"; } var DrillingFace; -(function (DrillingFace) { +(function (DrillingFace) +{ //正反面时,使用Front和Back DrillingFace[DrillingFace["Front"] = 0] = "Front"; DrillingFace[DrillingFace["Back"] = 1] = "Back"; })(DrillingFace || (DrillingFace = {})); var Production; -(function (Production) { +(function (Production) +{ /**获取板件拆单数据 */ - function GetBoardSplitOrderData(br) { + function GetBoardSplitOrderData(br) + { let sealedContour = GetSealedBoardContour(br, true); if (!sealedContour || equaln(sealedContour.Area, 0)) { Toaster({ @@ -15527,7 +16690,8 @@ var Production; }; } Production.GetBoardSplitOrderData = GetBoardSplitOrderData; - function GetBoardInfo(br, size) { + function GetBoardInfo(br, size) + { let data = br.BoardProcessOption; let spliteSize = Production.GetSpiteSize(br); let isRect = !!spliteSize || !br.IsSpecialShape; @@ -15555,7 +16719,8 @@ var Production; /** * 转换成多段线并且将圆弧打断(大于1/4的话) */ - function ConverToPolylineAndSplitArc(cu, isOutline = true, isSplite = true) { + function ConverToPolylineAndSplitArc(cu, isOutline = true, isSplite = true) + { let ptsBuls; if (cu instanceof Circle) { let pl = ConverCircleToPolyline(cu); @@ -15581,7 +16746,8 @@ var Production; return ptsBuls; } Production.ConverToPolylineAndSplitArc = ConverToPolylineAndSplitArc; - function ConverCircleToPolyline(cir) { + function ConverCircleToPolyline(cir) + { let arcs = cir.GetSplitCurves([0, 0.25, 0.5, 0.75]); let pl = new Polyline(); pl.OCS = cir.OCS; @@ -15591,11 +16757,13 @@ var Production; } Production.ConverCircleToPolyline = ConverCircleToPolyline; const SPLITBUL = Math.tan(Math.PI / 8); - function GetSpliteCount(allAngle) { + function GetSpliteCount(allAngle) + { return Math.ceil(Math.abs(allAngle) / Math.PI * 2); } /** 打断多段线超过1/4圆的圆弧*/ - function SplitePolylineAtArc(cu, isSplite = true) { + function SplitePolylineAtArc(cu, isSplite = true) + { let ptsBuls = cu.PtsBuls; let ocsInv = cu.OCSInv; let result = { pts: [], buls: [] }; @@ -15639,7 +16807,8 @@ var Production; return result; } Production.SplitePolylineAtArc = SplitePolylineAtArc; - function SplitetArc(arc, hasEnd = false) { + function SplitetArc(arc, hasEnd = false) + { let result = { pts: [], buls: [] }; let bul = arc.Bul; if (Math.abs(bul) > SPLITBUL + 1e-8) { @@ -15669,7 +16838,8 @@ var Production; * 获取封边数据 * 封边数据未统一逆时针顺序,用于拆单 * */ - function GetBoardSealingData(br) { + function GetBoardSealingData(br) + { let sealCus = GetBoardSealingCurves(br); let highSeal = GetBoardHighSeal(br, sealCus); let sealData = []; @@ -15696,7 +16866,8 @@ var Production; } else if (cu instanceof Circle) { let length = 2 * Math.PI * cu.Radius / 4; - sealData.push(...Array.from({ length: 4 }, () => { + sealData.push(...Array.from({ length: 4 }, () => + { return { ...data, length }; })); } @@ -15707,7 +16878,8 @@ var Production; return sealData; } Production.GetBoardSealingData = GetBoardSealingData; - function GetMetalTotalEntitys(md, isHole = false, filter) { + function GetMetalTotalEntitys(md, isHole = false, filter) + { let holes = []; if (isHole && !md.HardwareOption.isHole) return []; @@ -15725,8 +16897,10 @@ var Production; return holes; } Production.GetMetalTotalEntitys = GetMetalTotalEntitys; - function GetOriginBoardModelingData(br) { - const getModelings = (ms) => { + function GetOriginBoardModelingData(br) + { + const getModelings = (ms) => + { var _a; let data = []; for (let m of ms) { @@ -15751,10 +16925,12 @@ var Production; return { modeling, sideModeling }; } Production.GetOriginBoardModelingData = GetOriginBoardModelingData; - function GetBoardModelingData(br, offsetTanslation) { + function GetBoardModelingData(br, offsetTanslation) + { const tool = FeedingToolPath.GetInstance(); const tMtx = MoveMatrix(offsetTanslation.clone().negate()); - const getModelings = (ms, isSide) => { + const getModelings = (ms, isSide) => + { var _a; let data = []; for (let m of ms) { @@ -15794,7 +16970,8 @@ var Production; /**获取板件的轮廓 *有拆单尺寸返回矩形 *用于拆单的轮廓统一逆时针 */ - function GetSpliteOutline(br, isSplite) { + function GetSpliteOutline(br, isSplite) + { let con = GetSpliteOutlineBySpliteSize(br); if (con) return con; @@ -15810,7 +16987,8 @@ var Production; return pl; } Production.GetSpliteOutline = GetSpliteOutline; - function GetSpiteSize(br) { + function GetSpiteSize(br) + { let param = { L: br.Height, W: br.Width, H: br.Thickness }; let spliteHeight = safeEval(br.BoardProcessOption.spliteHeight, param); let spliteWidth = safeEval(br.BoardProcessOption.spliteWidth, param); @@ -15823,7 +17001,8 @@ var Production; return; } Production.GetSpiteSize = GetSpiteSize; - function GetSpliteOutlineBySpliteSize(br) { + function GetSpliteOutlineBySpliteSize(br) + { let size = GetSpiteSize(br); if (size) return new Polyline().RectangleFrom2Pt(new Vector3, new Vector3(size.spliteWidth, size.spliteHeight)); @@ -15831,7 +17010,8 @@ var Production; } Production.GetSpliteOutlineBySpliteSize = GetSpliteOutlineBySpliteSize; /**孔信息,侧孔的z 均为 从上到下距离 */ - function GetBoardHolesData(br, offsetTanslation, sealedContour) { + function GetBoardHolesData(br, offsetTanslation, sealedContour) + { let data = { frontBackHoles: [], sideHoles: [] @@ -15911,11 +17091,13 @@ var Production; } Production.GetBoardHolesData = GetBoardHolesData; /**拆单那边需要把侧孔 z 坐标转换为从上到下 */ - function InvertPosition(pos, thickness) { + function InvertPosition(pos, thickness) + { pos.z = thickness - pos.z; } /**分析常规排钻 */ - function ParseCylHoles(d, br, offsetTanslation, data, outline) { + function ParseCylHoles(d, br, offsetTanslation, data, outline) + { let processData = br.BoardProcessOption; let brNormal = br.Normal; let roMat = new Matrix4().extractRotation(br.OCSInv); @@ -16016,7 +17198,8 @@ var Production; }); } /**分析自定义圆柱排钻 */ - function ParseExtrudeHoles(d, br, offsetTanslation, data, outline, isCheckGroove = false) { + function ParseExtrudeHoles(d, br, offsetTanslation, data, outline, isCheckGroove = false) + { if (!d.isHole) return; let brNormal = br.Normal; @@ -16094,7 +17277,8 @@ var Production; } } } - function GetBoardMetals(br) { + function GetBoardMetals(br) + { let mids = br.RelativeHardware; let metalsData = { metals: 0, @@ -16115,7 +17299,8 @@ var Production; } return metalsData; } - function GetHardwareCompositeData(en) { + function GetHardwareCompositeData(en) + { let size = en.BoundingBoxInOCS.getSize(new Vector3); let data = { ...en.HardwareOption }; const actualVal = safeEval(data.actualExpr, { L: size.x, W: size.y, H: size.z }); @@ -16144,7 +17329,8 @@ var Production; return metalData; } Production.GetHardwareCompositeData = GetHardwareCompositeData; - function GetHardwareToplineData(en) { + function GetHardwareToplineData(en) + { let data = { ...en.HardwareOption }; let datas = []; let map = new Map(); @@ -16182,11 +17368,13 @@ var Production; } Production.GetHardwareToplineData = GetHardwareToplineData; /**获取排钻数量 */ - function GetTotalDrillCount(brs) { + function GetTotalDrillCount(brs) + { return lookOverBoardInfosTool.GetCount(brs); } Production.GetTotalDrillCount = GetTotalDrillCount; - function GetCabSize(brList) { + function GetCabSize(brList) + { let brMap = new Map(); //根据柜名房名分类 for (let b of brList) { @@ -16210,21 +17398,24 @@ var Production; return sizeData; } Production.GetCabSize = GetCabSize; - function Data2Polyline(data, isClose = true) { + function Data2Polyline(data, isClose = true) + { let pl = new Polyline(data.pts.map((p, i) => ({ pt: new Vector2(p.x, p.y), bul: data.buls[i] }))); if (isClose) pl.CloseMark = true; return pl; } Production.Data2Polyline = Data2Polyline; - function Report(ens, msg) { + function Report(ens, msg) + { if (IsDev()) return; ShowSelectObjects(ens); SendReport(msg); } Production.Report = Report; - function Get2DModeing(br, offset) { + function Get2DModeing(br, offset) + { let res = []; let tmtx = MoveMatrix(offset.clone().negate()); for (let m of br.Modeling2D) { @@ -16238,7 +17429,8 @@ var Production; return res; } Production.Get2DModeing = Get2DModeing; - function Get3DModeing(br, offset) { + function Get3DModeing(br, offset) + { let res = []; for (let m of br.Modeling3D) { let d = { @@ -16282,11 +17474,13 @@ var Production; *曲线列表分段 * @l-arc-l,l-arc-arc-l,l-arc-l-arc-l.... */ -function ParagraphCulist(cus) { +function ParagraphCulist(cus) +{ let newCulist = []; let usedCu = new WeakSet(); //归类曲线,返回归类是否成功 - const paragraph = (cu, originCu, cuList, isBack) => { + const paragraph = (cu, originCu, cuList, isBack) => + { const cuIsLine = cu instanceof Line; const originCuIsLine = originCu instanceof Line; if (usedCu.has(cu)) @@ -16371,7 +17565,8 @@ function ParagraphCulist(cus) { /** *计算封边 */ -function CalcEdgeSealing(cus) { +function CalcEdgeSealing(cus) +{ if (cus.length <= 1) return; let oldLine; @@ -16447,7 +17642,8 @@ function CalcEdgeSealing(cus) { } return true; } -function GetBoardHighSeal(br, sealcus) { +function GetBoardHighSeal(br, sealcus) +{ let highSeals = br.BoardProcessOption.highSealed.slice().filter(d => d.size !== null && d.size !== undefined); let sealDown = parseFloat(br.BoardProcessOption[EBoardKeyList.DownSealed]); let sealUp = parseFloat(br.BoardProcessOption[EBoardKeyList.UpSealed]); @@ -16473,7 +17669,8 @@ function GetBoardHighSeal(br, sealcus) { return highSeals; } /**偏移前后曲线起点没改变 */ -function OffsetOutlineSpNotChange(oldcu, newCu) { +function OffsetOutlineSpNotChange(oldcu, newCu) +{ if (!newCu) return false; let sDerv = oldcu.GetFistDeriv(0).normalize(); @@ -16487,7 +17684,8 @@ function OffsetOutlineSpNotChange(oldcu, newCu) { * 消除共线的数据,不改变轮廓方向 * isOffset-是否偏移轮廓用于查看 * */ -function GetBoardSealingCurves(br, isOffset = false) { +function GetBoardSealingCurves(br, isOffset = false) +{ let cu = Production.GetSpliteOutlineBySpliteSize(br); if (cu) return cu.Explode(); @@ -16522,7 +17720,8 @@ function GetBoardSealingCurves(br, isOffset = false) { * hasSealing 轮廓是否包含封边 * 用户计算拆单侧孔面id */ -function GetSealedBoardContour(br, hasSealing) { +function GetSealedBoardContour(br, hasSealing) +{ if (equaln(br.ContourCurve.Area, 0)) return; let offsetCus = []; @@ -16570,7 +17769,8 @@ function GetSealedBoardContour(br, hasSealing) { * @param feedingDepth 走刀深度 * @param knifAngle 通常为60度.按弧度表示 */ -function VKnifToolPath(polyline, feedingDepth, knifAngle) { +function VKnifToolPath(polyline, feedingDepth, knifAngle) +{ let x = feedingDepth * Math.tan(knifAngle); let cus = polyline.Explode(); arrayRemoveIf(cus, c => c.Length < 0.01); @@ -16591,7 +17791,7 @@ function VKnifToolPath(polyline, feedingDepth, knifAngle) { c2 = new Line(c2.StartPoint, c2.StartPoint.add(c2.GetFistDeriv(0).multiplyScalar(100))); ptsbul.push(d); if (!isClose && i === cus.length - 1) //最后一条 - { + { ptsbul.push({ pt: c1.EndPoint, bul: 0 }); break; } @@ -16620,982 +17820,9 @@ function VKnifToolPath(polyline, feedingDepth, knifAngle) { } return ptsbul; } -function VData2Curve(data) { - let curves = []; - for (let i = 0; i < data.length - 1; i++) { - let p1 = new Vector3(data[i].pt.x, data[i].pt.y, data[i].pt.z); - let p2 = new Vector3(data[i + 1].pt.x, data[i + 1].pt.y, data[i + 1].pt.z); - if (equaln(data[i].bul, 0)) { - curves.push(new Line(p1, p2)); - } - else { - curves.push(new Arc().ParseFromBul(p1, p2, data[i].bul)); - } - } - return curves; -} -var Board_1; -/** - * 板件实体 - */ -let Board = Board_1 = class Board extends ExtrudeSolid { - constructor() { - super(); - this._Rotation = { - x: 0, - y: 0, - z: 0 - }; - this._Name = ""; - //板件排钻表,与之碰撞板件为key - this._DrillList = new Map(); - this._LayerNails = []; - this.RelativeHardware = []; - this.OpenDir = BoardOpenDir.None; - this._IsChaiDan = true; - this._2DModelingList = []; - this._3DModelingList = []; - this.OffsetPathCache = new Map(); - this.InitBoardData(); - } - /** - * 创建一个代理数组,数组改变时被监听 - */ - CreateArray() { - return new Proxy([], { - set: (target, key, value, receiver) => { - if (Reflect.get(target, key, receiver) !== value) - this.WriteAllObjectRecord(); - return Reflect.set(target, key, value, receiver); - } - }); - } - InitBoardData() { - let defaultData = { - roomName: "", - cabinetName: "", - boardName: "", - material: "", - color: "", - lines: LinesType.Positive, - bigHoleDir: FaceDirection.Front, - composingFace: ComposingType.Arbitrary, - highSealed: this.CreateArray(), - sealedUp: "1", - sealedDown: "1", - sealedLeft: "1", - sealedRight: "1", - spliteHeight: "", - spliteWidth: "", - spliteThickness: "", - highDrill: this.CreateArray(), - frontDrill: true, - backDrill: true, - drillType: "", - remarks: this.CreateArray(), - }; - this._BoardProcessOption = new Proxy(defaultData, { - get: function (target, key, receiver) { - return Reflect.get(target, key, receiver); - }, - set: (target, key, value, receiver) => { - if (Reflect.get(target, key, receiver) !== value) { - this.WriteAllObjectRecord(); - if (key === "highDrill" || key === EBoardKeyList.HighSealed) { - let arr = this.CreateArray(); - arr.push(...value); - target[key] = arr; - if (key === EBoardKeyList.HighSealed) - this.Update(UpdateDraw.Geometry); - return true; - } - let result = Reflect.set(target, key, value, receiver); - if (key === EBoardKeyList.Lines) - this.Update(UpdateDraw.Geometry); - return result; - } - return true; - } - }); - } - //初始化板件 来自长宽高 - InitBoard(length, width, thickness, boardType = BoardType.Layer) { - this._BoardType = boardType; - if (boardType === BoardType.Layer) { - this.ColorIndex = 2; - this._Name = "层板"; - } - else if (boardType === BoardType.Vertical) { - this.ColorIndex = 11; - this._Name = "立板"; - } - else { - this.ColorIndex = 3; - this._Name = "背板"; - } - let types = [...userConfig.DrillConfigs.keys(), "不排"]; - let type = types.includes(this.BoardProcessOption.drillType) ? this.BoardProcessOption.drillType : types[0]; - this._BoardProcessOption.drillType = type; - this._BoardProcessOption.highDrill = Array(4).fill(type); - this.ConverToRectSolid(width, length, thickness); - this.Update(UpdateDraw.Geometry); - } - static CreateBoard(length, width, thickness, boardType = BoardType.Layer) { - let board = new Board_1(); - board.InitBoard(length, width, thickness, boardType); - board.ApplyMatrix(board.RotateMat); - board._SpaceOCS.identity(); - return board; - } - get DrillList() { - return this._DrillList; - } - get LayerNails() { - return this._LayerNails; - } - AppendNails(ids) { - this.WriteAllObjectRecord(); - this._LayerNails.push(...ids); - } - ClearLayerNails() { - this.WriteAllObjectRecord(); - for (let nail of this._LayerNails) { - if (nail.Object && !nail.IsErase) - nail.Object.Erase(); - } - this._LayerNails.length = 0; - } - /** - * 你可以安心的修改它,这样会直接影响到板件,因为板件对这个对象添加了代理. - */ - get BoardProcessOption() { - return this._BoardProcessOption; - } - set BoardProcessOption(obj) { - Object.assign(this._BoardProcessOption, obj, { [EBoardKeyList.HighSealed]: obj[EBoardKeyList.HighSealed].slice() }); - } - get NeedUpdateRelevanceGroove() { - if (super.NeedUpdateRelevanceGroove) - return true; - for (let k of this.RelativeHardware) { - if (!k || !k.Object) - continue; - if (this.__CacheKnifVersion__[k.Index] !== (k.Object).__UpdateVersion__) - return true; - } - return false; - } - GetRelevanceKnifes(knifs) { - super.GetRelevanceKnifes(knifs); - for (let e of this.RelativeHardware) { - if (e.IsErase) - continue; - let hardware = e.Object; - if (hardware instanceof HardwareCompositeEntity) { - if (hardware.HardwareOption.isHole) { - let holes = hardware.GetAllEntity(true, e => e instanceof ExtrudeHole || e instanceof ExtrudeSolid); - for (let i = 0; i < holes.length; i++) { - let h = holes[i]; - let g = h instanceof ExtrudeHole ? h.Convert2ExtrudeSolid() : h; - g.__TempIndexVersion__ = { Index: hardware.Id.Index, Version: hardware.__UpdateVersion__ }; - knifs.push(g); - } - } - } - } - } - ClearRelevance(en) { - for (let id of this.RelativeHardware) { - let e = id.Object; - if (e instanceof HardwareCompositeEntity) { - arrayRemoveIf(e.RelevanceBoards, i => !i || i.Index === this.Id.Index); - } - } - this.RelativeHardware.length = 0; - super.ClearRelevance(en); - } - get SplitBoards() { - let brs = this.SplitExtrudes; - //拆单或者bbs的时候会重新加入最新的原板件的排钻和层板钉数据 - for (let br of brs) { - if (br.__OriginalEnt__) { - br._DrillList = new Map(this._DrillList.entries()); - br._LayerNails = [...this._LayerNails]; - br.ProcessingGroupList = [...this.ProcessingGroupList]; - br._BoardProcessOption = { ...this._BoardProcessOption }; - //如果是矩形板,关联切割后的板件,用上下左右封边重新填充高级封边,避免近乎矩形的板件封边看上去不对 #I2AQ9R - if (this.isRect) - br._BoardProcessOption.highSealed.length = 0; - } - } - return brs; - } - get BoardModeling() { - let models = []; - for (let g of this.grooves) { - let cu = g.ContourCurve.Clone().ApplyMatrix(this.OCSInv.multiply(g.OCS)); - let outline = Contour.CreateContour(cu, false); - let holes = []; - for (let subG of g.Grooves) { - let holeCu = subG.ContourCurve.Clone().ApplyMatrix(this.OCSInv.multiply(subG.OCS)); - holes.push(Contour.CreateContour(holeCu, false)); - } - let s = new Shape(outline, holes); - models.push({ - shape: s, - thickness: g.Thickness, - dir: equaln(g.Position.applyMatrix4(this.OCSInv).z, 0) && g.Thickness < this.thickness - 1e-6 ? FaceDirection.Back : FaceDirection.Front, - knifeRadius: g.KnifeRadius, - addLen: g.GroovesAddLength, - addWidth: g.GroovesAddWidth, - addDepth: g.GroovesAddDepth, - }); - } - return models; - } - set BoardModeling(models) { - this.WriteAllObjectRecord(); - this.grooves.length = 0; - for (let model of models) { - let g = new ExtrudeSolid(); - g.OCS = this.OCS; - g.ContourCurve = model.shape.Outline.Curve; - g.Thickness = model.thickness; - g.GroovesAddLength = model.addLen; - g.KnifeRadius = model.knifeRadius; - for (let hole of model.shape.Holes) { - let subG = new ExtrudeSolid(); - subG.OCS = this.OCS; - subG.ContourCurve = hole.Curve; - subG.Thickness = model.thickness; - g.AppendGroove(subG); - } - if (model.dir === FaceDirection.Front) - g.ApplyMatrix(MoveMatrix(new Vector3(0, 0, this.thickness - g.Thickness))); - this.grooves.push(g); - } - this.Update(); - } - get Modeling2D() { - return [...this._2DModelingList]; - } - set Modeling2D(ms) { - this.WriteAllObjectRecord(); - this._2DModelingList = ms; - this.OffsetPathCache.clear(); - this._2D3DPathObject = null; - this.Update(UpdateDraw.Geometry); - } - get Modeling3D() { - return [...this._3DModelingList]; - } - set Modeling3D(ms) { - this.WriteAllObjectRecord(); - this._2D3DPathObject = null; - this._3DModelingList = ms; - this.Update(UpdateDraw.Geometry); - } - ClearModeling2DList() { - this.WriteAllObjectRecord(); - this._2DModelingList.length = 0; - this.Update(UpdateDraw.Geometry); - } - ClearModeling3DList() { - this.WriteAllObjectRecord(); - this._3DModelingList.length = 0; - this.Update(UpdateDraw.Geometry); - } - get IsChaiDan() { - return this._IsChaiDan; - } - set IsChaiDan(v) { - if (this._IsChaiDan !== v) { - this.WriteAllObjectRecord(); - this._IsChaiDan = v; - this.Update(UpdateDraw.Geometry); - } - } - ClearBoardModeling() { - this.WriteAllObjectRecord(); - this.grooves.length = 0; - this.Update(UpdateDraw.Geometry); - } - /** - * 注意传入的排钻列表,避免指针被引用 - */ - AppendDrillList(k, drs) { - this.WriteAllObjectRecord(); - let oldDrs = this._DrillList.get(k); - if (oldDrs) - oldDrs.push(...drs); //同类型板件时,会触发这里. - else - this._DrillList.set(k, drs); - } - ClearDrillList(k) { - let drids = this._DrillList.get(k); - if (drids) { - this.WriteAllObjectRecord(); - for (let drillents of drids) { - for (let objId of drillents) { - if (!objId.IsErase) - objId.Object.Erase(); - } - } - this._DrillList.delete(k); - if (k && k.Object) { - //必须在这里删除 - let br = k.Object; - br.ClearDrillList(this.Id); - } - } - } - ClearAllDrillList() { - for (const [id] of this._DrillList) { - this.ClearDrillList(id); - } - } - Erase(isErase = true) { - if (isErase === this.IsErase) - return; - super.Erase(isErase); - if (!isErase) - return; - //记录数据,避免下面记录的时候,排钻已经被删除,导致排钻数据被优化掉. - this.WriteAllObjectRecord(); - for (const [, driss] of this._DrillList) { - for (let dris of driss) - for (let d of dris) - if (d && d.Object) - d.Object.Erase(); - } - this.ClearLayerNails(); - } - get RotateMat() { - let roMat = new Matrix4(); - switch (this._BoardType) { - case BoardType.Layer: - roMat.makeBasis(new Vector3(0, 1, 0), new Vector3(-1, 0, 0), new Vector3(0, 0, 1)); - break; - case BoardType.Vertical: - roMat.makeBasis(new Vector3(0, 1, 0), new Vector3(0, 0, 1), new Vector3(1, 0, 0)); - break; - case BoardType.Behind: - roMat.makeBasis(new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, -1, 0)); - } - return roMat; - } - get Height() { - return this.height; - } - set Height(v) { - if (this.ContourCurve instanceof Circle) - return; - if (!equaln(v, this.height, 1e-2)) { - this.WriteAllObjectRecord(); - let refHeight = this.height / 2; - let dist = v - this.height; - let contour = Contour.CreateContour(this.ContourCurve, false); - let isSuccess = contour.UnEqualProportionScale(refHeight, dist, "y"); - if (isSuccess) { - this.height = v; - this.GrooveCheckAllAutoSplit(); - this.Update(); - } - } - } - get Width() { - return this.width; - } - set Width(v) { - if (this.ContourCurve instanceof Circle) - return; - if (!equaln(v, this.width, 1e-2)) { - this.WriteAllObjectRecord(); - let refDist = this.width / 2; - let dist = v - this.width; - let contour = Contour.CreateContour(this.ContourCurve, false); - let isSuccess = contour.UnEqualProportionScale(refDist, dist, "x"); - if (isSuccess) { - this.width = v; - this.GrooveCheckAllAutoSplit(); - this.Update(); - } - } - } - get BoardType() { - return this._BoardType; - } - set BoardType(type) { - this.WriteAllObjectRecord(); - if (type !== this._BoardType) { - let spaceCS = this._SpaceOCS.clone(); - this._BoardType = type; - this.ApplyMatrix(this.OCSInv); - this.ApplyMatrix(this.RotateMat); - this._SpaceOCS.identity(); - this.ApplyMatrix(spaceCS); - this.Update(); - } - } - //设置板件类型并且不做任何的事情 - SetBoardType(type) { - this.WriteAllObjectRecord(); - this._BoardType = type; - } - //最左下角的点 - get MinPoint() { - switch (this._BoardType) { - case BoardType.Layer: - return new Vector3(0, this.height).applyMatrix4(this.OCS); - case BoardType.Vertical: - return this.Position; - case BoardType.Behind: - return new Vector3(0, 0, this.thickness).applyMatrix4(this.OCS); - } - } - get MaxPoint() { - let pt = new Vector3(this.width, this.height, -this.thickness); - pt.applyMatrix4(this.OCS); - return pt; - } - get IsRect() { - return this.isRect; - } - get IsSpecialShape() { - return !this.isRect; - } - get HasGroove() { - return this.grooves.length > 0; - } - get Name() { - return this._Name; - } - set Name(n) { - this.WriteAllObjectRecord(); - this._Name = n; - } - /** - * 板件的轮廓,在板件坐标系中的表现方式. - */ - get ContourCurve() { - return super.ContourCurve; - } - set ContourCurve(cu) { - //标识是否被初始化 - TempRectHoleOption.up = ""; - if (!this.contourCurve || cu.EndParam !== this.contourCurve.EndParam || !this.BoardProcessOption.drillType) { - let drillTypes = [...userConfig.DrillConfigs.keys(), "不排"]; - let defaultType = this._BoardProcessOption.drillType; - if (!defaultType || !drillTypes.includes(defaultType)) { - defaultType = drillTypes[0]; - this._BoardProcessOption.drillType = defaultType; - } - this._BoardProcessOption.highDrill = Array(cu.EndParam).fill(defaultType); - } - else { - if (this.isRect) - InitRectBoardHoleOption(this, TempRectHoleOption); - } - super.ContourCurve = cu; - if (this.isRect && TempRectHoleOption.up) - SetRectHighHole(this, TempRectHoleOption); - } - Explode() { - return Board2Regions(this); - // return this.m_Shape.Explode().map(cu => cu.ApplyMatrix(this.OCS)); - } - RotateBoard(rox, roy, roz) { - this.WriteAllObjectRecord(); - this._Rotation.x = rox; - this._Rotation.y = roy; - this._Rotation.z = roz; - let spcocs = this.SpaceOCS; - let roMatX = new Matrix4().makeRotationX(rox); - let roMatY = new Matrix4().makeRotationY(roy); - let roMatZ = new Matrix4().makeRotationZ(roz); - this.ApplyMatrix(this.OCSInv) - .ApplyMatrix(this.RotateMat) - .ApplyMatrix(roMatX) - .ApplyMatrix(roMatY) - .ApplyMatrix(roMatZ) - .ApplyMatrix(spcocs); - this._SpaceOCS.copy(spcocs); - this.Update(); - } - get Rotation() { - return this._Rotation; - } - ApplyMirrorMatrix(m) { - return this; - } - get UCGenerator() { - if (this.BoardProcessOption.lines === LinesType.Positive) - return boardUVGenerator; - else - return boardUVGenerator2; - } - UpdateUV(geo, ocs, isRev = false) { - super.UpdateUV(geo, ocs, this.BoardProcessOption.lines === LinesType.Reverse); - } - //从一个实体拷贝数据,实体类型必须相同. - CopyFrom(obj) { - this.WriteAllObjectRecord(); - let drillBak = this._DrillList; - this._DrillList = new Map(); - let layerNailsBak = this._LayerNails; - this._LayerNails = []; - super.CopyFrom(obj); - this._DrillList = drillBak; - this._LayerNails = layerNailsBak; - } - Clone() { - let br = super.Clone(); - br._DrillList.clear(); - br._LayerNails.length = 0; - br.RelativeHardware.length = 0; - return br; - } - Join(target) { - let res = super.Join(target); - if (res && target.RelativeHardware) { - for (let hw of target.RelativeHardware) { - if (!this.RelativeHardware.includes(hw)) - this.RelativeHardware.push(hw); - } - } - return res; - } - GetLinesDir() { - let l; - let len; - let width; - switch (this.BoardProcessOption.lines) { - case LinesType.Positive: - len = this.height / 3; - width = Math.min(this.width, this.height) / 8; - break; - case LinesType.Reverse: - len = this.width / 2; - width = Math.min(this.width, this.height) / 8; - break; - case LinesType.CanReversal: - len = this.height / 3; - width = this.width / 2; - } - l = new LineSegments(BufferGeometryUtils.CreateFromPts(PointShapeUtils.LinesDirPts(len, width, this.BoardProcessOption.lines)), ColorMaterial.GetLineMaterial(8)); - let l1 = l.clone(); - l1.material = ColorMaterial.GetLineMaterial(7); - l.position.set(this.width / 2, this.height / 2, 0); - l1.position.set(this.width / 2, this.height / 2, this.thickness); - l.updateMatrix(); - l1.updateMatrix(); - return [l, l1]; - } - Get2DAnd3DPaths(obj) { - if (this._2D3DPathObject) - return this._2D3DPathObject; - this._2D3DPathObject = new Object3D(); - let group2 = new Object3D(); - for (let vm of this._2DModelingList) { - let path = vm.path; - for (let item of vm.items) { - let tempPath = this.GetOffsetPath(path, item); - if (tempPath) { - let curves = VData2Curve(VKnifToolPath(tempPath, item.depth, item.knife.angle / 2)); - let o = new Object3D(); - for (let c of curves) { - c.ColorIndex = tempPath.ColorIndex; - o.add(c.GetDrawObjectFromRenderType(RenderType.Wireframe)); - } - if (vm.dir === FaceDirection.Back) - o.applyMatrix4(ZMirrorMatrix); - else - o.position.setZ(this.thickness); - o.updateMatrix(); - group2.add(o); - } - } - } - let group = new Object3D(); - let tempIndex = 1; - let tempMap = new Map(); - for (let vm of this._3DModelingList) { - let key = `${vm.dir}-${vm.knife.id}`; - let color = tempMap.get(key); - if (!color) { - color = tempIndex; - tempIndex++; - tempMap.set(key, color); - } - for (let i = 0; i < vm.path.length - 1; i++) { - let d1 = vm.path[i]; - let d2 = vm.path[i + 1]; - if (equaln(d1.bul, 0)) { - let geo = BufferGeometryUtils.CreateFromPts([d1.pt, d2.pt]); - group.add(new Line$1(geo, ColorMaterial.GetLineMaterial(color))); - } - else { - let arc = new Arc().ParseFromBul(d1.pt, d2.pt, d1.bul); - arc.ColorIndex = color; - group.add(arc.GetDrawObjectFromRenderType(RenderType.Wireframe)); - } - } - } - this._2D3DPathObject.add(group); - this._2D3DPathObject.add(group2); - return this._2D3DPathObject; - } - HandleSpliteEntitys(splitEntitys) { - var _a; - let nails = []; - for (let nail of this.LayerNails) { - if ((nail === null || nail === void 0 ? void 0 : nail.Object) && !nail.IsErase) - nails.push(nail); - } - let record = this._Owner.Object; - for (let en of splitEntitys) { - let ocsInv = en.OCSInv; - let nids = []; - let needAddNailEnts = []; - nails = nails.filter(id => { - let n = id.Object; - let position = n.Position.applyMatrix4(ocsInv).setZ(0); - if (en.contourCurve.PtInCurve(position)) { - let n1 = n.Clone(); - n1.MId = n.MId; - n1.FId = n.FId; - if (n.MId === this.Id) { - n1.MId = en.Id; - needAddNailEnts.push(n1.FId.Object); - } - if (n.FId === this.Id) { - n1.FId = en.Id; - needAddNailEnts.push(n1.MId.Object); - } - n.Erase(); - record.Add(n1); - nids.push(n1.Id); - return false; - } - return true; - }); - en.AppendNails(nids); - needAddNailEnts.forEach(e => e.AppendNails(nids)); - if (!userConfig.openDrillingReactor) { - for (let [bid, idss] of this._DrillList) { - if (!bid) - continue; - let board = bid.Object; - for (let ids of idss) { - if (!((_a = ids[0]) === null || _a === void 0 ? void 0 : _a.Object) || ids[0].IsErase) - continue; - let holes = ids.map(i => i.Object); - if (holes[0] instanceof CylinderHole) { - let isInBoard = CyHoleInBoard(holes, en, en.OCSInv); - if (isInBoard) { - let cloneHoles = holes.map(h => h.Clone()); - for (let h of cloneHoles) { - if (h.FId === this.Id) { - h.FId = en.Id; - } - if (h.MId === this.Id) { - h.MId = en.Id; - } - record.Add(h); - } - for (let h of holes) - h.Erase(); - en.AppendDrillList(bid, [cloneHoles.map(c => c.Id)]); - board.AppendDrillList(en.Id, [cloneHoles.map(c => c.Id)]); - } - } - } - } - } - } - } - InitDrawObject(renderType = RenderType.Wireframe) { - let obj; - if (renderType === RenderType.Edge) { - obj = new Object3D(); - obj.add(new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(8))); - this.CheckSealing(obj); - } - else { - obj = super.InitDrawObject(renderType); - } - this.HandleBoardMaterial(renderType, obj); - return obj; - } - UpdateDrawObject(renderType, obj) { - let o = super.UpdateDrawObject(renderType, obj); - if (renderType === RenderType.Edge) { - obj.add(new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(8))); - this.CheckSealing(obj); - } - this.HandleBoardMaterial(renderType, obj); - return o; - } - GetOffsetPath(path, item) { - if (item.offset === 0) { - return path; - } - else { - let cache = this.OffsetPathCache.get(path); - if (!cache) { - cache = {}; - this.OffsetPathCache.set(path, cache); - } - let tempPath = cache[item.offset.toString()]; - if (!tempPath) { - tempPath = path.GetOffsetCurves(item.offset)[0]; - cache[item.offset.toString()] = tempPath; - } - return tempPath; - } - } - HandleBoardMaterial(renderType, obj) { - if (!this.IsChaiDan) { - if (renderType === RenderType.Conceptual || renderType === RenderType.Physical2) { - obj.children.length = 1; - obj.children[0].material = ColorMaterial.GrayTransparentMeshMaterial; - } - else if (renderType !== RenderType.Wireframe) { - obj.material = ColorMaterial.GrayTransparentMeshMaterial; - } - } - if ((renderType === RenderType.Wireframe || renderType === RenderType.Conceptual) && userConfig.showLines && this.IsChaiDan) - obj.add(...this.GetLinesDir()); - if (this.Id) { - let o = this.Get2DAnd3DPaths(obj); - if (o.parent) - obj.children.push(o); - else - obj.add(o); - } - } - UpdateDrawObjectMaterial(renderType, obj) { - super.UpdateDrawObjectMaterial(renderType, obj); - if (!this.IsChaiDan) { - if (renderType === RenderType.Conceptual || renderType === RenderType.Physical2) { - obj.children[0].material = ColorMaterial.GrayTransparentMeshMaterial; - } - else if (renderType !== RenderType.Wireframe) { - obj.material = ColorMaterial.GrayTransparentMeshMaterial; - } - } - } - CheckSealing(obj) { - let sealingInfo = new Map(userConfig.sealingColorMap.filter(d => d[0] && d[1])); - if (sealingInfo.size === 0) - return; - let cus = GetBoardSealingCurves(this); - let highSeals = GetBoardHighSeal(this, cus); - for (let i = 0; i < cus.length; i++) { - let size = highSeals[i].size.toString(); - let color = sealingInfo.get(size); - if (color) { - cus[i].Position = cus[i].Position.add(new Vector3(0, 0, this.thickness / 2)); - let l = cus[i].GetDrawObjectFromRenderType(RenderType.Wireframe); - l.material = ColorMaterial.GetLineMaterial(parseFloat(color)); - obj.add(l); - } - } - } - GetStretchPoints() { - let pts = this.GetGripOrStretchPoints(DragPointType.Stretch); - for (let m of this._2DModelingList) { - pts.push(...m.path.GetStretchPoints().map(p => p.add(new Vector3(0, 0, m.dir === FaceDirection.Front ? this.thickness : 0)).applyMatrix4(this.OCS))); - } - return pts; - } - MoveStretchPoints(indexList, vec) { - let exCount = arraySum(this.GetStrectchPointCountList(DragPointType.Stretch)); - let originIndexList = []; - let mIndexList = []; - for (let i of indexList) { - if (i < exCount) - originIndexList.push(i); - else - mIndexList.push(i - exCount); - } - let oldOcs = this.OCS; - super.MoveStretchPoints(originIndexList, vec); - if (!this.Id) - return; - arraySortByNumber(mIndexList); - let localVec = vec.clone().applyMatrix4(this.OCSInv.setPosition(ZeroVec)); - let offset = 0; - let icount = mIndexList.length; - let i = 0; - for (let m of this._2DModelingList) { - let count = m.path.GetDragPointCount(DragPointType.Stretch); - offset += count; - let iList = []; - for (; i < icount; i++) { - if (mIndexList[i] < offset) - iList.push(mIndexList[i] - offset + count); - else - break; - } - if (iList.length > 0) { - m.path.MoveStretchPoints(iList, localVec); - } - m.path.ApplyMatrix(oldOcs).ApplyMatrix(this.OCSInv); - } - this.OffsetPathCache.clear(); - this._2D3DPathObject = null; - this.Update(UpdateDraw.Geometry); - } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { - let pts = super.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform); - if (snapMode === ObjectSnapMode.End) { - for (let vm of this._2DModelingList) { - if (!this.OffsetPathCache.has(vm.path)) - continue; - for (let item of vm.items) { - if (item.offset === 0) - continue; - let paths = this.OffsetPathCache.get(vm.path); - let polyline = paths[item.offset.toString()]; - let ps = polyline.GetStretchPoints(); - for (let p of ps) { - if (vm.dir === FaceDirection.Front) - p.add(new Vector3(0, 0, this.thickness)); - p.applyMatrix4(this.OCS); - } - pts.push(...ps); - } - } - } - return pts; - } - DeferUpdate() { - if (this.NeedUpdateFlag & UpdateDraw.Matrix) { - if (this.RelativeHardware.some(id => !id.IsErase)) - this.NeedUpdateFlag |= UpdateDraw.Geometry; - } - super.DeferUpdate(); - } - _ReadFile(file) { - super._ReadFile(file); - let ver = file.Read(); - if (ver < 6) - this._SpaceOCS.fromArray(file.Read()); - this._BoardType = file.Read(); - this._Name = file.Read(); - //兼容旧版本 - if (ver > 2) { - deserializationBoardData(file, this._BoardProcessOption, ver); - } - else { - let opt = file.Read(); - this._BoardProcessOption = Object.assign(this._BoardProcessOption, typeof opt === "string" ? JSON.parse(opt) : opt); - } - //读取排钻列表 - this._DrillList.clear(); - let size = file.Read(); - //没有与任何板件关联的排钻 - let noRelevancyDrillings = []; - for (let i = 0; i < size; i++) { - let id = file.ReadObjectId(); - let drIdList = []; - let count = file.Read(); - for (let i = 0; i < count; i++) { - let drIDs = []; - let count1 = file.Read(); - for (let j = 0; j < count1; j++) { - let fileId = file.ReadObjectId(); - fileId && drIDs.push(fileId); - } - if (drIDs.length > 0) - drIdList.push(drIDs); - } - if (drIdList.length === 0) - continue; - if (!id) - noRelevancyDrillings.push(...drIdList); - else - this._DrillList.set(id, drIdList); - } - if (noRelevancyDrillings.length > 0) - this._DrillList.set(undefined, noRelevancyDrillings); - if (ver > 1) { - this._LayerNails.length = 0; - let nailsCount = file.Read(); - for (let i = 0; i < nailsCount; i++) { - let objId = file.ReadObjectId(); - if (objId) - this._LayerNails.push(objId); - } - } - if (ver > 4) - this._Rotation = { x: file.Read(), y: file.Read(), z: file.Read() }; - if (ver >= 7) { - let count = file.Read(); - this.RelativeHardware.length = 0; - for (let i = 0; i < count; i++) { - let objId = file.ReadObjectId(); - if (objId) - this.RelativeHardware.push(objId); - } - } - if (ver >= 8) - this.OpenDir = file.Read(); - if (ver >= 9) - this._IsChaiDan = file.Read(); - if (ver >= 10) { - DeserializationBoard2DModeingData(file, this._2DModelingList); - DeserializationBoard3DModeingData(file, this._3DModelingList); - } - this.OffsetPathCache.clear(); - this._2D3DPathObject = null; - } - WriteFile(file) { - super.WriteFile(file); - file.Write(10); - // file.Write(this._SpaceOCS.toArray()); ver < 6 - file.Write(this._BoardType); - file.Write(this._Name); - serializeBoardData(file, this._BoardProcessOption); - file.Write(this._DrillList.size); - for (let [id, idList] of this._DrillList) { - file.WriteObjectId(id); - file.Write(idList.length); - for (let ids of idList) { - file.Write(ids.length); - for (let id of ids) - file.WriteObjectId(id); - } - } - file.Write(this._LayerNails.length); - for (let nail of this._LayerNails) { - file.WriteObjectId(nail); - } - file.Write(this._Rotation.x); - file.Write(this._Rotation.y); - file.Write(this._Rotation.z); - file.Write(this.RelativeHardware.length); - for (let id of this.RelativeHardware) - file.WriteObjectId(id); - file.Write(this.OpenDir); - file.Write(this._IsChaiDan); - SerializeBoard2DModeingData(file, this._2DModelingList); - SerializeBoard3DModeingData(file, this._3DModelingList); - } -}; -__decorate([ - AutoRecord -], Board.prototype, "RelativeHardware", void 0); -__decorate([ - AutoRecord -], Board.prototype, "OpenDir", void 0); -Board = Board_1 = __decorate([ - Factory -], Board); - -function FastWireframe(br, color = 0) { +function FastWireframe(br, color = 0) +{ color = color || br.ColorIndex; let material = ColorMaterial.GetLineMaterial(color); let thickness = br.Thickness; @@ -17630,7 +17857,8 @@ function FastWireframe(br, color = 0) { } return result; } -function FastWireframe2(dr, color = 0) { +function FastWireframe2(dr, color = 0) +{ color = color || dr.ColorIndex; let material = ColorMaterial.GetLineMaterial(color); let height = dr.Height; @@ -17660,12 +17888,14 @@ function FastWireframe2(dr, color = 0) { /** * 简化优化版本的曲线求交, 优化版本可以参考(算法导论33.2 确定任意一对线段是否相交 p599) */ -class CurveIntersection { +class CurveIntersection +{ /** * @param {Curve[]} cus 请注意数组的顺序会被更改,如果你在意数组的顺序,请拷贝数组后传进来 * @memberof CurveIntersection */ - constructor(cus, parseIntersectionParam = false, intType = IntersectOption.OnBothOperands, fuzz = 1e-6) { + constructor(cus, parseIntersectionParam = false, intType = IntersectOption.OnBothOperands, fuzz = 1e-6) + { this.fuzz = fuzz; //用来缓存的曲线包围盒 this.boxMap = new Map(); @@ -17703,10 +17933,12 @@ class CurveIntersection { } } } - IntersectWith2(c1, c2, intType) { + IntersectWith2(c1, c2, intType) + { return c1.IntersectWith2(c2, intType); } - AppendIntersectionParams(curve, params) { + AppendIntersectionParams(curve, params) + { let arr = this.intersect2.get(curve); if (!arr) { arr = []; @@ -17714,16 +17946,20 @@ class CurveIntersection { } arr.push(...params); } - GenBox(cus) { + GenBox(cus) + { for (let c of cus) this.boxMap.set(c, c.BoundingBox); } - SortCurve(cus) { - cus.sort((c1, c2) => { + SortCurve(cus) + { + cus.sort((c1, c2) => + { return this.boxMap.get(c1).min.x - this.boxMap.get(c2).min.x; }); } - GetIntersect(cu) { + GetIntersect(cu) + { if (this.intersect.has(cu)) return this.intersect.get(cu); let m = new Map(); @@ -17731,13 +17967,16 @@ class CurveIntersection { return m; } } -class CurveIntersection2 extends CurveIntersection { +class CurveIntersection2 extends CurveIntersection +{ /** * Curve2Polyline使用这个时,为了避免多余的交点导致曲线切割过度,过滤掉无关的点 */ - IntersectWith2(c1, c2, intType) { + IntersectWith2(c1, c2, intType) + { let pts = c1.IntersectWith2(c2, intType); - return pts.filter(p => { + return pts.filter(p => + { let inC1 = c1.ParamOnCurve(p.thisParam) || c1.StartPoint.distanceTo(p.pt) < this.fuzz || c1.EndPoint.distanceTo(p.pt) < this.fuzz; if (!inC1) return false; @@ -17750,7 +17989,8 @@ class CurveIntersection2 extends CurveIntersection { /** * 某些时候我们不能创建轮廓,此时我们使用类似c2r的方法来构建一个外部轮廓. */ -function CreateContour2(curves, fuzz = 1e-4) { +function CreateContour2(curves, fuzz = 1e-4) +{ for (let c of curves) if (c instanceof Circle) return Contour.CreateContour(c); @@ -17825,7 +18065,8 @@ function CreateContour2(curves, fuzz = 1e-4) { * @param [ignoreSpike=true] 忽略尖角优化(如果不忽略,那么尖角将会变钝(有点奇怪)) * @returns 偏移后的点表 */ -function FastOffset(contour, offsetDist = 1, ignoreSpike = true) { +function FastOffset(contour, offsetDist = 1, ignoreSpike = true) +{ let res = []; for (let i = 0; i < contour.length; i++) { let v = AsVector3(getBevelVec(contour[i], contour[FixIndex(i - 1, contour)], contour[FixIndex(i + 1, contour)])); @@ -17836,7 +18077,8 @@ function FastOffset(contour, offsetDist = 1, ignoreSpike = true) { return res; } //Ref:threejs ExtrudeGeometry源码 -function getBevelVec(inPt, inPrev, inNext, ignoreSpike = true) { +function getBevelVec(inPt, inPrev, inNext, ignoreSpike = true) +{ // computes for inPt the corresponding point inPt' on a new contour // shifted by 1 unit (length of normalized vector) to the left // if we walk along contour clockwise, this new contour is outside the old one @@ -17910,7 +18152,8 @@ function getBevelVec(inPt, inPrev, inNext, ignoreSpike = true) { } var DepthType; -(function (DepthType) { +(function (DepthType) +{ DepthType[DepthType["Front"] = 1] = "Front"; DepthType[DepthType["Back"] = 2] = "Back"; DepthType[DepthType["All"] = 3] = "All"; @@ -17919,8 +18162,10 @@ const ExtrudeBuildConfig = { bevel: false }; /** * 槽的几何数据,包括槽的墙面和槽的盖子 */ -class Groove { - constructor(contour, holes, depthType, depth, allDepth, box = contour.BoundingBox) { +class Groove +{ + constructor(contour, holes, depthType, depth, allDepth, box = contour.BoundingBox) + { this.depthType = depthType; this.depth = depth; this.allDepth = allDepth; @@ -17935,7 +18180,8 @@ class Groove { * @param groove this - groove * @param [eachOther=true] 相互裁剪 */ - ClipTo(groove, eachOther = true) { + ClipTo(groove, eachOther = true) + { //相同深度和面不用操作 if (groove.depthType === this.depthType && groove.depth === this.depth) return; @@ -17955,7 +18201,8 @@ class Groove { wall.ClipTo(this, false); } } - ClipLid(groove) { + ClipLid(groove) + { if (this.depthType === DepthType.All) return; if (groove.depthType === DepthType.All) @@ -17973,7 +18220,8 @@ class Groove { this.lid.SplitTo(groove.lid); } } - Draw(verticesArray, uvArray, edgeBuild, rotateUv) { + Draw(verticesArray, uvArray, edgeBuild, rotateUv) + { this.contourWall.Draw(verticesArray, uvArray, edgeBuild); for (let wall of this.holeWalls) wall.Draw(verticesArray, uvArray, edgeBuild); @@ -17983,7 +18231,8 @@ class Groove { this.lid.Draw(verticesArray, uvArray, isFront, isFront ? this.allDepth - this.depth : this.depth, rotateUv, this.allDepth); } } -function CreateTape(faceType, startParam, endParam, depth, allDepth) { +function CreateTape(faceType, startParam, endParam, depth, allDepth) +{ if (faceType === DepthType.Front) return new Tape(startParam, endParam, allDepth - depth, allDepth); else @@ -17991,21 +18240,26 @@ function CreateTape(faceType, startParam, endParam, depth, allDepth) { } //朝向类型 var DirectionType; -(function (DirectionType) { +(function (DirectionType) +{ DirectionType[DirectionType["Outer"] = 0] = "Outer"; DirectionType[DirectionType["Inner"] = 1] = "Inner"; //内墙 })(DirectionType || (DirectionType = {})); //轮廓树节点,用于重新确认外墙和网洞的关系 -class ContourTreeNode { - constructor(contour, children = []) { +class ContourTreeNode +{ + constructor(contour, children = []) + { this.contour = contour; this.children = children; } - SetParent(node) { + SetParent(node) + { this.parent = node; node.children.push(this); } - Draw(verticesArray, uvArray, front, z, rotateUv, allDepth) { + Draw(verticesArray, uvArray, front, z, rotateUv, allDepth) + { // TestDraw(this.contour.Curve, depth); let pts = this.contour.Curve.GetStretchPoints(); let isFace; @@ -18019,7 +18273,8 @@ class ContourTreeNode { } } let vertices = [...pts]; - let holes = this.children.map(h => { + let holes = this.children.map(h => + { // TestDraw(h.contour.Curve, depth + 1); let pts = h.contour.Curve.GetStretchPoints(); vertices.push(...pts); @@ -18038,7 +18293,8 @@ class ContourTreeNode { AddVertice(vertices[f[1]]); } } - function AddVertice(v, inz = z) { + function AddVertice(v, inz = z) + { verticesArray.push(v.x, v.y, inz); if (rotateUv) uvArray.push(v.y * 1e-3, v.x * 1e-3); @@ -18078,7 +18334,8 @@ class ContourTreeNode { } } } - static ParseContourTree(contourNodes) { + static ParseContourTree(contourNodes) + { contourNodes.sort((c1, c2) => c1.contour.Curve.Area - c2.contour.Curve.Area); for (let i = 0; i < contourNodes.length; i++) { const node1 = contourNodes[i]; @@ -18094,14 +18351,17 @@ class ContourTreeNode { } } } -class EdgeGeometryBuild { - constructor(allDepth) { +class EdgeGeometryBuild +{ + constructor(allDepth) + { this.allDepth = allDepth; this.lineVerticesArray = []; this.frontLines = []; this.backLines = []; } - AddLidLine(p1, p2, depth) { + AddLidLine(p1, p2, depth) + { if (depth === 0) { p1 = p1.clone().setZ(0); p2 = p2.clone().setZ(0); @@ -18115,7 +18375,8 @@ class EdgeGeometryBuild { this.frontLines.push(line); } } - BuildLid(verticesArray, uvArray, rotateUv) { + BuildLid(verticesArray, uvArray, rotateUv) + { var _a; let arr = [this.backLines, this.frontLines]; for (let index = 0; index < 2; index++) { @@ -18143,25 +18404,30 @@ class EdgeGeometryBuild { /** * 胶带 */ -class Tape { - constructor(start, end, bottom, top) { +class Tape +{ + constructor(start, end, bottom, top) + { this.start = start; this.end = end; this.bottom = bottom; this.top = top; } //用于测试 - get Curve() { + get Curve() + { return new Polyline().RectangleFrom2Pt(new Vector3(this.start, this.bottom), new Vector3(this.end, this.top)); } - Clip(t) { + Clip(t) + { let yr = IntersectRange(this.bottom, this.top, t.bottom, t.top, 1e5); if (yr === undefined) return [this]; let xr = IntersectRange(this.start, this.end, t.start, t.end, 1e5); if (xr === undefined) return [this]; - let rem = SubtractRange(this.start, this.end, t.start, t.end, 1e5).map(r => { + let rem = SubtractRange(this.start, this.end, t.start, t.end, 1e5).map(r => + { return new Tape(r[0], r[1], this.bottom, this.top); }); let remR = SubtractRange(this.bottom, this.top, t.bottom, t.top, 1e5); @@ -18170,7 +18436,8 @@ class Tape { } return rem; } - Split(xlst) { + Split(xlst) + { let ret = []; let pre = this.start; for (let x of xlst) { @@ -18191,20 +18458,24 @@ class Tape { /** * 二维形状,内部用曲线胶带表示(用来计算盖子差集算法) */ -class CurveTapeShape { - constructor(contour, holes) { +class CurveTapeShape +{ + constructor(contour, holes) + { this.children = []; this.contour = new CurveTape(contour, DirectionType.Outer); this.holes = holes.map(h => new CurveTape(h, DirectionType.Inner)); } - CloneNew() { + CloneNew() + { let s = new CurveTapeShape(this.contour.contour, this.holes.map(h => h.contour)); return s; } /** * 删除包含,同向 */ - ClipTo(s, append = false) { + ClipTo(s, append = false) + { for (let c of [this.contour, ...this.holes]) if (c.tapes.length > 0) c.ClipTo(s); @@ -18215,7 +18486,8 @@ class CurveTapeShape { } } //合理打断(以保证三维网格对齐(否则圆弧点将无法正确的对齐)) - SplitTo(s) { + SplitTo(s) + { for (let c of [this.contour, ...this.holes]) { for (let c2 of [s.contour, ...s.holes]) { let int = GetIntersection(c.contour.Curve, c2.contour.Curve); @@ -18226,13 +18498,15 @@ class CurveTapeShape { /** * 只保留被包含部分 */ - ReverseClipTo(s) { + ReverseClipTo(s) + { for (let c of [this.contour, ...this.holes]) if (c.tapes.length > 0) c.ReverseClipTo(s); return this; } - ChildrenClip() { + ChildrenClip() + { for (let i = 0; i < this.children.length; i++) { let s1 = this.children[i]; for (let j = i + 1; j < this.children.length; j++) { @@ -18242,7 +18516,8 @@ class CurveTapeShape { } } } - Draw(verticesArray, uvArray, front, z, rotateUv, allDepth) { + Draw(verticesArray, uvArray, front, z, rotateUv, allDepth) + { this.ChildrenClip(); let polylines = this.contour.Curves; for (let h of this.holes) @@ -18275,7 +18550,8 @@ class CurveTapeShape { const SplitLength = 4; const MinSplitCount = 12; const MaxSplitCount = 360; -function SplitCurveParams(cu) { +function SplitCurveParams(cu) +{ let xparams = []; if (cu instanceof Circle) { let splitCount = cu.Radius / SplitLength; @@ -18315,14 +18591,17 @@ function SplitCurveParams(cu) { /** * 曲线胶带(一维) */ -class CurveTape { - constructor(contour, wallType) { +class CurveTape +{ + constructor(contour, wallType) + { this.contour = contour; this.wallType = wallType; this.splitParams = []; this.tapes = [[0, this.contour.Curve.EndParam]]; } - get Curves() { + get Curves() + { let xparams = SplitCurveParams(this.contour.Curve); if (this.splitParams.length > 0) { xparams.push(...this.splitParams); @@ -18330,10 +18609,12 @@ class CurveTape { arrayRemoveDuplicateBySort(xparams, (p1, p2) => equaln(p1, p2)); } let polylines = []; - function TD(p) { + function TD(p) + { return { pt: AsVector2(p), bul: 0 }; } - const addPolyline = (t) => { + const addPolyline = (t) => + { let pts = [TD(this.contour.Curve.GetPointAtParam(t[0]))]; for (let x of xparams) { if (x <= t[0]) @@ -18359,7 +18640,8 @@ class CurveTape { /** * 分析与另一个形状的包含关系 */ - Parse(s) { + Parse(s) + { let [res1] = ParseCurveParamRangeRelation(this.contour.Curve, s.contour.contour.Curve); if (this.wallType === DirectionType.Inner) [res1.syntropy, res1.reverse] = [res1.reverse, res1.syntropy]; @@ -18380,7 +18662,8 @@ class CurveTape { /** * 删除包含,同向面 */ - ClipTo(s) { + ClipTo(s) + { let d = this.Parse(s); this.tapes = SubtractRanges(this.tapes, d.container, this.contour.Curve.EndParam); this.tapes = SubtractRanges(this.tapes, d.syntropy, this.contour.Curve.EndParam); @@ -18389,13 +18672,16 @@ class CurveTape { /** * 保留被包含的部分 */ - ReverseClipTo(s) { + ReverseClipTo(s) + { this.tapes = this.Parse(s).container; return this; } } -class ExtudeWall { - constructor(curve, depthType, depth, allDepth, wallType) { +class ExtudeWall +{ + constructor(curve, depthType, depth, allDepth, wallType) + { this.curve = curve; this.depthType = depthType; this.depth = depth; @@ -18409,7 +18695,8 @@ class ExtudeWall { * @param groove this - groove * @param [clipSyntropy=false] 删除同向的面 */ - ClipTo(groove, clipSyntropy = false) { + ClipTo(groove, clipSyntropy = false) + { let [res1] = ParseCurveParamRangeRelation(this.curve, groove.contourWall.curve); if (this.wallType !== groove.contourWall.wallType) [res1.syntropy, res1.reverse] = [res1.reverse, res1.syntropy]; @@ -18439,7 +18726,8 @@ class ExtudeWall { for (let c of params) this.ClipFromParam(c[0], c[1], groove.depthType, groove.depth); } - ClipReverse(wall) { + ClipReverse(wall) + { let [res1] = ParseCurveParamRangeRelation(this.curve, wall.curve); for (let c of res1.syntropy) this.ClipFromParam(c[0], c[1], wall.depthType, wall.depth); @@ -18452,7 +18740,8 @@ class ExtudeWall { * @param faceType 裁剪面朝向 * @param depth 裁剪面的深度 */ - ClipFromParam(startParam, endParam, faceType, depth) { + ClipFromParam(startParam, endParam, faceType, depth) + { if (equaln(startParam, endParam)) return; if (startParam > endParam) { @@ -18467,15 +18756,17 @@ class ExtudeWall { this.Tape = taps; return this; } - Draw(verticesArray, uvArray, edgeBuild) { + Draw(verticesArray, uvArray, edgeBuild) + { let xparams = SplitCurveParams(this.curve); let isOuter = this.wallType === DirectionType.Outer; let allDepth = this.allDepth; - function AddVertice(v) { + function AddVertice(v) + { verticesArray.push(v.x); verticesArray.push(v.y); if (isOuter && ExtrudeBuildConfig.bevel) //如果倒角,则执行下面的代码 - { + { if (v.z === 0) verticesArray.push(1); else if (v.z === allDepth) @@ -18527,7 +18818,8 @@ class ExtudeWall { //#endregion //和X平行平行 let isXPar = (vs[0].y + vs[1].y + vs[2].y) < 0.01; - function AddUv(p) { + function AddUv(p) + { if (isXPar) uvArray.push((p.z - 1) * 1e-3, p.y * 1e-3); else @@ -18567,7 +18859,8 @@ class ExtudeWall { /** * 分析两个曲线关系(包含,分离,同向共线,反向共线)(用参数范围表示) */ -function ParseCurveParamRangeRelation(cu1, cu2, reverseParse = false) { +function ParseCurveParamRangeRelation(cu1, cu2, reverseParse = false) +{ let ins = GetIntersection(cu1, cu2); let c1Res = { container: [], syntropy: [], reverse: [], outer: [] }; let c2Res = { container: [], syntropy: [], reverse: [], outer: [] }; @@ -18653,7 +18946,8 @@ function ParseCurveParamRangeRelation(cu1, cu2, reverseParse = false) { } return [c1Res, c2Res]; } -function CenterPoint(cu, start, end) { +function CenterPoint(cu, start, end) +{ let lenStart = cu.GetDistAtParam(start); let lenEnd = cu.GetDistAtParam(end); if (end > start) @@ -18673,7 +18967,8 @@ function CenterPoint(cu, start, end) { // UnionRange(0.8, 0.1, 0.3, 0.5, 1);//? // //[ 0.3, 0.10000000000000009 ] ]  // UnionRange(0.8, 0.1, 0.3, 0.9, 1);//? -function SubtractRange(a, b, c, d, end) { +function SubtractRange(a, b, c, d, end) +{ if (a < 0 || b < 0) return []; if (a > b) @@ -18688,7 +18983,7 @@ function SubtractRange(a, b, c, d, end) { if (c >= b || d <= a) return [[a, b]]; if (c <= a) // c1 a1 b1 - { + { if (d >= b) return []; return [[d, b]]; @@ -18697,10 +18992,12 @@ function SubtractRange(a, b, c, d, end) { return [[a, c], [d, b]]; return [[a, c]]; } -function SubtractRange2(r, sr, end) { +function SubtractRange2(r, sr, end) +{ return SubtractRange(r[0], r[1], sr[0], sr[1], end); } -function SubtractRanges(ranges, subRanges, end) { +function SubtractRanges(ranges, subRanges, end) +{ let rets = ranges; for (let sr of subRanges) { let temps = []; @@ -18710,7 +19007,8 @@ function SubtractRanges(ranges, subRanges, end) { } return rets; } -function IntersectRange(a, b, c, d, end) { +function IntersectRange(a, b, c, d, end) +{ let b1 = b < a ? b + end : b; let d1 = d < c ? d + end : d; let a1 = a; @@ -18722,16 +19020,18 @@ function IntersectRange(a, b, c, d, end) { return [c1, Math.min(b1, d1)]; } const alMatrix4 = new Matrix4; -class ExtrudeGeometryBuilder { - constructor(br) { +class ExtrudeGeometryBuilder +{ + constructor(br) + { this.br = br; this.verticesArray = []; //用于构建三维网格 this.uvArray = []; //uv this.GenerateMeshData(br); } - GenerateMeshData(br) { + GenerateMeshData(br, rotateUv) + { this.edgeAndLidBuilder = new EdgeGeometryBuild(this.br.Thickness); - let rotateUv = (br instanceof Board && br.BoardProcessOption.lines === LinesType.Reverse); //计算墙(创建轮廓取出,为了得到正确的轮廓曲线(逆时针之类的)) let outerWall = new ExtudeWall(Contour.CreateContour(br.ContourCurve.Clone()).Curve, DepthType.All, br.Thickness, br.Thickness, DirectionType.Outer); let grooves = this.ParseGrooves(); @@ -18750,19 +19050,22 @@ class ExtrudeGeometryBuilder { this.edgeAndLidBuilder.BuildLid(this.verticesArray, this.uvArray, rotateUv); intCache.clear(); } - get MeshGeometry() { + get MeshGeometry() + { let geo = new BufferGeometry(); geo.setAttribute('position', new Float32BufferAttribute(this.verticesArray, 3)); geo.setAttribute('uv', new Float32BufferAttribute(this.uvArray, 2)); geo.computeVertexNormals(); return geo; } - get EdgeGeometry() { + get EdgeGeometry() + { let geo = new BufferGeometry(); geo.setAttribute('position', new Float32BufferAttribute(this.edgeAndLidBuilder.lineVerticesArray, 3)); return geo; } - ParseGrooves() { + ParseGrooves() + { let br = this.br; const brOcsInv = br.OCSInv; let grooves = []; @@ -18802,7 +19105,8 @@ class ExtrudeGeometryBuilder { } } let intCache = new Map(); -function GetIntersection(cu1, cu2) { +function GetIntersection(cu1, cu2) +{ let m = intCache.get(cu1); if (m) { let r = m.get(cu2); @@ -18820,7 +19124,8 @@ function GetIntersection(cu1, cu2) { d.argParam = MathUtils.clamp(d.argParam, 0, cu2EndParam); } m.set(cu2, r); - let r2 = r.map(r => { + let r2 = r.map(r => + { return { thisParam: r.argParam, argParam: r.thisParam, pt: r.pt }; }); let m2 = intCache.get(cu2); @@ -18833,8 +19138,10 @@ function GetIntersection(cu1, cu2) { } var ExtrudeSolid_1; -let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { - constructor() { +let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity +{ + constructor() + { super(); /* ------------ @@ -18863,35 +19170,44 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.groovesAddLength = 0; this.groovesAddWidth = 0; this.groovesAddDepth = 0; - this.RelevanceKnifs = this.CreateProxyArray((v) => { + this.RelevanceKnifs = this.CreateProxyArray((v) => + { //可以更新自己,但是不建议,建议手动更新 }); - this.RelevanceMeats = this.CreateProxyArray((v) => { + this.RelevanceMeats = this.CreateProxyArray((v) => + { //可以更新肉,简单是不建议,建议手动更新 }); } - get KnifeRadius() { + get KnifeRadius() + { return this.knifeRadius; } - set KnifeRadius(v) { + set KnifeRadius(v) + { if (!equaln(v, this.knifeRadius)) { this.WriteAllObjectRecord(); this.knifeRadius = v; } } - get BoundingBox() { + get BoundingBox() + { return this.BoundingBoxInOCS.applyMatrix4(this.OCS); } - get BoundingBoxInOCS() { + get BoundingBoxInOCS() + { return new Box3Ext(new Vector3(), new Vector3(this.width, this.height, this.thickness)); } - get OBB() { + get OBB() + { return new OBB(this.OCS, new Vector3(this.width, this.height, this.thickness).multiplyScalar(0.5)); } - get GroovesAddLength() { + get GroovesAddLength() + { return this.groovesAddLength; } - set GroovesAddLength(v) { + set GroovesAddLength(v) + { if (!equaln(v, this.groovesAddLength)) { this.WriteAllObjectRecord(); this.groovesAddLength = v; @@ -18899,10 +19215,12 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.__UpdateVersion__++; } } - get GroovesAddWidth() { + get GroovesAddWidth() + { return this.groovesAddWidth; } - set GroovesAddWidth(v) { + set GroovesAddWidth(v) + { if (!equaln(v, this.groovesAddWidth)) { this.WriteAllObjectRecord(); this.groovesAddWidth = v; @@ -18910,10 +19228,12 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.__UpdateVersion__++; } } - get GroovesAddDepth() { + get GroovesAddDepth() + { return this.groovesAddDepth; } - set GroovesAddDepth(v) { + set GroovesAddDepth(v) + { if (!equaln(v, this.groovesAddDepth)) { this.WriteAllObjectRecord(); this.groovesAddDepth = v; @@ -18921,11 +19241,13 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.__UpdateVersion__++; } } - Clone() { + Clone() + { let en = super.Clone(); return en; } - ApplyMatrix(m) { + ApplyMatrix(m) + { //暂时关闭更新,避免内部实体还没有更新位置时,先更新了实体的Geometry,导致后续没有进行更新 let updateBak = this.AutoUpdate; this.AutoUpdate = false; @@ -18941,7 +19263,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.DeferUpdate(); return this; } - ApplyScaleMatrix(m) { + ApplyScaleMatrix(m) + { this.WriteAllObjectRecord(); let cu = this.ContourCurve; cu.ApplyMatrix(this.OCS); @@ -18950,10 +19273,12 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.CheckContourCurve(); return this; } - get Position() { + get Position() + { return super.Position; } - set Position(p) { + set Position(p) + { let v = p.clone().sub(this.Position); if (equalv3(v, ZeroVec)) return; @@ -18964,16 +19289,20 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { //由于修改矩阵会导致bsp错误 this.csg = undefined; } - get Width() { + get Width() + { return this.width; } - get Height() { + get Height() + { return this.height; } - get Thickness() { + get Thickness() + { return this.thickness; } - set Thickness(thickness) { + set Thickness(thickness) + { if (!equaln(thickness, this.thickness, 1e-3)) { this.WriteAllObjectRecord(); if (this.grooves.length > 0) { @@ -18992,24 +19321,28 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.Update(UpdateDraw.Geometry); } } - get Grooves() { + get Grooves() + { return this.grooves; } /** * 返回未拷贝的轮廓曲线 */ - get ContourCurve() { + get ContourCurve() + { if (!this.contourCurve) this.GeneralRectContour(); return this.contourCurve; } - set ContourCurve(cu) { + set ContourCurve(cu) + { this.SetContourCurve(cu); } /** * 生成矩形轮廓(强制) */ - GeneralRectContour() { + GeneralRectContour() + { if (!this.contourCurve || !(this.contourCurve instanceof Polyline)) this.contourCurve = new Polyline(); this.contourCurve.Rectangle(this.width, this.height); @@ -19019,7 +19352,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { /** * 转换成矩形拉伸实体 */ - ConverToRectSolid(width = this.width, height = this.height, thickness = this.thickness) { + ConverToRectSolid(width = this.width, height = this.height, thickness = this.thickness) + { this.WriteAllObjectRecord(); this.height = height; this.width = width; @@ -19032,7 +19366,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { * 更新拉伸实体的轮廓 * @param curve 曲线已经存在WCS坐标系 */ - SetContourCurve(curve) { + SetContourCurve(curve) + { if (!curve.IsClose) return; let area = curve.Area; @@ -19050,7 +19385,7 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { let isMirror = equaln(ocs.elements[10], -1, 1e-4); let isRotate = !equaln(ocs.elements[0], 1); if (isMirror || isRotate) // || ocs.elements[9] || ocs.elements[10] - { + { for (let p of pts) { Vector2ApplyMatrix4(ocs, p.pt); if (isMirror) @@ -19072,7 +19407,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { * 在不改变Normal和实体显示的情况下,修改X轴的指向 * @param xAxis */ - SetXAxis(xAxis) { + SetXAxis(xAxis) + { let m = this.OCSInv.setPosition(ZeroVec); let x = xAxis.applyMatrix4(m).setZ(0).normalize(); if (equalv3(ZeroVec, x)) @@ -19102,7 +19438,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { * >判断是否矩形 * >修正轮廓基点 */ - CheckContourCurve() { + CheckContourCurve() + { let box = this.ContourCurve.BoundingBox; let size = box.getSize(new Vector3()); this.width = size.x; @@ -19118,13 +19455,15 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this._Matrix.setPosition(this.Position.add(v)); } } - get IsRect() { + get IsRect() + { return this.isRect; } /** * 这个拉伸实体的面域形状 */ - get Shape() { + get Shape() + { let contour = Contour.CreateContour(this.ContourCurve.Clone(), false); let holes = []; for (let g of this.grooves) { @@ -19136,7 +19475,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { /** * 实体合并(不会删除target) */ - Join(target) { + Join(target) + { let [n, tn] = [this.Normal, target.Normal]; if (!isParallelTo(n, tn)) return Status.False; @@ -19144,7 +19484,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { let targetZMin = target.Position.applyMatrix4(this.OCSInv).z; let targetZMax = targetZMin + target.Thickness * (isEqualNorm ? 1 : -1); [targetZMin, targetZMax] = arraySortByNumber([targetZMin, targetZMax]); - const MergeRelevance = () => { + const MergeRelevance = () => + { if (!this.Id || !target.Id) return; for (let kf of target.RelevanceKnifs) { @@ -19211,7 +19552,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { } return Status.False; } - get Volume() { + get Volume() + { let sum = this.ContourCurve.Area * this.thickness; for (let g of this.grooves) sum -= g.Volume; @@ -19224,7 +19566,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { * @param [checkIntersect=true] 检查相交,性能优化 * @returns 切割是否成功 */ - Subtract(extrudes, output = undefined, checkIntersect = true) { + Subtract(extrudes, output = undefined, checkIntersect = true) + { if (checkIntersect) { let box = this.BoundingBox; extrudes = extrudes.filter(e => box.intersectsBox(e.BoundingBox)); @@ -19261,7 +19604,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { } return false; } - RelevanceSubtract(knif, check = false) { + RelevanceSubtract(knif, check = false) + { if (!this.Id || !knif.Id) return; //判断是否已经存在 @@ -19276,7 +19620,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { /** * 当实体被分裂后,加入新图纸时,需要修复关联拉槽 */ - RepairRelevance() { + RepairRelevance() + { if (!this.Id) { console.error("不能修复未加入到图纸的板件!"); return; @@ -19294,21 +19639,24 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { } } } - AppendGroove(groove) { + AppendGroove(groove) + { this.WriteAllObjectRecord(); this.grooves.push(groove); } /** 添加槽进板件,并且自动分裂. * 通常槽已经校验过准确性,所以不在校验 */ - AppendGrooves(grooves, output = undefined) { + AppendGrooves(grooves, output = undefined) + { if (grooves.length === 0) return; this.WriteAllObjectRecord(); this.grooves.push(...grooves); this.GrooveCheckAllAutoSplit(output); } - GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) { + GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) + { switch (snapMode) { case ObjectSnapMode.End: return this.GetStretchPoints(); @@ -19338,7 +19686,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { return []; } //#region Stretch - GetStrectchPointCountList(dragType) { + GetStrectchPointCountList(dragType) + { let counts = [this.ContourCurve.GetDragPointCount(dragType) * 2]; for (let g of this.grooves) { let c = g.ContourCurve.GetDragPointCount(dragType) * 2; @@ -19348,7 +19697,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { } return counts; } - GetGripOrStretchPoints(dragType) { + GetGripOrStretchPoints(dragType) + { let isGrip = dragType === DragPointType.Grip; let pts = isGrip ? this.ContourCurve.GetGripPoints() : this.ContourCurve.GetStretchPoints(); let v = new Vector3(0, 0, this.thickness); @@ -19360,7 +19710,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { } return pts; } - MoveGripOrStretchPoints(indexList, vec, dragType) { + MoveGripOrStretchPoints(indexList, vec, dragType) + { this.WriteAllObjectRecord(); let counts = this.GetStrectchPointCountList(dragType); if (dragType === DragPointType.Stretch && indexList.length === arraySum(counts)) { @@ -19409,22 +19760,27 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.AutoUpdate = updateBak; this.Update(); } - GetGripPoints() { + GetGripPoints() + { return this.GetGripOrStretchPoints(DragPointType.Grip); } - MoveGripPoints(indexList, vec) { + MoveGripPoints(indexList, vec) + { this.MoveGripOrStretchPoints(indexList, vec, DragPointType.Grip); } - GetStretchPoints() { + GetStretchPoints() + { return this.GetGripOrStretchPoints(DragPointType.Stretch); } - MoveStretchPoints(indexList, vec) { + MoveStretchPoints(indexList, vec) + { this.MoveGripOrStretchPoints(indexList, vec, DragPointType.Stretch); } /** * 只对自身的轮廓和厚度进行拉伸,忽略子实体 */ - MoveGripOrStretchPointsOnly(indexList, vec, dragType) { + MoveGripOrStretchPointsOnly(indexList, vec, dragType) + { let stretchCount = this.ContourCurve.GetDragPointCount(dragType); if (dragType === DragPointType.Stretch) { //Move @@ -19483,7 +19839,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { else this.ContourCurve.MoveStretchPoints(indexList, localVec); } - IsStretchThickness(indexs) { + IsStretchThickness(indexs) + { let count = this.ContourCurve.GetStretchPoints().length; if (indexs.length === count) { let isF = indexs[0] < count; @@ -19491,7 +19848,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { } return false; } - get CSG() { + get CSG() + { if (this.csg) return this.csg; this.csg = Geometry2CSG(this.MeshGeometry); @@ -19503,7 +19861,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { * @param target 该对象可能被修改(内部不拷贝该实体) * @param useClone 转换后的实体是目标实体拷贝后修改的 */ - ConverToLocalGroove(target) { + ConverToLocalGroove(target) + { if (!this.OBB.intersectsOBB(target.OBB)) return []; let n1 = this.Normal; @@ -19625,14 +19984,15 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { * (步骤2) * 更新凹槽位置和厚度(校验凹槽的Z轴位置是否存在交集) */ - GrooveCheckPosition(target) { + GrooveCheckPosition(target) + { if (target.Width < 1e-2 || target.Height < 1e-2 || target.Thickness < 1e-2) return Status.False; let tp = target.Position.applyMatrix4(this.OCSInv); let minZ = tp.z; let maxZ = tp.z + target.thickness; if (minZ <= 1e-2) //背面 - { + { target.Thickness = Math.min(maxZ, this.thickness); if (!(equaln(minZ, 0))) target.ApplyMatrix(MoveMatrix(this.Normal.multiplyScalar(-minZ))); @@ -19649,13 +20009,15 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { * (步骤3) * 计算凹槽合并 */ - GrooveCheckMerge() { + GrooveCheckMerge() + { let gs = []; while (this.grooves.length > 0) { let g = this.grooves.pop(); while (this.grooves.length > 0) { //剩余的 无法合并的板件 - let remGs = this.grooves.filter(gn => { + let remGs = this.grooves.filter(gn => + { if (equaln(g.knifeRadius, gn.knifeRadius)) return g.Join(gn) === Status.False; else @@ -19679,7 +20041,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { * @param target 不拷贝修改 * @returns this[] 凹槽在本实体中正确的约束状态.(可能分裂成为多个) */ - GrooveCheckContour(target) { + GrooveCheckContour(target) + { let matrixToTarget = target.OCSInv.multiply(this.OCS); matrixToTarget.elements[14] = 0; //z->0 let thisShape = this.Shape.ApplyMatrix(matrixToTarget); @@ -19708,12 +20071,14 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { * @param splitEntitys 分裂出来的实体 * @returns [Status] Status : 消失不见 */ - ContourCheckSubtract(splitEntitys) { + ContourCheckSubtract(splitEntitys) + { let shapeManager = new ShapeManager(); shapeManager.AppendShapeList(new Shape(Contour.CreateContour(this.ContourCurve.Clone(), false))); let subtractShape = new ShapeManager(); let grooves = []; - arrayRemoveIf(this.grooves, groove => { + arrayRemoveIf(this.grooves, groove => + { if (equaln(groove.thickness, this.thickness)) { let grooveCurve = groove.ContourCurve.Clone(); let matrixToLocal = this.OCSInv.multiply(groove.OCS); @@ -19768,7 +20133,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { * 无法知道修改了内部凹槽之后是否会更新到轮廓. * 所以默认全部校验内部的凹槽 */ - GrooveCheckAll(splitEntitys) { + GrooveCheckAll(splitEntitys) + { if (this.IsLazyGrooveCheck) { this.IsNeedGrooveCheck = true; return; @@ -19776,7 +20142,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.IsNeedGrooveCheck = false; this.WriteAllObjectRecord(); //校验Z轴位置 - arrayRemoveIf(this.grooves, g => { + arrayRemoveIf(this.grooves, g => + { return this.GrooveCheckPosition(g) === Status.False; }); //清除全深洞的子槽 @@ -19837,7 +20204,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.Update(); } /** 校验内部槽并且自动分裂 */ - GrooveCheckAllAutoSplit(output = undefined) { + GrooveCheckAllAutoSplit(output = undefined) + { let splitEntitys = []; this.GrooveCheckAll(splitEntitys); if (output) @@ -19852,14 +20220,16 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { } } HandleSpliteEntitys(splitEntitys) { } - LazyGrooveCheckAll() { + LazyGrooveCheckAll() + { if (this.IsNeedGrooveCheck) this.GrooveCheckAllAutoSplit(); this.IsLazyGrooveCheck = false; } //#endregion //#region Draw - GetPrintObject3D() { + GetPrintObject3D() + { let geometry = new LineGeometry(); let lineSegments = new Float32Array(this.EdgeGeometry.attributes.position.array); let instanceBuffer = new InstancedInterleavedBuffer(lineSegments, 6, 1); @@ -19869,7 +20239,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { let mesh = new Mesh(this.MeshGeometry, ColorMaterial.GetPrintConceptualMaterial()); return [line, mesh]; } - InitDrawObject(renderType = RenderType.Wireframe) { + InitDrawObject(renderType = RenderType.Wireframe) + { if (renderType === RenderType.Wireframe) { return new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(this.ColorIndex)); } @@ -19895,10 +20266,12 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { return new Object3D().add(mesh, new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(7))); } } - get UCGenerator() { + get UCGenerator() + { return boardUVGenerator; } - get NeedUpdateRelevanceGroove() { + get NeedUpdateRelevanceGroove() + { if (!this.__CacheKnifVersion__) return true; for (let k of this.RelevanceKnifs) { @@ -19912,7 +20285,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { /** * 计算关联拉槽,更新绘制对象(MeshGeometry和EdgeGeometry) */ - CalcRelevanceGroove() { + CalcRelevanceGroove() + { var _a, _b, _c, _d, _e, _f; //避免Jig实体更新,导致性能暴跌. if (!this.Id) @@ -19983,14 +20357,16 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { /** * 如果实体被切割,那么将返回分裂的实体数组,否则返回自身 */ - get SplitExtrudes() { + get SplitExtrudes() + { if (this.NeedUpdateRelevanceGroove) this.Update(UpdateDraw.Geometry); //我们先直接更新绘制 if (this.NeedUpdateRelevanceGroove) //如果更新失败,那么我们更新这个槽(似乎也证明了我们没有绘制实体) this.CalcRelevanceGroove(); //注意,这也将更新绘制的实体(EdgeGeo,MeshGeo)(如果拆单也用这个,可能会带来性能损耗) return this.__CacheSplitExtrudes; } - GetRelevanceKnifes(knifs) { + GetRelevanceKnifes(knifs) + { var _a; for (let e of this.RelevanceKnifs) { if (!e.IsErase) @@ -19999,7 +20375,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.__CacheKnifVersion__[e.Index] = (_a = e === null || e === void 0 ? void 0 : e.Object) === null || _a === void 0 ? void 0 : _a.__UpdateVersion__; } } - ClearRelevance(en) { + ClearRelevance(en) + { if (en) { let oldLen = this.RelevanceKnifs.length; arrayRemoveIf(this.RelevanceKnifs, id => !(id === null || id === void 0 ? void 0 : id.Object) || id.Index === en.Id.Index); @@ -20028,7 +20405,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { } this.Update(); } - get MeshGeometry() { + get MeshGeometry() + { if (this._MeshGeometry) return this._MeshGeometry; if (this.thickness <= 0) @@ -20069,7 +20447,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.UpdateUV(null, null); return this._MeshGeometry; } - get EdgeGeometry() { + get EdgeGeometry() + { if (this._EdgeGeometry) return this._EdgeGeometry; this.CalcRelevanceGroove(); @@ -20105,7 +20484,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this.MeshGeometry; return this._EdgeGeometry; } - UpdateUV(geo, ocs, isRev = false) { + UpdateUV(geo, ocs, isRev = false) + { var _a; let mat; if (this.Material && this.Material.Object) @@ -20123,7 +20503,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { ScaleUV(geo); } } - UpdateBufferGeometryUvs(isRev) { + UpdateBufferGeometryUvs(isRev) + { let uvs = this._MeshGeometry.attributes.uv; for (let i = 0; i < uvs.count; i++) { let x = uvs.getX(i) * 1e3; @@ -20134,7 +20515,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { uvs.setXY(i, x / this.width, y / this.height); } } - DeferUpdate() { + DeferUpdate() + { if (this.NeedUpdateFlag & UpdateDraw.Matrix) { //如果是Jig实体,那么就算它有关联切割,我们也不更新实体(因为似乎没必要?) if (this.Id && this.RelevanceKnifs.some(id => !id.IsErase)) @@ -20142,7 +20524,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { } super.DeferUpdate(); } - UpdateDrawGeometry() { + UpdateDrawGeometry() + { this.csg = undefined; if (this._EdgeGeometry) this._EdgeGeometry.dispose(); @@ -20151,7 +20534,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { this._MeshGeometry.dispose(); this._MeshGeometry = undefined; } - UpdateDrawObject(renderType, obj) { + UpdateDrawObject(renderType, obj) + { DisposeThreeObj(obj); Object3DRemoveAll(obj); if (renderType === RenderType.Wireframe) { @@ -20180,7 +20564,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { return obj.add(mesh, new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(7))); } } - UpdateDrawObjectMaterial(renderType, obj) { + UpdateDrawObjectMaterial(renderType, obj) + { if (renderType === RenderType.Wireframe) { let l = obj; l.material = ColorMaterial.GetLineMaterial(this.ColorIndex); @@ -20198,22 +20583,26 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { mesh.material = this.MeshMaterial; } } - UpdateJigMaterial(color = 8) { + UpdateJigMaterial(color = 8) + { } //#endregion //#region -------------------------File------------------------- /** * 简化的文件读取和写入,只写入必要的数据,没有id,没有其他版本号 */ - ReadFileLite(file) { + ReadFileLite(file) + { this.ReadFileOnly(file); this._Matrix.fromArray(file.Read()); } - WriteFileLite(file) { + WriteFileLite(file) + { this.WriteFileOnly(file); file.Write(this._Matrix.toArray()); } - ReadFileOnly(file) { + ReadFileOnly(file) + { let ver = file.Read(); this.height = Number(file.Read()); this.width = Number(file.Read()); @@ -20250,7 +20639,8 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { } } } - WriteFileOnly(file) { + WriteFileOnly(file) + { file.Write(3); file.Write(this.height); file.Write(this.width); @@ -20273,12 +20663,14 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { file.WriteSoftObjectId(id); } //对象从文件中读取数据,初始化自身 - _ReadFile(file) { + _ReadFile(file) + { super._ReadFile(file); this.ReadFileOnly(file); } //对象将自身数据写入到文件. - WriteFile(file) { + WriteFile(file) + { super.WriteFile(file); this.WriteFileOnly(file); } @@ -20286,13 +20678,15 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity { ExtrudeSolid = ExtrudeSolid_1 = __decorate([ Factory ], ExtrudeSolid); -function FastMeshGeometry(width, height, thickness) { +function FastMeshGeometry(width, height, thickness) +{ let geo = new BoxGeometry(width, height, thickness); geo.translate(width * 0.5, height * 0.5, thickness * 0.5); return geo; } CADFactory.RegisterObjectAlias(ExtrudeSolid, "ExtureSolid"); -function ProjectBoard(knifBoard, projectBoard) { +function ProjectBoard(knifBoard, projectBoard) +{ let n1 = knifBoard.Normal; let n2 = projectBoard.Normal; if (!isPerpendicularityTo(n1, n2)) @@ -20310,7 +20704,8 @@ function ProjectBoard(knifBoard, projectBoard) { dir.clone().multiplyScalar(-lineLength).add(p2), dir.clone().multiplyScalar(lineLength).add(p2), ]; - let pl = new Polyline(pts.map(p => { + let pl = new Polyline(pts.map(p => + { return { pt: AsVector2(p), bul: 0 }; })); pl.CloseMark = true; diff --git a/types/Geometry/ExtrudeEdgeGeometry2.d.ts b/types/Geometry/ExtrudeEdgeGeometry2.d.ts index 8e1f3ac..c84100f 100644 --- a/types/Geometry/ExtrudeEdgeGeometry2.d.ts +++ b/types/Geometry/ExtrudeEdgeGeometry2.d.ts @@ -3,7 +3,8 @@ import { Contour } from "../DatabaseServices/Contour"; import { ExtrudeSolid, ExtureContourCurve } from "../DatabaseServices/Entity/Extrude"; import { Line } from "../DatabaseServices/Entity/Line"; import { Polyline } from "../DatabaseServices/Entity/Polyline"; -export declare enum DepthType { +export declare enum DepthType +{ Front = 1, Back = 2, All = 3 @@ -14,7 +15,8 @@ export declare const ExtrudeBuildConfig: { /** * 槽的几何数据,包括槽的墙面和槽的盖子 */ -export declare class Groove { +export declare class Groove +{ depthType: DepthType; depth: number; allDepth: number; @@ -31,11 +33,13 @@ export declare class Groove { private ClipLid; Draw(verticesArray: number[], uvArray: number[], edgeBuild: EdgeGeometryBuild, rotateUv: boolean): void; } -declare enum DirectionType { +declare enum DirectionType +{ Outer = 0, Inner = 1 } -export declare class ContourTreeNode { +export declare class ContourTreeNode +{ contour: Contour; children: ContourTreeNode[]; parent: ContourTreeNode; @@ -44,7 +48,8 @@ export declare class ContourTreeNode { Draw(verticesArray: number[], uvArray: number[], front: boolean, z: number, rotateUv: boolean, allDepth: number): void; static ParseContourTree(contourNodes: ContourTreeNode[]): void; } -declare class EdgeGeometryBuild { +declare class EdgeGeometryBuild +{ allDepth: number; lineVerticesArray: number[]; frontLines: Line[]; @@ -56,7 +61,8 @@ declare class EdgeGeometryBuild { /** * 二维形状,内部用曲线胶带表示(用来计算盖子差集算法) */ -export declare class CurveTapeShape { +export declare class CurveTapeShape +{ children: CurveTapeShape[]; contour: CurveTape; holes: CurveTape[]; @@ -77,7 +83,8 @@ export declare class CurveTapeShape { /** * 曲线胶带(一维) */ -declare class CurveTape { +declare class CurveTape +{ contour: Contour; wallType: DirectionType; tapes: Range[]; @@ -97,7 +104,8 @@ declare class CurveTape { */ ReverseClipTo(s: CurveTapeShape): this; } -declare class ExtudeWall { +declare class ExtudeWall +{ curve: ExtureContourCurve; depthType: DepthType; depth: number; @@ -127,23 +135,25 @@ declare class ExtudeWall { * 曲线参数范围关系(包含,分离,同向共线,反向共线) * 用来表示某一曲线在另一个曲线内的关系 */ -interface CurveParamRangeRelation { +interface CurveParamRangeRelation +{ outer: Range[]; container: Range[]; syntropy: Range[]; reverse: Range[]; } declare type Range = [number, number]; -export declare class ExtrudeGeometryBuilder { +export declare class ExtrudeGeometryBuilder +{ private br; verticesArray: number[]; uvArray: number[]; edgeAndLidBuilder: EdgeGeometryBuild; - constructor(br: ExtrudeSolid); + constructor(br: ExtrudeSolid, rotateUv: boolean); protected GenerateMeshData(br: ExtrudeSolid): void; get MeshGeometry(): BufferGeometry; get EdgeGeometry(): BufferGeometry; protected ParseGrooves(): Groove[]; } -export {}; -//# sourceMappingURL=ExtrudeEdgeGeometry2.d.ts.map \ No newline at end of file +export { }; +//# sourceMappingURL=ExtrudeEdgeGeometry2.d.ts.map