@@ -236,7 +236,7 @@ class ConverterOSG : public StatusCallback
236
236
237
237
// #define DEBUG_DRAW_NORMALS
238
238
239
- static void drawMeshSet (const shared_ptr<carve::mesh::MeshSet<3 > >& meshset, osg::Geode* geode, double crease_angle, double min_triangle_area, bool add_color_array = false )
239
+ void drawMeshSet (const shared_ptr<carve::mesh::MeshSet<3 > >& meshset, osg::Geode* geode, double crease_angle, double min_triangle_area, bool add_color_array, bool disableBackFaceCulling )
240
240
{
241
241
if (!meshset)
242
242
{
@@ -467,6 +467,12 @@ class ConverterOSG : public StatusCallback
467
467
geometry->addPrimitiveSet (new osg::DrawArrays (osg::PrimitiveSet::TRIANGLES, 0 , vertices_tri->size ()));
468
468
geode->addDrawable (geometry);
469
469
470
+ // disable back face culling for open meshes
471
+ if (disableBackFaceCulling)
472
+ {
473
+ geometry->getOrCreateStateSet ()->setAttributeAndModes (m_cull_back_off.get (), osg::StateAttribute::OFF);
474
+ }
475
+
470
476
#ifdef DEBUG_DRAW_NORMALS
471
477
osg::ref_ptr<osg::Vec3Array> vertices_normals = new osg::Vec3Array ();
472
478
for (size_t i = 0 ; i < vertices_tri->size (); ++i)
@@ -667,7 +673,7 @@ class ConverterOSG : public StatusCallback
667
673
}
668
674
}
669
675
670
- void applyAppearancesToGroup (const std::vector<shared_ptr<AppearanceData> >& vec_product_appearances, osg::Group* grp)
676
+ void applyAppearancesToGroup (const std::vector<shared_ptr<AppearanceData> >& vec_product_appearances, osg::Group* grp, float transparencyOverride )
671
677
{
672
678
for (size_t ii = 0 ; ii < vec_product_appearances.size (); ++ii)
673
679
{
@@ -680,7 +686,7 @@ class ConverterOSG : public StatusCallback
680
686
if (appearance->m_apply_to_geometry_type == AppearanceData::GEOM_TYPE_SURFACE || appearance->m_apply_to_geometry_type == AppearanceData::GEOM_TYPE_ANY)
681
687
{
682
688
osg::ref_ptr<osg::StateSet> item_stateset;
683
- convertToOSGStateSet (appearance, item_stateset);
689
+ convertToOSGStateSet (appearance, item_stateset, transparencyOverride );
684
690
if (item_stateset)
685
691
{
686
692
osg::StateSet* existing_item_stateset = grp->getStateSet ();
@@ -712,7 +718,7 @@ class ConverterOSG : public StatusCallback
712
718
mat_in.m [3 ][0 ], mat_in.m [3 ][1 ], mat_in.m [3 ][2 ], mat_in.m [3 ][3 ]);
713
719
}
714
720
715
- void convertMeshSets (std::vector<shared_ptr<carve::mesh::MeshSet<3 > > >& vecMeshSets, osg::Geode* geode, size_t ii_item)
721
+ void convertMeshSets (std::vector<shared_ptr<carve::mesh::MeshSet<3 > > >& vecMeshSets, osg::Geode* geode, size_t ii_item, bool disableBackfaceCulling )
716
722
{
717
723
double min_triangle_area = m_geom_settings->getMinTriangleArea ();
718
724
double eps = m_geom_settings->getEpsilonCoplanarDistance ();
@@ -721,15 +727,12 @@ class ConverterOSG : public StatusCallback
721
727
{
722
728
shared_ptr<carve::mesh::MeshSet<3 > >& item_meshset = vecMeshSets[ii];
723
729
724
- // static void retriangulateMeshSetSimple(shared_ptr<carve::mesh::MeshSet<3> >&meshset, bool ignoreResultOpenEdges, GeomProcessingParams & params, size_t retryCount);
725
-
726
730
double epsCoplanarFacesAngle = eps;
727
731
double minFaceArea = eps;
728
732
bool dumpMeshes = false ;
729
733
GeomProcessingParams params (eps, epsCoplanarFacesAngle, minFaceArea, dumpMeshes);
730
734
MeshOps::retriangulateMeshSetSimple (item_meshset, true , params, 0 );
731
- // osg::ref_ptr<osg::Geode> geode = item_group;//new osg::Geode();
732
- drawMeshSet (item_meshset, geode, crease_angle, min_triangle_area);
735
+ drawMeshSet (item_meshset, geode, crease_angle, min_triangle_area, false , disableBackfaceCulling);
733
736
734
737
if (m_render_crease_edges)
735
738
{
@@ -748,7 +751,6 @@ class ConverterOSG : public StatusCallback
748
751
749
752
void convertGeometricItem (const shared_ptr<ItemShapeData>& item_data, shared_ptr<IfcProduct>& ifc_product, size_t ii_representation, size_t ii_item, osg::Group* parentNode, float transparencyOverride)
750
753
{
751
-
752
754
bool includeChildren = false ;
753
755
if (item_data->hasGeometricRepresentation (includeChildren))
754
756
{
@@ -760,29 +762,27 @@ class ConverterOSG : public StatusCallback
760
762
product_guid = ifc_product->m_GlobalId ->m_value ;
761
763
}
762
764
765
+ std::string ifc_entity_type = EntityFactory::getStringForClassID (ifc_product->classID ());
763
766
std::stringstream strs_product_switch_name;
764
- strs_product_switch_name << product_guid << " :" << EntityFactory::getStringForClassID (ifc_product-> classID ()) << " group" ;
767
+ strs_product_switch_name << product_guid << " :" << ifc_entity_type << " group" ;
765
768
std::string product_switch_name = strs_product_switch_name.str ();
766
769
767
770
#ifdef _DEBUG
768
771
int tag = ifc_product->m_tag ;
769
- if (product_guid.compare (" 3WMG3ehJnBiu4F_L5ltNmO" ) == 0 )
772
+ if (product_guid.compare (" 3WMG3ehJnBiu4F_L5ltNmO" ) == 0 || ifc_product-> classID () == IFC4X3::IFCWINDOW )
770
773
{
771
774
int wait = 0 ;
772
775
}
773
776
#endif
774
777
775
- // create shape for open shells
776
778
if (item_data->m_meshsets_open .size () > 0 )
777
779
{
778
- osg::ref_ptr<osg::Geode> geode_open_meshes = new osg::Geode ();
779
- convertMeshSets (item_data->m_meshsets_open , geode_open_meshes, ii_item);
780
780
// disable back face culling for open meshes
781
- geode_open_meshes->getOrCreateStateSet ()->setAttributeAndModes (m_cull_back_off.get (), osg::StateAttribute::OFF);
782
- item_geode->addChild (geode_open_meshes);
781
+ convertMeshSets (item_data->m_meshsets_open , item_geode, ii_item, true );
783
782
}
784
783
785
- convertMeshSets (item_data->m_meshsets , item_geode, ii_item);
784
+ // create shape for closed meshes
785
+ convertMeshSets (item_data->m_meshsets , item_geode, ii_item, false );
786
786
787
787
// create shape for points
788
788
const std::vector<shared_ptr<carve::input::VertexData> >& vertex_points = item_data->getVertexPoints ();
@@ -862,18 +862,12 @@ class ConverterOSG : public StatusCallback
862
862
txt->setText (text_str.c_str ());
863
863
txt->getOrCreateStateSet ()->setMode (GL_LIGHTING, osg::StateAttribute::OFF);
864
864
865
- osg::ref_ptr<osg::Geode> geode = new osg::Geode ();
866
- geode ->addDrawable (txt);
867
- // representation_switch ->addChild(geode );
865
+ osg::ref_ptr<osg::Geode> geodeText = new osg::Geode ();
866
+ geodeText ->addDrawable (txt);
867
+ item_geode ->addChild (geodeText );
868
868
}
869
869
}
870
870
871
- // apply statesets if there are any
872
- if (item_data->m_vec_item_appearances .size () > 0 )
873
- {
874
- applyAppearancesToGroup (item_data->m_vec_item_appearances , item_geode);
875
- }
876
-
877
871
// If anything has been created, add it to the product group
878
872
if (item_geode->getNumChildren () > 0 )
879
873
{
@@ -884,9 +878,22 @@ class ConverterOSG : public StatusCallback
884
878
}
885
879
#endif
886
880
881
+ // apply statesets if there are any
882
+ if (item_data->m_vec_item_appearances .size () > 0 )
883
+ {
884
+ applyAppearancesToGroup (item_data->m_vec_item_appearances , item_geode, transparencyOverride);
885
+ }
886
+
887
887
if (transparencyOverride > 0 )
888
888
{
889
- SceneGraphUtils::setMaterialAlpha (item_geode, transparencyOverride, false );
889
+ bool hasTriangles = SceneGraphUtils::hasTrianglesWithMaterial (item_geode);
890
+ bool createMaterialIfNotExisting = false ;
891
+
892
+ if (!hasTriangles)
893
+ {
894
+ createMaterialIfNotExisting = true ;
895
+ }
896
+ SceneGraphUtils::setMaterialAlpha (item_geode, transparencyOverride, createMaterialIfNotExisting );
890
897
}
891
898
892
899
parentNode->addChild (item_geode);
@@ -898,8 +905,6 @@ class ConverterOSG : public StatusCallback
898
905
const shared_ptr<ItemShapeData>& child = item_data->m_child_items [i_item];
899
906
convertGeometricItem (child, ifc_product, ii_representation, i_item, parentNode, transparencyOverride);
900
907
}
901
-
902
-
903
908
}
904
909
905
910
// \brief method convertProductShapeToOSG: creates geometry objects from an IfcProduct object
@@ -923,8 +928,7 @@ class ConverterOSG : public StatusCallback
923
928
924
929
product_guid = product_shape->m_entity_guid ;
925
930
auto it_find = m_map_entity_guid_to_switch.find (product_guid);
926
-
927
- if (it_find != m_map_entity_guid_to_switch.end ())
931
+ if (it_find == m_map_entity_guid_to_switch.end ())
928
932
{
929
933
m_map_entity_guid_to_switch[product_guid] = product_switch;
930
934
}
@@ -937,10 +941,9 @@ class ConverterOSG : public StatusCallback
937
941
if (!product_shape->m_ifc_object_definition .expired ())
938
942
{
939
943
shared_ptr<IfcObjectDefinition> ifc_object_def (product_shape->m_ifc_object_definition );
940
- shared_ptr<IfcProduct> ifc_product = dynamic_pointer_cast<IfcProduct>(ifc_object_def);
941
-
942
944
entityType = EntityFactory::getStringForClassID (ifc_object_def->classID ());
943
-
945
+
946
+ shared_ptr<IfcProduct> ifc_product = dynamic_pointer_cast<IfcProduct>(ifc_object_def);
944
947
if (ifc_product)
945
948
{
946
949
// enable transparency for certain objects
@@ -976,7 +979,7 @@ class ConverterOSG : public StatusCallback
976
979
}
977
980
978
981
#ifdef _DEBUG
979
- if (product_guid.compare (" 3WMG3ehJnBiu4F_L5ltNmO " ) == 0 )
982
+ if (product_guid.compare (" 0mmrfTIC96mu8Q5Pb3rKvn " ) == 0 )
980
983
{
981
984
int wait = 0 ;
982
985
}
@@ -1005,7 +1008,7 @@ class ConverterOSG : public StatusCallback
1005
1008
// TODO: if no color or material is given, set color 231/219/169 for walls, 140/140/140 for slabs
1006
1009
if (product_shape->m_vec_product_appearances .size () > 0 )
1007
1010
{
1008
- applyAppearancesToGroup (product_shape->m_vec_product_appearances , product_transform);
1011
+ applyAppearancesToGroup (product_shape->m_vec_product_appearances , product_transform, transparencyOverride );
1009
1012
}
1010
1013
1011
1014
++m_numConvertedProducts;
@@ -1162,15 +1165,15 @@ class ConverterOSG : public StatusCallback
1162
1165
progressValueCallback (0.9 , " scenegraph" );
1163
1166
}
1164
1167
1165
- void convertToOSGStateSet (const shared_ptr<AppearanceData>& appearence, osg::ref_ptr<osg::StateSet>& target_stateset)
1168
+ void convertToOSGStateSet (const shared_ptr<AppearanceData>& appearence, osg::ref_ptr<osg::StateSet>& target_stateset, float transparencyOverride )
1166
1169
{
1167
1170
if (!appearence)
1168
1171
{
1169
1172
return ;
1170
1173
}
1171
- const float shininess = appearence->m_shininess ;
1172
- const float transparency = appearence->m_transparency ;
1173
- const bool set_transparent = appearence->m_set_transparent ;
1174
+ float shininess = appearence->m_shininess ;
1175
+ float transparency = appearence->m_transparency ;
1176
+ bool set_transparent = appearence->m_set_transparent ;
1174
1177
1175
1178
const float color_ambient_r = appearence->m_color_ambient .r ();
1176
1179
const float color_ambient_g = appearence->m_color_ambient .g ();
@@ -1187,6 +1190,12 @@ class ConverterOSG : public StatusCallback
1187
1190
const float color_specular_b = appearence->m_color_specular .b ();
1188
1191
const float color_specular_a = appearence->m_color_specular .a ();
1189
1192
1193
+ if (transparencyOverride > 0 )
1194
+ {
1195
+ set_transparent = true ;
1196
+ transparency = transparencyOverride;
1197
+ }
1198
+
1190
1199
osg::Vec4f ambientColor (color_ambient_r, color_ambient_g, color_ambient_b, transparency);
1191
1200
osg::Vec4f diffuseColor (color_diffuse_r, color_diffuse_g, color_diffuse_b, transparency);
1192
1201
osg::Vec4f specularColor (color_specular_r, color_specular_g, color_specular_b, transparency);
@@ -1202,7 +1211,7 @@ class ConverterOSG : public StatusCallback
1202
1211
target_stateset = new osg::StateSet ();
1203
1212
target_stateset->setAttribute (mat, osg::StateAttribute::ON);
1204
1213
1205
- if (appearence-> m_set_transparent )
1214
+ if (set_transparent )
1206
1215
{
1207
1216
mat->setTransparency (osg::Material::FRONT, transparency);
1208
1217
target_stateset->setMode (GL_BLEND, osg::StateAttribute::ON);
0 commit comments