diff --git a/__test__/Interfere/interfere.test.ts b/__test__/Interfere/interfere.test.ts index 60adb5235..631232a52 100644 --- a/__test__/Interfere/interfere.test.ts +++ b/__test__/Interfere/interfere.test.ts @@ -85,4 +85,11 @@ describe("干涉测试", () => { "file": [2, "Board", 8, 2, 100, false, 1, 11, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 279.67078189300446, 184.15912208504804, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 279.67078189300446, 184.15912208504804, 0, 1], 0, 3, 2349, 330, 17, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [0, 0], 0, [330, 0], 0, [330, 2349], 0, [0, 2349], 0, true, 1, 3, 976.6666666666679, 6, 5, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [0, 0], 0, [6, 0], 0, [6, 976.6666666666679], 0, [0, 976.6666666666679], 0, true, 0, 2.5, 6, 0, 0, 0, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 291.67078189300446, 490.159122085048, 1360.3333333333321, 1], 3, 0, 0, 0, 0, 0, 10, 1, "左侧板", "客厅", "鞋柜", "", "", "", 0, 0, "三合一", 2, 0, "1", "1", "1", "1", "", "", "", 4, "三合一", "三合一", "三合一", "三合一", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, "Board", 8, 2, 101, false, 1, 3, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 291.67078189300446, 496.159122085048, 1360.3333333333321, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 296.67078189300446, 184.15912208504804, 1365.3333333333321, 1], 0, 3, 976.6666666666679, 768, 6, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [0, 0], 0, [768, 0], 0, [768, 976.6666666666679], 0, [0, 976.6666666666679], 0, true, 0, 2.5, 6, 0, 0, 0, 0, 10, 2, "薄背板", "客厅", "鞋柜", "", "", "", 0, 1, "不排", 2, 0, "0", "0", "0", "0", "", "", "", 4, "不排", "不排", "不排", "不排", false, false, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0], "basePt": { "x": 279.67078189300446, "y": 184.15912208504804, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1] }; await Check(d, 0); }); + + test('干涉检查错误(retessellate后正常)', async () => + { + let d = + { "file": [2, "Board", 10, 2, 278, 0, 1, 4, 71, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 2245.0804020100513, 20, 335.6783919596659, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2245.0804020100513, 20, 335.6783919596659, 1], 0, 0, 1, 3, 875, 420, 18, false, "Polyline", 10, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 634.0000000009315, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 2, 10, [420, -634.0000000009315], 0, [420, 240.99999999906845], 0, [0, 240.99999999906845], 0, [0, 75.99999999999977], 0, [18, 75.99999999999977], 0, [18, 75.99999999999977], 0, [36, 75.99999999999977], 0, [36.00000000000002, 2.9999999999997726], 0, [1.8947806286936004e-14, 3], 0, [0, -634.0000000009315], 0, true, 1, 3, 805, 9, 10, true, "Polyline", 10, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 2, 4, [0, 0], 0, [9, 0], 0, [9, 805], 0, [0, 805], 0, true, 0, 3, 6, 1.5, 1, 0, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 2245.0804020100513, 413, 395.6783919596659, 1], 3, 0, 0, 0, 0, 0, 10, 1, "@右侧板切角处封边", "餐边柜", "10", "福人-L3002", "颗粒板", "福人L3002", 2, 1, "三合一", 2, 10, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, "0.5", "0.5", "0.5", "0.5", "", "", "", 10, "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", true, true, 0, 6, 261, 2, 3, 650, 651, 652, 3, 653, 654, 655, 279, 2, 3, 666, 667, 668, 3, 669, 670, 671, 298, 2, 3, 674, 675, 676, 3, 677, 678, 679, 307, 2, 3, 682, 683, 684, 3, 685, 686, 687, 342, 2, 3, 690, 691, 692, 3, 693, 694, 695, 344, 4, 3, 698, 699, 700, 3, 701, 702, 703, 1, 704, 1, 705, 0, 0, 0, 0, 0, 0, true, 0, 0, "Board", 10, 2, 633, 0, 1, 4, 71, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 1760.0804020100513, 422, 395.6783919596659, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1760.0804020100513, 422, 395.6783919596659, 1], 0, 0, 1, 3, 805, 495, 9, true, "Polyline", 10, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 2, 4, [495, 0], 0, [495, 805], 0, [0, 805], 0, [0, 0], 0, true, 0, 3, 6, 1.5, 1, 0, 0, 10, 2, "薄背板", "餐边柜", "10", "福人-L3002", "颗粒板", "福人L3002", 2, 0, "不排", 2, 0, "0.5", "0.5", "0.5", "0.5", "", "", "", 4, "不排", "不排", "不排", "不排", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0], "basePt": { "x": 1760.0804020100513, "y": 20, "z": 335.6783919596659 }, "ucs": [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1] }; + await Check(d, 0); + }); }); diff --git a/src/csg/core/Geometry2CSG.ts b/src/csg/core/Geometry2CSG.ts index a30e17238..f10ea7670 100644 --- a/src/csg/core/Geometry2CSG.ts +++ b/src/csg/core/Geometry2CSG.ts @@ -1,7 +1,8 @@ import geom3, { Geom3 } from "@jscad/modeling/src/geometries/geom3"; import { create, Poly3 } from "@jscad/modeling/src/geometries/poly3"; import { Vec3 } from "@jscad/modeling/src/maths/vec3"; -import { BufferGeometry, Face3, Geometry, Vector2, Vector3 } from "three"; +import retessellate from "@jscad/modeling/src/operations/modifiers/retessellate"; +import { BufferGeometry, Face3, Geometry, Plane, Vector2, Vector3 } from "three"; import { Geom3Res } from "../../Common/CSGIntersect"; import { AsVector2, AsVector3, equalv3, ZeroVec } from "../../Geometry/GeUtils"; import { CSG } from "./CSG"; @@ -101,7 +102,7 @@ export function Geometry2CSG2(geometry: Geometry | BufferGeometry): Geom3 } polygons.push(create(vertices)); } - return geom3.create(polygons); + return retessellate(geom3.create(polygons)) as Geom3; } export function CSG2Geometry2(csg: Geom3 | Geom3Res): Geometry @@ -109,13 +110,19 @@ export function CSG2Geometry2(csg: Geom3 | Geom3Res): Geometry let geo = new Geometry; for (let poly of csg.polygons) { + let normal: Vector3;//面的法线 //@ts-ignore - let normal = new Vector3().fromArray(poly.plane); + if (poly.plane) + //@ts-ignore + normal = new Vector3().fromArray(poly.plane); let startIndex = geo.vertices.length; for (let v of poly.vertices) geo.vertices.push(new Vector3().fromArray(v)); + if (!normal && poly.vertices.length > startIndex + 2)//如果没有法线,则自己计算 + normal = new Plane().setFromCoplanarPoints(geo.vertices[startIndex], geo.vertices[startIndex + 1], geo.vertices[startIndex + 2]).normal; + for (let i = poly.vertices.length - 3; i >= 0; i--) { let f = new Face3(