-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy patheffects.py
More file actions
1679 lines (1494 loc) · 67.1 KB
/
effects.py
File metadata and controls
1679 lines (1494 loc) · 67.1 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
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
#region Imports
import bpy
from bpy.props import *
from bpy.types import (Panel,StringProperty, EnumProperty,Menu,Operator,PropertyGroup,Scene, WindowManager)
from bpy.app.handlers import persistent
import bpy.utils.previews
import os
import random
from . modules.easybpy import *
#endregion
#region Useful Variables
preview_collections = {}
#endregion
#region Useful Functions
def alistdir(directory):
'''
'Alternative / Avoidance List Dir'
An alternative version of os.listdir function that ignores files beginning
with a '.', specifically aimed at preventing .DS_Store files on MacOS from
disrupting the import process of content packs. Introduced with 9.1.1.
'''
filelist = os.listdir(directory)
return [x for x in filelist if not (x.startswith('.'))]
#endregion
#region PREOPERATION FUNCTIONS
def generate_ambient_occlusion_group(target, group_name):
# Set up the AO baking process.
select_only(target)
#bpy.ops.mesh.vertex_color_add()
#vc = target.data.vertex_colors[-1]
bpy.ops.geometry.color_attribute_add(name="Ambient Occlusion")
vc = target.data.attributes['Ambient Occlusion']
vc.name = group_name
bpy.context.scene.cycles.bake_type = 'AO'
bpy.context.scene.render.bake.target = 'VERTEX_COLORS'
bpy.ops.object.bake(type='AO')
# Prepare the weight group.
bpy.ops.object.vertex_group_add()
vertex_group = target.vertex_groups[-1]
vertex_group.name = group_name
vertex_colors = vc.data
# Construct the weight group.
colors = {}
corners = {}
for loop in target.data.loops:
vi = loop.vertex_index
if vi not in colors:
colors[vi] = Vector(vertex_colors[loop.index].color[:3])
corners[vi] = 1.0
else:
colors[vi] += Vector(vertex_colors[loop.index].color[:3])
corners[vi]+=1.0
for vindex in colors:
vertex_group.add([vindex], sum(colors[vindex]/corners[vindex])/3.0, 'REPLACE')
return vertex_group
class BYGEN_OT_groupmask_ambient_occlusion(bpy.types.Operator):
bl_idname = "object.bygen_groupmask_ambient_occlusion"
bl_label = "Generate AO Group Mask"
bl_description = "Generates an AO mask group on the selected object"
bl_options = {'REGISTER','UNDO'}
def execute(self, context):
generate_ambient_occlusion_group(ao(),"Ambient Occlusion")
return{'FINISHED'}
#endregion
#region V10 WIP
def import_content(type,
name, #wm.volume_effects
context,
directory, #os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_ve, wm.content_packs_ve+'.blend'))
template, #True or False
single, #True or False
weight, #True or False
unique_collection, #True or False
colpath, #os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_ve, wm.content_packs_ve+'.blend\\Collection\\'))
colname, #wm.volume_effects
objpath,
objname,
treepath,
treename):
# Setting up context
scene = context.scene
bytool = scene.by_tool
wm = context.window_manager
# Beginning procedure:
if bpy.context.active_object != None:
objs = selected_objects()
# Getting all useful directories for obtaining data (objects, node trees, etc.) from the content packs.
directory = directory # was os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_ve, wm.content_packs_ve+'.blend'))
colpath = colpath # was os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_ve, wm.content_packs_ve+'.blend\\Collection\\'))
colname = name # was wm.volume_effects
treepath = treepath # was os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_ve, wm.content_packs_ve+'.blend\\NodeTree\\'))
treename = name # was wm.volume_effects
#region CASE - TEMPLATE
#TODO, code from mesh effects parametric template.
if template == True:
if directory and os.path.exists(directory):
if name.startswith("(Tr)"):
#Since this is a complex geometry nodes effect requiring mesh references,
#we will look for a separate object specifically pre-prepared to be imported
#as a template object - which is separate from the object container for the
#effect.
# Updating the filename to find the complex template.
objname = name + " Template"
# Duplicating the appending code in case we need to handle the importing
# of complex templates slightly differently in the future.
ret = bpy.ops.wm.append(filename = objname, directory = objpath)
template = bpy.context.selected_objects[-1]
for m in template.modifiers:
if m.type=='SUBSURF':
m.show_viewport = True
m.show_render = True
else:
#Since this is not a complex (G) effect, we will just be importing the object
#that contains the modifier stack which constructs the effect.
ret = bpy.ops.wm.append(filename = objname, directory = objpath)
template = bpy.context.selected_objects[-1]
for m in template.modifiers:
if m.type=='SUBSURF':
m.show_viewport = True
m.show_render = True
return {'FINISHED'}
else:
#endregion
#region CASE (S)
# Find blend file with same name as folder (wm.content_packs_ve+'.blend')
if directory and os.path.exists(directory):
if name.startswith("(S)"):
'''
This is an (S) type effect, meaning a simple geometry node tree with no collection to import.
This means we can go straight to the importing of the geo nodes tree and assign it to the object/s.
Weight painting, and whether we can operate on only a single object, are cases that will be considered.
'''
if single == True:
# TODO Make objs a list with only a single object, being the active one - mainly for weight painting use case.
pass
for o in objs:
# Import geo tree from content pack
bpy.ops.wm.append(filename = treename, directory = treepath)
# Get the imported tree by name (store in surface_tree)
imported_tree = bpy.data.node_groups[treename]
# Add geonodes modifier to object (store in geomod)
geomod = o.modifiers.new("Geometry Nodes", "NODES")
# Assign new surface_effect geonode tree to new geomod
geomod.node_group = imported_tree
# Change surface_tree name to 'objname_treename_randID'
randID = random.randint(1,9999)
imported_tree.name = o.name+"_"+treename+"_"+str(randID)
# Open the tree nodes
nodes = imported_tree.nodes
if weight == True: # TODO Check this weight paint functionality.
# Do weight paint stuff here
select_only(o)
bpy.ops.object.vertex_group_add()
group = o.vertex_groups[-1]
group.name = name
# Get the correct input for the attribute toggle
id = ""
ginput = get_node(nodes, "Group Input")
for o in ginput.outputs:
if o.name.lower() == "weight":
id = o.identifier
id_prop_path = "[\""+id+"_use_attribute\"]"
id_prop_name = id+"_attribute_name"
bpy.ops.object.geometry_nodes_input_attribute_toggle(input_name=id, modifier_name=geomod.name)
geomod[id_prop_name] = group.name
# Set mode to weight paint
bpy.ops.object.mode_set(mode="WEIGHT_PAINT")
pass
#endregion
#region CASE (C)
elif name.startswith("(C)"):
'''
This is a (C) type effect, meaning there is a collection to import with the geometry node tree.
Weight painting, and whether we can operate on only a single object, are cases that will be considered.
'''
# Collection
col = None
# If the user wants to create a unique collection.
if unique_collection == True:
# Append collection to file (store ref in col) <- (optional: link)
bpy.ops.wm.append(filename = colname, directory = colpath)
col = get_collection(name)
# Else: The user does not want to create a unique collection.
else:
# If the collection already exists in the blend file.
if collection_exists(name):
# Let's grab the collection.
col = get_collection(name)
# Else: The collection does not already exist in the blend file.
else:
# Let's create the collection.
bpy.ops.wm.append(filename = colname, directory = colpath)
col = get_collection(name)
# if col:
if col:
for o in objs:
# Import geo tree from content pack
bpy.ops.wm.append(filename = treename, directory = treepath)
# Get the imported tree by name (store in surface_tree)
imported_tree = bpy.data.node_groups[treename]
# Add geonodes modifier to object (store in geomod)
geomod = o.modifiers.new("Geometry Nodes", "NODES")
# Assign new surface_effect geonode tree to new geomod
geomod.node_group = imported_tree
# Change surface_tree name to 'objname_treename_randID'
randID = random.randint(1,9999)
imported_tree.name = o.name+"_"+treename+"_"+str(randID)
# Open surface tree nodes
nodes = imported_tree.nodes
if weight == True: # TODO Check this weight paint functionality.
# Do weight paint stuff here
select_only(o)
bpy.ops.object.vertex_group_add()
group = o.vertex_groups[-1]
group.name = name
# Get the correct input for the attribute toggle
id = ""
ginput = get_node(nodes, "Group Input")
for o in ginput.outputs:
if o.name.lower() == "weight":
id = o.identifier
id_prop_path = "[\""+id+"_use_attribute\"]"
id_prop_name = id+"_attribute_name"
bpy.ops.object.geometry_nodes_input_attribute_toggle(input_name=id, modifier_name=geomod.name)
geomod[id_prop_name] = group.name
# Set mode to weight paint
bpy.ops.object.mode_set(mode="WEIGHT_PAINT")
pass
# Put col in correct node (collection info node)
colinfo = get_node(nodes, "Collection Info")
colinfo.inputs[0].default_value = col
#endregion
#region CASE (Tr)
elif name.startswith("(Tr)"): # Currently looking for (G)
'''
This is a (Tr) type effect, meaning that once an entire object has been brought in with its modifier stack,
the originally selected object will become a hidden source, whereas this imported object will become the host
for the effect. The Tr stands for Target Remote.
Checks for object references, looking for 'object' inputs in the geometry nodes group inputs / modifier
stack inputs, will also be performed where appropriate.
'''
# Complex geo nodes stacks which require extra base referencing
# Assume base object is selected and make a copy.
base = ao()
new = copy_object(base)
select_only(new)
# Append the template object
ret = bpy.ops.wm.append(filename = objname, directory = objpath)
template = bpy.context.selected_objects[-1]
# Select the object with moodifier stack.
select_only(new)
select_object(template) # <- Active selection
# Copy over modifiers from template.
bpy.ops.object.make_links_data(type='MODIFIERS')
# Set active back to base
select_only(new)
# Loop modifiers to find geometry nodes:
#for m in template.modifiers:
for m in new.modifiers:
# Get geo node modifiers
if m.type == "NODES":
nodes = m.node_group.nodes
''' - Assigning the object reference
for n in nodes:
if n.type == "OBJECT_INFO":
# Set all object references to base
n.inputs[0].default_value = base
'''
# Using the modifier input method.
id = ""
ginput = get_node(nodes, "Group Input")
for o in ginput.outputs:
if o.name.lower() == "object":
id = o.identifier #Input_3 for example
m[id] = base
# For some reason this hack workaround is needed because
# bpy.context.view_layer.update() doesn't work.
hide_in_viewport(new)
show_in_viewport(new)
if m.type == "SKIN":
bpy.ops.mesh.customdata_skin_add()
# Clean up by deleting template and hiding base
#hide(base)
hide_in_viewport(base)
hide_in_render(base)
delete_object(template)
pass
#endregion
#region CASE (Ts)
elif name.startswith("(Ts)"):
'''
This is a (Ts) type effect, meaning that once an entire object has been brought in with its modifier stack,
it is copied over to the originally selected object, and the imported object is deleted.
The Ts stands for Target Self.
Checks for object references, looking for 'object' inputs in the geometry nodes group inputs / modifier
stack inputs, will also be performed where appropriate.
'''
# Append template object
base = ao()
ret = bpy.ops.wm.append(filename = objname, directory = objpath)
template = bpy.context.selected_objects[-1]
# Select the object with moodifier stack.
select_only(base)
select_object(template) # <- Active selection
# Copy over modifiers from template.
bpy.ops.object.make_links_data(type='MODIFIERS')
# Set active back to base
select_only(base)
# Loop modifiers to find geometry nodes:
#for m in template.modifiers:
for m in base.modifiers:
# Get geo node modifiers
if m.type == "NODES":
nodes = m.node_group.nodes
''' - Assigning the object reference
for n in nodes:
if n.type == "OBJECT_INFO":
# Set all object references to base
n.inputs[0].default_value = base
'''
# Using the modifier input method.
id = ""
ginput = get_node(nodes, "Group Input")
for o in ginput.outputs:
if o.name.lower() == "object":
id = o.identifier #Input_3 for example
m[id] = base
# For some reason this hack workaround is needed because
# bpy.context.view_layer.update() doesn't work.
hide_in_viewport(base)
show_in_viewport(base)
if m.type == "SKIN":
bpy.ops.mesh.customdata_skin_add()
# Clean up by deleting template
delete_object(template)
pass
#endregion
#region Ending Import
else:
print(wm.content_packs_ve + " - pack file does not exist.")
return {'FINISHED'}
pass
#endregion
#endregion
#region SURFACE EFFECTS
def content_packs_se_from_directory(self, context):
wm = context.window_manager
enum_items = []
if context is None:
return enum_items
#directory = "content_packs"
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs'))
#pcoll = preview_collections["categories"]
if directory and os.path.exists(directory):
# Scan directory for folders
pack_paths = alistdir(directory)
for p in pack_paths:
#--- Folder Check
cpack = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', p))
folders = alistdir(cpack)
if 'thumbnails_surface_effects' in folders:
enum_items.append((p, p, 'Content Pack'))
#---
return enum_items
def get_surface_effect_thumbnails(self, context):
enum_items = []
#if context is None:
# return enum_items
wm = context.window_manager
#directory = wm.surface_effects_dir
#directory = "content_packs\\"+wm.content_packs_se+"\\thumbnails_surface_effects"
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_se, 'thumbnails_surface_effects'))
# Get collection defined in register function
pcoll = preview_collections["main"]
if directory == pcoll.surface_effects_dir:
print(">>> SE DIRECTORY ALREADY")
return pcoll.surface_effects
#print("Scanning directory %s" % directory)
if directory and os.path.exists(directory):
# Scan directory for jpg files
image_paths = []
for fn in alistdir(directory):
if fn.lower().endswith(".jpg"):
image_paths.append(fn)
for i, name in enumerate(image_paths):
# Generate a thumbnail preview for a file.
filepath = os.path.join(directory, name)
icon = pcoll.get(name)
if not icon:
thumb = pcoll.load(name, filepath, 'IMAGE')
else:
thumb = pcoll[name]
trimname = name.split('.')
#enum_items.append((name, name, "", thumb.icon_id, i))
enum_items.append((trimname[0], trimname[0], "", thumb.icon_id, i))
pcoll.surface_effects = enum_items
pcoll.surface_effects_dir = directory
return pcoll.surface_effects
class BYGEN_OT_surface_effect_import(bpy.types.Operator):
bl_idname = "object.bygen_surface_effect_import"
bl_label = "Import Surface Effect"
bl_description = "Imports and adds the selected surface effect."
bl_options = {'REGISTER','UNDO'}
def execute(self, context):
# Setting up context
scene = context.scene
bytool = scene.by_tool
wm = context.window_manager
# Getting all useful directories for obtaining data (objects, node trees, etc.) from the content packs.
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_se, wm.content_packs_se+'.blend'))
colpath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_se, wm.content_packs_se+'.blend','Collection'))
colname = wm.surface_effects
treepath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_se, wm.content_packs_se+'.blend','NodeTree'))
treename = wm.surface_effects
import_content(
type = "N/A",
name = colname,
context = context,
directory = directory,
template = False,
single = False,
weight = False,
unique_collection = bytool.se_unique_collection,
colpath = colpath,
colname = colname,
objpath = "",
objname = "",
treepath = treepath,
treename = treename
)
return {'FINISHED'}
class BYGEN_OT_surface_effect_weight_paint(bpy.types.Operator):
bl_idname = "object.bygen_surface_effect_weight_paint"
bl_label = "Apply (Vertex Paint)"
bl_description = "Imports the effect and sets it up for vertex painting."
bl_options = {'REGISTER','UNDO'}
def execute(self, context):
# Setting up context
scene = context.scene
bytool = scene.by_tool
wm = context.window_manager
# Getting all useful directories for obtaining data (objects, node trees, etc.) from the content packs.
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_se, wm.content_packs_se+'.blend'))
colpath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_se, wm.content_packs_se+'.blend','Collection'))
colname = wm.surface_effects
treepath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_se, wm.content_packs_se+'.blend','NodeTree'))
treename = wm.surface_effects
import_content(
type = "N/A",
name = colname,
context = context,
directory = directory,
template = False,
single = True,
weight = True,
unique_collection = bytool.se_unique_collection,
colpath = colpath,
colname = colname,
objpath = "",
objname = "",
treepath = treepath,
treename = treename
)
return {'FINISHED'}
class BYGEN_OT_refresh_effect_properties(bpy.types.Operator):
bl_idname = "object.bygen_refresh_effect_properties"
bl_label = "Refresh Effect Properties"
bl_description = "Refreshes the effect properties"
def execute(self, context):
thumbnail_update_call(self, context)
return {'FINISHED'}
class BYGEN_PT_SurfaceEffects(Panel):
bl_idname = "BYGEN_PT_SurfaceEffects"
bl_label = "Surface Effects"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "BY-GEN"
def draw_header(self, context):
self.layout.label(text = "", icon = "PARTICLE_POINT")
def draw(self, context):
layout = self.layout
scene = context.scene
bytool = scene.by_tool
wm = context.window_manager
column = layout.column()
row = column.row()
#row.scale_y = 1.2
row.prop(wm, "content_packs_se", text = "")
row.operator("wm.url_open", text="", icon='FILEBROWSER').url = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs'))
row.operator("wm.url_open", text="", icon='URL').url = "https://curtisholt.online/by-gen"
row.operator("object.bygen_refresh_effect_properties", text="", icon='FILE_REFRESH')
# Displaying the thumbnail selection window:
row = layout.row()
row.template_icon_view(wm, "surface_effects", show_labels=True, scale=8, scale_popup=8)
box = layout.box()
col = box.column()
#row = layout.row()
colrow = col.row(align=True)
colrow.operator("object.bygen_surface_effect_import", text = "Apply to Selected")
colrow = col.row(align=True)
colrow.operator("object.bygen_surface_effect_weight_paint", text = "Apply (Weight Paint)")#, icon = "MOD_VERTEX_WEIGHT"
colrow = col.row(align=True)
colrow.prop(bytool, "se_unique_collection")
class BYGEN_PT_SurfaceHelperTools(Panel):
bl_idname = "BYGEN_PT_SurfaceHelperTools"
bl_label = "Helper Tools"
bl_parent_id = "BYGEN_PT_SurfaceEffects"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "BY-GEN"
def draw_header(self, context):
self.layout.label(text = "", icon = "TOOL_SETTINGS")
def draw(self, context):
layout = self.layout
scene = context.scene
bytool = scene.by_tool
box = layout.box()
col = box.column()
colrow = col.row(align=True)
colrow.label(text = "Vertex Group Operations")
colrow = col.row(align=True)
colrow.operator("object.vertex_group_assign_new", text = "Vertex Group from Selected")
#colrow = col.row(align=True)
#colrow.label(text = "Vertex Group Masks")
#colrow = col.row(align=True)
#colrow.operator("object.bygen_groupmask_ambient_occlusion", text = "Ambient Occlusion")
#endregion
#region MESH EFFECTS
#region Mesh Panel
class BYGEN_PT_MeshEffects(Panel):
bl_idname = "BYGEN_PT_MeshEffects"
bl_label = "Mesh Effects"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "BY-GEN"
def draw_header(self, context):
self.layout.label(text = "", icon = "MESH_DATA")
def draw(self, context):
layout = self.layout
#endregion
#region Mesh Legacy
class BYGEN_PT_ModifierStyles(Panel):
bl_idname = "BYGEN_PT_ModifierStyles"
bl_label = "Modifier Styles"
bl_parent_id = "BYGEN_PT_MeshEffects"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "BY-GEN"
def draw_header(self, context):
self.layout.label(text = "", icon = "MODIFIER")
def draw(self, context):
layout = self.layout
scene = context.scene
bytool = scene.by_tool
box = layout.box()
col = box.column()
colrow = col.row(align=True)
colrow.prop(bytool, "modAllow")
colrow = col.row(align=True)
colrow.label(text="Modify Mode")
colrow = col.row(align=True)
colrow.prop(bytool, "mode_modify", text="")
if bytool.mode_modify == "MODE_DEST":
colrow = col.row(align=True)
colrow.separator()
colrow = col.row(align=True)
colrow.label(text="Displacement Type")
colrow = col.row(align=True)
colrow.prop(bytool, "mode_mod_disp", text="")
if bytool.mode_modify == "MODE_HSFRAME":
colrow = col.row(align = True)
colrow.prop(bytool, "mod_hssolid_allow_mirror")
colrow = col.row(align = True)
colrow.operator("object.bygen_invert_solidify")
if bytool.mode_modify == "MODE_HSF":
colrow = col.row(align=True)
colrow.separator()
colrow = col.row(align=True)
colrow.label(text="Displacement Type")
colrow = col.row(align=True)
colrow.prop(bytool, "mode_mod_disp", text="")
colrow = col.row(align=True)
colrow.prop(bytool, "mod_decimate_collapse", text="Decimate Collapse")
colrow = col.row(align=True)
colrow.prop(bytool, "mod_decimate_angle", text="Decimate Angle")
colrow = col.row(align=True)
colrow.prop(bytool, "mod_hsf_allow_mirror", text="Mirror")
if bytool.mode_modify == "MODE_HSS":
colrow = col.row(align=True)
colrow.separator()
colrow = col.row(align=True)
colrow.prop(bytool, "mod_hss_allow_mirror", text="Mirror")
if bytool.mode_modify == "MODE_HP":
colrow = col.row(align=True)
colrow.separator()
colrow = col.row(align=True)
colrow.prop(bytool, "mod_hp_allow_triangulate", text="Triangulate")
if bytool.mode_modify == "MODE_MSHELL":
colrow = col.row(align=True)
colrow.separator()
colrow = col.row(align=True)
colrow.prop(bytool, "mod_mshell_allow_triangulate", text = "Triangulate")
if bytool.mode_modify == "MODE_OSHELL":
colrow = col.row(align=True)
colrow.separator()
colrow = col.row(align=True)
colrow.prop(bytool, "mod_oshell_allow_triangulate", text="Triangulate")
colrow = col.row(align=True)
colrow.label(text="Displacement Type")
colrow = col.row(align=True)
colrow.prop(bytool, "mode_mod_disp", text="")
colrow = col.row(align=True)
colrow.prop(bytool, "mod_decimate_angle", text="Decimate Angle")
if bytool.mode_modify == "MODE_PC":
colrow = col.row(align=True)
colrow.separator()
colrow = col.row(align=True)
colrow.prop(bytool, "mod_pc_create_material", text="Create Emissive Mat")
colrow = col.row(align=True)
colrow.separator()
colrow = col.row(align=True)
colrow.operator("object.bygen_modify")
colrow = col.row(align=True)
colrow.separator()
#endregion
#region Mesh Parametric
def content_packs_mp_from_directory(self, context):
wm = context.window_manager
enum_items = []
if context is None:
return enum_items
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs'))
if directory and os.path.exists(directory):
# Scan directory for folders
pack_paths = alistdir(directory)
for p in pack_paths:
#--- Folder Check
cpack = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', p))
folders = alistdir(cpack)
if 'thumbnails_mesh_parametric' in folders:
enum_items.append((p, p, 'Content Pack'))
#---
return enum_items
def get_mesh_parametric_thumbnails(self, context):
enum_items = []
wm = context.window_manager
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_mp, 'thumbnails_mesh_parametric'))
# Get collection defined in register function
pcoll = preview_collections["main"]
if directory == pcoll.mesh_parametric_effects_dir:
print(">>> MD DIRECTORY ALREADY")
return pcoll.mesh_parametric_effects
if directory and os.path.exists(directory):
# Scan directory for jpg files
image_paths = []
for fn in alistdir(directory):
if fn.lower().endswith(".jpg"):
image_paths.append(fn)
for i, name in enumerate(image_paths):
# Generate a thumbnail preview for a file.
filepath = os.path.join(directory, name)
icon = pcoll.get(name)
if not icon:
thumb = pcoll.load(name, filepath, 'IMAGE')
else:
thumb = pcoll[name]
trimname = name.split('.')
enum_items.append((trimname[0], trimname[0], "", thumb.icon_id, i))
pcoll.mesh_parametric_effects = enum_items
pcoll.mesh_parametric_effects_dir = directory
return pcoll.mesh_parametric_effects
class BYGEN_OT_mesh_parametric_import(bpy.types.Operator):
bl_idname = "object.bygen_mesh_parametric_import"
bl_label = "Import Parametric Mesh Effect"
bl_description = "Imports and adds the selected parametric mesh effect"
bl_options = {'REGISTER','UNDO'}
def execute(self, context):
# Setting up context
scene = context.scene
bytool = scene.by_tool
wm = context.window_manager
# Beginning procedure:
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_mp, wm.content_packs_mp+'.blend'))
#objpath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_mp, wm.content_packs_mp+'.blend\\Object\\'))
objpath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_mp, wm.content_packs_mp+'.blend','Object'))
objname = wm.mesh_parametric_effects
import_content(
type = "N/A",
name = objname,
context = context,
directory = directory,
template = False,
single = False,
weight = False,
unique_collection = False,
colpath = "",
colname = "",
objpath = objpath,
objname = objname,
treepath = "",
treename = ""
)
return {'FINISHED'}
class BYGEN_OT_mesh_parametric_import_template(bpy.types.Operator):
bl_idname = "object.bygen_mesh_parametric_import_template"
bl_label = "Import Parametric Mesh Template"
bl_description = "Imports and adds the selected parametric mesh effect template"
bl_options = {'REGISTER','UNDO'}
def execute(self, context):
# Setting up context
scene = context.scene
bytool = scene.by_tool
wm = context.window_manager
# Beginning procedure:
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_mp, wm.content_packs_mp+'.blend'))
objpath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_mp, wm.content_packs_mp+'.blend','Object'))
objname = wm.mesh_parametric_effects
import_content(
type = "N/A",
name = objname,
context = context,
directory = directory,
template = True,
single = False,
weight = False,
unique_collection = False,
colpath = "",
colname = "",
objpath = objpath,
objname = objname,
treepath = "",
treename = ""
)
return {'FINISHED'}
class BYGEN_PT_MeshParametric(Panel):
bl_idname = "BYGEN_PT_MeshParametric"
bl_label = "Parametric"
bl_parent_id = "BYGEN_PT_MeshEffects"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "BY-GEN"
def draw_header(self, context):
self.layout.label(text = "", icon = "OUTLINER_OB_MESH")
def draw(self, context):
layout = self.layout
wm = context.window_manager
scene = context.scene
bytool = scene.by_tool
column = layout.column()
row = column.row()
#row.scale_y = 1.2
row.prop(wm, "content_packs_mp", text = "")
row.operator("wm.url_open", text="", icon='FILEBROWSER').url = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs'))
row.operator("wm.url_open", text="", icon='URL').url = "https://curtisholt.online/by-gen"
row.operator("object.bygen_refresh_effect_properties", text="", icon='FILE_REFRESH')
# Displaying the thumbnail selection window:
row = layout.row()
row.template_icon_view(wm, "mesh_parametric_effects", show_labels=True, scale=8, scale_popup=8)
box = layout.box()
col = box.column()
colrow = col.row(align=True)
colrow.operator("object.bygen_mesh_parametric_import", text = "Apply to Selected")
colrow = col.row(align=True)
colrow.operator("object.bygen_mesh_parametric_import_template", text = "Import Template")
#colrow.prop(bytool, "mp_unique_collection")
#endregion
#region Mesh Structural
def content_packs_ms_from_directory(self, context):
wm = context.window_manager
enum_items = []
if context is None:
return enum_items
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs'))
if directory and os.path.exists(directory):
# Scan directory for folders
pack_paths = alistdir(directory)
for p in pack_paths:
#--- Folder Check
cpack = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', p))
folders = alistdir(cpack)
if 'thumbnails_mesh_structural' in folders:
enum_items.append((p, p, 'Content Pack'))
#---
return enum_items
def get_mesh_structural_thumbnails(self, context):
enum_items = []
wm = context.window_manager
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_ms, 'thumbnails_mesh_structural'))
# Get collection defined in register function
pcoll = preview_collections["main"]
if directory == pcoll.mesh_structural_effects_dir:
print(">>> MD DIRECTORY ALREADY")
return pcoll.mesh_structural_effects
if directory and os.path.exists(directory):
# Scan directory for jpg files
image_paths = []
for fn in alistdir(directory):
if fn.lower().endswith(".jpg"):
image_paths.append(fn)
for i, name in enumerate(image_paths):
# Generate a thumbnail preview for a file.
filepath = os.path.join(directory, name)
icon = pcoll.get(name)
if not icon:
thumb = pcoll.load(name, filepath, 'IMAGE')
else:
thumb = pcoll[name]
trimname = name.split('.')
enum_items.append((trimname[0], trimname[0], "", thumb.icon_id, i))
pcoll.mesh_structural_effects = enum_items
pcoll.mesh_structural_effects_dir = directory
return pcoll.mesh_structural_effects
class BYGEN_OT_mesh_structural_import(bpy.types.Operator):
bl_idname = "object.bygen_mesh_structural_import"
bl_label = "Import Structural Mesh Effect"
bl_description = "Imports and adds the selected structural mesh effect"
bl_options = {'REGISTER','UNDO'}
def execute(self, context):
# Setting up context
scene = context.scene
bytool = scene.by_tool
wm = context.window_manager
# Getting all useful directories for obtaining data (objects, node trees, etc.) from the content packs.
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_ms, wm.content_packs_ms+'.blend'))
colpath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_ms, wm.content_packs_ms+'.blend','Collection'))
colname = wm.mesh_structural_effects
treepath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_ms, wm.content_packs_ms+'.blend','NodeTree'))
treename = wm.mesh_structural_effects
import_content(
type = "N/A",
name = colname,
context = context,
directory = directory,
template = False,
single = False,
weight = False,
unique_collection = False,
colpath = colpath,
colname = colname,
objpath = "",
objname = "",
treepath = treepath,
treename = treename
)
return {'FINISHED'}
class BYGEN_OT_mesh_structural_import_template(bpy.types.Operator):
bl_idname = "object.bygen_mesh_structural_import_template"
bl_label = "Import Structural Mesh Template"
bl_description = "Imports and adds the selected structural mesh effect template"
bl_options = {'REGISTER','UNDO'}
def execute(self, context):
# Setting up context
scene = context.scene
bytool = scene.by_tool
wm = context.window_manager
# Beginning procedure:
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_ms, wm.content_packs_ms+'.blend'))
objpath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'content_packs', wm.content_packs_ms, wm.content_packs_ms+'.blend','Object'))
objname = wm.mesh_structural_effects
import_content(
type = "N/A",
name = objname,
context = context,
directory = directory,
template = True,
single = False,
weight = False,
unique_collection = False,
colpath = "",