diff --git a/README.md b/README.md index 0e30ef7..a9c662b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/geo_edit.py b/geo_edit.py index b51a07d..4e14123 100755 --- a/geo_edit.py +++ b/geo_edit.py @@ -14,6 +14,8 @@ if len(sys.argv) < 4: print(" del_model Delete models with the name matching regular expression.") print(" geo_name Rename the name of the .geo .") print(" rename_model Rename model to .") + print(" rename_texture Rename texture to .") + print(" rescale_all 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()