-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoperators.py
2181 lines (1904 loc) · 114 KB
/
operators.py
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
# BEGIN LICENSE & COPYRIGHT BLOCK.
#
# Copyright (C) 2022-2024 Kiril Strezikozin
# BakeMaster Blender Add-on (version 2.7.0)
#
# This file is a part of BakeMaster Blender Add-on, a plugin for texture
# baking in open-source Blender 3d modelling software.
# The author can be contacted at <[email protected]>.
#
# Redistribution and use for any purpose including personal, educational, and
# commercial, with or without modification, are permitted provided
# that the following conditions are met:
#
# 1. The current acquired License allows copies/redistributions of this
# software be made to UNLIMITED END USER SEATS (OPEN SOURCE LICENSE).
# 2. Redistributions of this source code or partial usage of this source code
# must follow the terms of this license and retain the above copyright
# notice, and the following disclaimer.
# 3. The name of the author may be used to endorse or promote products derived
# from this software. In such a case, a prior written permission from the
# author is required.
#
# This program is free software and 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. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# You should have received a copy of the GNU General Public License in the
# GNU.txt file along with this program. If not,
# see <http://www.gnu.org/licenses/>.
#
# END LICENSE & COPYRIGHT BLOCK.
import bpy
import webbrowser
from .utils import *
from .labels import BM_Labels
class BM_OT_Table_of_Objects(bpy.types.Operator):
bl_idname = 'bakemaster.table_of_objects'
bl_label = ""
bl_description = "Move the bake priority of object in the list up and down.\nWhen Name Matching is on, moving Containers bake priority is possible"
bl_options = {'INTERNAL', 'UNDO'}
control : bpy.props.EnumProperty(
items = [('UP', "Up", ""), ('DOWN', "Down", "")])
def invoke(self, context, event):
scene = context.scene
global_active_index = scene.bm_props.global_active_index
try:
scene.bm_table_of_objects[global_active_index]
except IndexError:
pass
else:
item = scene.bm_table_of_objects[global_active_index]
if self.control == 'UP' and global_active_index > 0:
# default move for regular objects
if scene.bm_props.global_use_name_matching is False:
scene.bm_table_of_objects.move(global_active_index, global_active_index - 1)
# sync texset objs
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update cage and highpolies source objects indexes
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
scene.bm_props.global_active_index -= 1
# move nm items
else:
to_move = []
move_to_index = -1
# moving universal container
if item.nm_is_universal_container:
move_starter_index = -1
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == item.nm_master_index:
to_move.append(index)
# finding where to move to
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_is_universal_container and object.nm_master_index + 1 == item.nm_master_index or object.nm_is_detached and object.nm_master_index + 1 == item.nm_master_index:
move_starter_index = index
move_to_index = index
break
to_move.append(global_active_index)
if move_starter_index == -1:
return {'FINISHED'}
# moving each in to_move on the starter_index and index += 1 each move iteration
increaser = 0
for index in sorted(to_move):
scene.bm_table_of_objects.move(index, move_starter_index + increaser)
# sync texset objs
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update cage and highpolies source objects indexes
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
increaser += 1
# moving local container (cant move out of its uni)
elif item.nm_is_local_container:
move_starter_index = -1
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and object.nm_item_local_container_master_index == item.nm_master_index:
to_move.append(index)
if object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and object.nm_is_local_container and object.nm_master_index + 1 == item.nm_master_index:
if move_starter_index == -1:
move_starter_index = index
move_to_index = index
to_move.append(global_active_index)
if move_starter_index == -1:
return {'FINISHED'}
# moving all items within the same local container
increaser = 0
for index in sorted(to_move):
scene.bm_table_of_objects.move(index, move_starter_index + increaser)
# sync texset objs
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update cage and highpolies source objects indexes
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
increaser += 1
# move local item
elif item.nm_is_detached is False:
move_starter_index = -1
len_of_local_items = 0
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and object.nm_item_local_container_master_index == item.nm_item_local_container_master_index and object.nm_master_index < item.nm_master_index:
len_of_local_items += 1
if object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and object.nm_item_local_container_master_index == item.nm_item_local_container_master_index and object.nm_master_index + 1 == item.nm_master_index:
if move_starter_index == -1:
move_starter_index = index
move_to_index = index
# if there are no other local items within the same local container, do not move the item
if len_of_local_items < 1:
return {'FINISHED'}
else:
scene.bm_table_of_objects.move(global_active_index, move_starter_index)
# sync texset objs
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update cage and highpolies source objects indexes
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
# move detached
else:
move_starter_index = -1
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_is_detached and object.nm_master_index + 1 == item.nm_master_index:
move_starter_index = index
move_to_index = index
break
elif object.nm_is_universal_container and object.nm_master_index + 1 == item.nm_master_index:
move_starter_index = index
move_to_index = index
break
if move_starter_index == -1:
return {'FINISHED'}
# moving detached on top of the previous uni_c or before the previous detached
scene.bm_table_of_objects.move(global_active_index, move_starter_index)
# sync texset objs
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update cage and highpolies source objects indexes
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
# updating active index
if move_to_index != -1:
scene.bm_props.global_active_index = move_to_index
# updating nm master_indexes
BM_Table_of_Objects_NameMatching_UpdateAllNMIndexes(context)
# update texsets objs because object was moved
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
elif self.control == 'DOWN' and global_active_index < len(scene.bm_table_of_objects) - 1:
# default move for regular objects
if scene.bm_props.global_use_name_matching is False:
scene.bm_table_of_objects.move(global_active_index, global_active_index + 1)
# sync texset objs
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update cage and highpolies source objects indexes
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
scene.bm_props.global_active_index += 1
# move nm items
else:
to_move = []
move_to_index = -1
len_of_locals = 0
len_of_move_to = 0
# moving universal container
if item.nm_is_universal_container:
move_starter_index = -1
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == item.nm_master_index:
to_move.append(index)
len_of_move_to += 1
# finding where to move to
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_is_detached and object.nm_master_index - 1 == item.nm_master_index:
move_starter_index = index
move_to_index = index - len_of_move_to
break
elif object.nm_is_universal_container and object.nm_master_index - 1 == item.nm_master_index:
move_starter_index = index
for object1 in scene.bm_table_of_objects:
if object1.nm_item_uni_container_master_index == object.nm_master_index:
len_of_locals += 1
move_to_index = global_active_index + len_of_locals + 1
break
to_move.append(global_active_index)
if move_starter_index == -1:
return {'FINISHED'}
# moving each in to_move on the starter_index and index -= 1 each move iteration
for index in sorted(to_move):
scene.bm_table_of_objects.move(global_active_index, move_starter_index + len_of_locals)
# sync texset objs
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update cage and highpolies source objects indexes
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
# moving local container (cant move out of its uni)
elif item.nm_is_local_container:
move_starter_index = -1
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and object.nm_item_local_container_master_index == item.nm_master_index:
to_move.append(index)
len_of_move_to += 1
# finding where to move to
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and object.nm_is_local_container and object.nm_master_index - 1 == item.nm_master_index:
move_starter_index = index
for object1 in scene.bm_table_of_objects:
if object1.nm_item_uni_container_master_index == object.nm_item_uni_container_master_index and object1.nm_item_local_container_master_index == object.nm_master_index:
len_of_locals += 1
move_to_index = global_active_index + len_of_locals + 1
break
to_move.append(global_active_index)
if move_starter_index == -1:
return {'FINISHED'}
# moving all items within the same local container
for index in sorted(to_move):
scene.bm_table_of_objects.move(global_active_index, move_starter_index + len_of_locals)
# sync texset objs
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update cage and highpolies source objects indexes
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
# move local item
elif item.nm_is_detached is False:
move_starter_index = -1
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and object.nm_item_local_container_master_index == item.nm_item_local_container_master_index and object.nm_master_index > item.nm_master_index:
len_of_locals += 1
# finding where to move to
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and object.nm_item_local_container_master_index == item.nm_item_local_container_master_index and object.nm_master_index - 1 == item.nm_master_index:
move_starter_index = index
move_to_index = index
break
# if there are no other local items within the same local container, do not move the item
if len_of_locals < 1:
return {'FINISHED'}
else:
scene.bm_table_of_objects.move(global_active_index, move_starter_index)
# sync texset objs
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update cage and highpolies source objects indexes
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
# move detached
else:
move_starter_index = -1
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_is_detached and object.nm_master_index - 1 == item.nm_master_index:
move_starter_index = index
move_to_index = index
break
elif object.nm_is_universal_container and object.nm_master_index - 1 == item.nm_master_index:
for object1 in scene.bm_table_of_objects:
if object1.nm_item_uni_container_master_index == object.nm_master_index:
len_of_locals += 1
move_to_index = global_active_index + len_of_locals + 1
move_starter_index = index + len_of_locals
break
if move_starter_index == -1:
return {'FINISHED'}
# moving detached on top of the previous uni_c or before the previous detached
scene.bm_table_of_objects.move(global_active_index, move_starter_index)
# sync texset objs
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update cage and highpolies source objects indexes
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
# updating active index
if move_to_index != -1:
scene.bm_props.global_active_index = move_to_index
# updating nm master_indexes
BM_Table_of_Objects_NameMatching_UpdateAllNMIndexes(context)
# update texsets objs because object was moved
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
return {'FINISHED'}
class BM_OT_Table_of_Objects_Add(bpy.types.Operator):
bl_idname = 'bakemaster.table_of_objects_add'
bl_label = ""
bl_description = "Add selected mesh object(s) in the scene to the list below.\nWhen Name Matching is on, added object(s) will be automatically matched"
bl_options = {'INTERNAL', 'UNDO'}
def execute(self, context):
scene = context.scene
is_mesh = True
exists = False
objects = []
objects_data = []
# get prefixes
lowpoly_prefix_raw = context.scene.bm_props.global_lowpoly_tag
highpoly_prefix_raw = context.scene.bm_props.global_highpoly_tag
cage_prefix_raw = context.scene.bm_props.global_cage_tag
decal_prefix_raw = context.scene.bm_props.global_decal_tag
refresh_nm_config = False
if context.object:
for object in scene.bm_table_of_objects:
objects.append(object.global_object_name)
try:
context.scene.objects[object.global_object_name]
except (KeyError, AttributeError, UnboundLocalError):
pass
else:
object_pointer = context.scene.objects[object.global_object_name]
objects_data.append(object_pointer.data)
# default add
if scene.bm_props.global_use_name_matching is False:
if context.object:
use_sort_alpha = False
for area in bpy.context.screen.areas:
if area is None or area.type != 'OUTLINER':
continue
for spc in area.spaces:
if spc is None or spc.type != 'OUTLINER':
continue
elif spc.display_mode not in {'VIEW_LAYER', 'SCENES'}:
continue
use_sort_alpha = spc.use_sort_alpha
break
if use_sort_alpha:
selected_objs = sorted(
context.selected_objects, key=lambda x: x.name)
else:
selected_objs = context.selected_objects
for object in selected_objs:
if object.type == 'MESH':
if object not in objects and object.data not in objects_data:
# remove None all highpolies
BM_ITEM_PROPS_hl_highpoly_UpdateOnAdd(context)
# set hl_use_cage to False for data-classes with hl_use_cage True and None hl_cage
BM_ITEM_PROPS_hl_cage_UpdateOnAdd(context)
new_item = scene.bm_table_of_objects.add()
# Default Preset
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
DefaultPreset_Apply.obj(context, new_item)
# update texsets objs source indexes
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
new_item.global_object_name = object.name
# new_item.bake_batchname_preview = BM_ITEM_PROPS_bake_batchname_ConstructPreview(context, new_item.bake_batchname)
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
else:
exists = True
else:
is_mesh = False
# adding with name matching
else:
if len(scene.bm_table_of_objects) == 0:
scene.bm_props.global_use_name_matching = False
refresh_nm_config = True
if context.object:
# new config
insert_data = []
new_data = []
all_objs = BM_Table_of_Objects_NameMatching_GetAllObjectNames(context)
use_sort_alpha = False
for area in bpy.context.screen.areas:
if area is None or area.type != 'OUTLINER':
continue
for spc in area.spaces:
if spc is None or spc.type != 'OUTLINER':
continue
elif spc.display_mode not in {'VIEW_LAYER', 'SCENES'}:
continue
use_sort_alpha = spc.use_sort_alpha
break
if use_sort_alpha:
selected_objs = sorted(
context.selected_objects, key=lambda x: x.name)
else:
selected_objs = context.selected_objects
# creating list of all objs to add
new_objs = []
for object in selected_objs:
# checks
if object.type != 'MESH':
is_mesh = False
continue
if object in objects or object.data in objects_data:
exists = True
continue
new_objs.append(object.name)
for object in scene.bm_table_of_objects:
if object.nm_is_detached:
new_objs.append(object.global_object_name)
# try match some
for object_name in new_objs:
object_name_chunked = BM_Table_of_Objects_NameMatching_GenerateNameChunks(object_name)
root_name = BM_Table_of_Objects_NameMatching_GetNameChunks(object_name_chunked, 'ROOT', context)
match_found = False
for object in scene.bm_table_of_objects:
if not any([object.nm_is_universal_container, object.nm_is_local_container, object.nm_is_detached]) and object.global_object_name != object_name:
pair_object_name_chunked = BM_Table_of_Objects_NameMatching_GenerateNameChunks(object.global_object_name)
pair_root_name = BM_Table_of_Objects_NameMatching_GetNameChunks(pair_object_name_chunked, 'ROOT', context)
# check if found match
if BM_Table_of_Objects_NameMatching_CombineToRaw(pair_root_name).find(BM_Table_of_Objects_NameMatching_CombineToRaw(root_name)) == 0 or BM_Table_of_Objects_NameMatching_CombineToRaw(root_name).find(BM_Table_of_Objects_NameMatching_CombineToRaw(pair_root_name)) == 0:
# add nm_master_indexes to new_data to insert new obj
# or a flag to add local_clowpoly
# low
if lowpoly_prefix_raw in object_name_chunked:
if lowpoly_prefix_raw in pair_object_name_chunked:
insert_data.append([object_name, object.nm_item_uni_container_master_index, object.nm_item_local_container_master_index, None, 'hl_is_lowpoly'])
else:
container_found = False
for object1 in scene.bm_table_of_objects:
if object1.nm_item_uni_container_master_index == object.nm_item_uni_container_master_index and object1.nm_is_local_container and object1.nm_is_lowpoly_container:
container_found = True
insert_data.append([object_name, object1.nm_item_uni_container_master_index, object1.nm_master_index, None, 'hl_is_lowpoly'])
if container_found is False:
insert_data.append([object_name, object.nm_item_uni_container_master_index, None, 0, 'hl_is_lowpoly'])
match_found = True
# high
if highpoly_prefix_raw in object_name_chunked:
if highpoly_prefix_raw in pair_object_name_chunked:
insert_data.append([object_name, object.nm_item_uni_container_master_index, object.nm_item_local_container_master_index, None, 'hl_is_highpoly'])
else:
container_found = False
for object1 in scene.bm_table_of_objects:
if object1.nm_item_uni_container_master_index == object.nm_item_uni_container_master_index and object1.nm_is_local_container and object1.nm_is_highpoly_container:
container_found = True
insert_data.append([object_name, object1.nm_item_uni_container_master_index, object1.nm_master_index, None, 'hl_is_highpoly'])
if container_found is False:
insert_data.append([object_name, object.nm_item_uni_container_master_index, None, 1, 'hl_is_highpoly'])
match_found = True
# cage
if cage_prefix_raw in object_name_chunked:
if cage_prefix_raw in pair_object_name_chunked:
insert_data.append([object_name, object.nm_item_uni_container_master_index, object.nm_item_local_container_master_index, None, 'hl_is_cage'])
else:
container_found = False
for object1 in scene.bm_table_of_objects:
if object1.nm_item_uni_container_master_index == object.nm_item_uni_container_master_index and object1.nm_is_local_container and object1.nm_is_cage_container:
container_found = True
insert_data.append([object_name, object1.nm_item_uni_container_master_index, object1.nm_master_index, None, 'hl_is_cage'])
if container_found is False:
insert_data.append([object_name, object.nm_item_uni_container_master_index, None, 2, 'hl_is_cage'])
match_found = True
break
# add it to construct new data if no match was found
if match_found is False:
new_data.append(object_name)
# insert matched data
container_props = ['nm_is_lowpoly_container', 'nm_is_highpoly_container', 'nm_is_cage_container']
container_names = ['Lowpolies', 'Highpolies', 'Cages']
skip_add_container = False
for shell in insert_data:
if shell[0] in BM_Table_of_Objects_NameMatching_GetAllObjectNames(context):
continue
# adding containers
if shell[3] is not None:
container_insert_index = 0
insert_index = 0
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == shell[1]:
container_insert_index = index
if object.nm_item_uni_container_master_index == shell[1] and getattr(object, container_props[shell[3]]):
skip_add_container = True
shell[2] = object.nm_master_index
if skip_add_container is False:
# remove None all highpolies
BM_ITEM_PROPS_hl_highpoly_UpdateOnAdd(context)
# set hl_use_cage to False for data-classes with hl_use_cage True and None hl_cage
BM_ITEM_PROPS_hl_cage_UpdateOnAdd(context)
new_container = scene.bm_table_of_objects.add()
# Default Preset
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
DefaultPreset_Apply.obj(context, new_container)
# update texsets objs source indexes
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
new_container.nm_container_name_old = BM_ITEM_PROPS_nm_container_name_GlobalUpdate_OnCreate(context, container_names[shell[3]])
new_container.nm_container_name = new_container.nm_container_name_old
new_container.nm_this_indent = 1
new_container.nm_is_local_container = True
new_container.nm_is_expanded = True
setattr(new_container, container_props[shell[3]], True)
# new_container.bake_batchname_preview = BM_ITEM_PROPS_bake_batchname_ConstructPreview(context, new_container.bake_batchname)
# remove None all highpolies
BM_ITEM_PROPS_hl_highpoly_UpdateOnAdd(context)
# set hl_use_cage to False for data-classes with hl_use_cage True and None hl_cage
BM_ITEM_PROPS_hl_cage_UpdateOnAdd(context)
new_item = scene.bm_table_of_objects.add()
# Default Preset
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
DefaultPreset_Apply.obj(context, new_item)
new_item.global_object_name = shell[0]
new_item.nm_this_indent = 2
new_item.nm_is_expanded = True
# setattr(new_item, shell[4], True)
# new_item.bake_batchname_preview = BM_ITEM_PROPS_bake_batchname_ConstructPreview(context, new_item.bake_batchname)
# move item to the right place
scene.bm_table_of_objects.move(len(scene.bm_table_of_objects) - 2, container_insert_index + 1)
scene.bm_table_of_objects.move(len(scene.bm_table_of_objects) - 1, container_insert_index + 2)
# update texsets objs source indexes
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
# update master indexes
BM_Table_of_Objects_NameMatching_UpdateAllNMIndexes(context)
# add to existing local_c
if shell[3] is None or skip_add_container:
insert_index = 0
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == shell[1] and object.nm_item_local_container_master_index == shell[2]:
insert_index = index
# remove None all highpolies
BM_ITEM_PROPS_hl_highpoly_UpdateOnAdd(context)
# set hl_use_cage to False for data-classes with hl_use_cage True and None hl_cage
BM_ITEM_PROPS_hl_cage_UpdateOnAdd(context)
new_item = scene.bm_table_of_objects.add()
# Default Preset
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
DefaultPreset_Apply.obj(context, new_item)
new_item.global_object_name = shell[0]
new_item.nm_this_indent = 2
new_item.nm_is_expanded = True
# setattr(new_item, shell[4], True)
# new_item.bake_batchname_preview = BM_ITEM_PROPS_bake_batchname_ConstructPreview(context, new_item.bake_batchname)
# move item to the right place
scene.bm_table_of_objects.move(len(scene.bm_table_of_objects) - 1, insert_index + 1)
# update texsets objs source indexes
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
# update master indexes
BM_Table_of_Objects_NameMatching_UpdateAllNMIndexes(context)
# construct new universal container
# trash existing new_data to refresh it
to_remove = []
for index, object in enumerate(scene.bm_table_of_objects):
if object.global_object_name in new_data:
to_remove.append(index)
for index in sorted(to_remove, reverse=True):
scene.bm_table_of_objects.remove(index)
# update table active index
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
# get groups, roots, detached from construct
NameChunks = BM_Table_of_Objects_NameMatching_GenerateNameChunks
CombineToRaw = BM_Table_of_Objects_NameMatching_CombineToRaw
groups, roots, detached = BM_Table_of_Objects_NameMatching_Construct(context, new_data)
### constructing new Table_of_Objects items
for index, shell in enumerate(groups):
# adding universal container to the bm_table_of_objects
# remove None all highpolies
BM_ITEM_PROPS_hl_highpoly_UpdateOnAdd(context)
# set hl_use_cage to False for data-classes with hl_use_cage True and None hl_cage
BM_ITEM_PROPS_hl_cage_UpdateOnAdd(context)
universal_container = context.scene.bm_table_of_objects.add()
# Default Preset
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
DefaultPreset_Apply.obj(context, universal_container)
# update texsets objs source indexes
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
# name is set to the root_name of the first object in the shell
universal_container.nm_container_name_old = BM_ITEM_PROPS_nm_container_name_GlobalUpdate_OnCreate(context, CombineToRaw(roots[shell[0]][0]))
universal_container.nm_container_name = universal_container.nm_container_name_old
universal_container.nm_this_indent = 0
universal_container.nm_is_universal_container = True
universal_container.nm_is_expanded = True
# universal_container.bake_batchname_preview = BM_ITEM_PROPS_bake_batchname_ConstructPreview(context, universal_container.bake_batchname)
# objs[] : 0 - lowpolies, 1 - highpolies, 2 - cages
object_names = [[], [], []]
for number in shell:
# adding each object_name in the root objects to matched categories
# based on if their names contain low_ high_ cage_ prefixes
for object_name in roots[number][1]:
try:
NameChunks(object_name).index(lowpoly_prefix_raw)
except ValueError:
pass
else:
object_names[0].append(object_name)
try:
NameChunks(object_name).index(highpoly_prefix_raw)
except ValueError:
pass
else:
object_names[1].append(object_name)
try:
NameChunks(object_name).index(cage_prefix_raw)
except ValueError:
pass
else:
object_names[2].append(object_name)
# adding local containers to the bm_table_of_objects if needed
# and adding all object_name in object_names to the bm_table_of_objects
names_starters = ["Lowpolies", "Highpolies", "Cages"]
prefix_props = ["hl_is_lowpoly", "hl_is_highpoly", "hl_is_cage"]
container_types_props = ["nm_is_lowpoly_container", "nm_is_highpoly_container", "nm_is_cage_container"]
for local_index, local_names in enumerate(object_names):
if len(local_names):
# remove None all highpolies
BM_ITEM_PROPS_hl_highpoly_UpdateOnAdd(context)
# set hl_use_cage to False for data-classes with hl_use_cage True and None hl_cage
BM_ITEM_PROPS_hl_cage_UpdateOnAdd(context)
local_container = context.scene.bm_table_of_objects.add()
# Default Preset
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
DefaultPreset_Apply.obj(context, local_container)
# update texsets objs source indexes
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
local_container.nm_container_name_old = names_starters[local_index]
local_container.nm_container_name = names_starters[local_index]
local_container.nm_this_indent = 1
local_container.nm_is_local_container = True
local_container.nm_is_expanded = True
setattr(local_container, container_types_props[local_index], True)
# local_container.bake_batchname_preview = BM_ITEM_PROPS_bake_batchname_ConstructPreview(context, local_container.bake_batchname)
for obj_index, object_name in enumerate(local_names):
# do not add detached names
if object_name in detached:
continue
# remove None all highpolies
BM_ITEM_PROPS_hl_highpoly_UpdateOnAdd(context)
# set hl_use_cage to False for data-classes with hl_use_cage True and None hl_cage
BM_ITEM_PROPS_hl_cage_UpdateOnAdd(context)
new_item = context.scene.bm_table_of_objects.add()
# Default Preset
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
DefaultPreset_Apply.obj(context, new_item)
# update texsets objs source indexes
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
new_item.global_object_name = object_name
new_item.nm_this_indent = 2
new_item.nm_is_expanded = True
# setattr(new_item, prefix_props[local_index], True)
# new_item.bake_batchname_preview = BM_ITEM_PROPS_bake_batchname_ConstructPreview(context, new_item.bake_batchname)
# auto configure decals, highpolies, and cages
universal_container.nm_uni_container_is_global = True
# adding detached as regular items
for object_name in detached:
# remove None all highpolies
BM_ITEM_PROPS_hl_highpoly_UpdateOnAdd(context)
# set hl_use_cage to False for data-classes with hl_use_cage True and None hl_cage
BM_ITEM_PROPS_hl_cage_UpdateOnAdd(context)
new_item = context.scene.bm_table_of_objects.add()
# Default Preset
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
DefaultPreset_Apply.obj(context, new_item)
# update texsets objs source indexes
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
new_item.global_object_name = object_name
new_item.nm_is_detached = True
new_item.nm_is_expanded = True
# new_item.bake_batchname_preview = BM_ITEM_PROPS_bake_batchname_ConstructPreview(context, new_item.bake_batchname)
# update master indexes
BM_Table_of_Objects_NameMatching_UpdateAllNMIndexes(context)
# update table active index
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
# update uni containers names
for index, object in enumerate(context.scene.bm_table_of_objects):
if object.nm_is_universal_container:
object.nm_container_name = BM_ITEM_PROPS_nm_container_name_GlobalUpdate_OnCreate(context, object.nm_container_name, index)
# refresh nm if was added on empty table
if refresh_nm_config:
scene.bm_props.global_use_name_matching = True
# reports
if exists:
self.report({'INFO'}, "Mesh exists in the list")
if not is_mesh:
self.report({'INFO'}, "Expected Mesh Object")
if len(context.selected_objects) == 0:
self.report({'INFO'}, "No Objects selected")
return {'FINISHED'}
class BM_OT_Table_of_Objects_Remove(bpy.types.Operator):
bl_idname = 'bakemaster.table_of_objects_remove'
bl_label = ""
bl_description = "Remove active object from the list below.\nWhen Name Matching is on, removing Container will remove all objects underneath it as well"
bl_options = {'INTERNAL', 'UNDO'}
def execute(self, context):
scene = context.scene
global_active_index = scene.bm_props.global_active_index
if len(scene.bm_table_of_objects):
item = scene.bm_table_of_objects[global_active_index]
# default removal
if scene.bm_props.global_use_name_matching is False or item.nm_is_detached is True:
# update use_cage
BM_ITEM_PROPS_hl_cage_UpdateOnRemove(context, global_active_index, 'OBJECT')
removed_was_highpoly = scene.bm_table_of_objects[global_active_index].hl_is_highpoly
if removed_was_highpoly is False:
highpolies_holder = context.scene.bm_table_of_objects[global_active_index]
BM_ITEM_PROPS_hl_highpoly_SyncedRemoval_UnsetHighpolies(context, highpolies_holder)
# update highpolies
BM_ITEM_PROPS_hl_highpoly_SyncedRemoval(context, global_active_index, 'OBJECT', removed_was_highpoly)
# remove obj from texset if it was there
BM_TEXSET_OBJECT_PROPS_global_object_SyncedRemoval(context, global_active_index)
scene.bm_table_of_objects.remove(global_active_index)
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
if global_active_index != 0:
scene.bm_props.global_active_index -= 1
else:
to_remove = []
uni_removed_index = -1
# removing local_c and its items
if item.nm_is_local_container:
len_of_local_items = 0
to_remove.append(global_active_index)
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and object.nm_item_local_container_master_index == item.nm_master_index:
to_remove.append(index)
if object.nm_is_universal_container and object.nm_master_index == item.nm_item_uni_container_master_index:
uni_removed_index = index
# removing uni if there was only one local
for index, object in enumerate(scene.bm_table_of_objects):
# found local in the same uni
if object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and object.nm_is_local_container is False and index not in to_remove:
len_of_local_items += 1
# removing uni if there was only one local
if len_of_local_items == 0 and uni_removed_index != -1:
to_remove.append(uni_removed_index)
for index in sorted(dict.fromkeys(to_remove), reverse=True):
# update use_cage
BM_ITEM_PROPS_hl_cage_UpdateOnRemove(context, index, 'OBJECT')
removed_was_highpoly = scene.bm_table_of_objects[index].hl_is_highpoly
if removed_was_highpoly is False:
highpolies_holder = context.scene.bm_table_of_objects[index]
BM_ITEM_PROPS_hl_highpoly_SyncedRemoval_UnsetHighpolies(context, highpolies_holder)
# update highpolies
BM_ITEM_PROPS_hl_highpoly_SyncedRemoval(context, index, 'OBJECT', removed_was_highpoly)
# remove obj from texset if it was there
BM_TEXSET_OBJECT_PROPS_global_object_SyncedRemoval(context, index)
scene.bm_table_of_objects.remove(index)
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
# removing uni_c and its items
elif item.nm_is_universal_container:
to_remove.append(global_active_index)
for index, object in enumerate(scene.bm_table_of_objects):
if object.nm_item_uni_container_master_index == item.nm_master_index:
to_remove.append(index)
for index in sorted(to_remove, reverse=True):
# update use_cage
BM_ITEM_PROPS_hl_cage_UpdateOnRemove(context, index, 'OBJECT')
removed_was_highpoly = scene.bm_table_of_objects[index].hl_is_highpoly
if removed_was_highpoly is False:
highpolies_holder = context.scene.bm_table_of_objects[index]
BM_ITEM_PROPS_hl_highpoly_SyncedRemoval_UnsetHighpolies(context, highpolies_holder)
# update highpolies
BM_ITEM_PROPS_hl_highpoly_SyncedRemoval(context, index, 'OBJECT', removed_was_highpoly)
# remove obj from texset if it was there
BM_TEXSET_OBJECT_PROPS_global_object_SyncedRemoval(context, index)
scene.bm_table_of_objects.remove(index)
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
# removing items in locals
else:
len_of_local = 0
len_of_local_items = 0
uni_removed_index = -1
local_removed_index = -1
for index, object in enumerate(scene.bm_table_of_objects):
# found item in the same local, adding item to to_remove[]
if object.nm_item_local_container_master_index == item.nm_item_local_container_master_index and object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index:
len_of_local += 1
# found the container the item belongs to
if object.nm_is_local_container and object.nm_master_index == item.nm_item_local_container_master_index and object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index:
local_removed_index = index
if object.nm_is_universal_container and object.nm_master_index == item.nm_item_uni_container_master_index:
uni_removed_index = index
# item is the only one in the local, detached its pairs and remove uni_c, local_cs, else just remove the item
if len_of_local > 1:
# update use_cage
BM_ITEM_PROPS_hl_cage_UpdateOnRemove(context, global_active_index, 'OBJECT')
removed_was_highpoly = scene.bm_table_of_objects[global_active_index].hl_is_highpoly
if removed_was_highpoly is False:
highpolies_holder = context.scene.bm_table_of_objects[global_active_index]
BM_ITEM_PROPS_hl_highpoly_SyncedRemoval_UnsetHighpolies(context, highpolies_holder)
# update highpolies
BM_ITEM_PROPS_hl_highpoly_SyncedRemoval(context, global_active_index, 'OBJECT', removed_was_highpoly)
# remove obj from texset if it was there
BM_TEXSET_OBJECT_PROPS_global_object_SyncedRemoval(context, global_active_index)
scene.bm_table_of_objects.remove(global_active_index)
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
else:
# same removal as uni_c removal
# if remove local container, if only had one local container, remove the uni_container as well then
if local_removed_index != -1 and uni_removed_index != -1:
to_remove.append(global_active_index)
to_remove.append(local_removed_index)
# removing uni if there was only one local
for index, object in enumerate(scene.bm_table_of_objects):
# found local in the same uni
if object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and object.nm_is_local_container is False and index not in to_remove:
len_of_local_items += 1
# removing uni if there was only one local
if len_of_local_items == 0:
to_remove.append(uni_removed_index)
for index in sorted(dict.fromkeys(to_remove), reverse=True):
# update use_cage
BM_ITEM_PROPS_hl_cage_UpdateOnRemove(context, index, 'OBJECT')
removed_was_highpoly = scene.bm_table_of_objects[index].hl_is_highpoly
if removed_was_highpoly is False:
highpolies_holder = context.scene.bm_table_of_objects[index]
BM_ITEM_PROPS_hl_highpoly_SyncedRemoval_UnsetHighpolies(context, highpolies_holder)
# update highpolies
BM_ITEM_PROPS_hl_highpoly_SyncedRemoval(context, index, 'OBJECT', removed_was_highpoly)
# remove obj from texset if it was there
BM_TEXSET_OBJECT_PROPS_global_object_SyncedRemoval(context, index)
scene.bm_table_of_objects.remove(index)
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# update highpolies and cages source indexes
BM_ITEM_PROPS_hl_highpoly_UpdateOnMove(context)
BM_ITEM_PROPS_hl_cage_UpdateOrder(context)
# updating nm master_indexes
BM_Table_of_Objects_NameMatching_UpdateAllNMIndexes(context)
# active index update
if global_active_index >= len(scene.bm_table_of_objects):
scene.bm_props.global_active_index = len(scene.bm_table_of_objects) - 1
# update texset objs order if anything was removed
BM_TEXSET_OBJECT_PROPS_global_object_name_UpdateOrder(context)
# item.use_target = False
# if item.use_source:
# for index1, item1 in enumerate(scene.bm_table_of_objects):
# if item.source_name == item1.object_pointer.name:
# item1.source = 'NONE'
# break
return {'FINISHED'}
class BM_OT_Table_of_Objects_Refresh(bpy.types.Operator):
bl_idname = 'bakemaster.table_of_objects_refresh'
bl_label = ""
bl_description = "Some objects cannot be found in the scene. Press the refresh button to remove them from the list"
bl_options = {'INTERNAL', 'UNDO'}
def execute(self, context):
scene = context.scene
to_remove = []
# return true if item does exist in the scene
def exists(name: str):
try:
scene.objects[name]
except (KeyError, AttributeError):
return False
else:
return True
for global_index, global_object in enumerate(scene.bm_table_of_objects):
try:
scene.objects[global_object.global_object_name]
except (KeyError, AttributeError):
if scene.bm_props.global_use_name_matching is False or global_object.nm_is_detached is True:
to_remove.append(global_index)
else:
if global_object.nm_is_local_container or global_object.nm_is_universal_container:
continue
# refreshing local items
item = global_object
len_of_local = 0
len_of_local_items = 0
uni_removed_index = -1
local_removed_index = -1
for index, object in enumerate(scene.bm_table_of_objects):
# found item in the same local
if object.nm_item_local_container_master_index == item.nm_item_local_container_master_index and object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index and exists(object.global_object_name):
len_of_local += 1
# found the container the item belongs to
if object.nm_is_local_container and object.nm_master_index == item.nm_item_local_container_master_index and object.nm_item_uni_container_master_index == item.nm_item_uni_container_master_index:
local_removed_index = index
if object.nm_is_universal_container and object.nm_master_index == item.nm_item_uni_container_master_index:
uni_removed_index = index
# item is the only one in the local, remove uni_c, local_cs, else just remove the item
if len_of_local > 1:
to_remove.append(global_index)
else:
# same removal as uni_c removal
# if remove local container, if only had one local container, remove the uni_container as well then
if local_removed_index != -1 and uni_removed_index != -1:
to_remove.append(global_index)
to_remove.append(local_removed_index)
# removing uni if there was only one local