mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 11:28:13 +00:00
Last minute refactoring
This commit is contained in:
@@ -36,8 +36,8 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
USDSerializer::USDSerializer(const std::string& out_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, ::logger* logger):
|
||||
WriteOnlyGeometrySerializer(geometry_settings, settings, logger),
|
||||
usd_serializer::usd_serializer(const std::string& out_filename, const ifcopenshell::geom::settings& settings, ::logger* logger):
|
||||
write_only_geometry_serializer(settings, logger),
|
||||
filename_(out_filename)
|
||||
{
|
||||
std::size_t found = filename_.find_last_of("/\\");
|
||||
@@ -47,7 +47,7 @@ USDSerializer::USDSerializer(const std::string& out_filename, const ifcopenshell
|
||||
if(!stage_)
|
||||
throw std::runtime_error("Could not create USD stage");
|
||||
|
||||
if (!settings.get<ifcopenshell::geometry::settings::UseYUp>().get()) {
|
||||
if (!settings.get<ifcopenshell::geom::settings::UseYUp>().get()) {
|
||||
pxr::UsdGeomSetStageUpAxis(stage_, pxr::UsdGeomTokens->z);
|
||||
}
|
||||
|
||||
@@ -60,11 +60,11 @@ USDSerializer::USDSerializer(const std::string& out_filename, const ifcopenshell
|
||||
ready_ = true;
|
||||
}
|
||||
|
||||
USDSerializer::~USDSerializer() {
|
||||
usd_serializer::~usd_serializer() {
|
||||
|
||||
}
|
||||
|
||||
std::vector<pxr::UsdShadeMaterial> USDSerializer::createMaterials(const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& styles)
|
||||
std::vector<pxr::UsdShadeMaterial> usd_serializer::createMaterials(const std::vector<ifcopenshell::geom::taxonomy::style::ptr>& styles)
|
||||
{
|
||||
if(styles.empty())
|
||||
throw std::runtime_error("No styles to create materials from");
|
||||
@@ -113,11 +113,11 @@ std::vector<pxr::UsdShadeMaterial> USDSerializer::createMaterials(const std::vec
|
||||
return materials;
|
||||
}
|
||||
|
||||
void USDSerializer::writeHeader() {
|
||||
void usd_serializer::writeHeader() {
|
||||
stage_->GetRootLayer()->SetComment("File generated by IfcOpenShell " + std::string(IFCOPENSHELL_VERSION));
|
||||
}
|
||||
|
||||
std::string USDSerializer::object_id_unique(const IfcGeom::Element* o) {
|
||||
std::string usd_serializer::object_id_unique(const ifcopenshell::geom::element* o) {
|
||||
auto it = element_names_.find(o->id());
|
||||
if (it != element_names_.end()) {
|
||||
return it->second;
|
||||
@@ -143,7 +143,7 @@ std::string USDSerializer::object_id_unique(const IfcGeom::Element* o) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T USDSerializer::writeNode(const IfcGeom::Element* o, const IfcGeom::Element* p) {
|
||||
T usd_serializer::writeNode(const ifcopenshell::geom::element* o, const ifcopenshell::geom::element* p) {
|
||||
written_.insert(o->id());
|
||||
|
||||
auto m = o->transformation().data()->ccomponents();
|
||||
@@ -153,7 +153,7 @@ T USDSerializer::writeNode(const IfcGeom::Element* o, const IfcGeom::Element* p)
|
||||
|
||||
bool is_root = false;
|
||||
std::string prefix = "/";
|
||||
if (geometry_settings_.get<ifcopenshell::geometry::settings::UseElementHierarchy>().get() && p == nullptr && o->parents().empty()) {
|
||||
if (settings_.get<ifcopenshell::geom::settings::UseElementHierarchy>().get() && p == nullptr && o->parents().empty()) {
|
||||
// Emitting hierarchy
|
||||
// p == nullptr means we're in the first pass serializing geometric elements
|
||||
// in that case empty parents vector means it's the root
|
||||
@@ -195,15 +195,15 @@ T USDSerializer::writeNode(const IfcGeom::Element* o, const IfcGeom::Element* p)
|
||||
return t;
|
||||
}
|
||||
|
||||
void USDSerializer::write(const IfcGeom::TriangulationElement* o) {
|
||||
IfcGeom::Element const * previous = nullptr;
|
||||
void usd_serializer::write(const ifcopenshell::geom::triangulation_element* o) {
|
||||
ifcopenshell::geom::element const * previous = nullptr;
|
||||
for (auto it = o->parents().begin(); it != o->parents().end(); ++it) {
|
||||
parents_.push_back({ *it, previous });
|
||||
previous = *it;
|
||||
}
|
||||
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 ifcopenshell::geom::Representation::triangulation& mesh = o->geometry();
|
||||
const auto verts = mesh.verts();
|
||||
const auto faces = mesh.faces();
|
||||
const auto material_ids = mesh.material_ids();
|
||||
@@ -240,7 +240,7 @@ void USDSerializer::write(const IfcGeom::TriangulationElement* o) {
|
||||
}
|
||||
}
|
||||
|
||||
void USDSerializer::finalize() {
|
||||
void usd_serializer::finalize() {
|
||||
// we write the parents at the end, because some parents might actually be
|
||||
// geometrical entities such as the IfcSite.
|
||||
std::set<int> written;
|
||||
@@ -254,7 +254,7 @@ void USDSerializer::finalize() {
|
||||
stage_->Save();
|
||||
}
|
||||
|
||||
template pxr::UsdGeomMesh USDSerializer::writeNode<pxr::UsdGeomMesh>(const IfcGeom::Element*, const IfcGeom::Element*);
|
||||
template pxr::UsdGeomXform USDSerializer::writeNode<pxr::UsdGeomXform>(const IfcGeom::Element*, const IfcGeom::Element*);
|
||||
template pxr::UsdGeomMesh usd_serializer::writeNode<pxr::UsdGeomMesh>(const ifcopenshell::geom::element*, const ifcopenshell::geom::element*);
|
||||
template pxr::UsdGeomXform usd_serializer::writeNode<pxr::UsdGeomXform>(const ifcopenshell::geom::element*, const ifcopenshell::geom::element*);
|
||||
|
||||
#endif // WITH_USD
|
||||
|
||||
Reference in New Issue
Block a user