-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path__init__.py
More file actions
164 lines (128 loc) · 7.35 KB
/
__init__.py
File metadata and controls
164 lines (128 loc) · 7.35 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
import bpy
import math
bl_info = {
"name": "Unity 6 Sided Skybox",
"author": "MehmetHY",
"version": (1, 0),
"blender": (2, 93, 0),
"location": "3D View -> N Panel -> Skybox -> Unity 6 Sided Skybox",
"description": "Render and export 6 sided skybox for Unity3D with a single click.",
"warning": "",
"doc_url": "",
"tracker_url": "https://github.com/MehmetHY/BlenderUnity6SidedSkybox",
"category": "Render"
}
class SkyboxProperties(bpy.types.PropertyGroup):
file_path: bpy.props.StringProperty(name='File Path', description='Output Directory', subtype='DIR_PATH')
file_name: bpy.props.StringProperty(name='File Name', description='Output Directory', subtype='FILE_NAME')
file_format: bpy.props.EnumProperty(items=[('PNG', 'PNG', ''), ('OPEN_EXR', 'EXR', ''), (
'HDR', 'HDR', ''), ('JPEG', 'JPEG', ''), ('JPEG2000', 'JPEG2000', ''), ('TIFF', 'TIFF', ''), ('BMP', 'BMP', ''), ('TARGA', 'TARGA', ''), ('TARGA_RAW', 'TARGA_RAW', '')], name='File Format', description='File Format', default='PNG')
dimensions: bpy.props.IntProperty(name='Dimensions', description='Image Dimensions', default=1024, min=1)
front_postfix: bpy.props.StringProperty(name='Front Postfix', description='Image output postfix of the front side', default='_front')
right_postfix: bpy.props.StringProperty(name='Right Postfix', description='Image output postfix of the right side', default='_right')
left_postfix: bpy.props.StringProperty(name='Left Postfix', description='Image output postfix of the Left side', default='_left')
back_postfix: bpy.props.StringProperty(name='Back Postfix', description='Image output postfix of the back side', default='_back')
up_postfix: bpy.props.StringProperty(name='Up Postfix', description='Image output postfix of the up side', default='_up')
down_postfix: bpy.props.StringProperty(name='Down Postfix', description='Image output postfix of the down side', default='_down')
class skybox_panel(bpy.types.Panel):
bl_idname = "RENDER_SKYBOX_PT_six_sided"
bl_label = "Unity 6 Sided Skybox"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Skybox"
@classmethod
def poll(cls, context):
return (context.scene is not None)
def draw(self, context):
prop_group = bpy.context.scene.skybox_props
layout = self.layout
row = layout.row()
row.label(text="Render")
box = layout.box()
box.operator('render.unity_render_skybox_6_sided', text='Render')
row = layout.row()
row.label(text="Output")
box = layout.box()
box.prop(prop_group, 'file_name', text="File Name")
box.prop(prop_group, 'file_path', text="Output Folder")
box.prop(prop_group, 'file_format', text="File Format")
box.prop(prop_group, 'dimensions', text="Dimensions")
box.prop(prop_group, 'front_postfix', text="Front Postfix")
box.prop(prop_group, 'right_postfix', text="Right Postfix")
box.prop(prop_group, 'left_postfix', text="Left Postfix")
box.prop(prop_group, 'back_postfix', text="Back Postfix")
box.prop(prop_group, 'up_postfix', text="Up Postfix")
box.prop(prop_group, 'down_postfix', text="Down Postfix")
class render_unity_skybox_6_sided(bpy.types.Operator):
bl_idname = 'render.unity_render_skybox_6_sided'
bl_label = 'Render Unity Skybox 6 Sided'
bl_description = 'Renders 6 sided skybox for Unity3D'
def execute(self, context):
self.init()
return {'FINISHED'}
def init(self):
# Deselect All
bpy.ops.object.select_all(action='DESELECT')
# Disable Bloom
self.pre_bloom_state = bpy.context.scene.eevee.use_bloom
bpy.context.scene.eevee.use_bloom = False
# Create Camera
self.cam_data = bpy.data.cameras.new('Unity Skybox 6 Sided Camera')
self.cam = bpy.data.objects.new('Unity Skybox 6 Sided Camera', self.cam_data)
bpy.context.collection.objects.link(self.cam)
bpy.context.scene.camera = self.cam
self.cam.data.lens_unit = 'FOV'
self.cam.data.angle = math.radians(90)
self.cam.select_set(state=True)
# Set Output Settings
bpy.context.scene.render.image_settings.file_format = bpy.context.scene.skybox_props.file_format
bpy.context.scene.render.resolution_x = bpy.context.scene.skybox_props.dimensions
bpy.context.scene.render.resolution_y = bpy.context.scene.skybox_props.dimensions
# Render
self.render_ft()
self.render_rt()
self.render_lf()
self.render_bk()
self.render_up()
self.render_dn()
# Clear
self.finalize()
def finalize(self):
bpy.ops.object.delete(confirm=False)
bpy.context.scene.eevee.use_bloom = self.pre_bloom_state
def render_ft(self):
bpy.ops.transform.rotate(value=math.radians(-90), orient_axis='X', orient_type='GLOBAL')
bpy.context.scene.render.filepath = f"{bpy.context.scene.skybox_props.file_path}{bpy.context.scene.skybox_props.file_name}{bpy.context.scene.skybox_props.front_postfix}"
bpy.ops.render.render(write_still=True)
def render_rt(self):
bpy.ops.transform.rotate(value=math.radians(-90), orient_axis='Z', orient_type='GLOBAL')
bpy.context.scene.render.filepath = f"{bpy.context.scene.skybox_props.file_path}{bpy.context.scene.skybox_props.file_name}{bpy.context.scene.skybox_props.right_postfix}"
bpy.ops.render.render(write_still=True)
def render_lf(self):
bpy.ops.transform.rotate(value=math.radians(180), orient_axis='Z', orient_type='GLOBAL')
bpy.context.scene.render.filepath = f"{bpy.context.scene.skybox_props.file_path}{bpy.context.scene.skybox_props.file_name}{bpy.context.scene.skybox_props.left_postfix}"
bpy.ops.render.render(write_still=True)
def render_bk(self):
bpy.ops.transform.rotate(value=math.radians(90), orient_axis='Z', orient_type='GLOBAL')
bpy.context.scene.render.filepath = f"{bpy.context.scene.skybox_props.file_path}{bpy.context.scene.skybox_props.file_name}{bpy.context.scene.skybox_props.back_postfix}"
bpy.ops.render.render(write_still=True)
def render_up(self):
bpy.ops.transform.rotate(value=math.radians(180), orient_axis='Z', orient_type='GLOBAL')
bpy.ops.transform.rotate(value=math.radians(-90), orient_axis='X', orient_type='GLOBAL')
bpy.context.scene.render.filepath = f"{bpy.context.scene.skybox_props.file_path}{bpy.context.scene.skybox_props.file_name}{bpy.context.scene.skybox_props.up_postfix}"
bpy.ops.render.render(write_still=True)
def render_dn(self):
bpy.ops.transform.rotate(value=math.radians(180), orient_axis='X', orient_type='GLOBAL')
bpy.context.scene.render.filepath = f"{bpy.context.scene.skybox_props.file_path}{bpy.context.scene.skybox_props.file_name}{bpy.context.scene.skybox_props.down_postfix}"
bpy.ops.render.render(write_still=True)
classes_to_register = (SkyboxProperties, skybox_panel, render_unity_skybox_6_sided)
def register():
for cls in classes_to_register:
bpy.utils.register_class(cls)
bpy.types.Scene.skybox_props = bpy.props.PointerProperty(type=SkyboxProperties)
def unregister():
for cls in classes_to_register:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.skybox_props
if __name__ == "__main__":
register()