-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
io_radiance_lighting_export.py
150 lines (108 loc) · 4.2 KB
/
io_radiance_lighting_export.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
141
142
143
144
145
146
147
148
149
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
bl_info = {
"name": "Export Radiance Lighting Files",
"description": "Export Radiance Lighting Files",
"author": "Francesco Anselmo",
"version": (0, 1),
"blender": (2, 57, 0),
"location": "File > Export > Export Radiance Lighting Files (.lum)",
"warning": "",
"wiki_url":"",
"category": "Import-Export",
}
import bpy
from mathutils import Vector
from os.path import splitext
from math import degrees
def write_lighting(context, filepath, frame_start, frame_end, only_selected=False):
fn = splitext(filepath)[0]
scene = bpy.context.scene
lighting = []
for obj in scene.objects:
if only_selected and not obj.select:
continue
if obj.type != 'LAMP':
continue
lighting.append((obj, obj.data))
frame_range = range(frame_start, frame_end + 1)
lumname = fn +'.lum'
fn = lumname
f = open(fn,'w')
for obj, obj_data in lighting:
if obj.type=='LAMP':
#name = bpy.path.clean_name(obj.name)
name = obj.name
#print(obj.type)
#print(name)
#print(dir(obj.data))
ies = obj_data.name
#print(obj.location)
x,y,z = obj.location
#print(x,y,z)
rx,ry,rz = obj.matrix_world.to_euler()
#print(rx, ry, rz)
rx = degrees(rx)
ry = degrees(ry)
rz = degrees(rz)
#print(rx, ry, rz)
#print(dir(obj.matrix_world))
xform = '!xform -rx %s -ry %s -rz %s -t %s %s %s %s.rad # %s\n' % (rx, ry, rz, x, y, z, ies, name)
print(xform)
f.write(xform)
#obj.select = False
f.close()
print("written:", fn)
from bpy.props import StringProperty, IntProperty, BoolProperty
from bpy_extras.io_utils import ExportHelper
class LightingExporter(bpy.types.Operator, ExportHelper):
"""Export Blender Lamps to Radiance Lighting files"""
bl_idname = "export.radiance_lighting"
bl_label = "Export Radiance Lighting Files"
filename_ext = ".lum"
filter_glob = StringProperty(default="*.lum", options={'HIDDEN'})
frame_start = IntProperty(name="Start Frame",
description="Start frame for export",
default=1, min=1, max=300000)
frame_end = IntProperty(name="End Frame",
description="End frame for export",
default=1, min=1, max=300000)
only_selected = BoolProperty(name="Only Selected",
default=True)
def execute(self, context):
write_lighting(context, self.filepath, self.frame_start, self.frame_start, self.only_selected)
return {'FINISHED'}
def invoke(self, context, event):
self.frame_start = context.scene.frame_start
self.frame_end = context.scene.frame_end
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
def menu_export(self, context):
import os
default_path = os.path.splitext(bpy.data.filepath)[0] + ".py"
self.layout.operator(LightingExporter.bl_idname, text="Radiance Lighting Files (.lum)").filepath = default_path
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_file_export.append(menu_export)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_file_export.remove(menu_export)
if __name__ == "__main__":
register()