forked from DLR-RM/BlenderProc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTexture.py
83 lines (60 loc) · 2.8 KB
/
Texture.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import random
import bpy
from src.main.Provider import Provider
class Texture(Provider):
""" Uniformly samples a Texture for material manipulator.
Example 1: Sample a random texture without exclusions:
{
"provider": "sampler.Texture",
}
Example 2: Sample a random texture within given textures:
{
"provider": "sampler.Texture",
"textures": ["VORONOI", "MARBLE", "MAGIC"]
}
Example 3: Add parameters for texture Voronoi (Voroni is currently the only texture supported for doing this):
{
"provider": "sampler.Texture",
"textures": ["VORONOI"],
"noise_scale": 40,
"noise_intensity": 1.1,
"nabla": {
"provider": "sampler.Value",
"type": "float",
"mode": "normal",
"mean": 0.0,
"std_dev": 0.05
}
}
**Configuration**:
.. csv-table::
:header: "Parameter", "Description"
"textures", "A list of texture names. If not None the provider returns a uniform random sampled texture of one"
"of those given texture names. Otherwise it returns a uniform random sampled texture of one of the"
"available blender textures. Type: list. Default: []. Available: ['CLOUDS', 'DISTORTED_NOISE',"
"'MAGIC', 'MARBLE', 'MUSGRAVE', 'NOISE', 'STUCCI', 'VORONOI', 'WOOD']"
"noise_scale", "Scaling for noise input. Type: float. Default: 0.25. Only for VORONOI."
"noise_intensity", "Scales the intensity of the noise. Type: float. Default: 1.0. Only for VORONOI."
"nabla", "Size of derivative offset used for calculating normal. Type: float. Default: 0.03. Only for VORONOI."
"""
def __init__(self, config):
Provider.__init__(self, config)
def run(self):
""" Samples a texture uniformly.
:return: Texture. Type: bpy.types.Texture
"""
possible_textures = ["CLOUDS", "DISTORTED_NOISE", "MAGIC", "MARBLE", "MUSGRAVE", "NOISE", "STUCCI",
"VORONOI", "WOOD"]
# given textures
given_textures = self.config.get_list("textures", [])
if len(given_textures) == 0:
texture_name = random.choice(possible_textures)
else:
texture_name = random.choice(given_textures).upper()
tex = bpy.data.textures.new("ct_{}".format(texture_name), texture_name)
if texture_name == "VORONOI":
#default values are the values blender uses as default for texture Voronoi
tex.noise_scale = self.config.get_float("noise_scale", 0.25)
tex.noise_intensity = self.config.get_float("noise_intensity", 1.0)
tex.nabla = self.config.get_float("nabla", 0.03)
return tex