Repository navigation
Expand file tree
/
Copy pathexportSkybox.py
More file actions
183 lines (147 loc) · 5.58 KB
/
Copy pathexportSkybox.py
File metadata and controls
183 lines (147 loc) · 5.58 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
##########################################################################
#
# Quick and dirty addon, exports Scene to Urho3D-friendly Skybox images.
# based on Blender's operator_file_export.py example.
#
# Copyright (c) 2017 Alex Piola
#
# Portions: Copyright (c) https://www.blender.org
# ( see https://www.blender.org/about/license/ )
#
# License
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
##########################################################################
import bpy
from bpy_extras.io_utils import ExportHelper
from bpy.types import Operator
from bpy.props import StringProperty, IntProperty, FloatProperty
bl_info = {
"name": "Export Skybox",
"description": "Export skybox-ready images of a scene",
"author": "Alex Piola",
"version": (0, 2),
"blender": (2, 78, 0),
"location": "File -> Export",
"warning": "Might contain bugs, use at your own risk",
"wiki_url": "",
"tracker_url": "",
"category": "Import-Export"}
def createCamera(camName):
cam = bpy.data.cameras.new("cam")
camObj = bpy.data.objects.new(camName,cam)
bpy.context.scene.objects.link(camObj)
return camObj
def deleteCamera(camNode):
bpy.ops.object.select_all(action='DESELECT')
camNode.select = True
bpy.ops.object.delete()
def run(context, filepath, resolution, focusDist, clipStart, clipEnd):
if bpy.context.mode != 'OBJECT':
bpy.ops.set_mode('OBJECT')
front = createCamera("front")
front.rotation_euler = [1.57079,0.0,0.0]
back = createCamera("back")
back.rotation_euler = [1.57079,0.0,3.141592]
right = createCamera("right")
right.rotation_euler = [1.57079,0.0,-1.57079]
left = createCamera("left")
left.rotation_euler = [1.57079,0.0,1.57079]
top = createCamera("top")
top.rotation_euler = [3.141592,0.0,0.0]
bottom = createCamera("bottom")
bottom.rotation_euler = [0.0,0.0,0.0]
cameras = [front,back,left,right,top,bottom]
for cam in cameras:
print(cam.data.angle)
cam.data.angle = 1.5708
cam.data.dof_distance = focusDist
cam.data.clip_end = clipEnd
cam.data.clip_start = clipStart
prevY = context.scene.render.resolution_y
prevX = context.scene.render.resolution_x
prevPerc = context.scene.render.resolution_percentage
prevPath = context.scene.render.filepath
prevUseNodes = context.scene.use_nodes
context.scene.render.resolution_y = resolution
context.scene.render.resolution_x = resolution
context.scene.render.resolution_percentage = 100
context.scene.use_nodes = True
path = filepath.split(".")
#Workaround for sky blend bug when looking up
world = bpy.data.worlds[0]
horizonColor = world.horizon_color
for cam in cameras:
context.scene.camera = cam
if cam.name == "top":
world.horizon_color = world.zenith_color;
else:
world.horizon_color = horizonColor;
context.scene.render.filepath = path[0]+"_"+cam.name+"."+path[1]
context.scene.render.use_compositing = True
bpy.ops.render.render(write_still=True)
deleteCamera(cam)
context.scene.render.resolution_y = prevY
context.scene.render.resolution_x = prevX
context.scene.render.resolution_percentage = prevPerc
context.scene.render.filepath = prevPath
context.scene.use_nodes = prevUseNodes
return {'FINISHED'}
class ExportSkybox(Operator, ExportHelper):
"""Exports the scene as skybox images while using Compositing nodes too."""
bl_idname = "export_skybox.data"
bl_label = "Export Skybox Images"
filename_ext = ".png"
filter_glob = StringProperty(
default="*.png",
options={'HIDDEN'},
maxlen=255,
)
resolution = IntProperty(
name="Resolution",
description="Resolution for the images",
min=16,max=16384,
default=1024,
)
focusDist = FloatProperty(
name="Focal Distance",
description="Distance for the focus point for DOF",
min=0.0000,
default=0.0,
)
clipStart = FloatProperty(
name="Clip Start",
description="Camera clip start distance",
min=0.0000,
default=0.100,
)
clipEnd = FloatProperty(
name="Clip End",
description="Camera clip end distance",
min=0.0000,
default=100.0,
)
def execute(self, context):
return run(context, self.filepath, self.resolution, self.focusDist, self.clipStart, self.clipEnd)
def menu_func_export(self, context):
self.layout.operator(ExportSkybox.bl_idname, text="Export Skybox")
def register():
bpy.utils.register_class(ExportSkybox)
bpy.types.INFO_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_class(ExportSkybox)
bpy.types.INFO_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
register()