def build_scene(num_cubes, color_array): # Generate positions of each cube cube_position_array, barycenter = generate_block_positions(num_cubes) # Place cubes scene = rtx.Scene(ambient_color=(0, 0, 0)) for position in cube_position_array: geometry = rtx.BoxGeometry(cube_size, cube_size, cube_size) geometry.set_position(( position[0] - barycenter[0], position[1] - barycenter[1], position[2] - barycenter[2], )) material = rtx.LambertMaterial(0.3) mapping = rtx.SolidColorMapping(random.choice(color_array)) cube = rtx.Object(geometry, material, mapping) scene.add(cube) # Place a light size = 50 geometry = rtx.SphereGeometry(size) geometry.set_position((size * 2, size * 2, 0)) material = rtx.EmissiveMaterial(100, visible=False) mapping = rtx.SolidColorMapping((1, 1, 1)) light = rtx.Object(geometry, material, mapping) scene.add(light) return scene
def create_geometry_by_type(geometry_type): if geometry_type == GeometryType.box: return rtx.BoxGeometry(width=0.75, height=0.75, depth=0.75), 0.375 if geometry_type == GeometryType.shpere: return rtx.SphereGeometry(radius=0.375), 0.375 if geometry_type == GeometryType.cylinder: return rtx.CylinderGeometry(radius=0.25, height=1), 0.5 if geometry_type == GeometryType.cone: return rtx.ConeGeometry(radius=0.375, height=1), 0.375 raise NotImplementedError
def build_geometry_by_type(geometry_type): if geometry_type == GeometryType.box: return rtx.BoxGeometry(width=1, height=1, depth=1) if geometry_type == GeometryType.shpere: return rtx.SphereGeometry(radius=0.5) if geometry_type == GeometryType.cylinder: return rtx.CylinderGeometry(radius=0.5, height=1) if geometry_type == GeometryType.cone: return rtx.ConeGeometry(radius=0.5, height=1) raise NotImplementedError
def build_scene(color_array): # Generate positions of each cube cube_position_array, shift = generate_block_positions(args.num_cubes) assert len(cube_position_array) == args.num_cubes # Place block scene = rtx.Scene(ambient_color=(0, 0, 0)) for position in cube_position_array: geometry = rtx.BoxGeometry(1, 1, 1) geometry.set_position(( position[0] - shift[0], position[1] - shift[1], position[2] - shift[2], )) material = rtx.LambertMaterial(0.3) mapping = rtx.SolidColorMapping(random.choice(color_array)) cube = rtx.Object(geometry, material, mapping) scene.add(cube) # Place lights size = 50 group = rtx.ObjectGroup() geometry = rtx.PlainGeometry(size, size) geometry.set_rotation((0, math.pi / 2, 0)) geometry.set_position((-10, 0, 0)) material = rtx.EmissiveMaterial(10, visible=False) mapping = rtx.SolidColorMapping((1, 1, 1)) light = rtx.Object(geometry, material, mapping) group.add(light) geometry = rtx.PlainGeometry(size, size) geometry.set_rotation((0, -math.pi / 2, 0)) geometry.set_position((10, 0, 0)) material = rtx.EmissiveMaterial(1, visible=False) mapping = rtx.SolidColorMapping((1, 1, 1)) light = rtx.Object(geometry, material, mapping) group.add(light) group.set_rotation((-math.pi / 3, math.pi / 4, 0)) scene.add(group) return scene
material = rtx.LambertMaterial(1.0) mapping = rtx.SolidColorMapping((1, 1, 1)) ceil = rtx.Object(geometry, material, mapping) scene.add(ceil) # light geometry = rtx.PlainGeometry(box_size / 4, box_size / 4) geometry.set_rotation((math.pi / 2, 0, 0)) geometry.set_position((0, box_size / 2 - 0.01, 0)) material = rtx.EmissiveMaterial(20.0) mapping = rtx.SolidColorMapping((1, 1, 1)) light = rtx.Object(geometry, material, mapping) scene.add(light) # place boxes geometry = rtx.BoxGeometry(1.6, 1.6, 1.6) geometry.set_position((-1, -box_size / 2 + 0.8, 1)) geometry.set_rotation((0, math.pi / 5, 0)) material = rtx.LambertMaterial(1.0) mapping = rtx.SolidColorMapping((1, 1, 1)) box = rtx.Object(geometry, material, mapping) scene.add(box) geometry = rtx.BoxGeometry(1.6, 3.2, 1.6) geometry.set_position((-1, -box_size / 2 + 1.6, -1)) geometry.set_rotation((0, math.pi / 5, 0)) material = rtx.LambertMaterial(1.0) mapping = rtx.SolidColorMapping((1, 1, 1)) box = rtx.Object(geometry, material, mapping) scene.add(box)