コード例 #1
0
def build_scene_composition(scene):
    scene.use_nodes = True
    utils.clean_nodes(scene.node_tree.nodes)

    render_layer_node = scene.node_tree.nodes.new(type="CompositorNodeRLayers")

    vignette_node = utils.create_vignette_node(scene.node_tree)
    vignette_node.inputs["Amount"].default_value = 0.70

    lens_distortion_node = scene.node_tree.nodes.new(type="CompositorNodeLensdist")
    lens_distortion_node.inputs["Distort"].default_value = -0.050
    lens_distortion_node.inputs["Dispersion"].default_value = 0.080

    color_correction_node = scene.node_tree.nodes.new(type="CompositorNodeColorCorrection")
    color_correction_node.master_saturation = 1.10
    color_correction_node.master_gain = 1.40

    glare_node = scene.node_tree.nodes.new(type="CompositorNodeGlare")
    glare_node.glare_type = 'GHOSTS'
    glare_node.iterations = 2
    glare_node.quality = 'HIGH'

    composite_node = scene.node_tree.nodes.new(type="CompositorNodeComposite")

    scene.node_tree.links.new(render_layer_node.outputs['Image'], vignette_node.inputs['Image'])
    scene.node_tree.links.new(vignette_node.outputs['Image'], lens_distortion_node.inputs['Image'])
    scene.node_tree.links.new(lens_distortion_node.outputs['Image'], color_correction_node.inputs['Image'])
    scene.node_tree.links.new(color_correction_node.outputs['Image'], glare_node.inputs['Image'])
    scene.node_tree.links.new(glare_node.outputs['Image'], composite_node.inputs['Image'])

    utils.arrange_nodes(scene.node_tree)
コード例 #2
0
def build_scene_composition(scene):
    scene.use_nodes = True
    utils.clean_nodes(scene.node_tree.nodes)

    render_layer_node = scene.node_tree.nodes.new(type="CompositorNodeRLayers")

    filter_node = scene.node_tree.nodes.new(type="CompositorNodeFilter")
    filter_node.filter_type = "SHARPEN"
    filter_node.inputs["Fac"].default_value = 0.1

    color_correction_node = scene.node_tree.nodes.new(
        type="CompositorNodeColorCorrection")
    color_correction_node.master_saturation = 1.10
    color_correction_node.master_gain = 1.20
    color_correction_node.midtones_gain = 1.20
    color_correction_node.shadows_gain = 1.50

    split_tone_node = utils.create_split_tone_node(scene.node_tree)
    split_tone_node.inputs["ShadowsHue"].default_value = 0.6
    split_tone_node.inputs["ShadowsSaturation"].default_value = 0.1

    composite_node = scene.node_tree.nodes.new(type="CompositorNodeComposite")

    scene.node_tree.links.new(render_layer_node.outputs['Image'],
                              filter_node.inputs['Image'])
    scene.node_tree.links.new(filter_node.outputs['Image'],
                              color_correction_node.inputs['Image'])
    scene.node_tree.links.new(color_correction_node.outputs['Image'],
                              split_tone_node.inputs['Image'])
    scene.node_tree.links.new(split_tone_node.outputs['Image'],
                              composite_node.inputs['Image'])

    utils.arrange_nodes(scene.node_tree)
コード例 #3
0
def set_scene_objects():
    mat = bpy.data.materials.new("Material")
    mat.use_nodes = True
    utils.clean_nodes(mat.node_tree.nodes)
    utils.build_pbr_nodes(mat.node_tree, base_color=(0.6, 0.6, 0.6, 1.0))

    left_object, center_object, right_object = utils.create_three_smooth_monkeys(
    )
    left_object.data.materials.append(mat)
    center_object.data.materials.append(mat)
    right_object.data.materials.append(mat)

    plane_size = 100.0
    current_object = utils.create_plane(size=plane_size, name="Floor")
    floor_mat = bpy.data.materials.new("Material_Plane")
    floor_mat.use_nodes = True
    utils.clean_nodes(floor_mat.node_tree.nodes)
    utils.build_checker_board_nodes(floor_mat.node_tree, plane_size)
    current_object.data.materials.append(floor_mat)

    sun_object = utils.create_sun_light()
    sun_object.data.use_nodes = True
    sun_object.data.node_tree.nodes["Emission"].inputs[
        "Strength"].default_value = 3.0

    bpy.ops.object.empty_add(location=(0.0, -0.70, 1.0))
    focus_target = bpy.context.object
    return focus_target
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
def set_scene_objects() -> bpy.types.Object:
    # Instantiate a floor plane
    utils.create_plane(size=200.0, location=(0.0, 0.0, -1.0))

    # Instantiate a triangle mesh
    bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=3)
    current_object = bpy.context.object

    # Assign random colors for each triangle
    mesh = current_object.data
    mesh.vertex_colors.new(name='Col')
    random_numbers = get_random_numbers(len(mesh.vertex_colors['Col'].data))
    for index, vertex_color in enumerate(mesh.vertex_colors['Col'].data):
        vertex_color.color = get_color(random_numbers[index // 3]) + tuple(
            [1.0])

    # Setup a material with wireframe visualization and per-face colors
    mat = bpy.data.materials.new("Material_Visualization")
    mat.use_nodes = True
    utils.clean_nodes(mat.node_tree.nodes)
    current_object.data.materials.append(mat)

    output_node = mat.node_tree.nodes.new(type='ShaderNodeOutputMaterial')
    principled_node = mat.node_tree.nodes.new(type='ShaderNodeBsdfPrincipled')
    rgb_node = mat.node_tree.nodes.new(type='ShaderNodeRGB')
    mix_node = mat.node_tree.nodes.new(type='ShaderNodeMixShader')
    wire_node = mat.node_tree.nodes.new(type='ShaderNodeWireframe')
    wire_mat_node = mat.node_tree.nodes.new(type='ShaderNodeBsdfDiffuse')
    attrib_node = mat.node_tree.nodes.new(type='ShaderNodeAttribute')

    attrib_node.attribute_name = 'Col'
    rgb_node.outputs['Color'].default_value = (0.1, 0.1, 0.1, 1.0)

    mat.node_tree.links.new(attrib_node.outputs['Color'],
                            principled_node.inputs['Base Color'])
    mat.node_tree.links.new(principled_node.outputs['BSDF'],
                            mix_node.inputs[1])
    mat.node_tree.links.new(rgb_node.outputs['Color'],
                            wire_mat_node.inputs['Color'])
    mat.node_tree.links.new(wire_mat_node.outputs['BSDF'], mix_node.inputs[2])
    mat.node_tree.links.new(wire_node.outputs['Fac'], mix_node.inputs['Fac'])
    mat.node_tree.links.new(mix_node.outputs['Shader'],
                            output_node.inputs['Surface'])

    utils.arrange_nodes(mat.node_tree)

    bpy.ops.object.empty_add(location=(0.0, -0.8, 0.0))
    focus_target = bpy.context.object

    return focus_target
コード例 #7
0
def set_scene_objects() -> bpy.types.Object:
    set_floor_and_lights()

    mat = bpy.data.materials.new("Peeling Paint Metal")
    mat.use_nodes = True
    utils.clean_nodes(mat.node_tree.nodes)

    utils.build_peeling_paint_metal_nodes(mat.node_tree)

    current_object = utils.create_smooth_monkey(location=(0.0, 0.0, 1.0))
    current_object.data.materials.append(mat)

    bpy.ops.object.empty_add(location=(0.0, -0.75, 1.20))
    focus_target = bpy.context.object
    return focus_target
コード例 #8
0
def set_scene_objects():
    image_path = "./assets/matcaps/blue.png"

    mat = bpy.data.materials.new("MatCap")
    mat.use_nodes = True
    utils.clean_nodes(mat.node_tree.nodes)
    utils.build_matcap_nodes(mat.node_tree, image_path)

    current_object = utils.create_smooth_monkey(location=(1.2, 0.0, 0.0))
    current_object.data.materials.append(mat)

    current_object = utils.create_smooth_sphere(location=(-1.2, 0.0, 0.0), subdivision_level=2)
    current_object.data.materials.append(mat)

    bpy.ops.object.empty_add(location=(0.0, 0.0, 0.0))
    focus_target = bpy.context.object
    return focus_target
コード例 #9
0
def set_scene_objects() -> bpy.types.Object:
    left_object, center_object, right_object = utils.create_three_smooth_monkeys(
    )

    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'])
    left_object.data.materials.append(mat)

    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'])
    center_object.data.materials.append(mat)

    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'])
    right_object.data.materials.append(mat)

    current_object = utils.create_plane(size=20.0, 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
コード例 #10
0
def set_floor_and_lights() -> None:
    size = 200.0
    current_object = utils.create_plane(size=size, name="Floor")
    floor_mat = bpy.data.materials.new("Material_Plane")
    floor_mat.use_nodes = True
    utils.clean_nodes(floor_mat.node_tree.nodes)
    utils.build_checker_board_nodes(floor_mat.node_tree, size)
    current_object.data.materials.append(floor_mat)

    utils.create_area_light(location=(6.0, 0.0, 4.0),
                            rotation=(0.0, math.pi * 60.0 / 180.0, 0.0),
                            size=5.0,
                            color=(1.00, 0.70, 0.60, 1.00),
                            strength=1500.0,
                            name="Main Light")
    utils.create_area_light(location=(-6.0, 0.0, 2.0),
                            rotation=(0.0, -math.pi * 80.0 / 180.0, 0.0),
                            size=5.0,
                            color=(0.30, 0.42, 1.00, 1.00),
                            strength=1000.0,
                            name="Sub Light")
コード例 #11
0
def build_scene(scene: bpy.types.Scene,
                input_bvh_path: str) -> bpy.types.Object:
    loader.build_pbr_textured_nodes_from_name("Concrete07",
                                              scale=(0.25, 0.25, 0.25))

    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(bvh_path=input_bvh_path)
    armature_mesh = utils.create_armature_mesh(scene, armature, 'Mesh')
    armature_mesh.data.materials.append(mat)

    current_object = utils.create_plane(size=16.0, name="Floor")
    current_object.data.materials.append(bpy.data.materials["Concrete07"])

    current_object = utils.create_plane(size=16.0, name="Wall")
    current_object.data.materials.append(bpy.data.materials["Concrete07"])
    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
コード例 #12
0
def build_scene_composition(scene):
    scene.use_nodes = True
    utils.clean_nodes(scene.node_tree.nodes)

    render_layer_node = scene.node_tree.nodes.new(type="CompositorNodeRLayers")

    lens_distortion_node = scene.node_tree.nodes.new(
        type="CompositorNodeLensdist")
    lens_distortion_node.inputs["Distort"].default_value = -0.050
    lens_distortion_node.inputs["Dispersion"].default_value = 0.050

    glare_node = scene.node_tree.nodes.new(type="CompositorNodeGlare")
    glare_node.glare_type = 'FOG_GLOW'
    glare_node.quality = 'HIGH'

    composite_node = scene.node_tree.nodes.new(type="CompositorNodeComposite")

    scene.node_tree.links.new(render_layer_node.outputs['Image'],
                              lens_distortion_node.inputs['Image'])
    scene.node_tree.links.new(lens_distortion_node.outputs['Image'],
                              glare_node.inputs['Image'])
    scene.node_tree.links.new(glare_node.outputs['Image'],
                              composite_node.inputs['Image'])
コード例 #13
0
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
コード例 #14
0
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
コード例 #15
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')

    # 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
コード例 #16
0
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