-
Notifications
You must be signed in to change notification settings - Fork 0
/
blenda_buda.py
66 lines (51 loc) · 1.43 KB
/
blenda_buda.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
import sys, os
import bpy
import mathutils
from mathutils import Vector
sys.path.append(os.path.dirname(__file__))
from model import coords, faces
from model import middle_sorted as leds
def create_sphere(name, origin):
bpy.ops.mesh.primitive_uv_sphere_add(
size=0.1,
rotation=(0, 0, 0),
location=origin
)
obj = bpy.context.object
obj.name = name
mesh = obj.data
mesh.name = name + '-mesh'
return obj
def make_material(name, diffuse, specular, alpha):
mat = bpy.data.materials.new(name)
mat.diffuse_color = diffuse
mat.diffuse_shader = 'LAMBERT'
mat.diffuse_intensity = 1.0
mat.specular_color = specular
mat.specular_shader = 'COOKTORR'
mat.specular_intensity = 0.5
mat.emit = 2.0
mat.alpha = alpha
mat.ambient = 1
return mat
def set_material(ob, mat):
me = ob.data
me.materials.append(mat)
red = make_material('red', (1,0,0), (1,1,1), 1)
blue = make_material('blue', (0,0,1), (0.5,0.5,0), 0.5)
mesh_name = "dome"
obj_name = "dome"
scene = bpy.context.scene
#for obj in scene.objects:
# scene.objects.unlink(obj)
mesh = bpy.data.meshes.new(mesh_name)
obj = bpy.data.objects.new(obj_name, mesh)
scene.objects.link(obj)
mesh.from_pydata(coords, [], faces)
mesh.update()
led_objects = []
for i, led in enumerate(leds):
obj = create_sphere('led-%03i' % i, Vector(tuple(led)))
led_objects.append(obj)
for obj in led_objects:
set_material(obj, blue)