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') # Material loader.build_pbr_textured_nodes_from_name("Metal07") # 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.data) cube.data.materials.append(bpy.data.materials["Metal07"]) # Set the armature as the parent of the cube using the "Automatic Weight" armature option bpy.ops.object.select_all(action='DESELECT') if bpy.app.version >= (2, 80, 0): cube.select_set(True) armature.select_set(True) bpy.context.view_layer.objects.active = armature else: 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(): num_suzannes = 7 for index in range(num_suzannes): bpy.ops.mesh.primitive_monkey_add(location=((index - (num_suzannes - 1) / 2) * 3.0, 0.0, 1.0)) current_object = bpy.context.object current_object.name = "Suzanne" + str(index) utils.add_subdivision_surface_modifier(current_object, 3) bpy.ops.mesh.primitive_plane_add(radius=10.0) return bpy.data.objects["Suzanne" + str(int((num_suzannes - 1) / 2))]
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 set_scene_objects() -> bpy.types.Object: loader.build_pbr_textured_nodes_from_name("Fabric02") loader.build_pbr_textured_nodes_from_name("Fabric03") bpy.data.materials["Fabric02"].node_tree.nodes["Principled BSDF"].inputs[ "Sheen"].default_value = 4.0 bpy.data.materials["Fabric03"].node_tree.nodes["Principled BSDF"].inputs[ "Sheen"].default_value = 4.0 set_floor_and_lights() current_object = utils.create_smooth_monkey(location=(0.0, 0.0, 1.0)) current_object.data.materials.append(bpy.data.materials["Fabric03"]) bpy.ops.object.modifier_add(type='COLLISION') if bpy.app.version >= (2, 80, 0): bpy.ops.mesh.primitive_grid_add(x_subdivisions=75, y_subdivisions=75, size=3.0, location=(0.0, 0.0, 2.75)) else: bpy.ops.mesh.primitive_grid_add(x_subdivisions=75, y_subdivisions=75, radius=1.5, calc_uvs=True, location=(0.0, 0.0, 2.75)) cloth_object = bpy.context.object cloth_object.name = "Cloth" bpy.ops.object.modifier_add(type='CLOTH') cloth_object.modifiers["Cloth"].collision_settings.use_collision = True cloth_object.modifiers[ "Cloth"].collision_settings.use_self_collision = True cloth_object.modifiers["Cloth"].settings.quality = 10 utils.set_smooth_shading(cloth_object.data) utils.add_subdivision_surface_modifier(cloth_object, 2) cloth_object.data.materials.append(bpy.data.materials["Fabric02"]) bpy.ops.object.empty_add(location=(0.0, -0.75, 1.05)) focus_target = bpy.context.object return focus_target
def set_scene_objects(): bpy.ops.mesh.primitive_monkey_add(location=(-3.0, 0.0, 1.0)) 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 nodes = mat.node_tree.nodes links = mat.node_tree.links utils.clean_nodes(nodes) output_node = nodes.new(type='ShaderNodeOutputMaterial') principled_node = nodes.new(type='ShaderNodeBsdfPrincipled') set_principled_node_as_glass(principled_node) links.new(principled_node.outputs['BSDF'], output_node.inputs['Surface']) current_object.data.materials.append(mat) bpy.ops.mesh.primitive_monkey_add(location=(0.0, 0.0, 1.0)) 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 nodes = mat.node_tree.nodes links = mat.node_tree.links utils.clean_nodes(nodes) output_node = nodes.new(type='ShaderNodeOutputMaterial') principled_node = nodes.new(type='ShaderNodeBsdfPrincipled') set_principled_node_as_gold(principled_node) links.new(principled_node.outputs['BSDF'], output_node.inputs['Surface']) current_object.data.materials.append(mat) bpy.ops.mesh.primitive_monkey_add(location=(+3.0, 0.0, 1.0)) 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 nodes = mat.node_tree.nodes links = mat.node_tree.links utils.clean_nodes(nodes) output_node = nodes.new(type='ShaderNodeOutputMaterial') principled_node = nodes.new(type='ShaderNodeBsdfPrincipled') set_principled_node_as_rough_blue(principled_node) links.new(principled_node.outputs['BSDF'], output_node.inputs['Surface']) current_object.data.materials.append(mat) bpy.ops.mesh.primitive_plane_add(radius=10.0) current_object = bpy.context.object current_object.name = "Floor" mat = bpy.data.materials.new("Material_Plane") mat.use_nodes = True nodes = mat.node_tree.nodes links = mat.node_tree.links utils.clean_nodes(nodes) output_node = nodes.new(type='ShaderNodeOutputMaterial') principled_node = nodes.new(type='ShaderNodeBsdfPrincipled') set_principled_node_as_ceramic(principled_node) links.new(principled_node.outputs['BSDF'], output_node.inputs['Surface']) current_object.data.materials.append(mat) bpy.ops.object.empty_add(location=(0.0, -0.75, 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