Materials/Textures – procedural¶
Objectives¶
Procedural textures are explained in this station. It is only the starting point to this complex topic. |
Instructions¶
Tasks: |
---|
- Run the script and check the functionality of the functions.
- Change the parameters of a texture.
- Set material and texture to a new object.
All types in one image – the mapping types will be shown in a separate station. On the picture you can see the names of the textures and how the rendered objects looks like.
Code used to render the image¶
#!bpy
"""
Name: 'material_procedural.py'
Blender: 2.69
Group: 'Materials and Textures'
Tooltip: 'Texturen procedurale'
"""
import bpy
def materialcheck(obj, materialtype):
""" Put a procedural textur on a object."""
# used names
matname = "mat" + materialart
texname = "tex" + materialart
# new material
material = bpy.data.materials.new(matname)
material.diffuse_color = (0, .5, 0)
obj.data.materials.append(material)
# new texture
textur = bpy.data.textures.new(texname, type=materialart)
# lits all properties and methods of a texture
# print(dir(textur))
# connect texture with material
bpy.data.materials[matname].texture_slots.add()
bpy.data.materials[matname].active_texture = textur
if __name__ == '__main__':
# switch to object mode if edit mode is activ
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode='OBJECT')
# clear the scene
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete()
# all names of procedurale texturen, without IMAGE and LANDSCAPE
materials = ['BLEND',
'CLOUDS',
'DISTORTED_NOISE',
'MAGIC',
'MARBLE',
'MUSGRAVE',
'NOISE',
'OCEAN',
'POINT_DENSITY',
'STUCCI',
'VORONOI',
'VOXEL_DATA',
'WOOD']
x, y, z = 1, 0, 1
for i in materials:
# new line in the middle of the list
if z % 7 == 0:
y = 4
x = 1
bpy.ops.mesh.primitive_cylinder_add(location=(x, y, 0))
obj = bpy.context.scene.objects.active
obj.name = 'obj-%0.2d' % (z)
obj = bpy.context.scene.objects['obj-%0.2d' % (z)]
x += 3
z += 1
materialcheck(obj, materialtype=i)
hint: | Run the script, set the camera on the right position and start the menu sequence: Render » Render Image. |
---|
Every texture has more or less parameters. In the property panel all
parameters are changeable. The names of parameters are printed with
the dir command.
print(dir(textur))
Output example for the texture »WOOD«:
['__doc__', '__module__', '__slots__', 'animation_data',
'animation_data_clear', 'animation_data_create', 'bl_rna',
'color_ramp', 'contrast', 'copy', 'evaluate', 'factor_blue',
'factor_green', 'factor_red', 'intensity', 'is_library_indirect',
'is_updated', 'is_updated_data', 'library', 'nabla', 'name',
'node_tree', 'noise_basis', 'noise_basis_2', 'noise_scale',
'noise_type', 'rna_type', 'saturation', 'tag', 'turbulence',
'type', 'update_tag', 'use_color_ramp', 'use_fake_user',
'use_nodes', 'use_preview_alpha', 'user_clear', 'users',
'wood_type']