Skip to content

Commit 01e793e

Browse files
committed
Halfspace solved
1 parent 3fa5b14 commit 01e793e

File tree

5 files changed

+93
-30
lines changed

5 files changed

+93
-30
lines changed

src/wasm/geometry/IfcGeometryProcessor.cpp

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,14 @@ namespace webifc::geometry
323323
flipWinding = true;
324324
}
325325

326-
double d = EXTRUSION_DISTANCE_HALFSPACE_M / _geometryLoader.GetLinearScalingFactor();
326+
double d = 1;
327327

328328
IfcProfile profile;
329329
profile.isConvex = false;
330330
profile.curve = GetRectangleCurve(d, d, glm::dmat3(1));
331331

332332
auto geom = Extrude(profile, extrusionNormal, d, _errorHandler);
333+
geom.halfSpace = true;
333334

334335
// @Refactor: duplicate of extrudedareasolid
335336
if (flipWinding)
@@ -785,17 +786,15 @@ namespace webifc::geometry
785786
glm::dvec4(1, 0, 0, 0),
786787
glm::dvec4(0, 1, 0, 0),
787788
glm::dvec4(0, 0, 1, 0),
788-
glm::dvec4(0, 0, 0, 1)
789-
);
789+
glm::dvec4(0, 0, 0, 1));
790790
if (profilePlacementID)
791791
{
792792
auto trans2d = _geometryLoader.GetAxis2Placement2D(profilePlacementID);
793793
profileTransform = glm::dmat4(
794794
glm::dvec4(trans2d[0][0], trans2d[0][1], 0, 0),
795795
glm::dvec4(trans2d[1][0], trans2d[1][1], 0, 0),
796796
glm::dvec4(0, 0, 1, 0),
797-
glm::dvec4(trans2d[2][0], trans2d[2][1], 0, 1)
798-
);
797+
glm::dvec4(trans2d[2][0], trans2d[2][1], 0, 1));
799798
}
800799

801800
glm::dvec3 dir = _geometryLoader.GetCartesianPoint3D(directionID);
@@ -807,13 +806,13 @@ namespace webifc::geometry
807806
glm::dvec4(dx * radius, 0),
808807
glm::dvec4(dy * radius, 0),
809808
glm::dvec4(0, 0, 1, 0),
810-
glm::dvec4(0 ,0 ,0 ,1));
811-
809+
glm::dvec4(0, 0, 0, 1));
810+
812811
glm::dmat4 extrusionScale = glm::dmat4(
813812
glm::dvec4(1, 0, 0, 0),
814813
glm::dvec4(0, 1, 0, 0),
815814
glm::dvec4(dz * depth, 0),
816-
glm::dvec4(0 ,0 ,0 ,1));
815+
glm::dvec4(0, 0, 0, 1));
817816

818817
profileTransform *= profileScale;
819818
extrusionScale *= profileTransform;
@@ -842,17 +841,15 @@ namespace webifc::geometry
842841
glm::dvec4(1, 0, 0, 0),
843842
glm::dvec4(0, 1, 0, 0),
844843
glm::dvec4(0, 0, 1, 0),
845-
glm::dvec4(0, 0, 0, 1)
846-
);
844+
glm::dvec4(0, 0, 0, 1));
847845
if (profilePlacementID)
848846
{
849847
auto trans2d = _geometryLoader.GetAxis2Placement2D(profilePlacementID);
850848
profileTransform = glm::dmat4(
851849
glm::dvec4(trans2d[0][0], trans2d[0][1], 0, 0),
852850
glm::dvec4(trans2d[1][0], trans2d[1][1], 0, 0),
853851
glm::dvec4(0, 0, 1, 0),
854-
glm::dvec4(trans2d[2][0], trans2d[2][1], 0, 1)
855-
);
852+
glm::dvec4(trans2d[2][0], trans2d[2][1], 0, 1));
856853
}
857854

858855
glm::dvec3 dir = _geometryLoader.GetCartesianPoint3D(directionID);
@@ -867,13 +864,13 @@ namespace webifc::geometry
867864
glm::dvec4(dx * dimx, 0),
868865
glm::dvec4(dy * dimy, 0),
869866
glm::dvec4(0, 0, 1, 0),
870-
glm::dvec4(0 ,0 ,0 ,1));
871-
867+
glm::dvec4(0, 0, 0, 1));
868+
872869
glm::dmat4 extrusionScale = glm::dmat4(
873870
glm::dvec4(1, 0, 0, 0),
874871
glm::dvec4(0, 1, 0, 0),
875872
glm::dvec4(dz * depth, 0),
876-
glm::dvec4(0 ,0 ,0 ,1));
873+
glm::dvec4(0, 0, 0, 1));
877874

878875
profileTransform *= profileScale;
879876
extrusionScale *= profileTransform;
@@ -915,10 +912,10 @@ namespace webifc::geometry
915912
double dirDot = glm::dot(dir, glm::dvec3(0, 0, 1));
916913
bool flipWinding = dirDot < 0; // can't be perp according to spec
917914

918-
// TODO: correct dump in case of compositeProfile
919-
#ifdef CSG_DEBUG_OUTPUT
920-
io::DumpSVGCurve(profile.curve.points, "IFCEXTRUDEDAREASOLID_curve.html");
921-
#endif
915+
// TODO: correct dump in case of compositeProfile
916+
#ifdef CSG_DEBUG_OUTPUT
917+
io::DumpSVGCurve(profile.curve.points, "IFCEXTRUDEDAREASOLID_curve.html");
918+
#endif
922919

923920
IfcGeometry geom;
924921

@@ -955,10 +952,10 @@ namespace webifc::geometry
955952
}
956953
}
957954

958-
// TODO: correct dump in case of compositeProfile
959-
#ifdef CSG_DEBUG_OUTPUT
960-
io::DumpIfcGeometry(geom, "IFCEXTRUDEDAREASOLID_geom.obj");
961-
#endif
955+
// TODO: correct dump in case of compositeProfile
956+
#ifdef CSG_DEBUG_OUTPUT
957+
io::DumpIfcGeometry(geom, "IFCEXTRUDEDAREASOLID_geom.obj");
958+
#endif
962959

963960
_expressIDToGeometry[line.expressID] = geom;
964961
mesh.expressID = line.expressID;
@@ -1540,7 +1537,44 @@ namespace webifc::geometry
15401537

15411538
if (doit)
15421539
{
1543-
result = fuzzybools::Subtract(result, secondGeom);
1540+
if (secondGeom.halfSpace)
1541+
{
1542+
glm::dvec3 origin = secondGeom.halfSpaceOrigin;
1543+
glm::dvec3 x = secondGeom.halfSpaceX - origin;
1544+
glm::dvec3 y = secondGeom.halfSpaceY - origin;
1545+
glm::dvec3 z = secondGeom.halfSpaceZ - origin;
1546+
glm::dmat4 trans = glm::dmat4(
1547+
glm::dvec4(x, 0),
1548+
glm::dvec4(y, 0),
1549+
glm::dvec4(z, 0),
1550+
glm::dvec4(0, 0, 0, 1)
1551+
);
1552+
IfcGeometry newSecond;
1553+
1554+
double scaleX = 1;
1555+
double scaleY = 1;
1556+
double scaleZ = 1;
1557+
1558+
for (uint32_t i = 0; i < result.numPoints; i++)
1559+
{
1560+
glm::dvec3 p = result.GetPoint(i);
1561+
glm::dvec3 vec = (p - origin);
1562+
double dx = glm::dot(vec, x);
1563+
double dy = glm::dot(vec, y);
1564+
double dz = glm::dot(vec, z);
1565+
if (glm::abs(dx) > scaleX) {scaleX = glm::abs(dx); }
1566+
if (glm::abs(dy) > scaleY) {scaleY = glm::abs(dy); }
1567+
if (glm::abs(dz) > scaleZ) {scaleZ = glm::abs(dz); }
1568+
}
1569+
newSecond.AddGeometry(secondGeom, trans, scaleX * 2, scaleY * 2, scaleZ * 2, secondGeom.halfSpaceOrigin);
1570+
IfcGeometry newFirst;
1571+
newFirst.AddGeometry(result);
1572+
result = fuzzybools::Subtract(result, newSecond);
1573+
}
1574+
else
1575+
{
1576+
result = fuzzybools::Subtract(result, secondGeom);
1577+
}
15441578
}
15451579
}
15461580
finalResult.AddGeometry(result);

src/wasm/geometry/operations/geometryutils.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,15 @@ namespace webifc::geometry {
685685
if (meshGeom.numFaces)
686686
{
687687
IfcGeometry newGeom;
688-
688+
newGeom.halfSpace = meshGeom.halfSpace;
689+
if (newGeom.halfSpace)
690+
{
691+
newGeom.halfSpaceOrigin = newMat * glm::dvec4(meshGeom.halfSpaceOrigin, 1);
692+
newGeom.halfSpaceX = newMat * glm::dvec4(meshGeom.halfSpaceX, 1);
693+
newGeom.halfSpaceY = newMat * glm::dvec4(meshGeom.halfSpaceY, 1);
694+
newGeom.halfSpaceZ = newMat * glm::dvec4(meshGeom.halfSpaceZ, 1);
695+
}
696+
689697
for (uint32_t i = 0; i < meshGeom.numFaces; i++)
690698
{
691699
fuzzybools::Face f = meshGeom.GetFace(i);

src/wasm/geometry/representation/IfcGeometry.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace webifc::geometry {
5454
return (uint32_t)(size_t)&fvertexData[0];
5555
}
5656

57-
void IfcGeometry::AddGeometry(fuzzybools::Geometry geom)
57+
void IfcGeometry::AddGeometry(fuzzybools::Geometry geom, glm::dmat4 trans, double scx, double scy, double scz, glm::dvec3 origin)
5858
{
5959

6060
for (uint32_t i = 0; i < geom.numFaces; i++)
@@ -63,6 +63,21 @@ namespace webifc::geometry {
6363
glm::dvec3 a = geom.GetPoint(f.i0);
6464
glm::dvec3 b = geom.GetPoint(f.i1);
6565
glm::dvec3 c = geom.GetPoint(f.i2);
66+
if(scx != 1 || scy != 1 || scz != 1)
67+
{
68+
double aax = glm::dot(trans[0], glm::dvec4(a - origin, 1)) * scx;
69+
double aay = glm::dot(trans[1], glm::dvec4(a - origin, 1)) * scy;
70+
double aaz = glm::dot(trans[2], glm::dvec4(a - origin, 1)) * scz;
71+
a = origin + glm::dvec3(aax * trans[0]) + glm::dvec3(aay * trans[1]) + glm::dvec3(aaz * trans[2]);
72+
double bbx = glm::dot(trans[0], glm::dvec4(b - origin, 1)) * scx;
73+
double bby = glm::dot(trans[1], glm::dvec4(b - origin, 1)) * scy;
74+
double bbz = glm::dot(trans[2], glm::dvec4(b - origin, 1)) * scz;
75+
b = origin + glm::dvec3(bbx * trans[0]) + glm::dvec3(bby * trans[1]) + glm::dvec3(bbz * trans[2]);
76+
double ccx = glm::dot(trans[0], glm::dvec4(c - origin, 1)) * scx;
77+
double ccy = glm::dot(trans[1], glm::dvec4(c - origin, 1)) * scy;
78+
double ccz = glm::dot(trans[2], glm::dvec4(c - origin, 1)) * scz;
79+
c = origin + glm::dvec3(ccx * trans[0]) + glm::dvec3(ccy * trans[1]) + glm::dvec3(ccz * trans[2]);
80+
}
6681
AddFace(a, b, c);
6782
}
6883

src/wasm/geometry/representation/IfcGeometry.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ namespace webifc::geometry {
1717

1818
struct IfcGeometry : fuzzybools::Geometry
1919
{
20+
bool halfSpace = false;
21+
glm::dvec3 halfSpaceOrigin = glm::dvec3(0, 0, 0);
22+
glm::dvec3 halfSpaceX = glm::dvec3(1, 0, 0);
23+
glm::dvec3 halfSpaceY = glm::dvec3(0, 1, 0);
24+
glm::dvec3 halfSpaceZ = glm::dvec3(0, 0, 1);
2025
void ReverseFaces();
2126
uint32_t GetVertexData();
22-
void AddGeometry(fuzzybools::Geometry geom);
27+
void AddGeometry(fuzzybools::Geometry geom, glm::dmat4 trans = glm::dmat4(1), double scx = 1, double scy = 1, double scz = 1, glm::dvec3 origin = glm::dvec3(0, 0, 0));
2328
uint32_t GetVertexDataSize();
2429
uint32_t GetIndexData();
2530
uint32_t GetIndexDataSize();

src/wasm/web-ifc-test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ int main()
267267
// std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#ifcrevolvedarea/v41.ifc");
268268
// std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#398 solved/398.ifc");
269269
// std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#384/384.ifc");
270-
// std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#359/359.ifc");
270+
// std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#359 Solved/359.ifc");
271271
// std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#mep/DM1-3_RIV.ifc");
272272
// std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#block/ark_tyen_barnehage.ifc");
273273
// std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#solids/01-Architecture.ifc");
@@ -322,15 +322,16 @@ int main()
322322
// SpecificLoadTest(loader, geometryLoader, 10333); //359
323323
// SpecificLoadTest(loader, geometryLoader, 10340); //359
324324
// SpecificLoadTest(loader, geometryLoader, 10349); //359
325+
// SpecificLoadTest(loader, geometryLoader, 8233); //359
325326
// SpecificLoadTest(loader, geometryLoader, 4235596); //DM1-3_RIV
326327
// SpecificLoadTest(loader, geometryLoader, 20906); //01-Architecture
327328
// SpecificLoadTest(loader, geometryLoader, 186); //TESTED_Simple_project_01
328329
// SpecificLoadTest(loader, geometryLoader, 22620); //TESTED_Simple_project_01
329330
// SpecificLoadTest(loader, geometryLoader, 22551); //TESTED_Simple_project_01
330331
// SpecificLoadTest(loader, geometryLoader, 474567); //Queens_demo_wip
331332
// SpecificLoadTest(loader, geometryLoader, 474551); //Queens_demo_wip
332-
SpecificLoadTest(loader, geometryLoader, 247738); //Queens_demo_wip
333-
// SpecificLoadTest(loader, geometryLoader, 245903); //Queens_demo_wip
333+
// SpecificLoadTest(loader, geometryLoader, 247738); //Queens_demo_wip
334+
SpecificLoadTest(loader, geometryLoader, 245903); //Queens_demo_wip
334335
// SpecificLoadTest(loader, geometryLoader, 242768); //Queens_demo_wip
335336
// SpecificLoadTest(loader, geometryLoader, 378325); //Solibri Building
336337

0 commit comments

Comments
 (0)