From 80fe9b87dad2d89afb8edf170eeb3c457c381d2c Mon Sep 17 00:00:00 2001 From: Five-Damned-Dollarz <79036198+Five-Damned-Dollarz@users.noreply.github.com> Date: Thu, 4 Mar 2021 16:57:41 +1100 Subject: [PATCH] Vertex animation exports should now be scaled and translated correctly! With that, we're feature complete - on to optimizing, bug finding/fixing, etc. --- src/abc.py | 1 + src/builder.py | 7 ++++--- src/writer_abc_v6_pc.py | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/abc.py b/src/abc.py index 620aa54..2ce1935 100644 --- a/src/abc.py +++ b/src/abc.py @@ -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 = [] diff --git a/src/builder.py b/src/builder.py index 23254cd..8165df4 100644 --- a/src/builder.py +++ b/src/builder.py @@ -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 @@ -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)] @@ -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 diff --git a/src/writer_abc_v6_pc.py b/src/writer_abc_v6_pc.py index abf3795..eaae007 100644 --- a/src/writer_abc_v6_pc.py +++ b/src/writer_abc_v6_pc.py @@ -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)))