mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:23:53 +00:00
Various improvements to USD serializer related to object naming
This commit is contained in:
@@ -1446,7 +1446,7 @@ std::vector<IfcGeom::filter_t> setup_filters(const std::vector<geom_filter>& fil
|
|||||||
layer_filter.populate(f.values);
|
layer_filter.populate(f.values);
|
||||||
} else if (f.type == geom_filter::ENTITY_ARG) {
|
} else if (f.type == geom_filter::ENTITY_ARG) {
|
||||||
attribute_filter.include = f.include;
|
attribute_filter.include = f.include;
|
||||||
attribute_filter.traverse = f.traverse;
|
attribute_filter.traverse = attribute_filter.traverse_openings = f.traverse;
|
||||||
attribute_filter.attribute_name = f.arg;
|
attribute_filter.attribute_name = f.arg;
|
||||||
attribute_filter.populate(f.values);
|
attribute_filter.populate(f.values);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,17 +117,28 @@ void USDSerializer::writeHeader() {
|
|||||||
stage_->GetRootLayer()->SetComment("File generated by IfcOpenShell " + std::string(IFCOPENSHELL_VERSION));
|
stage_->GetRootLayer()->SetComment("File generated by IfcOpenShell " + std::string(IFCOPENSHELL_VERSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
std::string USDSerializer::object_id_unique(const IfcGeom::Element* o) {
|
||||||
std::string nameObject(const IfcGeom::Element* o) {
|
auto it = element_names_.find(o->id());
|
||||||
std::string name = o->name();
|
if (it != element_names_.end()) {
|
||||||
const std::string type = o->type();
|
return it->second;
|
||||||
const std::string id = std::to_string(o->id());
|
}
|
||||||
if (name.empty()) {
|
int postfix = 0;
|
||||||
name = type + "_UnNamed_" + id;
|
auto name = object_id(o);
|
||||||
} else {
|
auto suffix = "-" + boost::to_lower_copy(o->context());
|
||||||
name = type + "_" + usd_utils::toPath(name) + "_" + id;
|
if (name.size() > suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), name.rbegin())) {
|
||||||
|
name = name.substr(0, name.size() - suffix.size());
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
auto unique_name = name;
|
||||||
|
if (postfix) {
|
||||||
|
unique_name += "_" + std::to_string(postfix);
|
||||||
}
|
}
|
||||||
return name;
|
unique_name = usd_utils::toPath(unique_name);
|
||||||
|
if (emitted_names_.find(unique_name) == emitted_names_.end()) {
|
||||||
|
emitted_names_.insert(unique_name);
|
||||||
|
return element_names_[o->id()] = unique_name;
|
||||||
|
}
|
||||||
|
postfix += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +164,7 @@ T USDSerializer::writeNode(const IfcGeom::Element* o, const IfcGeom::Element* p)
|
|||||||
m = placements_[p->id()]->ccomponents().inverse() * m;
|
m = placements_[p->id()]->ccomponents().inverse() * m;
|
||||||
} else {
|
} else {
|
||||||
std::vector<std::string> names;
|
std::vector<std::string> names;
|
||||||
std::transform(o->parents().begin(), o->parents().end(), std::back_inserter(names), nameObject);
|
std::transform(o->parents().begin(), o->parents().end(), std::back_inserter(names), [this](auto& i) { return object_id_unique(i); });
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
std::copy(names.begin(), names.end(), std::ostream_iterator<std::string>(oss, "/"));
|
std::copy(names.begin(), names.end(), std::ostream_iterator<std::string>(oss, "/"));
|
||||||
prefix += oss.str();
|
prefix += oss.str();
|
||||||
@@ -161,12 +172,13 @@ T USDSerializer::writeNode(const IfcGeom::Element* o, const IfcGeom::Element* p)
|
|||||||
// std::ostringstream pss;
|
// std::ostringstream pss;
|
||||||
// pss << "MATT" << std::endl << std::endl;
|
// pss << "MATT" << std::endl << std::endl;
|
||||||
// pss << m << std::endl << std::endl << o->parents().back()->transformation().data()->ccomponents() << std::endl << std::endl;
|
// pss << m << std::endl << std::endl << o->parents().back()->transformation().data()->ccomponents() << std::endl << std::endl;
|
||||||
|
if (!o->parents().empty())
|
||||||
m = o->parents().back()->transformation().data()->ccomponents().inverse() * m;
|
m = o->parents().back()->transformation().data()->ccomponents().inverse() * m;
|
||||||
// pss << m << std::endl << std::endl;
|
// pss << m << std::endl << std::endl;
|
||||||
// auto psss = pss.str();
|
// auto psss = pss.str();
|
||||||
// std::wcout << psss.c_str() << std::endl;
|
// std::wcout << psss.c_str() << std::endl;
|
||||||
}
|
}
|
||||||
auto el_path = prefix + nameObject(o);
|
auto el_path = prefix + object_id_unique(o);
|
||||||
paths_[o->id()] = el_path;
|
paths_[o->id()] = el_path;
|
||||||
|
|
||||||
T t = T::Define(stage_, pxr::SdfPath(el_path));
|
T t = T::Define(stage_, pxr::SdfPath(el_path));
|
||||||
@@ -189,7 +201,8 @@ void USDSerializer::write(const IfcGeom::TriangulationElement* o) {
|
|||||||
parents_.push_back({ *it, previous });
|
parents_.push_back({ *it, previous });
|
||||||
previous = *it;
|
previous = *it;
|
||||||
}
|
}
|
||||||
pxr::UsdGeomMesh usd_mesh = writeNode<pxr::UsdGeomMesh>(o);
|
pxr::UsdGeomXform usd_mesh_container = writeNode<pxr::UsdGeomXform>(o); // writeNode<pxr::UsdGeomMesh>(o);
|
||||||
|
auto usd_mesh = pxr::UsdGeomMesh::Define(stage_, pxr::SdfPath(usd_mesh_container.GetPath().GetString() + "/" + o->context()));
|
||||||
const IfcGeom::Representation::Triangulation& mesh = o->geometry();
|
const IfcGeom::Representation::Triangulation& mesh = o->geometry();
|
||||||
const auto verts = mesh.verts();
|
const auto verts = mesh.verts();
|
||||||
const auto faces = mesh.faces();
|
const auto faces = mesh.faces();
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ private:
|
|||||||
std::set<int> written_;
|
std::set<int> written_;
|
||||||
std::map<int, std::string> paths_;
|
std::map<int, std::string> paths_;
|
||||||
std::map<int, ifcopenshell::geometry::taxonomy::matrix4::ptr> placements_;
|
std::map<int, ifcopenshell::geometry::taxonomy::matrix4::ptr> placements_;
|
||||||
|
std::set<std::string> emitted_names_;
|
||||||
|
std::map<int, std::string> element_names_;
|
||||||
public:
|
public:
|
||||||
USDSerializer(const std::string&, const ifcopenshell::geometry::Settings&, const ifcopenshell::geometry::SerializerSettings&);
|
USDSerializer(const std::string&, const ifcopenshell::geometry::Settings&, const ifcopenshell::geometry::SerializerSettings&);
|
||||||
virtual ~USDSerializer();
|
virtual ~USDSerializer();
|
||||||
@@ -89,6 +91,7 @@ public:
|
|||||||
bool isTesselated() const { return true; }
|
bool isTesselated() const { return true; }
|
||||||
void setUnitNameAndMagnitude(const std::string&, float) {}
|
void setUnitNameAndMagnitude(const std::string&, float) {}
|
||||||
void setFile(IfcParse::IfcFile*) {}
|
void setFile(IfcParse::IfcFile*) {}
|
||||||
|
std::string object_id_unique(const IfcGeom::Element* o);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user