def build_scene(scene, input_bvh_path): mat = bpy.data.materials.new("BlueMetal") mat.use_nodes = True utils.clean_nodes(mat.node_tree.nodes) output_node = mat.node_tree.nodes.new(type='ShaderNodeOutputMaterial') principled_node = mat.node_tree.nodes.new(type='ShaderNodeBsdfPrincipled') principled_node.inputs['Base Color'].default_value = (0.1, 0.2, 0.7, 1.0) principled_node.inputs['Metallic'].default_value = 0.9 principled_node.inputs['Roughness'].default_value = 0.1 mat.node_tree.links.new(principled_node.outputs['BSDF'], output_node.inputs['Surface']) utils.arrange_nodes(mat.node_tree) armature = create_armature_from_bvh(scene, bvh_path=input_bvh_path) armature_mesh = utils.create_armature_mesh(scene, armature, 'Mesh') armature_mesh.data.materials.append(mat) mat = bpy.data.materials.new("Concrete07") mat.use_nodes = True utils.clean_nodes(mat.node_tree.nodes) utils.build_pbr_textured_nodes( mat.node_tree, color_texture_path= "./assets/textures/[2K]Concrete07/Concrete07_col.jpg", roughness_texture_path= "./assets/textures/[2K]Concrete07/Concrete07_rgh.jpg", normal_texture_path= "./assets/textures/[2K]Concrete07/Concrete07_nrm.jpg", displacement_texture_path= "./assets/textures/[2K]Concrete07/Concrete07_disp.jpg", ambient_occlusion_texture_path= "./assets/textures/[2K]Concrete07/Concrete07_AO.jpg", scale=(0.25, 0.25, 0.25)) bpy.ops.mesh.primitive_plane_add(radius=8.0, calc_uvs=True) current_object = bpy.context.object current_object.name = "Floor" current_object.data.materials.append(mat) bpy.ops.mesh.primitive_plane_add(radius=8.0, calc_uvs=True) current_object = bpy.context.object current_object.name = "Wall" current_object.data.materials.append(mat) current_object.location = (0.0, 6.0, 0.0) current_object.rotation_euler = (0.5 * math.pi, 0.0, 0.0) bpy.ops.object.empty_add(location=(0.0, 0.0, 0.8)) focus_target = bpy.context.object utils.add_copy_location_constraint(copy_to_object=focus_target, copy_from_object=armature, use_x=True, use_y=True, use_z=False, bone_name='Hips') return focus_target
def set_scene_objects(): bpy.ops.mesh.primitive_monkey_add(location=(0.0, 0.0, 1.0), rotation=(0.0, 0.0, -math.pi * 60.0 / 180.0), calc_uvs=True) current_object = bpy.context.object current_object.name = "Suzanne_Center" utils.add_subdivision_surface_modifier(current_object, 4) mat = bpy.data.materials.new("Material_Center") mat.use_nodes = True utils.clean_nodes(mat.node_tree.nodes) utils.build_pbr_textured_nodes( mat.node_tree, color_texture_path="./assets/textures/[2K]Metal07/Metal07_col.jpg", metallic_texture_path="./assets/textures/[2K]Metal07/Metal07_met.jpg", roughness_texture_path="./assets/textures/[2K]Metal07/Metal07_rgh.jpg", normal_texture_path="./assets/textures/[2K]Metal07/Metal07_nrm.jpg", displacement_texture_path= "./assets/textures/[2K]Metal07/Metal07_disp.jpg") current_object.data.materials.append(mat) # Keyframes current_object.location = (0.0, 0.0, 0.2) current_object.scale = (0.0, 0.0, 0.0) current_object.rotation_euler = (0.0, 0.0, -math.pi * (360.0 * 3.0 + 60.0) / 180.0) current_object.keyframe_insert(data_path='location', frame=4) current_object.keyframe_insert(data_path='scale', frame=4) current_object.keyframe_insert(data_path='rotation_euler', frame=4) current_object.location = (0.0, 0.0, 1.0) current_object.scale = (1.0, 1.0, 1.0) current_object.rotation_euler = (0.0, 0.0, -math.pi * 60.0 / 180.0) current_object.keyframe_insert(data_path='location', frame=42) current_object.keyframe_insert(data_path='scale', frame=42) current_object.keyframe_insert(data_path='rotation_euler', frame=42) bpy.ops.mesh.primitive_plane_add(radius=6.0, calc_uvs=True) current_object = bpy.context.object current_object.name = "Floor" mat = bpy.data.materials.new("Material_Plane") mat.use_nodes = True utils.clean_nodes(mat.node_tree.nodes) utils.build_pbr_textured_nodes( mat.node_tree, color_texture_path="./assets/textures/[2K]Marble01/Marble01_col.jpg", roughness_texture_path= "./assets/textures/[2K]Marble01/Marble01_rgh.jpg", normal_texture_path="./assets/textures/[2K]Marble01/Marble01_nrm.jpg", displacement_texture_path= "./assets/textures/[2K]Marble01/Marble01_disp.jpg") current_object.data.materials.append(mat) bpy.ops.object.empty_add(location=(0.0, -0.70, 1.0)) focus_target = bpy.context.object return focus_target
def add_named_material(name: str, scale=(1.0, 1.0, 1.0), displacement_scale: float = 1.0) -> bpy.types.Material: mat = utils.add_material(name, use_nodes=True, make_node_tree_empty=True) utils.build_pbr_textured_nodes(mat.node_tree, color_texture_path=texture_paths[name]["color"], roughness_texture_path=texture_paths[name]["roughness"], normal_texture_path=texture_paths[name]["normal"], metallic_texture_path=texture_paths[name]["metallic"], displacement_texture_path=texture_paths[name]["displacement"], ambient_occlusion_texture_path=texture_paths[name]["ambient_occlusion"], scale=scale, displacement_scale=displacement_scale) return mat
def set_scene_objects(): current_object = create_skinned_object() current_object.rotation_euler = (0.0, 0.0, math.pi * 60.0 / 180.0) bpy.ops.mesh.primitive_plane_add(radius=6.0, calc_uvs=True) current_object = bpy.context.object current_object.name = "Floor" mat = bpy.data.materials.new("Marble01") mat.use_nodes = True utils.clean_nodes(mat.node_tree.nodes) utils.build_pbr_textured_nodes( mat.node_tree, color_texture_path="./assets/textures/[2K]Marble01/Marble01_col.jpg", roughness_texture_path= "./assets/textures/[2K]Marble01/Marble01_rgh.jpg", normal_texture_path="./assets/textures/[2K]Marble01/Marble01_nrm.jpg", displacement_texture_path= "./assets/textures/[2K]Marble01/Marble01_disp.jpg") current_object.data.materials.append(mat) bpy.ops.object.empty_add(location=(0.0, 0.0, 1.0)) focus_target = bpy.context.object return focus_target
def create_skinned_object(): # Edit mode bpy.ops.object.add(type='ARMATURE', enter_editmode=True, location=(0.0, 0.0, 0.0)) armature = bpy.context.object bone1 = armature.data.edit_bones.new('Bone1') bone1.head = (0.0, 0.0, 0.0) bone1.tail = (0.0, 0.0, 1.0) bone2 = armature.data.edit_bones.new('Bone2') bone2.parent = bone1 bone2.use_connect = True bone2.tail = (0.0, 0.0, 2.0) # Pose mode bpy.ops.object.mode_set(mode='POSE') bone2 = armature.pose.bones['Bone2'] bone2.rotation_mode = 'XYZ' bone2.rotation_euler = (0.0, 0.0, 0.0) bone2.keyframe_insert(data_path='rotation_euler', frame=4) bone2.rotation_euler = (+math.pi * 30.0 / 180.0, 0.0, 0.0) bone2.keyframe_insert(data_path='rotation_euler', frame=12) bone2.rotation_euler = (-math.pi * 30.0 / 180.0, 0.0, 0.0) bone2.keyframe_insert(data_path='rotation_euler', frame=20) bone2.rotation_euler = (+math.pi * 30.0 / 180.0, 0.0, 0.0) bone2.keyframe_insert(data_path='rotation_euler', frame=28) bone2.rotation_euler = (0.0, 0.0, 0.0) bone2.keyframe_insert(data_path='rotation_euler', frame=36) # Object mode bpy.ops.object.mode_set(mode='OBJECT') # Mesh bpy.ops.mesh.primitive_cube_add(location=(0.0, 0.0, 1.0), calc_uvs=True) cube = bpy.context.object cube.name = "Cuboid" cube.scale = (0.5, 0.5, 1.0) utils.add_subdivision_surface_modifier(cube, 3, is_simple=True) utils.add_subdivision_surface_modifier(cube, 3, is_simple=False) utils.set_smooth_shading(cube) mat = bpy.data.materials.new("Metal07") mat.use_nodes = True utils.clean_nodes(mat.node_tree.nodes) utils.build_pbr_textured_nodes( mat.node_tree, color_texture_path="./assets/textures/[2K]Metal07/Metal07_col.jpg", metallic_texture_path="./assets/textures/[2K]Metal07/Metal07_met.jpg", roughness_texture_path="./assets/textures/[2K]Metal07/Metal07_rgh.jpg", normal_texture_path="./assets/textures/[2K]Metal07/Metal07_nrm.jpg", displacement_texture_path= "./assets/textures/[2K]Metal07/Metal07_disp.jpg") cube.data.materials.append(mat) # Set the armature as the parent of the cube using the "Automatic Weight" armature option bpy.ops.object.select_all(action='DESELECT') cube.select = True armature.select = True bpy.context.scene.objects.active = armature bpy.ops.object.parent_set(type='ARMATURE_AUTO') return armature
def set_scene_objects(): bpy.ops.mesh.primitive_monkey_add(location=(- 1.8, 0.0, 1.0), rotation=(0.0, 0.0, - math.pi * 60.0 / 180.0), calc_uvs=True) current_object = bpy.context.object current_object.name = "Suzanne_Left" utils.add_subdivision_surface_modifier(current_object, 4) mat = bpy.data.materials.new("Material_Left") mat.use_nodes = True utils.clean_nodes(mat.node_tree.nodes) utils.build_pbr_textured_nodes( mat.node_tree, color_texture_path="./assets/textures/[2K]Leather05/Leather05_col.jpg", roughness_texture_path="./assets/textures/[2K]Leather05/Leather05_rgh.jpg", normal_texture_path="./assets/textures/[2K]Leather05/Leather05_nrm.jpg", displacement_texture_path="./assets/textures/[2K]Leather05/Leather05_disp.jpg" ) current_object.data.materials.append(mat) bpy.ops.mesh.primitive_monkey_add(location=(0.0, 0.0, 1.0), rotation=(0.0, 0.0, - math.pi * 60.0 / 180.0), calc_uvs=True) current_object = bpy.context.object current_object.name = "Suzanne_Center" utils.add_subdivision_surface_modifier(current_object, 4) mat = bpy.data.materials.new("Material_Center") mat.use_nodes = True utils.clean_nodes(mat.node_tree.nodes) utils.build_pbr_textured_nodes( mat.node_tree, color_texture_path="./assets/textures/[2K]Metal07/Metal07_col.jpg", metallic_texture_path="./assets/textures/[2K]Metal07/Metal07_met.jpg", roughness_texture_path="./assets/textures/[2K]Metal07/Metal07_rgh.jpg", normal_texture_path="./assets/textures/[2K]Metal07/Metal07_nrm.jpg", displacement_texture_path="./assets/textures/[2K]Metal07/Metal07_disp.jpg" ) current_object.data.materials.append(mat) bpy.ops.mesh.primitive_monkey_add(location=(+ 1.8, 0.0, 1.0), rotation=(0.0, 0.0, - math.pi * 60.0 / 180.0), calc_uvs=True) current_object = bpy.context.object current_object.name = "Suzanne_Right" utils.add_subdivision_surface_modifier(current_object, 4) mat = bpy.data.materials.new("Material_Right") mat.use_nodes = True utils.clean_nodes(mat.node_tree.nodes) utils.build_pbr_textured_nodes( mat.node_tree, color_texture_path="./assets/textures/[2K]Fabric02/fabric02_col.jpg", roughness_texture_path="./assets/textures/[2K]Fabric02/fabric02_rgh.jpg", normal_texture_path="./assets/textures/[2K]Fabric02/fabric02_nrm.jpg", displacement_texture_path="./assets/textures/[2K]Fabric02/fabric02_disp.jpg" ) current_object.data.materials.append(mat) bpy.ops.mesh.primitive_plane_add(radius=6.0, calc_uvs=True) current_object = bpy.context.object current_object.name = "Floor" mat = bpy.data.materials.new("Material_Plane") mat.use_nodes = True utils.clean_nodes(mat.node_tree.nodes) utils.build_pbr_textured_nodes( mat.node_tree, color_texture_path="./assets/textures/[2K]Marble01/Marble01_col.jpg", roughness_texture_path="./assets/textures/[2K]Marble01/Marble01_rgh.jpg", normal_texture_path="./assets/textures/[2K]Marble01/Marble01_nrm.jpg", displacement_texture_path="./assets/textures/[2K]Marble01/Marble01_disp.jpg" ) current_object.data.materials.append(mat) bpy.ops.mesh.primitive_plane_add(radius=6.0, location=(0.0, 4.0, 0.0), rotation=(math.pi * 90.0 / 180.0, 0.0, 0.0), calc_uvs=True) current_object = bpy.context.object current_object.name = "Wall" mat = bpy.data.materials.new("Material_Plane") mat.use_nodes = True utils.clean_nodes(mat.node_tree.nodes) utils.build_pbr_textured_nodes( mat.node_tree, color_texture_path="./assets/textures/[2K]Marble01/Marble01_col.jpg", roughness_texture_path="./assets/textures/[2K]Marble01/Marble01_rgh.jpg", normal_texture_path="./assets/textures/[2K]Marble01/Marble01_nrm.jpg", displacement_texture_path="./assets/textures/[2K]Marble01/Marble01_disp.jpg" ) current_object.data.materials.append(mat) bpy.ops.object.empty_add(location=(0.0, -0.70, 1.0)) focus_target = bpy.context.object return focus_target