Skip to content

Commit

Permalink
update graphics based on backend changes (#711)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohamed Koubaa <koubaa@github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: pyansys-ci-bot <pyansys.github.bot@ansys.com>
  • Loading branch information
4 people committed Apr 17, 2024
1 parent 5874a36 commit 09810d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/711.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
update graphics based on backend changes
8 changes: 2 additions & 6 deletions src/ansys/mechanical/core/embedding/viz/pyvista_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@
def _transform_to_pyvista(transform: "Ansys.ACT.Math.Matrix4D"):
"""Convert the Transformation matrix to a numpy array."""
np_transform = np.array([transform[i] for i in range(16)]).reshape(4, 4)
# There's a bug in mechanical, the scenegraph wrappers use theMatrix4D
# type, which puts the transformations in the transposed location relative
# to pyvista. But they use the same matrix layout as pyvista, so that
# doesn't conform to the expectations of Matrix4D. When it is fixed there,
# the below line has to be uncommented

# np_transform = np_transform.transpose()
# The mechanical scenegraph transform node is the transpose of the pyvista transform matrix
np_transform = np_transform.transpose()
return np_transform


Expand Down
23 changes: 13 additions & 10 deletions src/ansys/mechanical/core/embedding/viz/usd_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
from .utils import bgr_to_rgb_tuple, get_nodes_and_coords


def _transform_to_rotation_quat(transform: "Ansys.ACT.Math.Matrix4D") -> Gf.Quatf:
def _transform_to_rotation_translation(
transform: "Ansys.ACT.Math.Matrix4D",
) -> typing.Tuple[Gf.Quatf, Gf.Vec3f]:
"""Convert the Transformation matrix to a single-precision quaternion."""
transforms = [transform[i] for i in range(16)]
m = Gf.Matrix4d()
Expand All @@ -44,14 +46,14 @@ def _transform_to_rotation_quat(transform: "Ansys.ACT.Math.Matrix4D") -> Gf.Quat
m.SetRow(2, transforms[8:12])
m.SetRow(3, transforms[12:16])

# TODO: m = m.GetTranspose() # if/when needed?

# Get quaternion from transformation matrix
quatd: Gf.Quatd = m.ExtractRotationQuat()

# Convert to single precision
quatf = Gf.Quatf(quatd)
return quatf
# Get translation from transformation matrix
transd: Gf.Vec3d = m.ExtractTranslation()

# Return as single precision
return Gf.Quatf(quatd), Gf.Vec3f(transd)


def _convert_tri_tessellation_node(
Expand Down Expand Up @@ -79,12 +81,13 @@ def _convert_transform_node(
) -> Usd.Prim:
"""Convert a mechanical transform node into a Usd Xform prim."""
prim = UsdGeom.Xform.Define(stage, path)
prim.AddOrientOp().Set(_transform_to_rotation_quat(node.Transform))
rotation, translation = _transform_to_rotation_translation(node.Transform)
prim.AddOrientOp().Set(rotation)
prim.AddTranslateOp().Set(translation)
child_node = node.Child
child_path = prim.GetPath().AppendPath("TriTessellation")
if isinstance(child_node, Ansys.Mechanical.Scenegraph.TriTessellationNode):
_convert_tri_tessellation_node(
node.Child, stage, prim.GetPath().AppendPath("TriTessellation"), rgb
)
_convert_tri_tessellation_node(child_node, stage, child_path, rgb)
return prim


Expand Down

0 comments on commit 09810d3

Please sign in to comment.