-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblenderscript_v01.py
140 lines (120 loc) · 4.67 KB
/
blenderscript_v01.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import bpy
import bmesh
def create():
scn = bpy.context.scene
scn.render.engine = 'CYCLES'
scn.world.use_nodes = True
set_background()
#context
bpyscene = bpy.context.scene
# Create an empty mesh and the object.
mesh = bpy.data.meshes.new('Basic_Sphere')
basic_sphere = bpy.data.objects.new("Basic_Sphere", mesh)
# Add the object into the scene.
bpyscene.objects.link(basic_sphere)
bpyscene.objects.active = basic_sphere
basic_sphere.select = True
# Construct the bmesh cube and assign it to the blender mesh.
bm = bmesh.new()
bmesh.ops.create_uvsphere(bm, u_segments=32, v_segments=16, diameter=1)
bm.to_mesh(mesh)
bm.free()
# add subsurf mod and smooth
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.shade_smooth()
# add material to the UV Sphere
ob = bpy.context.active_object
ob.select = True
#scene.objects.active = ob
# Get material
g_mat = bpy.data.materials.get("green_glow")
if g_mat is None:
# create material
create_materials("green_glow")
g_mat = bpy.data.materials.get("green_glow")
# Assign it to object
if ob.data.materials:
# assign to 1st material slot
ob.data.materials[0] = g_mat
else:
# no slots
ob.data.materials.append(g_mat)
print ("Green Material assigned")
# move UV Sphere
bpy.ops.object.move_to_layer(layers=(False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False))
# Text
bpy.ops.object.text_add(view_align=False, enter_editmode=False, location=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.ops.transform.rotate(value=1.5708, axis=(1, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
bpy.context.object.data.extrude = 0.02
# Delete default "Text"
bpy.ops.object.editmode_toggle()
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
# Set new word
chars = "Digital"
for char in chars:
bpy.ops.font.text_insert(text=char)
bpy.ops.object.editmode_toggle()
# add material to the Text
ob.select = True
ob = bpy.context.active_object
#scene.objects.active = ob
# Get material
mat = bpy.data.materials.get("white_glow")
if mat is None:
# create material
create_materials("white_glow")
mat = bpy.data.materials.get("white_glow")
# Assign it to object
if ob.data.materials:
# assign to 1st material slot
ob.data.materials[0] = mat
else:
# no slots
ob.data.materials.append(mat)
print ("Green Material assigned")
# text to mesh
bpy.ops.object.convert(target='MESH')
# Particle system
bpy.ops.object.particle_system_add()
bpy.data.particles["ParticleSettings"].effector_weights.gravity = 0
bpy.data.particles["ParticleSettings"].render_type = 'OBJECT'
bpy.data.particles["ParticleSettings"].dupli_object = bpy.data.objects["Basic_Sphere"]
def set_background():
# darken the background
bpy.context.scene.world.node_tree.nodes['Background'].inputs['Color'].default_value = (0, 0, 0, 1)
print("Set background color")
def create_materials(mat_name):
mat = bpy.data.materials.new(name=mat_name)
# get the material
mat = bpy.data.materials[mat_name]
mat.use_nodes = True
# get the nodes
nodes = mat.node_tree.nodes
# clear all nodes to start clean
for node in nodes:
nodes.remove(node)
# create emission node
node_emission = nodes.new(type='ShaderNodeEmission')
if (mat_name == "white_glow"):
node_emission.inputs[0].default_value = (1,1,1,1) # white RGBA
else:
node_emission.inputs[0].default_value = (0,1,0,1) # white RGBA
node_emission.inputs[1].default_value = 2.0 # strength
node_emission.location = 0,0
# create output node
node_output = nodes.new(type='ShaderNodeOutputMaterial')
node_output.location = 400,0
# link nodes
links = mat.node_tree.links
link = links.new(node_emission.outputs[0], node_output.inputs[0])
# remove links
#links.remove(link)
# Animate Particle System
#def animate():
# Move / Animate Sphere
if __name__ == "__main__":
create()