21
21
22
22
import bpy
23
23
from bpy_extras .io_utils import ExportHelper
24
- from rprblender .engine .export_engine import ExportEngine
24
+ from rprblender .engine .export_engine import ExportEngine , ExportEngine2
25
25
import os .path
26
26
import json
27
27
from rprblender .utils .user_settings import get_user_settings
34
34
log = Log (tag = 'operators.export_scene' )
35
35
36
36
37
+ CONTOUR_AOVS = (pyrpr .AOV_GEOMETRIC_NORMAL , pyrpr .AOV_MATERIAL_ID , pyrpr .AOV_OBJECT_ID )
38
+
39
+
37
40
class RPR_EXPORT_OP_export_rpr_scene (RPR_Operator , ExportHelper ):
38
41
bl_idname = "rpr.export_scene_rpr"
39
42
bl_label = "RPR (.rpr)"
@@ -118,10 +121,7 @@ def execute(self, context):
118
121
filepath_json = os .path .splitext (filepath_frame )[0 ] + '.json'
119
122
scene .frame_set (i )
120
123
121
- exporter = ExportEngine ()
122
- exporter .sync (context )
123
- exporter .export_to_rpr (filepath_frame , flags )
124
- self .save_json (filepath_json , scene , context .view_layer )
124
+ self .export_scene_to_file (context , scene , filepath_frame , filepath_json , flags )
125
125
log .info (f"Finished frame { i } export to '{ filepath_frame } '" )
126
126
127
127
scene .frame_set (orig_frame )
@@ -131,19 +131,28 @@ def execute(self, context):
131
131
time_started = time .time ()
132
132
133
133
filepath_json = os .path .splitext (self .filepath )[0 ] + '.json'
134
- exporter = ExportEngine ()
135
- exporter .sync (context )
136
- exporter .export_to_rpr (self .filepath , flags )
137
- self .save_json (filepath_json , scene , context .view_layer )
134
+ self .export_scene_to_file (context , scene , self .filepath , filepath_json , flags )
138
135
139
136
log .info (f"Finished RPR export in { time .time () - time_started } s" )
140
137
141
138
return {'FINISHED' }
142
139
140
+ def export_scene_to_file (self , context , scene , filepath , filepath_json , flags ):
141
+ if scene .rpr .render_quality == 'FULL' :
142
+ exporter = ExportEngine ()
143
+ else :
144
+ exporter = ExportEngine2 ()
145
+ exporter .sync (context )
146
+ exporter .export_to_rpr (filepath , flags )
147
+ self .save_json (filepath_json , scene , context .view_layer )
148
+
143
149
def save_json (self , filepath , scene , view_layer ):
144
150
''' save scene settings to json at filepath '''
145
151
output_base = os .path .splitext (filepath )[0 ]
146
152
153
+ devices = get_user_settings ().final_devices
154
+ use_contour = scene .rpr .is_contour_used and not devices .cpu_state
155
+
147
156
data = {
148
157
'width' : int (scene .render .resolution_x * scene .render .resolution_percentage / 100 ),
149
158
'height' : int (scene .render .resolution_y * scene .render .resolution_percentage / 100 ),
@@ -189,22 +198,35 @@ def save_json(self, filepath, scene, view_layer):
189
198
190
199
aovs = {}
191
200
for i , enable_aov in enumerate (view_layer .rpr .enable_aovs ):
192
- if enable_aov :
193
- aov = view_layer .rpr .aovs_info [i ]
194
- aov_name = aov_map [aov ['rpr' ]]
201
+ aov = view_layer .rpr .aovs_info [i ]
202
+ aov_type = aov ['rpr' ]
203
+ if enable_aov or (use_contour and aov_type in CONTOUR_AOVS ):
204
+ aov_name = aov_map [aov_type ]
195
205
aovs [aov_name ] = output_base + '.' + aov_name + '.png'
206
+
196
207
data ['aovs' ] = aovs
197
208
198
209
# set devices based on final render
199
210
device_settings = {}
200
- devices = get_user_settings ().final_devices
201
-
202
211
device_settings ['cpu' ] = int (devices .cpu_state )
203
212
device_settings ['threads' ] = devices .cpu_threads
204
213
205
214
for i , gpu_state in enumerate (devices .available_gpu_states ):
206
215
device_settings [f'gpu{ i } ' ] = int (gpu_state )
207
216
217
+ if use_contour :
218
+ data ['contour' ] = {
219
+ "object.id" : int (scene .rpr .contour_use_object_id ),
220
+ "material.id" : int (scene .rpr .contour_use_material_id ),
221
+ "normal" : int (scene .rpr .contour_use_shading_normal ),
222
+ "threshold.normal" : scene .rpr .contour_normal_threshold ,
223
+ "linewidth.objid" : scene .rpr .contour_object_id_line_width ,
224
+ "linewidth.matid" : scene .rpr .contour_material_id_line_width ,
225
+ "linewidth.normal" : scene .rpr .contour_shading_normal_line_width ,
226
+ "antialiasing" : scene .rpr .contour_antialiasing ,
227
+ "debug" : int (scene .rpr .contour_use_shading_normal )
228
+ }
229
+
208
230
data ['context' ] = device_settings
209
231
210
232
with open (filepath , 'w' ) as outfile :
0 commit comments