break else: raise ValueError("Rigid Body Orientation not Resetting to 0,0,0 after 3 attempts. This happens sometimes (bug), please just run the script again.") # Scan points points = scan() assert(len(points) > 100), "Only {} points detected. Tracker is not detecting enough points to model. Is the projector turned on?".format(len(points)) # Rotate all points to be mean-centered and aligned to Optitrack Markers direction or largest variance. markers = np.array(rigid_bodies[arena_name].point_cloud_markers) points = points - np.mean(markers, axis=0) if args.mean_center else points points = np.dot(points, rotation_matrix(np.radians(orienting.rotate_to_var(markers)), [0, 1, 0])[:3, :3]) if args.pca_rotate else points # TODO: RE-ADD PCA Rotation! # Plot preview of data collected from matplotlib import pyplot as plt plot_3d(points, square_axis=True) plt.show() # Get vertex positions and normal directions from the collected data. vertices, normals = meshify(points, n_surfaces=args.n_sides) vertices = {wall: fan_triangulate(reorder_vertices(verts)) for wall, verts in vertices.items()} # Triangulate # Write wavefront .obj file to app data directory and user-specified directory for importing into Blender. wave_str = data_to_wavefront(arena_name, vertices, normals) # Write to app data directory # with open(path.join(rc.data_dir, 'arena.obj'), 'wb') as wavfile: with open('arena.obj', 'wb') as wavfile: wavfile.write(wave_str) # If specified, optionally also save .obj file to another directory.
save_files = save_files + [args.save_filename] if args.save_filename else save_files for filename in save_files: with open(filename, 'wb') as myfile: pickle.dump({'imgPoints': screenPos, 'objPoints': pointPos}, myfile) if not args.silent_mode: print('Saved to: {}'.format(os.path.splitext(filename)[0] + '.pickle')) # Else, get the data from file. else: with open(args.load_filename) as datafile: data = pickle.load(datafile) assert isinstance(data, dict) and 'imgPoints' in data.keys() and 'objPoints' in data.keys(), "Loaded Datafile in wrong format. See help for more info." screenPos, pointPos = data['imgPoints'], data['objPoints'] import matplotlib.pyplot as plt plot_3d(pointPos, square_axis=True) plt.show() # Calibrate projector data position, rotation = calibrate(screenPos, pointPos) if not args.silent_mode: print('\nEstimated Projector Position:\n\t{}\nEstimated Projector Rotation:\n{}\n'.format(position, rotation)) # Save Results to application data. if not args.test_mode: # Save Data in format for putting into a ratcave.graphics.Camera projector_data = {'position': position, 'rotation': rotation, 'fov_y': args.fov_y} with open('projector_data.pickle', "wb") as datafile: pickle.dump(projector_data, datafile)