mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 14:02:27 +00:00
usd rotateXYZop
This commit is contained in:
@@ -30,6 +30,8 @@
|
|||||||
#include "pxr/usd/usdShade/shader.h"
|
#include "pxr/usd/usdShade/shader.h"
|
||||||
#include "pxr/usd/usdShade/materialBindingAPI.h"
|
#include "pxr/usd/usdShade/materialBindingAPI.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
USDSerializer::USDSerializer(const std::string& out_filename, const SerializerSettings& settings):
|
USDSerializer::USDSerializer(const std::string& out_filename, const SerializerSettings& settings):
|
||||||
WriteOnlyGeometrySerializer(settings),
|
WriteOnlyGeometrySerializer(settings),
|
||||||
filename_(out_filename)
|
filename_(out_filename)
|
||||||
@@ -102,6 +104,24 @@ std::vector<pxr::UsdShadeMaterial> USDSerializer::createMaterials(const std::vec
|
|||||||
return materials;
|
return materials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pxr::GfVec3f USDSerializer::rotation_degrees_from_matrix(const std::vector<double>& matrix) const {
|
||||||
|
const double epsilon = 1e-6;
|
||||||
|
double angleX, angleY, angleZ;
|
||||||
|
|
||||||
|
angleX = atan2(-matrix[5], matrix[8]);
|
||||||
|
if (std::abs(std::abs(matrix[5]) - 1.0) < epsilon) {
|
||||||
|
angleZ = 0.0;
|
||||||
|
angleY = atan2(matrix[6], matrix[0]);
|
||||||
|
} else {
|
||||||
|
angleZ = atan2(matrix[1], matrix[4]);
|
||||||
|
angleY = atan2(matrix[2], matrix[8]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pxr::GfVec3f(static_cast<float>(angleX * 180.0 / M_PI),
|
||||||
|
static_cast<float>(angleY * 180.0 / M_PI),
|
||||||
|
static_cast<float>(angleZ * 180.0 / M_PI));
|
||||||
|
}
|
||||||
|
|
||||||
void USDSerializer::writeHeader() {
|
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));
|
||||||
}
|
}
|
||||||
@@ -126,12 +146,13 @@ void USDSerializer::write(const IfcGeom::TriangulationElement* o) {
|
|||||||
auto usd_mesh = pxr::UsdGeomMesh::Define(stage_, pxr::SdfPath("/World/" + name));
|
auto usd_mesh = pxr::UsdGeomMesh::Define(stage_, pxr::SdfPath("/World/" + name));
|
||||||
|
|
||||||
usd_mesh.AddTranslateOp().Set(pxr::GfVec3d(m[9], m[10], m[11]));
|
usd_mesh.AddTranslateOp().Set(pxr::GfVec3d(m[9], m[10], m[11]));
|
||||||
|
usd_mesh.AddRotateXYZOp().Set(rotation_degrees_from_matrix(m));
|
||||||
|
|
||||||
pxr::VtVec3fArray points;
|
pxr::VtVec3fArray points;
|
||||||
for(std::size_t i = 0; i < verts.size(); i+=3) {
|
for(std::size_t i = 0; i < verts.size(); i+=3) {
|
||||||
points.push_back(pxr::GfVec3f(static_cast<float>(verts[i] * m[0] + verts[i+1] * m[3] + verts[i+2] * m[6]),
|
points.push_back(pxr::GfVec3f(static_cast<float>(verts[i]),
|
||||||
static_cast<float>(verts[i] * m[1] + verts[i+1] * m[4] + verts[i+2] * m[7]),
|
static_cast<float>(verts[i+1]),
|
||||||
static_cast<float>(verts[i] * m[2] + verts[i+1] * m[5] + verts[i+2] * m[8])));
|
static_cast<float>(verts[i+2])));
|
||||||
}
|
}
|
||||||
usd_mesh.CreatePointsAttr().Set(points);
|
usd_mesh.CreatePointsAttr().Set(points);
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ private:
|
|||||||
std::map<std::string, pxr::UsdShadeMaterial> materials_;
|
std::map<std::string, pxr::UsdShadeMaterial> materials_;
|
||||||
|
|
||||||
std::vector<pxr::UsdShadeMaterial> createMaterials(const std::vector<IfcGeom::Material>&);
|
std::vector<pxr::UsdShadeMaterial> createMaterials(const std::vector<IfcGeom::Material>&);
|
||||||
|
pxr::GfVec3f rotation_degrees_from_matrix(const std::vector<double>&) const;
|
||||||
public:
|
public:
|
||||||
USDSerializer(const std::string&, const SerializerSettings&);
|
USDSerializer(const std::string&, const SerializerSettings&);
|
||||||
virtual ~USDSerializer();
|
virtual ~USDSerializer();
|
||||||
|
|||||||
Reference in New Issue
Block a user