def main(): """ create a window, add scene objects, then run rendering loop """ viewer = Viewer() shader = Shader("phong.vert", "phong.frag") node = Node(transform=rotate((0, 0, 1), 45)) viewer.add(node) light_dir = (0, -1, 0) node.add(*[ mesh for file in sys.argv[1:] for mesh in load_phong_mesh(file, shader, light_dir) ]) if len(sys.argv) != 2: print('Usage:\n\t%s [3dfile]*\n\n3dfile\t\t the filename of a model in' ' format supported by assimp.' % (sys.argv[0], )) # start rendering loop viewer.run()
def main(): """ create a window, add scene objects, then run rendering loop """ viewer = Viewer() # default color shader shader = Shader("color.vert", "color.frag") # think about it: we can re-use the same cylinder instance! cylinder = Cylinder(shader) # make a flat cylinder base_shape = Node(transform=scale(1, 0.7, 1)) base_shape.add(cylinder) # shape of robot base # make a thin cylinder arm_shape = Node(transform=translate(0, 3, 0) @ scale(0.1, 2.4, 0.1)) arm_shape.add(cylinder) # shape of arm # make a thin cylinder forearm_shape = Node(transform=translate(0, 7, 0) @ scale(0.1, 1.8, 0.1)) forearm_shape.add(cylinder) # shape of forearm theta = 45.0 # base horizontal rotation angle phi1 = 45.0 # arm angle phi2 = 20.0 # forearm angle transform_forearm = Node(transform=rotate((0.6, 0.5, 1), phi2)) transform_forearm.add(forearm_shape) transform_arm = Node(transform=rotate((0.3, 0.1, 0.9), phi1)) transform_arm.add(arm_shape, transform_forearm) transform_base = Node(transform=rotate((0.9, 0.1, 0.2), theta)) transform_base.add(base_shape, transform_arm) viewer.add(transform_base) # place instances of our basic objects # viewer.add(*[mesh for file in sys.argv[1:] for mesh in load(file, shader)]) # if len(sys.argv) < 2: # print('Usage:\n\t%s [3dfile]*\n\n3dfile\t\t the filename of a model in' # ' format supported by assimp.' % (sys.argv[0],)) # start rendering loop viewer.run()
def add_object(object, transform=identity()): obj = Node(transform=transform) obj.add(object) return obj