Skip to content

Commit

Permalink
fixed attach detach feature, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wasserwecken committed May 26, 2024
1 parent 79cf603 commit d054a2b
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 128 deletions.
2 changes: 1 addition & 1 deletion bvhio/lib/Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def readAsBvh(path: str, loadKeyFrames: bool = True) -> BvhContainer:
def convertBvhToHierarchy(bvh: BvhJoint) -> Joint:
"""Converts a deserialized bvh structure into a joint hierarchy."""
# copy data into a joint
restPose = Transform(name='RestPose', position=bvh.Offset, rotation=bvh.getRotation())
restPose = Transform(name=f'RestPose.{bvh.Name}', position=bvh.Offset, rotation=bvh.getRotation())
joint = Joint(bvh.Name, restPose=restPose)
for frame, key in enumerate(bvh.Keyframes):
joint.setKeyframe(frame, Transform.fromPose(key), keep=None)
Expand Down
11 changes: 3 additions & 8 deletions bvhio/lib/hierarchy/Joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,10 @@ def roll(self, degrees: float, recursive: bool = False) -> "Joint":

return self

def attach(self, *nodes: "Joint", keep: list[str] = ['position', 'rotation', 'scale']) -> "Joint":
def attach(self, *nodes: "Joint", keep: list[str] = ['position', 'rotation', 'scale', 'anim']) -> "Joint":
super().attach(*nodes, keep=keep)

self.RestPose.attach([node.RestPose for node in nodes], keep=keep)

if 'anim' in keep:
if keep is not None and 'anim' in keep:
root = self
while root.Parent is not None:
root = self.Parent
Expand All @@ -326,10 +324,7 @@ def attach(self, *nodes: "Joint", keep: list[str] = ['position', 'rotation', 'sc
def detach(self, *nodes: "Joint", keep: list[str] = ['position', 'rotation', 'scale', 'anim']) -> "Joint":
super().detach(*nodes, keep=keep)

for node in nodes:
node.RestPose.clearParent(keep=keep)

if 'anim' in keep:
if keep is not None and 'anim' in keep:
root = self
while root.Parent is not None:
root = self.Parent
Expand Down
Loading

0 comments on commit d054a2b

Please sign in to comment.