Added 'rename_texture' and 'rescale_all' operations to 'geo_edit.py' .

master
TigerKat 5 years ago
parent d4194576b7
commit b0b09d897e

@ -48,8 +48,9 @@ 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>.
rename_model <new> <old> | Rename a model from <new> to <old>.
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> .
Multiple operations can be specified and performed in the same run.
## Known Issues

@ -14,6 +14,8 @@ if len(sys.argv) < 4:
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(" 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.")
exit()
fn_in = sys.argv[1]
@ -54,7 +56,7 @@ while arg_i < len(sys.argv):
nameold = bytes(sys.argv[arg_i], "utf-8")
namenew = bytes(sys.argv[arg_i+1], "utf-8")
arg_i += 2
renamed = False
renamed = 0
for m in geo.models:
if m.name == nameold:
m.name = namenew
@ -63,6 +65,26 @@ while arg_i < len(sys.argv):
break
if renamed <= 0:
print(" **Warning!*** Rename failed, no model name matched '%s'." % (nameold.decode("utf-8"), ))
elif operation == "rename_texture":
nameold = bytes(sys.argv[arg_i], "utf-8")
namenew = bytes(sys.argv[arg_i+1], "utf-8")
arg_i += 2
renamed = 0
for i, t in enumerate(geo.header_texnames):
if t == nameold:
geo.header_texnames[i] = namenew
print("Renamed texture '%s' to '%s'" % (nameold.decode("utf-8"), namenew.decode("utf-8")))
renamed += 1
break
if renamed <= 0:
print(" **Warning!*** Rename failed, no texture name matched '%s'." % (nameold.decode("utf-8"), ))
elif operation == "rescale_all":
scale = float(sys.argv[arg_i])
arg_i += 1
for m in geo.models:
for i in range(len(m.verts)):
for j in range(3):
m.verts[i][j] *= scale
else:
print("Unknown operation: '%s'" % (operation, ))
exit()

Loading…
Cancel
Save