Skip to content

Commit

Permalink
add trimesh -i CLI helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Sep 27, 2024
1 parent 875c54e commit ba0afbd
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions trimesh/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,42 @@ def main():
from .exchange.load import load

parser = argparse.ArgumentParser()
parser.add_argument("file_name")
parser.add_argument("file_name", nargs="?")

parser.add_argument(
"-i",
"--interact",
action="store_true",
help="Get an interactive terminal with trimesh and loaded geometry",
)
parser.add_argument("-e", "--export", help="Export a loaded geometry to a new file.")

args = parser.parse_args()
load(args.file_name).show()

if args.file_name is None:
scene = None
else:
scene = load(args.file_name)

if args.export is not None:
scene.export(args.export)

if args.interact:
return interactive(scene)


def interactive(scene):
"""
Run an interactive session with a loaded scene and trimesh.
This uses the standard library `code.InteractiveConsole`
"""
local = locals()

from code import InteractiveConsole

# filter out junk variables.
InteractiveConsole(locals={k: v for k, v in local.items() if k != "local"}).interact()


if __name__ == "__main__":
Expand Down

0 comments on commit ba0afbd

Please sign in to comment.