Beispiel #1
0
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() -> 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 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