diff --git a/src/ifcgeom/IfcGeomObjects.cpp b/src/ifcgeom/IfcGeomObjects.cpp index 4b8f194c9b..654a8a394d 100644 --- a/src/ifcgeom/IfcGeomObjects.cpp +++ b/src/ifcgeom/IfcGeomObjects.cpp @@ -46,7 +46,7 @@ #include "../ifcgeom/IfcGeom.h" // Welds vertices that belong to different faces -bool weld_vertices = false; +bool weld_vertices = true; int IfcGeomObjects::IfcMesh::addvert(const gp_XYZ& p) { const float X = (float)p.X();const float Y = (float)p.Y();const float Z = (float)p.Z(); @@ -93,9 +93,7 @@ IfcGeomObjects::IfcMesh::IfcMesh(int i, const IfcGeom::ShapeList& shapes) { if ( ! tri.IsNull() ) { // A 3x3 matrix to rotate the vertex normals - const gp_Mat rotation_matrix = use_world_coords - ? trsf.VectorialPart() * loc.Transformation().VectorialPart() - : loc.Transformation().VectorialPart(); + const gp_Mat rotation_matrix = trsf.VectorialPart(); // Keep track of the number of times an edge is used // Manifold edges (i.e. edges used twice) are deemed invisible @@ -431,63 +429,47 @@ const IfcGeomObjects::IfcObject* IfcGeomObjects::GetObject(int id) { const IfcGeomObjects::IfcGeomObject* IfcGeomObjects::Get() { return current_geom_obj; } -bool IfcGeomObjects::Init(const char* fn, bool world_coords) { - return IfcGeomObjects::Init(fn, world_coords, 0, 0); +bool IfcGeomObjects::Init(const char* fn) { + return IfcGeomObjects::Init(fn, 0, 0); } -bool IfcGeomObjects::Init(const char* fn, bool world_coords, std::ostream* log1, std::ostream* log2) { +bool _Init() { + shapereps = Ifc::EntitiesByType(); + if ( ! shapereps ) return false; + + outer = shapereps->begin(); + entities.reset(); + current_geom_obj = _get(); + + if ( ! current_geom_obj ) return false; + + done = 0; + total = shapereps->Size(); + return true; +} +bool IfcGeomObjects::Init(const char* fn, std::ostream* log1, std::ostream* log2) { Ifc::SetOutput(log1,log2); - use_world_coords = world_coords; if ( !Ifc::Init(fn) ) return false; - - shapereps = Ifc::EntitiesByType(); - if ( ! shapereps ) return false; - - outer = shapereps->begin(); - entities.reset(); - current_geom_obj = _get(); - - if ( ! current_geom_obj ) return false; - - done = 0; - total = shapereps->Size(); - return true; + return _Init(); } -bool IfcGeomObjects::Init(std::istream& f, int len, bool world_coords, std::ostream* log1, std::ostream* log2) { +bool IfcGeomObjects::Init(std::istream& f, int len, std::ostream* log1, std::ostream* log2) { Ifc::SetOutput(log1,log2); - use_world_coords = world_coords; if ( !Ifc::Init(f, len) ) return false; - - shapereps = Ifc::EntitiesByType(); - if ( ! shapereps ) return false; - - outer = shapereps->begin(); - entities.reset(); - current_geom_obj = _get(); - - if ( ! current_geom_obj ) return false; - - done = 0; - total = shapereps->Size(); - return true; + return _Init(); } bool IfcGeomObjects::Init(void* data, int len) { Ifc::SetOutput(0,0); - use_world_coords = true; - weld_vertices = false; if ( !Ifc::Init(data, len) ) return false; - - shapereps = Ifc::EntitiesByType(); - if ( ! shapereps ) return false; - - outer = shapereps->begin(); - entities.reset(); - current_geom_obj = _get(); - - if ( ! current_geom_obj ) return false; - - done = 0; - total = shapereps->Size(); - return true; + return _Init(); +} +void IfcGeomObjects::Settings(int setting, bool value) { + switch ( setting ) { + case USE_WORLD_COORDS: + use_world_coords = value; + break; + case WELD_VERTICES: + weld_vertices = value; + break; + } } int IfcGeomObjects::Progress() { return 100 * done / total; diff --git a/src/ifcgeom/IfcGeomObjects.h b/src/ifcgeom/IfcGeomObjects.h index 6e28a71a93..9b64a8f63a 100644 --- a/src/ifcgeom/IfcGeomObjects.h +++ b/src/ifcgeom/IfcGeomObjects.h @@ -68,6 +68,9 @@ namespace IfcGeomObjects { + const int WELD_VERTICES = 1; + const int USE_WORLD_COORDS = 2; + typedef std::vector::const_iterator IntIt; typedef std::vector::const_iterator FltIt; typedef std::pair< float,std::pair > VertKey; @@ -111,10 +114,11 @@ namespace IfcGeomObjects { IfcGeomObject(int my_id, int p_id, const std::string& n, const std::string& t, const std::string& g, const gp_Trsf& trsf, IfcMesh* m); }; - bool Init(const char* fn, bool world_coords = false); - bool Init(const char* fn, bool world_coords = false, std::ostream* log1= 0, std::ostream* log2= 0); - bool Init(std::istream& f, int len, bool world_coords = false, std::ostream* log1= 0, std::ostream* log2= 0); + bool Init(const char* fn); bool Init(void* data, int len); + bool Init(const char* fn, std::ostream* log1= 0, std::ostream* log2= 0); + bool Init(std::istream& f, int len, std::ostream* log1= 0, std::ostream* log2= 0); + void Settings(int setting, bool value); bool CleanUp(); const IfcGeomObject* Get(); bool Next(); diff --git a/src/ifcjni/IfcJni.cpp b/src/ifcjni/IfcJni.cpp index ced1bf24fb..dc1edc0246 100644 --- a/src/ifcjni/IfcJni.cpp +++ b/src/ifcjni/IfcJni.cpp @@ -43,10 +43,11 @@ JNIEXPORT jobject JNICALL Java_org_ifcopenshell_IfcOpenShellModel_getGeometry (J jintArray indices = env->NewIntArray(o->mesh->faces.size()); jfloatArray positions = env->NewFloatArray(o->mesh->verts.size()); - jfloatArray normals = env->NewFloatArray(o->mesh->verts.size()); + jfloatArray normals = env->NewFloatArray(o->mesh->normals.size()); env->SetIntArrayRegion(indices,0,o->mesh->faces.size(),(jint*) &o->mesh->faces[0]); env->SetFloatArrayRegion(positions,0,o->mesh->verts.size(),(jfloat*) &o->mesh->verts[0]); + env->SetFloatArrayRegion(normals,0,o->mesh->normals.size(),(jfloat*) &o->mesh->normals[0]); jobject return_obj = env->NewObject(class_def, jconstructor, name, type, guid, indices, positions, normals); @@ -68,5 +69,7 @@ JNIEXPORT bool JNICALL Java_org_ifcopenshell_IfcOpenShellModel_setIfcData (JNIEn void* data = env->GetByteArrayElements(jdata, NULL); const int length = env->GetArrayLength(jdata); if ( ! data || ! length ) return false; + IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS,true); + IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,false); return has_more = IfcGeomObjects::Init(data,length); } \ No newline at end of file diff --git a/src/ifcmax/IfcMax.cpp b/src/ifcmax/IfcMax.cpp index 77a02a6d22..3aef09a617 100644 --- a/src/ifcmax/IfcMax.cpp +++ b/src/ifcmax/IfcMax.cpp @@ -109,7 +109,10 @@ int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, itfc->ProgressStart("Importing file...", TRUE, fn, NULL); - if ( ! IfcGeomObjects::Init((char*)name,false,0,0) ) return false; + IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS,false); + IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,true); + + if ( ! IfcGeomObjects::Init((char*)name,0,0) ) return false; std::map dict; MtlBaseLib* mats = itfc->GetSceneMtls(); diff --git a/src/ifcobj/IfcObj.cpp b/src/ifcobj/IfcObj.cpp index a4fb1bb71a..3ec2b728e0 100644 --- a/src/ifcobj/IfcObj.cpp +++ b/src/ifcobj/IfcObj.cpp @@ -47,12 +47,15 @@ int main ( int argc, char** argv ) { return 1; } + IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS,true); + IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,false); + // Stream for log messages, we don't want to interupt our new progress bar... std::stringstream ss; // Parse the file supplied in argv[1]. Returns true on succes. // The second argument defines whether geometry will be defined using global or local coordinates. - if ( ! IfcGeomObjects::Init(argv[1],true,&std::cout,&ss) ) { + if ( ! IfcGeomObjects::Init(argv[1],&std::cout,&ss) ) { std::cout << "[Error] unable to parse .ifc file or no geometrical entities found" << std::endl; return 1; } diff --git a/src/ifcwrap/Interface.h b/src/ifcwrap/Interface.h index 4428bac54c..1b885edf17 100644 --- a/src/ifcwrap/Interface.h +++ b/src/ifcwrap/Interface.h @@ -18,12 +18,17 @@ ********************************************************************************/ namespace IfcGeomObjects { + + const int WELD_VERTICES = 1; + const int USE_WORLD_COORDS = 2; + class IfcMesh { public: int id; std::vector verts; std::vector faces; std::vector edges; + std::vector normals; }; class IfcObject { @@ -43,7 +48,8 @@ namespace IfcGeomObjects { bool Next(); const IfcGeomObject* Get(); - bool Init(const char* fn, bool world_coords = false); + bool Init(const char* fn); + void Settings(int setting, bool value); int Progress(); const IfcObject* GetObject(int id); bool CleanUp();