Skip to content

Commit

Permalink
Vertex animation exports should now be scaled and translated correctly!
Browse files Browse the repository at this point in the history
With that, we're feature complete - on to optimizing, bug finding/fixing, etc.
  • Loading branch information
Five-Damned-Dollarz committed Mar 4, 2021
1 parent 600c58a commit 80fe9b8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def __init__(self):
# Note this should line up with md_vert_list, and go on for md_vert_count * keyframe_count
# List of 3 chars (verts)
self.vertex_deformations = []
self.vertex_deformation_bounds=dict()
# List of Vector (verts)
# Scaled by the animation bounding box
self.transformed_vertex_deformations = []
Expand Down
7 changes: 4 additions & 3 deletions src/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,6 @@ def from_armature(armature_object):

''' Vertex Animations '''

# Has an issue, probably in the mesh transforms
# TODO: try undoing the mesh bind pose so all pieces are centered on [0,0,0] before bounds calculation, and compression

# Then most trivially, you find min and max of each dimension, set scales to (maxes-mins), subtract mins from all points, then divide by scales.
# And the transform is set by doing the same subtract and divide to the origin
# Later on, to reduce artifacts, instead of just doing that and then scaling back up to 255 blindly, you could iterate over possible values UP to 255, and check sum of error^2 for each one, and choose the one with lowest total error
Expand All @@ -331,6 +328,8 @@ def from_armature(armature_object):

if mesh.shape_keys and len(mesh.shape_keys.key_blocks)>1:
for animation in model.animations:
print("Processing vertex animation", animation.name)

animation.vertex_deformations=dict()

shape_keys=[shape_key for shape_key in mesh.shape_keys.key_blocks if shape_key.name.startswith(animation.name)]
Expand Down Expand Up @@ -368,6 +367,8 @@ def from_armature(armature_object):
node.bounds_max.y=max(node.bounds_max.y, temp_vert.y)
node.bounds_max.z=max(node.bounds_max.z, temp_vert.z)

animation.vertex_deformation_bounds[node]=[node.bounds_min, node.bounds_max]

node.md_vert_list.extend(node_vertices if dirty_node else [])

scale=node.bounds_max-node.bounds_min
Expand Down
6 changes: 4 additions & 2 deletions src/writer_abc_v6_pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ def __init__(self, name, data):
index=keyframe_index*node.md_vert_count+md_vert_index
buffer.extend(struct.pack('BBB', int(anim.vertex_deformations[node][index].x*255), int(anim.vertex_deformations[node][index].y*255), int(anim.vertex_deformations[node][index].z*255)))

buffer.extend(self._vector_to_bytes((node.bounds_max-node.bounds_min)/255))
buffer.extend(self._vector_to_bytes(node.bounds_min))
scale=anim.vertex_deformation_bounds[node][1]-anim.vertex_deformation_bounds[node][0]

buffer.extend(self._vector_to_bytes(scale/255))
buffer.extend(self._vector_to_bytes(anim.vertex_deformation_bounds[node][0]))

sections.append(Section('Animation', bytes(buffer)))

Expand Down

0 comments on commit 80fe9b8

Please sign in to comment.