-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path__init__.py
1769 lines (1407 loc) · 69.6 KB
/
__init__.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
# -*- coding: utf8 -*-
# python
# ##### BEGIN GPL LICENSE BLOCK #####
#
# 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.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
bl_info = {
'name': 'EZ_Paint',
'author': 'Bart Crouch, scorpion81, Spirou4D, artistCDMJ, brockmann',
'version': (3, 12),
'blender': (2, 79, 0),
'location': 'Paint editor > 3D view',
'warning': '',
'description': 'Several improvements for PAINT MODE',
'wiki_url': '',
'tracker_url': '',
'category': 'Paint'}
import bgl, blf, bpy, mathutils, os, time, copy, math
from bpy.types import Operator, Menu, Panel, UIList
from bpy_extras.io_utils import ImportHelper
#################################################
# #
# Functions #
# #
#################################################
# Ecrit sur l'écran 3D: le nom de l'outil de peinture + le mode de fusion
def toolmode_draw_callback(self, context):
# polling
if not bpy.ops.paint.image_paint.poll():
return
# Fixe la ligne d'écriture
if context.region: # fixee à une hauteur de l'écran - 32px
main_y = context.region.height - 100
else:
return # Abandon car nous ne sommes pas en vue3D
blend_dic = {"MIX": "Mix",
"ADD": "Add",
"SUB": "Subtract",
"MUL": "Multiply",
"LIGHTEN": "Lighten",
"DARKEN": "Darken",
"ERASE_ALPHA": "Erase Alpha",
"ADD_ALPHA": "Add Alpha",
"OVERLAY": "Overlay",
"HARDLIGHT": "Hard light",
"COLORBURN": "Color burn",
"LINEARBURN": "Linear burn",
"COLORDODGE": "Color dodge",
"SCREEN": "Screen",
"SOFTLIGHT": "Soft light",
"PINLIGHT": "Pin light",
"VIVIDLIGHT": "Vivid light",
"LINEARLIGHT": "Linear light",
"DIFFERENCE": "Difference",
"EXCLUSION": "Exclusion",
"HUE": "Hue",
"SATURATION": "Saturation",
"LUMINOSITY": "Luminosity",
"COLOR": "Color"
} # dictionnaire des modes de fusion
wm = context.window_manager
brush = context.tool_settings.image_paint.brush
bhn, bhb = brush.name, brush.blend
# brush.blend ne fait pas référence à un fichier mais au mode de la brosse
text = bhn + " - " + blend_dic[bhb]
# écriture du texte au coin haut-gauche
bgl.glColor3f(.9, .9, .9) # en blanc sale
blf.position(0, 21, main_y, 0) # à la position en 4 chiffres
blf.draw(0, text)
# Texte estompé selon le temps, au dessus de la brosse à 40px en rouge
dt = time.time() - wm["ezp_toolmode_time"]
if dt < 2: # Aténuation de l'affichage selon le temps
if "ezp_toolmode_brushloc" not in wm:
return
brush_x, brush_y = wm["ezp_toolmode_brushloc"]
brush_x -= blf.dimensions(0, text)[0] / 2
bgl.glColor4f(0.9, 0.16, 0.16, min(1.0, (2 - dt)*2))
blf.position(0, brush_x, brush_y + 40, 0)
blf.draw(0, text)
# ---------------------------------------------------------------------------
# ajouter une propriété d'ID au gestionnaire de fenêtre
def init_temp_props():
wm = bpy.context.window_manager
wm["ezp_automergeuv"] = False # 1 int
wm["ezp_toolmode_time"] = time.time() # 1 int in sec
wm["ezp_toolmode_brushloc"] = (-1, -1) # 2 int
# enlever toutes propriétés d'ID du gestionnaire de fenêtres
def remove_temp_props():
wm = bpy.context.window_manager
if "ezp_automergeuv" in wm:
del wm["ezp_automergeuv"]
if "ezp_toolmode_time" in wm:
del wm["ezp_toolmode_time"]
if "ezp_toolmode_brushloc" in wm:
del wm["ezp_toolmode_brushloc"]
if "ezp_toolmode_on_screen" in wm:
del wm["ezp_toolmode_on_screen"]
# -----------------------------------------------------------------------------
# Retourner une liste de toutes les images qui ont été affichée dans un editeur d'image
def get_images_in_editors(context):
images = []
for area in context.screen.areas:
if area.type != 'IMAGE_EDITOR':
continue
for space in area.spaces:
if space.type != 'IMAGE_EDITOR':
continue
if space.image:
images.append(space.image)
area.tag_redraw() # mise à jour de l'editeur d'image
return(images)
##########################################
# #
# Classes #
# #
##########################################
###############################################################################
# PANNEAU DES OUTILS DE PEINTURE
class BrushPopup(Operator):
"""Brush popup"""
bl_idname = "view3d.brush_popup"
bl_label = "Brush settings"
COMPAT_ENGINES = {'BLENDER_RENDER', 'CYCLES'}
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(self, context):
if context.active_object:
A = context.active_object.type == 'MESH'
B = context.mode in {'PAINT_TEXTURE','PAINT_VERTEX','PAINT_WEIGHT'}
return A and B
@staticmethod
def check(self, context):
return True
@staticmethod
def paint_settings(context):
toolsettings = context.tool_settings
if context.vertex_paint_object:
return toolsettings.vertex_paint
elif context.weight_paint_object:
return toolsettings.weight_paint
elif context.image_paint_object:
if (toolsettings.image_paint and toolsettings.image_paint.detect_data()):
return toolsettings.image_paint
return None
return None
@staticmethod
def unified_paint_settings(parent, context):
ups = context.tool_settings.unified_paint_settings
parent.label(text="Unified Settings:")
row = parent.row()
row.prop(ups, "use_unified_size", text="Size")
row.prop(ups, "use_unified_strength", text="Strength")
if context.weight_paint_object:
parent.prop(ups, "use_unified_weight", text="Weight")
elif context.vertex_paint_object or context.image_paint_object:
parent.prop(ups, "use_unified_color", text="Color")
else:
parent.prop(ups, "use_unified_color", text="Color")
@staticmethod
def prop_unified_size(parent, context, brush, prop_name, icon='NONE', text="", slider=False):
ups = context.tool_settings.unified_paint_settings
ptr = ups if ups.use_unified_size else brush
parent.prop(ptr, prop_name, icon=icon, text=text, slider=slider)
@staticmethod
def prop_unified_strength(parent, context, brush, prop_name, icon='NONE', text="", slider=False):
ups = context.tool_settings.unified_paint_settings
ptr = ups if ups.use_unified_strength else brush
parent.prop(ptr, prop_name, icon=icon, text=text, slider=slider)
@staticmethod
def prop_unified_weight(parent, context, brush, prop_name, icon='NONE', text="", slider=False):
ups = context.tool_settings.unified_paint_settings
ptr = ups if ups.use_unified_weight else brush
parent.prop(ptr, prop_name, icon=icon, text=text, slider=slider)
@staticmethod
def prop_unified_color(parent, context, brush, prop_name, text=""):
ups = context.tool_settings.unified_paint_settings
ptr = ups if ups.use_unified_color else brush
parent.prop(ptr, prop_name, text=text)
@staticmethod
def prop_unified_color_picker(parent, context, brush, prop_name, value_slider=True):
ups = context.tool_settings.unified_paint_settings
ptr = ups if ups.use_unified_color else brush
parent.template_color_picker(ptr, prop_name, value_slider=value_slider)
def brush_texpaint_common(self, layout, context, brush, settings, projpaint=False):
capabilities = brush.image_paint_capabilities
col = layout.column()
if brush.image_tool in {'DRAW', 'FILL'}:
if brush.blend not in {'ERASE_ALPHA', 'ADD_ALPHA'}:
if not brush.use_gradient:
self.prop_unified_color_picker(col, context, brush, "color", value_slider=True)
if settings.palette:
col.template_palette(settings, "palette", color=True)
if brush.use_gradient:
col.label("Gradient Colors")
col.template_color_ramp(brush, "gradient", expand=True)
if brush.image_tool != 'FILL':
col.label("Background Color")
row = col.row(align=True)
self.prop_unified_color(row, context, brush, "secondary_color", text="")
if brush.image_tool == 'DRAW':
col.prop(brush, "gradient_stroke_mode", text="Mode")
if brush.gradient_stroke_mode in {'SPACING_REPEAT', 'SPACING_CLAMP'}:
col.prop(brush, "grad_spacing")
elif brush.image_tool == 'FILL':
col.prop(brush, "gradient_fill_mode")
else:
row = col.row(align=True)
self.prop_unified_color(row, context, brush, "color", text="")
if brush.image_tool == 'FILL' and not projpaint:
col.prop(brush, "fill_threshold")
else:
self.prop_unified_color(row, context, brush, "secondary_color", text="")
row.separator()
row.operator("paint.brush_colors_flip", icon='FILE_REFRESH', text="")
elif brush.image_tool == 'SOFTEN':
col = layout.column(align=True)
col.row().prop(brush, "direction", expand=True)
col.separator()
col.prop(brush, "sharp_threshold")
if not projpaint:
col.prop(brush, "blur_kernel_radius")
col.separator()
col.prop(brush, "blur_mode")
elif brush.image_tool == 'MASK':
col.prop(brush, "weight", text="Mask Value", slider=True)
elif brush.image_tool == 'CLONE':
col.separator()
if projpaint:
if settings.mode == 'MATERIAL':
col.prop(settings, "use_clone_layer", text="Clone from paint slot")
elif settings.mode == 'IMAGE':
col.prop(settings, "use_clone_layer", text="Clone from image/UV map")
if settings.use_clone_layer:
ob = context.active_object
col = layout.column()
if settings.mode == 'MATERIAL':
if len(ob.material_slots) > 1:
col.label("Materials")
col.template_list("MATERIAL_UL_matslots", "",
ob, "material_slots",
ob, "active_material_index", rows=2)
mat = ob.active_material
if mat:
col.label("Source Clone Slot")
col.template_list("TEXTURE_UL_texpaintslots", "",
mat, "texture_paint_images",
mat, "paint_clone_slot", rows=2)
elif settings.mode == 'IMAGE':
mesh = ob.data
clone_text = mesh.uv_texture_clone.name if mesh.uv_texture_clone else ""
col.label("Source Clone Image")
col.template_ID(settings, "clone_image")
col.label("Source Clone UV Map")
col.menu("VIEW3D_MT_tools_projectpaint_clone", text=clone_text, translate=False)
else:
col.prop(brush, "clone_image", text="Image")
col.prop(brush, "clone_alpha", text="Alpha")
col.separator()
if capabilities.has_radius:
row = col.row(align=True)
self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
self.prop_unified_size(row, context, brush, "use_pressure_size")
row = col.row(align=True)
if capabilities.has_space_attenuation:
row.prop(brush, "use_space_attenuation", toggle=True, icon_only=True)
self.prop_unified_strength(row, context, brush, "strength", text="Strength")
self.prop_unified_strength(row, context, brush, "use_pressure_strength")
if brush.image_tool in {'DRAW', 'FILL'}:
col.separator()
col.prop(brush, "blend", text="Blend")
col = layout.column()
# use_accumulate
if capabilities.has_accumulate:
col = layout.column(align=True)
col.prop(brush, "use_accumulate")
if projpaint:
col.prop(brush, "use_alpha")
col.prop(brush, "use_gradient")
col.separator()
col.template_ID(settings, "palette", new="palette.new")
def draw(self, context):
# Init values
toolsettings = context.tool_settings
settings = self.paint_settings(context)
layout = self.layout
col = layout.column()
if not settings:
row = col.row(align=True)
row.label(text="Setup texture paint, please!")
else:
brush = settings.brush
ipaint = toolsettings.image_paint
# Stroke mode
col.prop(brush, "stroke_method", text="")
if brush.use_anchor:
col.separator()
col.prop(brush, "use_edge_to_edge", "Edge To Edge")
if brush.use_airbrush:
col.separator()
col.prop(brush, "rate", text="Rate", slider=True)
if brush.use_space:
col.separator()
row = col.row(align=True)
row.prop(brush, "spacing", text="Spacing")
row.prop(brush, "use_pressure_spacing", toggle=True, text="")
if brush.use_line or brush.use_curve:
col.separator()
row = col.row(align=True)
row.prop(brush, "spacing", text="Spacing")
if brush.use_curve:
col.separator()
col.template_ID(brush, "paint_curve", new="paintcurve.new")
col.operator("paintcurve.draw")
else:
col.separator()
row = col.row(align=True)
row.prop(brush, "use_relative_jitter", icon_only=True)
if brush.use_relative_jitter:
row.prop(brush, "jitter", slider=True)
else:
row.prop(brush, "jitter_absolute")
row.prop(brush, "use_pressure_jitter", toggle=True, text="")
col = layout.column()
col.separator()
if brush.brush_capabilities.has_smooth_stroke:
col.prop(brush, "use_smooth_stroke")
if brush.use_smooth_stroke:
sub = col.column()
sub.prop(brush, "smooth_stroke_radius", text="Radius", slider=True)
sub.prop(brush, "smooth_stroke_factor", text="Factor", slider=True)
layout.prop(settings, "input_samples")
# Curve stroke
col = layout.column(align=True)
row = col.row(align=True)
row.operator("brush.curve_preset", icon='SMOOTHCURVE', text="").shape = 'SMOOTH'
row.operator("brush.curve_preset", icon='SPHERECURVE', text="").shape = 'ROUND'
row.operator("brush.curve_preset", icon='ROOTCURVE', text="").shape = 'ROOT'
row.operator("brush.curve_preset", icon='SHARPCURVE', text="").shape = 'SHARP'
row.operator("brush.curve_preset", icon='LINCURVE', text="").shape = 'LINE'
row.operator("brush.curve_preset", icon='NOCURVE', text="").shape = 'MAX'
# Symetries mode
col = layout.column(align=True)
row = col.row(align=True)
row.prop(ipaint, "use_symmetry_x", text="X", toggle=True)
row.prop(ipaint, "use_symmetry_y", text="Y", toggle=True)
row.prop(ipaint, "use_symmetry_z", text="Z", toggle=True)
# imagepaint tool operate buttons: UILayout.template_ID_preview()
col = layout.split().column()
###################################### ICI PROBLEME d'icones de brosse !
# bpy.context.tool_settings.image_paint.brush
col.template_ID_preview(settings, "brush", new="brush.add", rows=1, cols=3 )
########################################################################
# Texture Paint Mode #
if context.image_paint_object and brush:
self.brush_texpaint_common( layout, context, brush, settings, True)
########################################################################
# Weight Paint Mode #
elif context.weight_paint_object and brush:
col = layout.column()
row = col.row(align=True)
self.prop_unified_weight(row, context, brush, "weight", slider=True, text="Weight")
row = col.row(align=True)
self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
self.prop_unified_size(row, context, brush, "use_pressure_size")
row = col.row(align=True)
self.prop_unified_strength(row, context, brush, "strength", text="Strength")
self.prop_unified_strength(row, context, brush, "use_pressure_strength")
col.prop(brush, "vertex_tool", text="Blend")
if brush.vertex_tool == 'BLUR':
col.prop(brush, "use_accumulate")
col.separator()
col = layout.column()
col.prop(toolsettings, "use_auto_normalize", text="Auto Normalize")
col.prop(toolsettings, "use_multipaint", text="Multi-Paint")
########################################################################
# Vertex Paint Mode #
elif context.vertex_paint_object and brush:
col = layout.column()
self.prop_unified_color_picker(col, context, brush, "color", value_slider=True)
if settings.palette:
col.template_palette(settings, "palette", color=True)
self.prop_unified_color(col, context, brush, "color", text="")
col.separator()
row = col.row(align=True)
self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
self.prop_unified_size(row, context, brush, "use_pressure_size")
row = col.row(align=True)
self.prop_unified_strength(row, context, brush, "strength", text="Strength")
self.prop_unified_strength(row, context, brush, "use_pressure_strength")
col.separator()
col.prop(brush, "vertex_tool", text="Blend")
col.separator()
col.template_ID(settings, "palette", new="palette.new")
def invoke(self, context, event):
if context.space_data.type == 'IMAGE_EDITOR':
context.space_data.mode = 'PAINT'
return context.window_manager.invoke_props_dialog(self, width=148)
# return {'PASS_THROUGH'} ou {'CANCELLED'} si le bouton ok est cliqué
def execute(self, context):
return {'FINISHED'}
# PANNEAU DES MASQUES DE PEINTURE
class TexturePopup(Operator):
"""Texture popup"""
bl_idname = "view3d.texture_popup"
bl_label = "Texture & Mask"
COMPAT_ENGINES = {'BLENDER_RENDER', 'CYCLES'}
bl_options = {'REGISTER', 'UNDO'}
toggleMenu = bpy.props.BoolProperty(default=True) # toogle texture or Mask menu
def check(self, context):
return True
@classmethod
def poll(self, context):
obj = context.active_object
if obj is not None:
A = obj.type == 'MESH'
B = context.mode == 'PAINT_TEXTURE'
return A and B
def draw(self, context):
# Init values
toolsettings = context.tool_settings
brush = toolsettings.image_paint.brush
tex_slot = brush.texture_slot
mask_tex_slot = brush.mask_texture_slot
unified = toolsettings.unified_paint_settings
settings = toolsettings.image_paint
# ================================================== textures panel
layout = self.layout
# Parameter Toggle Menu
_TITLE = 'TEXTURES' if self.toggleMenu else 'MASKS'
_ICON = 'TEXTURE' if self.toggleMenu else 'MOD_MASK'
Menu = layout.row()
Menu.prop(self, "toggleMenu", text=_TITLE, icon=_ICON)
if self.toggleMenu:
col = layout.column() #TEXTURES
col.template_ID_preview(brush, "texture", new="texture.new", rows=3, cols=8)
if brush.texture:
row = layout.row(align=True)
row.operator("paint.modify_brush_textures", text="Modify brush Texture", icon='IMAGE_COL').toggleType=True
layout.label(text="Brush Mapping:")
# texture_map_mode
layout.row().prop(tex_slot, "tex_paint_map_mode", text="")
layout.separator()
if tex_slot.map_mode == 'STENCIL':
if brush.texture and brush.texture.type == 'IMAGE':
layout.operator("brush.stencil_fit_image_aspect")
layout.operator("brush.stencil_reset_transform")
# angle and texture_angle_source
if tex_slot.has_texture_angle:
col = layout.column()
col.label(text="Angle:")
col.prop(tex_slot, "angle", text="")
if tex_slot.has_texture_angle_source:
col.prop(tex_slot, "use_rake", text="Rake")
if brush.brush_capabilities.has_random_texture_angle \
and tex_slot.has_random_texture_angle:
col.prop(tex_slot, "use_random", text="Random")
if tex_slot.use_random:
col.prop(tex_slot, "random_angle", text="")
# scale and offset
split = layout.split()
split.prop(tex_slot, "offset")
split.prop(tex_slot, "scale")
row = layout.row()
row.operator(MakeBrushImageTexture.bl_idname)
else:
col = layout.column() #MASK TEXTURE
col.template_ID_preview(brush, "mask_texture", new="texture.new", \
rows=3, cols=8)
if brush.mask_texture:
row = layout.row(align=True)
row.operator("paint.modify_brush_textures", text="Modify brush Texture", icon='IMAGE_COL').toggleType=False
layout.label(text="Mask Mapping:")
# map_mode
layout.row().prop(mask_tex_slot, "mask_map_mode", text="")
layout.separator()
if mask_tex_slot.map_mode == 'STENCIL':
if brush.mask_texture and brush.mask_texture.type == 'IMAGE':
layout.operator("brush.stencil_fit_image_aspect").mask = True
layout.operator("brush.stencil_reset_transform").mask = True
col = layout.column()
col.prop(brush, "use_pressure_masking", text="")
# angle and texture_angle_source
if mask_tex_slot.has_texture_angle:
col = layout.column()
col.label(text="Angle:")
col.prop(mask_tex_slot, "angle", text="")
if mask_tex_slot.has_texture_angle_source:
col.prop(mask_tex_slot, "use_rake", text="Rake")
if brush.brush_capabilities.has_random_texture_angle and mask_tex_slot.has_random_texture_angle:
col.prop(mask_tex_slot, "use_random", text="Random")
if mask_tex_slot.use_random:
col.prop(mask_tex_slot, "random_angle", text="")
# scale and offset
split = layout.split()
split.prop(mask_tex_slot, "offset")
split.prop(mask_tex_slot, "scale")
row = layout.row()
row.operator(MakeBrushImageTextureMask.bl_idname)
def invoke(self, context, event):
if context.space_data.type == 'IMAGE_EDITOR':
context.space_data.mode = 'PAINT'
return context.window_manager.invoke_props_dialog(self, width=146)
def execute(self, context):
return {'FINISHED'}
# PANNEAU DES PROJECTPAINT SLOTS (& Blender MASKs)
class ProjectpaintPopup(Operator):
"""Slots ProjectPaint popup"""
bl_idname = "view3d.projectpaint"
bl_label = "Slots & VGroups"
COMPAT_ENGINES = {'BLENDER_RENDER', 'CYCLES'}
bl_options = {'REGISTER', 'UNDO'}
def check(self, context):
return True
@classmethod
def poll(cls, context):
brush = context.tool_settings.image_paint.brush
ob = context.active_object
group = ob.vertex_groups.active
if (brush is not None and ob is not None):
A = ob.type == 'MESH'
# -------------------------------
B = context.space_data.type == 'VIEW_3D'
if A:
C = context.mode in {'PAINT_TEXTURE','PAINT_VERTEX','PAINT_WEIGHT'}
D = context.mode == 'EDIT_MESH'
# -------------------------------
E = context.space_data.type == 'IMAGE_EDITOR'
if E:
F = context.mode == 'EDIT_MESH'
G = context.space_data.mode == 'PAINT'
# -------------------------------
H = context.mode == 'WEIGHT_PAINT' and ob.vertex_groups and ob.data.use_paint_mask_vertex
return A and (( B and (C or D)) or (E and (F or G) or H))
return False
def draw(self, context):
settings = context.tool_settings.image_paint
ob = context.active_object
Egne = bpy.context.scene.render.engine
layout = self.layout
#-----------------------------------------------------------Vertex Paint
ob = context.object
group = ob.vertex_groups.active
rows = 4 if group else 2
row = layout.row()
row.template_list("MESH_UL_vgroups", "", ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
col = row.column(align=True)
col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="").all = False
col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")
if group:
col.separator()
col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
if ob.vertex_groups and (ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex)):
row = layout.row()
sub = row.row(align=True)
sub.operator("object.vertex_group_assign", text="Assign")
sub.operator("object.vertex_group_remove_from", text="Remove")
sub = row.row(align=True)
sub.operator("object.vertex_group_select", text="Select")
sub.operator("object.vertex_group_deselect", text="Deselect")
layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
#--------------------------------------------------------------Mat Paint
if context.mode == 'PAINT_TEXTURE':
col = layout.column()
col.label("Painting Mode")
col.prop(settings, "mode", text="")
col.separator()
if settings.mode == 'MATERIAL':
if len(ob.material_slots) > 1:
col.label("Materials")
col.template_list("MATERIAL_UL_matslots", "layers",
ob, "material_slots",
ob, "active_material_index", rows=2)
mat = ob.active_material
if mat:
col.label("Available Paint Slots")
col.template_list("TEXTURE_UL_texpaintslots", "",
mat, "texture_paint_images",
mat, "paint_active_slot", rows=2)
if mat.texture_paint_slots:
slot = mat.texture_paint_slots[mat.paint_active_slot]
else:
slot = None
if (not mat.use_nodes) and context.scene.render.engine in {'BLENDER_RENDER', 'BLENDER_GAME'}:
row = col.row(align=True)
row.operator_menu_enum("paint.add_texture_paint_slot", "type")
row.operator("paint.delete_texture_paint_slot", text="", icon='X')
if slot:
col.prop(mat.texture_slots[slot.index], "blend_type")
col.separator()
if slot and slot.index != -1:
col.label("UV Map")
col.prop_search(slot, "uv_layer", ob.data, "uv_textures", text="")
elif settings.mode == 'IMAGE':
mesh = ob.data
uv_text = mesh.uv_textures.active.name if mesh.uv_textures.active else ""
col.label("Canvas Image")
col.template_ID(settings, "canvas")
col.operator("image.new", text="New").gen_context = 'PAINT_CANVAS'
col.label("UV Map")
col.menu("VIEW3D_MT_tools_projectpaint_uvlayer", text=uv_text, translate=False)
col.separator()
if Egne == 'CYCLES':
col.operator("paint.add_texture_paint_slot", text="Add Texture", icon="FACESEL_HLT").type="DIFFUSE_COLOR"
col.operator("object.save_ext_paint_texture", text="Save selected Slot")
else:
col.operator("image.save_dirty", text="Save All Images")
def invoke(self, context,event):
return context.window_manager.invoke_props_dialog(self, width=240)
def execute(self, context):
return {'FINISHED'}
################################################################################
# Ajouter un mat + 1 texture DIFF 1024x1024-alpha à l'objet selectionné
class AddDefaultMatDiff(Operator):
'''Create and assign a new mat + DIFF texture to the object'''
bl_idname = "object.add_default_image"
bl_label = "Add default image"
@classmethod
def poll(cls, context):
if context.active_object!=None:
return context.active_object.type=='MESH'
return False
def invoke(self, context, event):
ob = context.active_object
mat = bpy.data.materials.new("default")
#Add texture to the mat
tex = bpy.data.textures.new("default", 'IMAGE')
img = bpy.data.images.new("default", 1024, 1024, alpha=True)
ts = mat.texture_slots.add()
tex.image = img
ts.texture_coords = 'UV'
ts.use_map_color_diffuse = True
ts.texture = tex
ob.data.materials.append(mat)
return {'FINISHED'}
# Ajouter un mat standart + 3 textures DIFF/SPEC/NORM sans image à tous les objets selectionnés
class DefaultMaterial(Operator):
'''Add a default dif/spec/normal material to an object'''
bl_idname = "object.default_material"
bl_label = "Default material"
@classmethod
def poll(cls, context):
object = context.active_object
if not object or not object.data:
return False
return object.type == 'MESH'
def invoke(self, context, event):
objects = context.selected_objects
for ob in objects:
if not ob.data or ob.type != 'MESH':
continue
mat = bpy.data.materials.new(ob.name)
# diffuse texture
tex = bpy.data.textures.new(ob.name+"_DIFF", 'IMAGE')
ts = mat.texture_slots.add()
ts.texture_coords = 'UV'
ts.texture = tex
# specular texture
tex = bpy.data.textures.new(ob.name+"_SPEC", 'IMAGE')
ts = mat.texture_slots.add()
ts.texture_coords = 'UV'
ts.use_map_color_diffuse = False
ts.use_map_specular = True
ts.texture = tex
# normal texture
tex = bpy.data.textures.new(ob.name+"_NORM", 'IMAGE')
tex.use_normal_map = True
ts = mat.texture_slots.add()
ts.texture_coords = 'UV'
ts.use_map_color_diffuse = False
ts.use_map_normal = True
ts.texture = tex
ob.data.materials.append(mat)
return {'FINISHED'}
class MakeBrushImageTexture(Operator):
bl_label = "New Texture from Image"
bl_idname = "gizmo.image_texture"
filepath = bpy.props.StringProperty(subtype="FILE_PATH")
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def execute(self,context):
tex = bpy.data.textures.new("ImageTexture",'NONE')
tex.use_nodes = True
remove = tex.node_tree.nodes[1]
tex.node_tree.nodes.remove(remove)
tex.node_tree.nodes.new("TextureNodeImage")
tex.node_tree.links.new(tex.node_tree.nodes[0].inputs[0],tex.node_tree.nodes[1].outputs[0])
tex.node_tree.nodes[1].location = [0,50]
tex.node_tree.nodes[0].location = [200,50]
i = bpy.data.images.load(self.filepath)
tex.node_tree.nodes[1].image = i
if bpy.context.mode == 'PAINT_TEXTURE':
bpy.context.tool_settings.image_paint.brush.texture = tex
elif bpy.context.mode == 'PAINT_VERTEX':
bpy.context.tool_settings.vertex_paint.brush.texture = tex
elif bpy.context.mode == 'PAINT_WEIGHT':
bpy.context.tool_settings.weight_paint.brush.texture = tex
#elif bpy.context.mode == 'SCULPT':
#bpy.context.tool_settings.sculpt.brush.texture = tex
return set()
class MakeBrushImageTextureMask(Operator):
bl_label = "New Mask Texture from Image"
bl_idname = "gizmo.image_texture_mask"
filepath = bpy.props.StringProperty(subtype="FILE_PATH")
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def execute(self,context):
tex = bpy.data.textures.new("ImageTextureMask",'NONE')
tex.use_nodes = True
remove = tex.node_tree.nodes[1]
tex.node_tree.nodes.remove(remove)
tex.node_tree.nodes.new("TextureNodeImage")
tex.node_tree.nodes.new("TextureNodeRGBToBW")
tex.node_tree.links.new(tex.node_tree.nodes[0].inputs[0],tex.node_tree.nodes[2].outputs[0])
tex.node_tree.links.new(tex.node_tree.nodes[2].inputs[0],tex.node_tree.nodes[1].outputs[0])
tex.node_tree.nodes[1].location = [0,50]
tex.node_tree.nodes[2].location = [200,50]
tex.node_tree.nodes[0].location = [400,50]
i = bpy.data.images.load(self.filepath)
tex.node_tree.nodes[1].image = i
if bpy.context.mode == 'PAINT_TEXTURE':
bpy.context.tool_settings.image_paint.brush.mask_texture = tex
elif bpy.context.mode == 'PAINT_VERTEX':
bpy.context.tool_settings.vertex_paint.brush.mask_texture = tex
elif bpy.context.mode == 'PAINT_WEIGHT':
bpy.context.tool_settings.weight_paint.brush.mask_texture = tex
#elif bpy.context.mode == 'SCULPT':
#bpy.context.tool_settings.sculpt.brush.mask_texture = tex
return set()
# Importer en même temps tous les objets de plusieurs [fichiers .blend étant dans un dossier]!
class MassLinkAppend(Operator, ImportHelper):
'''Import objects from multiple blend-files at the same time'''
bl_idname = "wm.mass_link_append"
bl_label = "Mass Link/Append"
bl_options = {'REGISTER', 'UNDO'}
active_layer = bpy.props.BoolProperty(name="Active Layer",
default=True,
description="Put the linked objects on the active layer"
)
autoselect = bpy.props.BoolProperty(name="Select",
default=True,
description="Select the linked objects"
)
instance_groups = bpy.props.BoolProperty(name="Instance Groups",
default=False,
description="Create instances for each group as a DupliGroup"
)
link = bpy.props.BoolProperty(name="Link",
default=False,
description="Link the objects or datablocks rather than appending"
)
relative_path = bpy.props.BoolProperty(name="Relative Path",
default=True,
description="Select the file relative to the blend file"
)
def execute(self, context):
directory, filename = os.path.split(bpy.path.abspath(self.filepath))
files = []
# find all blend-files in the given directory
for root, dirs, filenames in os.walk(directory):
for file in filenames:
if file.endswith(".blend"):
files.append([root+os.sep, file])
break # don't search in subdirectories
# append / link objects
old_selection = context.selected_objects
new_selection = []
print("_______ Texture Paint Plus _______")
print("You can safely ignore the line(s) below")
for directory, filename in files:
# get object names
with bpy.data.libraries.load(directory + filename) as (append_lib, current_lib):
ob_names = append_lib.objects # les noms des objets à ajouter
for name in ob_names: