2121
2222import bpy
2323from bpy_extras .io_utils import ExportHelper
24- from rprblender .engine .export_engine import ExportEngine
24+ from rprblender .engine .export_engine import ExportEngine , ExportEngine2
2525import os .path
2626import json
2727from rprblender .utils .user_settings import get_user_settings
3434log = Log (tag = 'operators.export_scene' )
3535
3636
37+ CONTOUR_AOVS = (pyrpr .AOV_GEOMETRIC_NORMAL , pyrpr .AOV_MATERIAL_ID , pyrpr .AOV_OBJECT_ID )
38+
39+
3740class RPR_EXPORT_OP_export_rpr_scene (RPR_Operator , ExportHelper ):
3841 bl_idname = "rpr.export_scene_rpr"
3942 bl_label = "RPR (.rpr)"
@@ -118,10 +121,7 @@ def execute(self, context):
118121 filepath_json = os .path .splitext (filepath_frame )[0 ] + '.json'
119122 scene .frame_set (i )
120123
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 )
125125 log .info (f"Finished frame { i } export to '{ filepath_frame } '" )
126126
127127 scene .frame_set (orig_frame )
@@ -131,19 +131,28 @@ def execute(self, context):
131131 time_started = time .time ()
132132
133133 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 )
138135
139136 log .info (f"Finished RPR export in { time .time () - time_started } s" )
140137
141138 return {'FINISHED' }
142139
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+
143149 def save_json (self , filepath , scene , view_layer ):
144150 ''' save scene settings to json at filepath '''
145151 output_base = os .path .splitext (filepath )[0 ]
146152
153+ devices = get_user_settings ().final_devices
154+ use_contour = scene .rpr .is_contour_used and not devices .cpu_state
155+
147156 data = {
148157 'width' : int (scene .render .resolution_x * scene .render .resolution_percentage / 100 ),
149158 'height' : int (scene .render .resolution_y * scene .render .resolution_percentage / 100 ),
@@ -189,22 +198,35 @@ def save_json(self, filepath, scene, view_layer):
189198
190199 aovs = {}
191200 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 ]
195205 aovs [aov_name ] = output_base + '.' + aov_name + '.png'
206+
196207 data ['aovs' ] = aovs
197208
198209 # set devices based on final render
199210 device_settings = {}
200- devices = get_user_settings ().final_devices
201-
202211 device_settings ['cpu' ] = int (devices .cpu_state )
203212 device_settings ['threads' ] = devices .cpu_threads
204213
205214 for i , gpu_state in enumerate (devices .available_gpu_states ):
206215 device_settings [f'gpu{ i } ' ] = int (gpu_state )
207216
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+
208230 data ['context' ] = device_settings
209231
210232 with open (filepath , 'w' ) as outfile :
0 commit comments