def main(): path_to_obj = "models/teapot.obj" model = geom_tools.from_obj_file(path_to_obj) # Print various statistics print(f"Model loaded, " f"n vertices: {model.n_vertices()}, " f"n vts: {model.n_texture_vertices()}, " f"n polygons: {model.n_polygons()}, " f"n triangles: {model.n_triangles()}") # or simply print(model.summary()) print(model.vertices[:5]) # NumPy array, same for texture vertices, etc print( model.polygon_vertex_indices[:5] ) # List of lists, same for texture topology, triangulated topology, etc print(model.triangle_vertex_indices[:5] ) # Fan like triangulation of topology. Keep original triangles canvas_size = (300, 250) fit_to_view_transformation = geom_tools.fit_to_view_transform( bbox=model.bbox(), canvas_size=canvas_size) vertices = geom_tools.transform_vertices(fit_to_view_transformation, model.vertices) canvas = np.zeros((canvas_size[1], canvas_size[0], 3), dtype=np.uint8) for v in vertices.round().astype(np.int32): cv2.circle(canvas, (v[0], v[1]), 1, (0, 200, 0), -1) cv2.imshow("", canvas) cv2.waitKey()
def test_rotated_and_translated06(self): matrix = [[0, 1, 0], [1, 0, 0], [2, 0, 0]] vector = [2, 0, 3] res = geom_tools.transform_vertices((matrix, vector), vertices=[ [0, 0, 0], [1, 0, 5], ]) self.assertTrue(is_arrays_equal(res, [ [2, 0, 3], [2, 1, 5], ]))
def test_rotation_around_vertex01(self): rotation = [[0, -1, 0], [1, 0, 0], [0, 0, 1]] center = [0, 2, 0] transformation = geom_tools.rotation_around_vertex(rotation, center) vertices = [ [1, 0, 0], [0, 1, 0], [0, 0, 1], ] res = geom_tools.transform_vertices(transformation, vertices) ans = [ [2, 3, 0], [1, 2, 0], [2, 2, 1], ] self.assertTrue(is_arrays_equal(ans, res))
def test_find_rotation_and_translation01(self): src = [ [1, 0, 0], [0, 1, 0], [0, 0, 1], ] dst = [ [1, 0, 0], [0, 1, 0], [0, 0, 1], ] src = np.array(src) dst = np.array(dst) transformation = find_rotation_and_translation(src, dst) res = geom_tools.transform_vertices(transformation, src) self.assertTrue(geom_tools.utils.is_arrays_equal(res, dst))