mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 18:43:26 +00:00
Various improvements to USD serializer related to object naming
This commit is contained in:
@@ -117,17 +117,28 @@ void USDSerializer::writeHeader() {
|
||||
stage_->GetRootLayer()->SetComment("File generated by IfcOpenShell " + std::string(IFCOPENSHELL_VERSION));
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::string nameObject(const IfcGeom::Element* o) {
|
||||
std::string name = o->name();
|
||||
const std::string type = o->type();
|
||||
const std::string id = std::to_string(o->id());
|
||||
if (name.empty()) {
|
||||
name = type + "_UnNamed_" + id;
|
||||
} else {
|
||||
name = type + "_" + usd_utils::toPath(name) + "_" + id;
|
||||
std::string USDSerializer::object_id_unique(const IfcGeom::Element* o) {
|
||||
auto it = element_names_.find(o->id());
|
||||
if (it != element_names_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
int postfix = 0;
|
||||
auto name = object_id(o);
|
||||
auto suffix = "-" + boost::to_lower_copy(o->context());
|
||||
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;
|
||||
} else {
|
||||
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::copy(names.begin(), names.end(), std::ostream_iterator<std::string>(oss, "/"));
|
||||
prefix += oss.str();
|
||||
@@ -161,12 +172,13 @@ T USDSerializer::writeNode(const IfcGeom::Element* o, const IfcGeom::Element* p)
|
||||
// std::ostringstream pss;
|
||||
// pss << "MATT" << 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;
|
||||
// pss << m << std::endl << std::endl;
|
||||
// auto psss = pss.str();
|
||||
// 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;
|
||||
|
||||
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 });
|
||||
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 auto verts = mesh.verts();
|
||||
const auto faces = mesh.faces();
|
||||
|
||||
Reference in New Issue
Block a user