-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblenderconvert.py
117 lines (74 loc) · 2.63 KB
/
blenderconvert.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
import ria, bpy
def ConvertObjects(scene): #scene = bpy.context.scene
'''
Finds all objects (mesh, point, sun) excluding cameras, and converts them to Renderia form
'''
objects = []
for obj in scene.objects:
transform = ConvertObjectTransform(obj) #name, location, rotation, scale
if obj.type == "LIGHT":
energy = obj.data.energy #strength or power
specular = obj.data.specular_factor #specular
colour = tuple(obj.data.color)
if obj.data.type == "POINT":
radius = obj.data.shadow_soft_size #radius (point)
riaObj = ria.Point(*transform, colour, energy, specular, radius)
objects.append(riaObj)
if obj.data.type == "SUN":
angle = obj.data.angle #angle in radians (sun)
riaObj = ria.Directional(*transform , colour, energy, specular, angle)
objects.append(riaObj)
if obj.type == "MESH":
vertices = []
for vertex in obj.data.vertices:
coords = tuple(vertex.co)
vertices.append(
ria.Vector3 (*coords)
)
edges = []
for edge in obj.data.edges:
edges.append(
list(edge.vertices)
)
faces = []
for poly in obj.data.polygons:
faces.append(
list(poly.vertices)
)
mesh = ria.Mesh(vertices, edges, faces)
riaObj = ria.MeshObject(*transform, mesh)
objects.append(riaObj)
return objects
def ConvertCamera(scene):
cam = scene.camera
transform = ConvertObjectTransform(cam) #name, location, rotation, scale
if cam.data.type == "ORTHO":
orthoscale = cam.data.ortho_scale
riaCam = ria.Orthographic(*transform, orthoscale)
return riaCam
elif cam.data.type == "PERSP":
focallength = cam.data.lens #mm
fov = cam.data.angle # field of view (radians)
riaCam = ria.Perspective(*transform, fov, focallength)
return riaCam
else:
raise Exception("Wrong camera type.")
return
def ConvertObjectTransform(obj):
name = obj.name
location = ria.Vector3(
*tuple(
obj.location
)
)
rotation = ria.Vector3(
*tuple(
obj.rotation_euler
)
)
scale = ria.Vector3(
*tuple(
obj.scale
)
)
return name, location, rotation, scale