Coverage for trimesh/__main__.py: 0%

26 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-24 04:40 +0000

1import argparse 

2 

3 

4def main(): 

5 """ 

6 A simple command line utility for accessing trimesh functions. 

7 

8 To display a mesh: 

9 > trimesh hi.stl 

10 

11 To convert a mesh: 

12 > trimesh hi.stl -e hey.glb 

13 

14 To print some information about a mesh: 

15 > trimesh hi.stl --statistics 

16 """ 

17 from .exchange.load import load 

18 

19 parser = argparse.ArgumentParser() 

20 parser.add_argument("file_name", nargs="?") 

21 

22 parser.add_argument( 

23 "-i", 

24 "--interact", 

25 action="store_true", 

26 help="Get an interactive terminal with trimesh and loaded geometry", 

27 ) 

28 parser.add_argument("-e", "--export", help="Export a loaded geometry to a new file.") 

29 

30 args = parser.parse_args() 

31 

32 if args.file_name is None: 

33 parser.print_help() 

34 return 

35 else: 

36 scene = load(args.file_name) 

37 

38 summary(scene) 

39 

40 if args.export is not None: 

41 scene.export(args.export) 

42 

43 if args.interact: 

44 return interactive(scene) 

45 

46 scene.show() 

47 

48 

49def summary(geom): 

50 """ """ 

51 print(geom) # noqa: T201 

52 

53 

54def interactive(scene): 

55 """ 

56 Run an interactive session with a loaded scene and trimesh. 

57 

58 This uses the standard library `code.InteractiveConsole` 

59 """ 

60 local = locals() 

61 

62 from code import InteractiveConsole 

63 

64 # filter out junk variables. 

65 InteractiveConsole(locals={k: v for k, v in local.items() if k != "local"}).interact() 

66 

67 

68if __name__ == "__main__": 

69 main()