diff --git a/__test__/Geometry/__snapshots__/EdgeGeometry.test.ts.snap b/__test__/Geometry/__snapshots__/EdgeGeometry.test.ts.snap index fa3ba974f..ac928ce0f 100644 --- a/__test__/Geometry/__snapshots__/EdgeGeometry.test.ts.snap +++ b/__test__/Geometry/__snapshots__/EdgeGeometry.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`EdgeGeometry生成 1`] = `168`; +exports[`EdgeGeometry生成 1`] = `236`; exports[`EdgeGeometry生成 2`] = `410`; diff --git a/__test__/Interfere/interfere.test.ts b/__test__/Interfere/interfere.test.ts index 631232a52..14f2684c8 100644 --- a/__test__/Interfere/interfere.test.ts +++ b/__test__/Interfere/interfere.test.ts @@ -86,6 +86,20 @@ describe("干涉测试", () => await Check(d, 0); }); + test('精度问题导致的干涉错误4', async () => + { + let d = + { "file": [2, "Board", 10, 2, 102, 0, 1, 11, 71, [0, 1, 0, 0, 0, 0, 0.9999999999999997, 0, 0.9999999999999997, 0, 0, 0, 0, -1762.4672160804016, 80.46022110552803, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -13, -1257.9182774864782, 285.0116202989057, 1], 0, 0, 1, 3, 641.7206298171777, 904.5489385939234, 18, true, "Polyline", 10, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1.0000000000000002, 0, 0, 0, 0, 1.0000000000000002, 0, 504.54893859392337, 349.5513991933778, 0, 1], 0, 0, 1, [0, 0, 1.0000000000000002, 0, 1, 0, 0, 0, 0, 1.0000000000000002, 0, 0, -820.6061283078504, 258.1687625374293, 0, 1], 0, 0, 1, 2, 4, [400, -349.55139919337773], 0, [400, 292.16923062379993], 0, [-504.54893859392337, 292.16923062379993], 0, [-504.54893859392337, -349.55139919337773], 0, true, 1, 3, 205.84311938160272, 205.84311938160272, 1.9999999999999996, false, "Circle", 10, 2, 0, 0, 0, 1, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 102.92155969080136, 102.92155969080136, 0, 1], 0, 0, 1, [-1, 0, 0, 0, 0, 0.9999999999999998, 0, 0, 0, 0, 0.9999999999999998, 0, -297.0784403091985, -562.1026533844808, 385.627660497046, 1], 0, 0, 1, 1, 102.92155969080136, 0, 3, 0, 0, 0, 0, 0, [0, 1, 0, 0, 0, 0, 0.9999999999999997, 0, 0.9999999999999997, 0, 0, 0, 2.2737367544323206e-13, -1334.8398371772796, 227.09006060810373, 1], 3, 0, 0, 0, 0, 0, 10, 1, "抽侧", "aaa", "标准柜", "", "", "", 1, 1, "抽屉", 2, 0, "1", "1", "1", "1", "", "", "", 4, "抽屉", "抽屉", "抽屉", "抽屉", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, "Board", 10, 2, 103, 0, 1, 3, 71, [0, 0, 0.9999999999999997, 0, 0, 1, 0, 0, -0.9999999999999997, 0, 0, 0, 2.000000000000284, -1334.8398371772796, 227.0900606081037, 1], 0, 0, 1, [0, -1, 0, 0, 0, 0, 0.9999999999999997, 0, -0.9999999999999997, 0, 0, 0, 2.000000000000284, -1234.4182774864782, 327.51162029890503, 1], 0, 0, 1, 3, 205.84311938160272, 205.84311938160272, 1.9999999999999996, false, "Circle", 10, 2, 0, 0, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 102.92155969080136, 102.92155969080136, 0, 1], 0, 0, 1, [0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, -562.1026533844812, -297.07844030919864, 385.6276604970461, 1], 0, 0, 1, 1, 102.92155969080136, 0, 3, 0, 0, 0, 0, 0, 10, 0, "", "", "", "", "", "", 0, 0, "三合一", 2, 0, "1", "1", "1", "1", "", "", "", 1, "三合一", true, true, 0, 0, 0, 0, 0, 0, 0, 0, false, 0, 0], "basePt": { "x": 0, "y": -1762.4672160804016, "z": 80.46022110552803 }, "ucs": [0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1] }; + await Check(d, 0); + }); + + test('精度问题导致的干涉错误5', async () => + { + let d = + { "file": [2, "Board", 10, 2, 100, 0, 1, 11, 71, [0, 1, 0, 0, 0, 0, 0.9999999999999997, 0, 0.9999999999999997, 0, 0, 0, 503.3870967741933, -714.2456942353324, 229.26222543948407, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 490.3870967741933, -714.2456942353324, 204.26222543948407, 1], 0, 0, 1, 3, 120.00000000000003, 400, 18, true, "Polyline", 10, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1.0000000000000002, 0, 0, 0, 0, 1.0000000000000002, 0, 400, 120, 0, 1], 0, 0, 1, [0, 0, 1.0000000000000002, 0, 1, 0, 0, 0, 0, 1.0000000000000002, 0, 0, -993.3222694741212, -336.0771704180065, -503.3870967741824, 1], 0, 0, 1, 2, 4, [-400, -120], 0, [0, -120], 0, [0, 0], 0, [-400, 0], 0, true, 2, 3, 5, 5, 1.9999999999999996, false, "Circle", 10, 2, 0, 0, 0, 1, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2.5, 2.5, 0, 1], 0, 0, 1, [-1, 0, 0, 0, 0, 0.9999999999999996, 0, 0, 0, 0, 0.9999999999999996, 0, -397.4999999999998, -662.524213075282, 385.627660497046, 1], 0, 0, 1, 1, 2.5, 0, 3, 0, 0, 0, 0, 0, [0, 1, 0, 0, 0, 0, 0.9999999999999997, 0, 0.9999999999999997, 0, 0, 0, 503.3870967741934, -690.7456942353324, 246.76222543948333, 1], 3, 5, 5, 5, false, "Circle", 10, 2, 0, 0, 0, 2, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2.5, 2.5, 0, 1], 0, 0, 1, [-1, 0, 0, 0, 0, 0.9999999999999996, 0, 0, 0, 0, 0.9999999999999996, 0, -397.4999999999998, -662.524213075282, 385.627660497046, 1], 0, 0, 1, 1, 2.5, 0, 3, 0, 0, 0, 0, 0, [0, 1, 0, 0, 0, 0, 0.9999999999999997, 0, 0.9999999999999997, 0, 0, 0, 516.3870967741934, -643.1985796372617, 248.82949129157336, 1], 3, 0, 0, 0, 0, 0, 10, 1, "抽侧", "aaa", "标准柜", "", "", "", 1, 1, "抽屉", 2, 0, "1", "1", "1", "1", "", "", "", 4, "抽屉", "抽屉", "抽屉", "抽屉", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, "Board", 10, 2, 101, 0, 1, 3, 71, [0, 0, 0.9999999999999997, 0, 0, 1, 0, 0, -0.9999999999999997, 0, 0, 0, 505.3870967741936, -690.7456942353324, 246.7622254394834, 1], 0, 0, 1, [0, -1, 0, 0, 0, 0, 0.9999999999999997, 0, -0.9999999999999997, 0, 0, 0, 505.3870967741936, -690.7456942353324, 246.7622254394834, 1], 0, 0, 1, 3, 5, 5, 1.9999999999999996, false, "Circle", 10, 2, 0, 0, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2.5, 2.5, 0, 1], 0, 0, 1, [0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, -662.5242130752825, -397.5, 385.6276604970461, 1], 0, 0, 1, 1, 2.5, 0, 3, 0, 0, 0, 0, 0, 10, 0, "", "", "", "", "", "", 0, 0, "三合一", 2, 0, "1", "1", "1", "1", "", "", "", 1, "三合一", true, true, 0, 0, 0, 0, 0, 0, 0, 0, false, 0, 0], "basePt": { "x": 503.3870967741933, "y": -714.2456942353324, "z": 229.26222543948407 }, "ucs": [0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1] }; + await Check(d, 0); + }); + test('干涉检查错误(retessellate后正常)', async () => { let d = diff --git a/src/Common/InterfereUtil.ts b/src/Common/InterfereUtil.ts index 8fd02de42..83fd106f8 100644 --- a/src/Common/InterfereUtil.ts +++ b/src/Common/InterfereUtil.ts @@ -178,6 +178,8 @@ export class CheckInterfereTool geo.applyMatrix4(e1.OCSNoClone); let mesh = new Mesh(geo, this._MeshMaterial); + entitySet.add(e1); + entitySet.add(e2); objMap.push([mesh, [e1, e2]]); } } diff --git a/src/DatabaseServices/Shape2.ts b/src/DatabaseServices/Shape2.ts index 9a690cbad..0090cf478 100644 --- a/src/DatabaseServices/Shape2.ts +++ b/src/DatabaseServices/Shape2.ts @@ -1,5 +1,6 @@ import { EllipseCurve, Shape, Vector2 } from "three"; import { clamp } from "../Common/Utils"; +import { ARC_MaxSplitCount, Arc_MinSplitCount, ARC_SplitLength } from "../Geometry/ExtrudeMeshGeomBuilder/SplitCurveParams"; import { equalv2 } from "../Geometry/GeUtils"; import { Arc } from "./Entity/Arc"; @@ -27,10 +28,11 @@ export class Shape2 extends Shape tempArc.EndAngle = curve.aEndAngle; tempArc.Radius = Math.abs(curve.xRadius); - //根据圆弧的角度,来确定绘制个数 - let count = Math.max(2, Math.abs(Math.ceil((tempArc.AllAngle) / Math.PI)) * divisions); + //根据圆的半径来确定绘制个数(与SplitCurveParams一致) + let splitCount = tempArc.Radius / ARC_SplitLength; + splitCount = clamp(Math.floor(splitCount * 0.5) * 2, Arc_MinSplitCount, ARC_MaxSplitCount); - resolution = clamp(Math.ceil(tempArc.Length / 20), count, 60); + resolution = Math.max(2, Math.abs(Math.ceil((tempArc.AllAngle * 0.5) / Math.PI)) * splitCount); } else resolution = divisions * 2; diff --git a/src/Geometry/ExtrudeMeshGeomBuilder/SplitCurveParams.ts b/src/Geometry/ExtrudeMeshGeomBuilder/SplitCurveParams.ts index d57acf42d..befa789e7 100644 --- a/src/Geometry/ExtrudeMeshGeomBuilder/SplitCurveParams.ts +++ b/src/Geometry/ExtrudeMeshGeomBuilder/SplitCurveParams.ts @@ -7,9 +7,9 @@ import { ExtrudeContourCurve } from "../../DatabaseServices/Entity/Extrude"; import { BUL_IS_LINE_FUZZ } from "../../DatabaseServices/Entity/Polyline"; import { AsVector3, equaln } from "../GeUtils"; -const ARC_SplitLength = 4;//圆的分段长度 -const Arc_MinSplitCount = 12;//圆的最小分段个数 -const ARC_MaxSplitCount = 360;//圆的最大分段个数 +export const ARC_SplitLength = 4;//圆的分段长度 +export const Arc_MinSplitCount = 12;//圆的最小分段个数 +export const ARC_MaxSplitCount = 360;//圆的最大分段个数 /** * @@ -21,7 +21,8 @@ export function SplitCurveParams(cu: ExtrudeContourCurve): number[] if (cu instanceof Circle) { let splitCount = cu.Radius / ARC_SplitLength; - splitCount = clamp(Math.floor(splitCount), Arc_MinSplitCount, ARC_MaxSplitCount); + //保证是偶数(避免奇数和Shape2计算方式一致导致的干涉) + splitCount = clamp(Math.floor(splitCount * 0.5) * 2, Arc_MinSplitCount, ARC_MaxSplitCount); for (let i = 0; i < splitCount; i++) xparams.push(i / splitCount); }