Skip to content

Commit

Permalink
Order (#1)
Browse files Browse the repository at this point in the history
Order
  • Loading branch information
Narazaka authored Jan 18, 2020
2 parents a52c3cc + adace82 commit 074cc53
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions blender-shapekey-exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'category': 'Mesh',
'location': 'View 3D > Tool Shelf(2.79) / Sidebar(2.80) > Shapekey Exporter',
'description': 'Name based shapekey export and import tool',
"version" : (0, 1, 0),
"version" : (0, 2, 0),
"blender" : (2, 80, 0),
'tracker_url': 'https://github.com/Narazaka/blender-shapekey-exporter/issues',
}
Expand Down Expand Up @@ -59,7 +59,7 @@ def execute(self, context):
key_blocks = obj.data.shape_keys.key_blocks
data[object_name] = {
"base": base_key_block.name,
"diffs": {},
"diffs": [],
}
for key_block_name in key_blocks.keys():
key_block = key_blocks[key_block_name]
Expand All @@ -71,8 +71,11 @@ def execute(self, context):
diff_key_values = []
for i in range(len(key_values)):
diff_key_values.append((key_values[i] - base_key_values[i])[:])
data[object_name]["diffs"][key_block_name] = diff_key_values

data[object_name]["diffs"].append({
"name": key_block_name,
"values": diff_key_values,
})

with open(self.filepath, mode='w', encoding="utf8") as f:
json.dump(data, f, sort_keys=True, indent=4, ensure_ascii=False)

Expand Down Expand Up @@ -111,14 +114,15 @@ def execute(self, context):

key_blocks = obj.data.shape_keys.key_blocks
# overwrite always (TODO: selectable)
for key_block_name in data[object_name]["diffs"].keys():
for key_block_data in data[object_name]["diffs"]:
key_block_name = key_block_data["name"]
key_block = key_blocks.get(key_block_name)
if not key_block:
obj.shape_key_add()
key_blocks[-1].name = key_block_name
if base_key_block == key_block: # base
continue
key_values = [mathutils.Vector(vec) for vec in data[object_name]["diffs"][key_block_name]]
key_values = [mathutils.Vector(vec) for vec in key_block_data["values"]]
if len(key_values) != len(base_key_values):
raise RuntimeError("mesh vertex count is different: " + key_block_name)
for i in range(len(key_values)):
Expand Down

0 comments on commit 074cc53

Please sign in to comment.