I want to create a large set of spiral galaxies with textures using a python script.
I managed to create shader nodes and links to set up a material.
For the spiral shape, I need to perform a transformation of the standard uv-mesh. The transformation is written below. Basically, it is a proportional editing, where the center row of the rectangular mesh is grabbed and shifted horizontally.
bpy.ops.object.editmode_toggle()
bpy.ops.transform.translate(value=(1.03353, 0.00369117, 0), orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', mirror=True, use_proportional_edit=True, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
How can I include this transformation in the python script? My script has the following structure:
bpy.ops.mesh.primitive_uv_sphere_add(radius = 5, enter_editmode = False, location=(x,y,z))
sphere = bpy.context.active_object
sphere.data.materials.append(get_material(i))
sphere.scale[2]=0.1
and the function get_material(index)
def get_material(index):
mat = bpy.data.materials.new("GalaxyMaterial"+str(index))
mat.use_nodes = True
node_tree = mat.node_tree
nodes = node_tree.nodes
output = nodes.get("Material Output")
bsdf = nodes.get("Principled BSDF")
links =mat.node_tree.links
node_coord = nodes.new(type="ShaderNodeTexCoord")
node_texture = nodes.new(type='ShaderNodeTexNoise')
links.new(node_coord.outputs[2],node_texture.inputs[0])
node_texture.inputs[2].default_value=18
node_texture.inputs[3].default_value=5.3
node_texture.inputs[4].default_value=0.567
node_texture.inputs[5].default_value=1.1
node_ramp = nodes.new(type='ShaderNodeValToRGB')
node_ramp.color_ramp.elements[0].color = (0,0,0,1)
node_ramp.color_ramp.elements[0].position=0.45
node_ramp.color_ramp.elements[1].position=0.7
node_ramp.color_ramp.elements[1].color = (1,1,1,1)
links.new(node_texture.outputs[0],node_ramp.inputs[0])
links.new(node_ramp.outputs[0],bsdf.inputs[17])
return mat