5,332
edits
No edit summary |
|||
Line 28: | Line 28: | ||
See one of the following resources to get started: | See one of the following resources to get started: | ||
* [https://www.youtube.com/watch?v=XqX5wh4YeRw Python Crash Course for Blender! by Curtis Holt] | * [https://www.youtube.com/watch?v=XqX5wh4YeRw Python Crash Course for Blender! by Curtis Holt] | ||
===Meshes=== | |||
<syntaxhighlight lang="python"> | |||
vertices = [(-1, -1, 0), (1, -1, 0), | |||
(-1, 1, 0), (1, 1, 0)] | |||
edges = [(0,1), (1,2), (2,3), (3,0)] | |||
faces = [(0,1,2), (1,2,3)] | |||
uvs = [(0, 0), (1, 0), | |||
(0, 1), (1, 1)] | |||
# Create a new mesh | |||
new_mesh = bpy.data.meshes.new(mesh_name) | |||
new_mesh.from_pydata(vertices, edges, faces) | |||
new_mesh.update() | |||
# Add UVs | |||
uv_layer = new_mesh.uv_layers.new() | |||
for face in new_mesh.polygons: | |||
for vert_idx, loop_idx in zip(face.vertices, face.loop_indices): | |||
uv_layer.data[loop_idx].uv = uvs[vert_idx] | |||
</syntaxhighlight> | |||
===Materials=== | |||
<syntaxhighlight lang="python"> | |||
# Create a new material | |||
my_material = bpy.data.materials.new("My New Material") | |||
my_material.use_nodes = True | |||
# Add material to an object | |||
my_object.data.materials.append(my_material) | |||
</syntaxhighlight> | |||
===Saving scripts outside=== | ===Saving scripts outside=== |