-
Notifications
You must be signed in to change notification settings - Fork 4
/
BatchCameraRender.ms
3121 lines (2755 loc) · 118 KB
/
BatchCameraRender.ms
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
macroScript BatchCameraRender
category:"Sergo Pogosyan"
toolTip:""
buttonText:"BatchCam"
-- Batch Camera Render, maxscript tool for batch rendering in 3ds max
-- Copyright (C) 2010-2023, Sergo Pogosyan
--
-- 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.
------------------------------------------------------------------------------
-- BatchCameraRender.ms
-- By Sergo Pogosyan (www.sergepogosyan.com, [email protected])
-- Created On: 2009-05-25
-- tested using Max 2009, Max 2010, Max 2011, Max 2012, Max 2016
-------------------------------------------------------------------------------
-- Description:
-- macroscript aims to replace builtin batch render
-------------------------------------------------------------------------------
-- Installing and usage:
-- When you start this script it iterates over all cameras in scene and list them in the dialog box.
-- To each of these cameras you can assign frame resolution, number of frames to render including
-- nonsequential frames, output file location and lighting setup. All these properties can be changed
-- for one or several selected cameras. Output file location is split to folder path and file name,
-- so you can specify new folder for all selected cameras in scene. 'Lighting assignement' section contains
-- three list: Solo light list contains lights that will be only lights turned on during the rendering, 'Forced On'
-- and 'Forced Off' lights are turned on or off respectively during the rendering. After all these settings are setted
-- up check the camera(s) in the list and hit Render button. Check Net Render checkbox to submit network render job.
-------------------------------------------------------------------------------
(
--########################--
--GLOBAL VARS--
--########################--
--lights
LIGHT_LIST
--lighting state array structure: #( #(light_name, on/off), #(light_name, on/off), #(light_name, on/off) ... )
LIGHTING_STATE = #()
--render size presets
RESOLUTIONS = #([640,480],[768,576],[900,600],[1200,800],[1200,960],[1500,1000],[1920,1080],[2400,1200],[2400,1920])
--main rollout
local isDialogOpen = false --variable to save main window open/close state
global batchCameraRender_mainRollOut
WindowHook --native window object to handle local render cancellation
RenderCancelled = false
Output_Size_Rollout
Render_Output_Rollout
Frame_Range_Rollout
Scene_States_Rollout
Light_Assignement_Rollout
Net_Render_Options_Rollout
Vray_Settings_Rollout
Scripts_Rollout
global batchCameraRender_floater
global batchCameraRender_RenderCounter
global batchCameraRender_reload_cameras
global batchCameraRender_reset_render_counter
global batchCameraRender_getUserProperty
global batchCameraRender_populateScripts
global batchCameraRender_currentcamera
PostNotifier
PostNotifierInstalled = false
batchCamPreview = false --if the rendering is preview
global_found_ini_file_paths = #()
global_listview_height = 170
--listView items array
LV_ITEMS = #()
--default vray image file saving state
SAVE_VRAY_IMAGE_FILE_STATE = false
--script version
VERSION_STRING = "1.17"
BatchCam_CommonPropertiesNames = #("frames", "framerange_from", "framerange_to", "anim_frame_range", "frame_width", "frame_heigth", "render_output", \
"elements_state", "not_save_elements", "elements_output", "solo_lights", "on_lights", "off_lights", "scene_state", "state_set", "render_preset", "image_aspect", \
"region_enabled", "region_x", "region_y", "region_w", "region_h" )
BatchCam_ScriptsPropertiesNames = #("OnSubmitScriptEnable", "OnSubmitScript", "perCameraScriptEnable", "perCameraScript", "prerender_script", "prerender_enabled", "postrender_script", "postrender_enabled")
BatchCam_UserValuePropertiesNames = #("UserKey1", "UserKey2", "UserKey3", "UserVal1", "UserVal2", "UserVal3", "bbJobName", "elementName")
--########################--
--vray global vars
--########################--
struct BatchCam_VrayPropertiesMapping (propertyName, propertyUIelement, propertyType)
BatchCam_VrayPropertiesNames = #("irmap_mode", "auto_save_irmap", "auto_switch_irmap", "irmap_read_file", "irmap_save_file", \
"lcmap_mode", "auto_save_lcmap", "auto_switch_lcmap", "lcmap_read_file", "lcmap_save_file", "vray_ortho_mode" )
BatchCam_VrayPropertiesMappingArray = #()
BatchCam_Vray_irmap_modes = #("Single Frame", "Multiframe incremental", "From file", "Add to current map", "Incremental add to current map", "Bucket mode",\
"Animation (prepass)", "Animation (rendering)")
BatchCam_Vray_lcmap_modes = #("Single Frame", "Fly-through", "From file", "Progressive path tracing")
--########################--
--Session-wide persistent variables
--########################--
global BatchCamRenderParamsBuffer
global BatchCam_rollout_state; if BatchCam_rollout_state == undefined then BatchCam_rollout_state = #( true, false, \
true , true, true, \
false, false, false, \
false, false
)
global BatchCam_rollout_names; if BatchCam_rollout_names == undefined then BatchCam_rollout_names = #( "batchCameraRender_mainRollOut", "Net_Render_Options_Rollout", \
"Output_Size_Rollout" , "Frame_Range_Rollout", "Render_Output_Rollout", \
"Vray_Settings_Rollout", "Scene_States_Rollout", "Scripts_Rollout", "Light_Assignement_Rollout", \
"aboutRoll"
)
global BatchCam_listItem_state
--########################--
--end of session-wide persistent variables
--########################--
include @"BatchCameraRender-functions-misc.ms"
include @"BatchCameraRender-functions-populating.ms"
include @"BatchCameraRender-functions-setters.ms"
include @"BatchCameraRender-functions-preparing.ms"
--########################--
--ROLLOUT--
--########################--
rollout batchCameraRender_mainRollOut "Camera Manager Settings"
(
button add_button "Add" align:#left width:65 across:5
button remove_button "Remove" align:#left offset:[-24,0] width:65
button copy_button "Copy" align:#right offset:[48,0] width:65
button paste_button "Paste" align:#right offset:[24,0] width:65
button refresh "Refresh" align:#right width:65
dotNetControl lv_objects "ListView" height:global_listview_height --height:170
button toggle_select_all "[Un]Select All" align:#left width:70 across:6
button toggle_check_all "[Un]Check All" align:#left width:70 offset: [-2,0]
button check_selected "Check Selected" align:#left width:80 offset: [-4,0]
button set_viewport "Set Viewport" align:#right width:70 offset: [6,0] tooltip:"Sets selected viewport to the camera selected in the list"
button get_viewport "Get Viewport" align:#right width:70 offset: [2,0] tooltip:"Selects viewport's camera in the list"
button get_selection "Get Selection" align:#right width:75 offset: [4,0] tooltip:"Selects cameras in the list based on scene selection"
button render_start "Render" align:#left width:70 offset: [0,0] across:5
button preview_start "Preview" align:#left width:70 offset: [-18,0]
checkbox net_render "Net Render" align:#left offset: [-15,4]
checkbox show_net_submit "Show Submit Dialog" align:#left offset: [-20,4]
button select_camera "Select Camera" align:#right width:75 offset: [0,0] tooltip:"Selects camera object in the scene"
--#####--
--list button event handlers--
--#####--
on batchCameraRender_mainRollOut resized height do saveVar2IniFile "Main_RollOut" "dialog_height" height[2]
on refresh pressed do
(
batchCameraRender_reload_cameras lv_objects
ui_elements_refresh lv_objects
)
on remove_button pressed do
(
local selectItems = batchCameraRender_mainRollOut.lv_objects.SelectedItems.GetEnumerator()
while selectItems.MoveNext() do
(
if (superclassof (selectItems.Current.tag.value) != camera) then
(
local camObj = getCameraFromCA (selectItems.Current.tag.value)
local custDef = (custAttributes.getDef (selectItems.Current.tag.value) baseObject:true)
custattributes.delete camObj custDef
)
)
BatchCameraRender_reload_cameras lv_objects
)
on add_button pressed do
(
local batchcam_custattr = attributes BatchCamAttr version:1
(
)
if (batchCameraRender_mainRollOut.lv_objects.SelectedItems.Count == 1) then
(
selected_item = (batchCameraRender_mainRollOut.lv_objects.SelectedItems.Item 0)
camera_obj = selected_item.tag.value
if (camera_obj != undefined) and (superclassof camera_obj == camera) then
(
custattributes.add camera_obj batchcam_custattr #unique
BatchCameraRender_reload_cameras lv_objects
)
)
)
on copy_button pressed do
(
BatchCamRenderParamsBuffer = BatchCameraRenderParamsStruct()
if (batchCameraRender_mainRollOut.lv_objects.SelectedItems.Count == 1) then
(
selected_item = (batchCameraRender_mainRollOut.lv_objects.SelectedItems.Item 0)
camera_obj = selected_item.tag.value
if camera_obj != undefined then
(
propertyNames = getPropNames BatchCamRenderParamsBuffer
for propertyName in propertyNames do
(
prop_value = getUserPropertyFromObject camera_obj (propertyName as string)
setProperty BatchCamRenderParamsBuffer propertyName prop_value
)
ui_elements_refresh lv_objects
)
)
)
on paste_button pressed do
(
if BatchCamRenderParamsBuffer != undefined then
(
if (batchCameraRender_mainRollOut.lv_objects.SelectedItems.Count > 0) then
(
for i=1 to batchCameraRender_mainRollOut.lv_objects.SelectedItems.Count do
(
selected_item = (batchCameraRender_mainRollOut.lv_objects.SelectedItems.Item (i-1))
propertyNames = getPropNames BatchCamRenderParamsBuffer
for propertyName in propertyNames do
(
prop_value = getProperty BatchCamRenderParamsBuffer propertyName
setUserProperty selected_item (propertyName as string) prop_value
)
)
BatchCameraRender_reload_cameras lv_objects
)
)
)
on net_render changed state do
(
saveVar2IniFile "Main_RollOut" "net_render_state" state
show_net_submit.enabled = state --enable show_net_submit checkbox
ui_elements_refresh lv_objects --refresh ui
)
on show_net_submit changed state do
(
saveVar2IniFile "Main_RollOut" "show_submit_dialog_state" state
ui_elements_refresh lv_objects
)
on toggle_select_all pressed do
(
local listItems = for i=0 to (lv_objects.Items.Count - 1) collect (lv_objects.Items.Item i)
local is_some_selected = (lv_objects.SelectedItems.Count > 0)
if is_some_selected then
lv_objects.SelectedItems.Clear()
else
(
lv_objects.BeginUpdate()
for i in listItems do
i.selected = true
lv_objects.EndUpdate()
)
lv_objects.HideSelection = false
local selectedItems = for i=0 to (lv_objects.SelectedItems.Count - 1) collect (lv_objects.SelectedItems.Item i)
populate_ui_elements selectedItems
ui_elements_refresh lv_objects
)
on toggle_check_all pressed do
(
local listItems = for i=0 to (lv_objects.Items.Count - 1) collect (lv_objects.Items.Item i)
is_some_checked = false
for i in listItems do
(
if i.checked then is_some_checked = true
)
if is_some_checked then
(
for i in listItems do
i.checked = false
)
else
(
for i in listItems do
i.checked = true
)
ui_elements_refresh lv_objects
)
on check_selected pressed do
(
for i in LV_ITEMS do
(
if i.selected then
i.checked = true
else
i.checked = false
)
ui_elements_refresh lv_objects
)
on select_camera pressed do
(
camera_selection_names = for obj in LV_ITEMS where obj.selected collect obj.text --get camera names from selected items in list
camera_selection = for obj in get_camera_list() where ((findItem camera_selection_names obj.name) != 0) collect obj --collect camera objects with names is in previous array
select camera_selection
)
--function to set selected camera to active viewport
on set_viewport pressed do
(
local tag_object = undefined
for item in LV_ITEMS while tag_object == undefined do
(
if item.selected then
(
tag_object = item.tag.value
)
)
if (tag_object != undefined) then
(
local cam_obj = undefined
if (superclassof tag_object == camera) then
cam_obj = tag_object
else
cam_obj = getCameraFromCA tag_object
viewport.setCamera cam_obj
local xres_prop = getUserProperty tag_object "BatchCameraRender_frame_width"
local yres_prop = getUserProperty tag_object "BatchCameraRender_frame_heigth"
if (isNotUndefined xres_prop) and (isNotUndefined yres_prop) then
(
if renderSceneDialog.isOpen() then
renderSceneDialog.close()
renderWidth = xres_prop as integer
renderHeight = yres_prop as integer
)
)
)
on get_selection pressed do
(
local camobjs = for obj in selection where superclassof obj == camera collect obj
local selectedItems = #()
for obj in camobjs do
(
local listItems = lv_objects.Items.GetEnumerator()
while listItems.MoveNext() do
(
local camObj = undefined
local itemObj = listItems.Current.tag.value
if (superclassof itemObj == camera) then
camObj = itemObj
else
camObj = getCameraFromCA itemObj
if (camObj.name == obj.name) then
(
append selectedItems (listItems.Current)
)
)
)
if selectedItems.count > 0 then
(
lv_objects.SelectedItems.Clear()
lv_objects.BeginUpdate()
for item in selectedItems do
item.selected = true
lv_objects.EndUpdate()
lv_objects.HideSelection = false
)
populate_ui_elements selectedItems
ui_elements_refresh lv_objects
)
on get_viewport pressed do
(
if viewport.getType() == #view_camera then
(
local camera_obj = viewport.getCamera()
local camera_name = camera_obj.name
local listItem = undefined
local listItems = lv_objects.Items.GetEnumerator()
while listItems.MoveNext() do
(
if (listItems.Current.tag.value.name == camera_name) then
(
listItem = listItems.Current
listItem.selected = true
listItem.EnsureVisible()
)
else
(
listItems.Current.selected = false
)
)
if (listItem != undfined) then
populate_ui_elements #(listItem)
ui_elements_refresh lv_objects
)
)
fn onWmCommand ev args =
(
-- format "ev:%\n" (ev)
-- local query_approved = queryBox "Cancel all jobs?\n\n" title:"Warning: Cancel pressed"
-- if query_approved then
-- (
RenderCancelled = true
dotnet.removeAllEventHandlers WindowHook
-- )
)
fn DMNotification =
(
local win_handle = DialogMonitorOPS.GetWindowHandle()
if (win_handle != 0) then
(
local win_text = (UIAccessor.GetWindowText win_handle)
local win_class = (UIAccessor.GetWindowClassName win_handle)
if (matchPattern win_text pattern:"Rendering*" ignoreCase:false) then
(
WindowHook.ReleaseHandle()
WindowHook.AssignHandle (dotnetobject "IntPtr" win_handle)
dotnet.removeAllEventHandlers WindowHook
dotnet.addEventHandler WindowHook "WmCommand" onWmCommand
)
)
true
)
fn do_render preview allCameras=
(
local temp_string
local temp_string1
local temp_string2
local temp_string3
local temp_string5
--store parameter
renderParamBuf = BatchCam_RenderParameterStore()
renderParamBuf = storeRenderParams renderParamBuf
rendUseActiveView = true
--refill light_list in case some lights were removed or added during script running state
LIGHT_LIST = collect_scene_lights()
--save lights state
store_lighting_state()
--render preset saving
INIFileDir = ((getdir #plugcfg) + "\\BatchCameraRender\\")
if (getDirectories INIFileDir).count == 0 then makeDir INIFileDir
tempRP_file = INIFileDir + "temp_render_preset.rps"
renderpresets.SaveAll 0 tempRP_file
renderPresetsApplied = false
lightStateApplied = false
RenderCancelled = false
--if not netrender then set cancellation detection handler here
if (not net_render.checked) do
(
DialogMonitorOPS.unRegisterNotification id:#get_render_win
DialogMonitorOPS.RegisterNotification DMNotification id:#get_render_win
DialogMonitorOPS.Enabled = true
)
-- THIS SECTION SHOULD BE UNDER TRY-CATCH BLOCK
-- try
(
local firstCamera = true
for item in LV_ITEMS while not RenderCancelled do
(
if allCameras or item.checked then
(
if isVrayRenderer() and (hasproperty (renderers.current) "V_Ray_settings") then
(
-- actionMan.executeAction 369690881 "1"
if not firstCamera then
sleep 2
firstCamera = false
)
--get camera name
local camera_to_render = item.tag.value
local cam_obj = undefined
if (superclassof camera_to_render == camera) then
cam_obj = camera_to_render
else
cam_obj = getCameraFromCA camera_to_render
--unhide camera objects
if (cam_obj.isHiddenInVpt) then
(
cam_obj.isHidden = false
hideByCategory.cameras = false
)
-- set the render preset
temp_string = getUserProperty camera_to_render "BatchCameraRender_render_preset"
if isNotUndefined temp_string then
(
setSilentMode true --set silent to prevent dialogs with gamma warning
presetsArray = #()
if (maxVersion())[1] >= 11000 then --run renderPresetMRUList command only if script is running under 3dsmax 2009+
presetsArray = renderPresetMRUList
presetsNames = for preset in presetsArray collect preset[1]
presetIndex = finditem presetsNames temp_string
if presetIndex != 0 then
(
presetFile = presetsArray[presetIndex][2]
renderpresets.LoadAll 0 presetFile
renderPresetsApplied = true
)
setSilentMode false
)
if not preview then
(
--set frame range
temp_string1 = getUserProperty camera_to_render "BatchCameraRender_frames"
temp_string2 = getUserProperty camera_to_render "BatchCameraRender_framerange_from"
temp_string3 = getUserProperty camera_to_render "BatchCameraRender_framerange_to"
temp_string5 = getUserProperty camera_to_render "BatchCameraRender_anim_frame_range"
if isNotUndefined temp_string5 then
(
rendTimeType = 3
temp_frame_range = get_key_range cam_obj
rendStart = temp_frame_range[1].frame
rendEnd = temp_frame_range[2].frame
)
else if isNotUndefined temp_string1 then
( --render_frames
rendTimeType = 4
rendPickupFrames = temp_string1 as string
)
else if isNotUndefined temp_string2 then
(
--single frame
--frame range
rendTimeType = 3
rendStart = temp_string2 as integer
rendEnd = temp_string3 as integer
)
)
else
rendTimeType = 1
rendNThFrame = Frame_Range_Rollout.render_every_nth.value as integer
if not preview then
(
--get and set frame resolution
xres_prop = getUserProperty camera_to_render "BatchCameraRender_frame_width"
yres_prop = getUserProperty camera_to_render "BatchCameraRender_frame_heigth"
if (isNotUndefined xres_prop) and (isNotUndefined yres_prop) then
(
renderWidth = xres_prop as integer
renderHeight = yres_prop as integer
)
)
else
(
local xres_prop = 0
local yres_prop = 0
if (temp_width = loadVarFromIniFile "Output_Size_Rollout" "preview_width") != undefined then
xres_prop = (temp_width as integer)
else
xres_prop = 1000
image_aspect = getUserProperty camera_to_render "BatchCameraRender_image_aspect"
if (isNotUndefined image_aspect) then
yres_prop = xres_prop / (image_aspect as float)
else
yres_prop = xres_prop / 1.333
renderWidth = xres_prop as integer
renderHeight = yres_prop as integer
)
--set render region
local use_region = getUserProperty camera_to_render "BatchCameraRender_region_enabled"
if (isNotUndefined use_region) and (use_region as BooleanClass) then
(
setRenderType #region
local reg_x = getUserProperty camera_to_render "BatchCameraRender_region_x"
local reg_y = getUserProperty camera_to_render "BatchCameraRender_region_y"
local reg_w = getUserProperty camera_to_render "BatchCameraRender_region_w"
local reg_h = getUserProperty camera_to_render "BatchCameraRender_region_h"
if (isNotUndefined reg_x) and (isNotUndefined reg_y) and\
(isNotUndefined reg_w) and (isNotUndefined reg_h) then
(
reg_x = reg_x as float
reg_y = reg_y as float
reg_w = reg_w as float
reg_h = reg_h as float
--convert percentage to viewport sizes
local x = (renderWidth / 100.0) * reg_x
local y = (renderHeight / 100.0) * reg_y
local w = ((renderWidth / 100.0) * (reg_w - reg_x))
local h = ((renderHeight / 100.0) * (reg_h - reg_y))
viewport.setRegionRect (viewport.activeViewport) (box2 x y w h)
)
)
--get and set file name
temp_string = getUserProperty camera_to_render "BatchCameraRender_render_output"
if (shouldBeSaved()) and (isNotUndefined temp_string) then
(
temp_string = parse_file_name_template temp_string (compose_parsing_dictionary camera_to_render)
temp_path = getFilenamePath temp_string
if (not (doesFileExist temp_path)) then
(
--if silent_mode is on try to create new path
if Net_Render_Options_Rollout.silent_add_path_mode.checked then
(
if not makeDir temp_path all:true then
throw ("Failed to create path: "+ temp_path) --if path making fails throw exception
)
else
(
throw ("Path does not exist: "+ temp_path) --if path making fails throw exception
)
)
rendSaveFile = Render_Output_Rollout.save_file.checked
rendOutputFilename = temp_string
)
else
rendSaveFile = false
local elementsPath = prepare_render_elements camera_to_render
prepare_vray_settings camera_to_render temp_string elementsPath
--get lightstate
temp_string1 = getUserProperty camera_to_render "BatchCameraRender_solo_lights"
temp_string2 = getUserProperty camera_to_render "BatchCameraRender_on_lights"
temp_string3 = getUserProperty camera_to_render "BatchCameraRender_off_lights"
if isNotUndefined temp_string1 then
(
temparray = filterString temp_string1 ","
turn_solo_lights_on temparray
lightStateApplied = true
)
else --if solo lights are listed then don't process other light setting
(
if isNotUndefined temp_string3 then --turn off exclude lights first, then turn on include lights
(
temparray = filterString temp_string3 ","
force_lights_off temparray
lightStateApplied = true
)
if isNotUndefined temp_string2 then --turn on include lights.
(
temparray = filterString temp_string2 ","
force_lights_on temparray
lightStateApplied = true
)
)
--set scene state
temp_string = getUserProperty camera_to_render "BatchCameraRender_scene_state"
if isNotUndefined temp_string then
(
temp_string = parse_file_name_template temp_string (compose_parsing_dictionary camera_to_render)
sceneStateMgr.RestoreAllParts temp_string
)
--set state set
local ss_class = dotnetclass "Autodesk.Max.StateSets.Plugin"
if ss_class != undefined then --if state sets supported
(
temp_string = getUserProperty camera_to_render "BatchCameraRender_state_set"
if isNotUndefined temp_string then
(
local stateSetsDotNetObject = dotNetObject "Autodesk.Max.StateSets.Plugin"
local stateSets = stateSetsDotNetObject.Instance
local masterState = stateSets.EntityManager.RootEntity.MasterStateSet
if (masterState.CurrentState != undefined) then --reset the state before applying anything
masterState.SetCurrentStateSet undefined
local state_set = masterState.GetDescendant temp_string
if (state_set != undefined) then
masterState.SetCurrentStateSet #(state_set)
)
)
--scripts setting
callbacks.removeScripts id:#BatchCameraRender
--set global variables to be visible in submit and render scripts
batchCameraRender_currentcamera = cam_obj
temp_string = getUserProperty camera_to_render "BatchCameraRender_prerender_enabled"
if (not preview) and (isNotUndefined temp_string) then
(
if (temp_string as BooleanClass) then
(
temp_string = getUserProperty camera_to_render "BatchCameraRender_prerender_script"
callbacks.addScript #preRender fileName:temp_string id:#BatchCameraRender persistent:true
)
)
temp_string = getUserProperty camera_to_render "BatchCameraRender_postrender_enabled"
if (not preview) and (isNotUndefined temp_string) then
(
if (temp_string as BooleanClass) then
(
temp_string = getUserProperty camera_to_render "BatchCameraRender_postrender_script"
callbacks.addScript #postRender fileName:temp_string id:#BatchCameraRender persistent:true
)
)
--per camera submit scripts section
if (not preview) and (Scripts_Rollout.enable_percamera_submit.state) then
(
try
(
maxscript_file_name = Scripts_Rollout.percamera_submit_script.text
if isNotUndefinedOrEmpty maxscript_file_name then
(
if (doesFileExist maxscript_file_name) then
filein maxscript_file_name
)
)
catch
(
messagebox (getCurrentException()) title:"Submit Script Error"
)
)
--save render location to last render property
if (not preview) then
setUserProperty item "BatchCameraRender_lastRenderPath" rendOutputFilename
--start render
if (not preview) and (Net_Render_Options_Rollout.UseDeadline.checked) then
(
viewport.setCamera cam_obj
submit_to_deadline cam_obj
)
else if (not preview) and net_render.checked and (not show_net_submit.checked) then
(
net_render_auto_submit cam_obj
)
else
(
if (not preview) then
rendUseNet = net_render.checked
else
rendUseNet = false
viewport.setCamera cam_obj
max quick render
)
--remove callbacks after render started
callbacks.removeScripts id:#BatchCameraRender
--restore saved render_preset if render presets was applied during the rendering
if renderPresetsApplied then
(
INIFileDir = ((getdir #plugcfg) + "\\BatchCameraRender\\")
tempRP_file = INIFileDir + "temp_render_preset.rps"
if doesFileExist tempRP_file then
renderpresets.LoadAll 0 tempRP_file
)
restoreRenderParams renderParamBuf
--restore lights state
--light state have to be restored after each camera iteration if it was applied in the loop
if lightStateApplied then
restore_lighting_state()
) -- if close
) -- end of for loop
DialogMonitorOPS.unRegisterNotification id:#get_render_win
DialogMonitorOPS.Enabled = false
) -- end of try close
-- catch
-- (
-- messagebox (getCurrentException()) title:"Error"
-- restore_lighting_state()
-- )
)
fn quietRender =
(
SetQuietMode true
batchCamPreview = false
if renderSceneDialog.isOpen() then
renderSceneDialog.close()
--increment render try counter to be used in keyword syntax
Net_Render_Options_Rollout.Try_Counter.value += 1
batchCameraRender_RenderCounter = Net_Render_Options_Rollout.Try_Counter.value
renderSceneDialog.close()
batchCameraRender_reload_cameras batchCameraRender_mainRollOut.lv_objects
if (Scripts_Rollout.enable_onsubmit.state) then
(
maxscript_file_name = Scripts_Rollout.onsubmit_script.text
if isNotUndefinedOrEmpty maxscript_file_name then
(
if (doesFileExist maxscript_file_name) then
filein maxscript_file_name
)
)
do_render false true
SetQuietMode false
)
--#####--
--render button event hadler--
--#####--
on render_start pressed do
(
batchCamPreview = false
query_approved = true
if renderSceneDialog.isOpen() then
renderSceneDialog.close()
--check the render type and suggest to switch to view mode
if (not GetQuietMode()) and query_approved and getRenderType() != #view and getRenderType() != #normal then
(
local message_text = "Render Type set to \"" + (getRenderType() as string) + "\".\n\nWould you like to switch to View mode?"
local message_buttons = (dotnetclass "MessageBoxButtons").YesNoCancel
local message_icon = (dotnetclass "MessageBoxIcon").Question
result = (dotnetclass "MessageBox").show message_text "Caution" message_buttons message_icon
if (result == ((dotnetclass "DialogResult").Yes)) then
setRenderType #view
else if (result == ((dotnetclass "DialogResult").No)) then
query_approved = true
else
query_approved = false
)
if (not GetQuietMode()) and query_approved and net_render.checked and (not (Render_Output_Rollout.save_file.checked or Vray_Settings_Rollout.save_vray_image_file.checked)) then
query_approved = queryBox "You are about to submit network rendering with no assigned file.\n\nDo you want to continue?" title:"Warning:No files saved"
if query_approved then
(
--increment render try counter to be used in keyword syntax
Net_Render_Options_Rollout.Try_Counter.value += 1
batchCameraRender_RenderCounter = Net_Render_Options_Rollout.Try_Counter.value
renderSceneDialog.close()
batchCameraRender_reload_cameras batchCameraRender_mainRollOut.lv_objects
--on submit section - runs once per each render submit
--runs only if at least one job is checked it listview - currently on_render_start get called only if something is checked in listview
if shouldBeSaved() and (Scripts_Rollout.enable_onsubmit.state) then
(
-- try
(
maxscript_file_name = Scripts_Rollout.onsubmit_script.text
if isNotUndefinedOrEmpty maxscript_file_name then
(
if (doesFileExist maxscript_file_name) then
filein maxscript_file_name
)
)
-- catch
-- (
-- messagebox (getCurrentException()) title:"Submit Script Error"
-- )
)
do_render false false
)
else
(
--cancellation
)
)
on preview_start pressed do
(
batchCamPreview = true
renderSceneDialog.close()
batchCameraRender_reload_cameras batchCameraRender_mainRollOut.lv_objects
do_render true false
)
--############
--ON OPEN event handler
--initialization
--############
on batchCameraRender_mainRollOut open do
(
init_ListView lv_objects (get_camera_list())
--this array contains listview items for convinience
LV_ITEMS = for i=0 to (lv_objects.Items.Count - 1) collect (lv_objects.Items.Item i)
--init ui elements with session persistent variables
--net render checkbox
if (temp_state = loadVarFromIniFile "Main_RollOut" "net_render_state") != undefined then
net_render.checked = (temp_state as booleanClass)
else
(
net_render.checked = false
saveVar2IniFile "Main_RollOut" "net_render_state" false
)
if (temp_state = loadVarFromIniFile "Main_RollOut" "show_submit_dialog_state") != undefined then
show_net_submit.checked = (temp_state as booleanClass)
else
(
show_net_submit.checked = false
saveVar2IniFile "Main_RollOut" "show_submit_dialog_state" false
)
--refresh ui elements
if (lv_objects.items.count == 0) then --only call refresh if empty listview, because init_ListView/fill_ListView will refresh anyway
ui_elements_refresh lv_objects
--add onopen callback
callbacks.addScript #filePostOpen "batchCameraRender_reload_cameras batchCameraRender_mainRollOut.lv_objects" id:#batchcam
-- callbacks.addScript #filePostOpen "batchCameraRender_reset_render_counter()" id:#batchcam
callbacks.addScript #filePostMerge "batchCameraRender_reload_cameras batchCameraRender_mainRollOut.lv_objects" id:#batchcam
callbacks.addScript #systemPostNew "batchCameraRender_reload_cameras batchCameraRender_mainRollOut.lv_objects" id:#batchcam
callbacks.addScript #systemPostNew "batchCameraRender_reset_render_counter()" id:#batchcam
callbacks.addScript #systemPostReset "batchCameraRender_reload_cameras batchCameraRender_mainRollOut.lv_objects" id:#batchcam
callbacks.addScript #systemPostReset "batchCameraRender_reset_render_counter()" id:#batchcam
if (dotnetclass "WindowHook" == undefined) then
CreateNativeWindowOps() --create dotnet object in memory
if (WindowHook == undefined) then
(
WindowHook = dotnetobject "WindowHook"
-- format "windowhook ready:%\n" WindowHook
)
else
(
WindowHook.ReleaseHandle()
dotnet.removeAllEventHandlers WindowHook
)
if (dotnetclass "PostNotifier" == undefined) then
CreatePostNotifier()
if (PostNotifier == undefined) then
(
PostNotifier = dotnetobject "PostNotifier"
-- format "PostNotifier ready:%\n" PostNotifier
)
else
(
dotnet.removeAllEventHandlers PostNotifier
)
)
on batchCameraRender_mainRollOut close do
(
--store checked state of the items to array
for i=1 to lv_objects.Items.count do
(
BatchCam_listItem_state[i] = lv_objects.Items.Item[i-1].checked
)
--set flag to show that main window is closed
isDialogOpen = false
updateToolbarButtons()
--remove all script callbacks
callbacks.removeScripts id:#batchcam
if (WindowHook != undefined) then
(
WindowHook.ReleaseHandle()
dotnet.removeAllEventHandlers WindowHook
)
if (PostNotifier != undefined) then
(
dotnet.removeAllEventHandlers PostNotifier
)
DialogMonitorOPS.unRegisterNotification id:#get_render_win
DialogMonitorOPS.Enabled = false
)
on batchCameraRender_mainRollOut moved pos do
(
if (batchCameraRender_mainRollOut.placement != #minimized) and (batchCameraRender_mainRollOut.placement != #maximized) then