diff --git a/README.md b/README.md index 72b2e92..51c89ad 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Operation | Description --------------------------- | --------------------------- del_model <reg_ex> | Deletes all models whose name contains the regular expression <reg_ex>. geo_name <name> | Change the .geo's name to <name>. + swap_left_right <reg_ex> | Swap left and right bones for all models matching <reg_ex>. rename_model <old> <new> | Rename a model from <old> to <new>. rename_texture <old> <new> | Rename a texture from <old> to <new>. rescale_all <scale> | Rescale all vertices in all models by multiplying them all by <scale> . diff --git a/bones.py b/bones.py index dc702fa..f624903 100644 --- a/bones.py +++ b/bones.py @@ -114,9 +114,27 @@ BONES_LIST = [ "Leg_R_Jet2", ] +BONES_LEFT = [] +BONES_RIGHT = [] +BONES_SWAP = [] + BONES_LOOKUP = {} for i in range(len(BONES_LIST)): BONES_LOOKUP[BONES_LIST[i]] = i BONES_LOOKUP[BONES_LIST[i].upper()] = i BONES_LOOKUP[BONES_LIST[i].lower()] = i + if BONES_LIST[i][-1] == "L": + BONES_LEFT.append(BONES_LIST[i]) + if BONES_LIST[i][-1] == "R": + BONES_RIGHT.append(BONES_LIST[i]) +for i in range(len(BONES_LIST)): + j = i + n = BONES_LIST[i] + if n in BONES_LEFT: + n = BONES_RIGHT[BONES_LEFT.index(n)] + j = BONES_LOOKUP[n] + elif n in BONES_RIGHT: + n = BONES_LEFT[BONES_RIGHT.index(n)] + j = BONES_LOOKUP[n] + BONES_SWAP.append(j) diff --git a/geo_edit.py b/geo_edit.py index 415a006..d1ec61d 100755 --- a/geo_edit.py +++ b/geo_edit.py @@ -3,6 +3,10 @@ import sys import re from geo import Geo +try: + from .bones import * +except: + from bones import * @@ -13,6 +17,7 @@ if len(sys.argv) < 4: print("Operations:") print(" del_model Delete models with the name matching regular expression.") print(" geo_name Rename the name of the .geo .") + print(" swap_left_right Swap left and right bones for all models matching the regular expression.") print(" rename_model Rename model to .") print(" rename_texture Rename texture to .") print(" rescale_all Rescale all models by the given amount.") @@ -101,6 +106,18 @@ while arg_i < len(sys.argv): break if found <= 0: print(" **Warning!*** Set model scale failed, no model named '%s'." % (nameold.decode("utf-8"), )) + elif operation == "swap_left_right": + reg_exp_str = sys.argv[arg_i] + arg_i += 1 + reg_exp = re.compile(reg_exp_str) + for i in range(len(geo.models) - 1, -1, -1): + name = geo.models[i].name.decode("utf-8") + if reg_exp.search(name) is not None: + print("Swapping left and right in: %s" % (name, )) + model = geo.models[i] + for j in range(len(model.weight_bones)): + for k in range(len(model.weight_bones[j])): + model.weight_bones[j][k] = BONES_SWAP[model.weight_bones[j][k]] else: print("Unknown operation: '%s'" % (operation, )) exit()