Added 'swap_left_right' to 'geo_edit.py' to swap left and right bones in a .geo's model.

master
TigerKat 4 years ago
parent 176fe43faf
commit cce9cbefcc

@ -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> .

@ -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)

@ -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 <reg_ex_filter> Delete models with the name matching regular expression.")
print(" geo_name <geo_name> Rename the name of the .geo .")
print(" swap_left_right <reg_ex> Swap left and right bones for all models matching the regular expression.")
print(" rename_model <old> <new> Rename model <old> to <new>.")
print(" rename_texture <old> <new> Rename texture <old> to <new>.")
print(" rescale_all <scale> 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()

Loading…
Cancel
Save