Skip to content

Commit

Permalink
Fix: Multiple Transform connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry-Shen0527 committed Mar 20, 2024
1 parent 9e7f258 commit db0b2f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Framework3D/include/GCore/Components/XformComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class USTC_CG_API XformComponent : public GOperandComponent {
{
}

std::vector<pxr::GfVec3d> translation;
std::vector<pxr::GfVec3f> translation;
std::vector<pxr::GfVec3f> scale;
std::vector<pxr::GfVec3f> rotation;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void node_exec(ExeParams params)
geometry.attach_component(xform);
}

xform->translation.push_back(pxr::GfVec3d(t_x, t_y, t_z));
xform->translation.push_back(pxr::GfVec3f(t_x, t_y, t_z));
xform->scale.push_back(pxr::GfVec3f(s_x, s_y, s_z));
xform->rotation.push_back(pxr::GfVec3f(r_x, r_y, r_z));

Expand Down
30 changes: 22 additions & 8 deletions Framework3D/source/nodes/nodes/geometry/node_write_usd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "Nodes/node_declare.hpp"
#include "Nodes/node_register.h"
#include "geom_node_base.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/rotation.h"

namespace USTC_CG::node_write_usd {
static void node_declare(NodeDeclarationBuilder& b)
Expand Down Expand Up @@ -106,16 +108,28 @@ static void node_exec(ExeParams params)
// Transform
assert(xform_component->translation.size() == xform_component->rotation.size());

for (int i = 0; i < xform_component->translation.size(); ++i) {
auto rotation = usdgeom.AddRotateXYZOp();
rotation.Set(xform_component->rotation[i]);

auto scale = usdgeom.AddScaleOp();
scale.Set(xform_component->scale[i]);
pxr::GfMatrix4d final_transform;
final_transform.SetIdentity();

auto translate = usdgeom.AddTranslateOp();
translate.Set(xform_component->translation[i]);
for (int i = 0; i < xform_component->translation.size(); ++i) {
pxr::GfMatrix4d t;
t.SetTranslate(xform_component->translation[i]);
pxr::GfMatrix4d s;
s.SetScale(xform_component->scale[i]);

pxr::GfMatrix4d r_x;
r_x.SetRotate(pxr::GfRotation{ { 1, 0, 0 }, xform_component->rotation[i][0] });
pxr::GfMatrix4d r_y;
r_y.SetRotate(pxr::GfRotation{ { 0, 1, 0 }, xform_component->rotation[i][1] });
pxr::GfMatrix4d r_z;
r_z.SetRotate(pxr::GfRotation{ { 0, 0, 1 }, xform_component->rotation[i][2] });

auto transform = r_x * r_y * r_z * s * t;
final_transform = final_transform * transform;
}

auto xform_op = usdgeom.AddTransformOp();
xform_op.Set(final_transform);
}

// Material and Texture
Expand Down

0 comments on commit db0b2f7

Please sign in to comment.