| 117 | } |
| 118 | |
| 119 | IfcGeom::Representation::Triangulation::Triangulation(const BRep& shape_model) |
| 120 | : Representation(shape_model.settings(), shape_model.entity(), shape_model.id()) |
| 121 | , weld_offset_(0) |
| 122 | { |
| 123 | for (IfcGeom::ConversionResults::const_iterator iit = shape_model.begin(); iit != shape_model.end(); ++iit) { |
| 124 | |
| 125 | // Don't weld vertices that belong to different items to prevent non-manifold situations. |
| 126 | resetWelds(); |
| 127 | |
| 128 | int surface_style_id = -1; |
| 129 | if (iit->hasStyle()) { |
| 130 | auto jt = std::find(materials_.begin(), materials_.end(), iit->StylePtr()); |
| 131 | if (jt == materials_.end()) { |
| 132 | surface_style_id = (int)materials_.size(); |
| 133 | materials_.push_back(iit->StylePtr()); |
| 134 | } else { |
| 135 | surface_style_id = (int)(jt - materials_.begin()); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if (settings().get<ifcopenshell::geometry::settings::ApplyDefaultMaterials>().get() && surface_style_id == -1) { |
| 140 | const auto& material = IfcGeom::get_default_style(shape_model.entity()); |
| 141 | auto mit = std::find(materials_.begin(), materials_.end(), material); |
| 142 | if (mit == materials_.end()) { |
| 143 | surface_style_id = (int)materials_.size(); |
| 144 | materials_.push_back(material); |
| 145 | } else { |
| 146 | surface_style_id = (int)(mit - materials_.begin()); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | iit->Shape()->Triangulate(settings(), *iit->Placement(), this, iit->ItemId(), surface_style_id); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /// Generates UVs for a single mesh using box projection. |
| 155 | /// @todo Very simple impl. Assumes that input vertices and normals match 1:1. |