Create material paletteΒΆ

This script creates leather materials with different colors.

Note

Please put the textures in the same directory as the script.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from p3dsdk import *
import os


def resource_path(filename: str) -> str:
    """Get a path relative to the script path"""
    return os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)


def import_texture(group: TextureGroup, filename: str, name: str) -> Texture:
    with open(resource_path(filename), 'rb') as f:  # Read the file as binary
        texture = group.import_from_encoded_data(f.read())
        texture.name = name
        return texture


with CurrentP3DSession(fallback_port=33900) as p3d:
    # Create a texture group to put our textures in
    texture_group = p3d.data.create_texture_group("Leather textures")
    p3d.data.active_texture_group = texture_group  # Optional, only to select the group in P3D

    # Import textures
    color_map = import_texture(texture_group, "Leather025_2K_Color.jpg", "Leather_Color")
    normal_map = import_texture(texture_group, "Leather025_2K_Normal.jpg", "Leather_Normal")
    roughness_map = import_texture(texture_group, "Leather025_2K_Roughness.jpg", "Leather_Roughness")

    # Create a material group to put our materials in
    material_group = p3d.data.create_material_group("Leathers")
    p3d.data.active_material_group = material_group  # Optional, only to select the group in P3D

    leather_colors = [
        ("Orange", (0.67, 0.25, 0.09)),
        ("Black", (0.09, 0.09, 0.09)),
        ("Blue", (0.00, 0.30, 0.39)),
    ]

    for color_name, color in leather_colors:
        material = material_group.create_standard_material("Leather %s" % color_name)

        # Diffuse properties
        material.diffuse_color = color
        material.diffuse_intensity = 0.7
        material.diffuse_map = color_map
        material.diffuse_map_width = 0.1  # 10 cm
        material.diffuse_map_height = 0.1  # 10 cm

        # Specular properties
        material.reflection_intensity = 0.3
        material.refraction_index = 1.55
        material.roughness_map = roughness_map
        material.roughness_map_width = 0.1  # 10 cm
        material.roughness_map_height = 0.1  # 10 cm
        material.roughness = 13

        # Bump properties
        material.bump_map = normal_map
        material.bump_mode = BumpMode.NORMAL
        material.bump_map_width = 0.1  # 10 cm
        material.bump_map_height = 0.1  # 10 cm
        material.bump_diffuse = True
        material.bump_diffuse_depth = -1
        material.bump_reflection = True
        material.bump_reflection_depth = -1

Download example

Textures

Color
Color Texture

Download color texture

Normal
Normal Texture

Download color texture

Roughness
Roughness Texture

Download roughness texture