-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathpaintingSet.py
196 lines (135 loc) · 6.51 KB
/
paintingSet.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
import bpy
from vtools_multiLayerPainting import createNodes
from vtools_multiLayerPainting import paintingLayers
#-- DEF ---
def addLayerSetTree(pNewSet):
newSet = bpy.context.scene.mlpLayerSetsCollection.add()
newSet.layerSetName = pNewSet.name
newSet.name = pNewSet.label
bpy.context.scene.mlpLayerSetsCollection_ID = len(bpy.context.scene.mlpLayerSetsCollection) - 1
def isLayerSet(pNode):
res = False
if pNode != None:
if pNode.type == "GROUP" and pNode.node_tree != None:
if pNode.node_tree.name.find("MTLayerSet") != -1:
res = True
return res
def getSelectedLayerSetNode():
layerSetNode = None
if bpy.context.scene.mlpLayerSetsCollection_ID != -1:
mainTree = bpy.context.object.active_material.node_tree
lsName = bpy.context.scene.mlpLayerSetsCollection[bpy.context.scene.mlpLayerSetsCollection_ID].layerSetName
layerSetNode = mainTree.nodes[lsName]
return layerSetNode
# --- CLASSES --------
class VTOOLS_OP_CollectPaintingSets(bpy.types.Operator):
bl_idname = "vtoolpt.collectpaintingsets"
bl_label = "Collect Painting Sets"
bl_description = "Collect Scene Painting Sets"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
bpy.ops.ed.undo_push()
createNodes.init()
mainTree = bpy.context.object.active_material.node_tree
bpy.context.scene.mlpLayerSetsCollection.clear()
bpy.context.scene.mlpLayerSetsCollection_ID = -1
for n in mainTree.nodes:
if isLayerSet(n) == True:
addLayerSetTree(n)
bpy.context.scene.mlpLayerSetsCollection_ID = len(bpy.context.scene.mlpLayerSetsCollection) - 1
bpy.context.scene.vt_mpPaintActiveMaterial = bpy.context.object.active_material.name
return {'FINISHED'}
class VTOOLS_OP_DeletePaintingSet(bpy.types.Operator):
bl_idname = "vtoolpt.deletepaintingset"
bl_label = "Delete Painting Set"
bl_description = "Delete selected painting set"
bl_options = {'REGISTER', 'UNDO'}
def deletePaintingLayers(self):
bpy.context.scene.mlpLayerTreeCollection_ID = 0
while len(bpy.context.scene.mlpLayerTreeCollection) > 0:
bpy.context.scene.mlpLayerTreeCollection_ID = 0
bpy.ops.vtoolpt.deletepaintinglayer()
bpy.context.scene.mlpLayerTreeCollection_ID = -1
def deleteLayerSet(self):
mainTree = bpy.context.object.active_material.node_tree
self.deletePaintingLayers()
lsn = getSelectedLayerSetNode()
if lsn != None:
currentSelected = bpy.context.scene.mlpLayerSetsCollection_ID
bpy.data.node_groups.remove(lsn.node_tree)
mainTree.nodes.remove(lsn)
bpy.context.scene.mlpLayerSetsCollection.remove(bpy.context.scene.mlpLayerSetsCollection_ID)
if currentSelected == 0 and len(bpy.context.scene.mlpLayerSetsCollection) > 0:
bpy.context.scene.mlpLayerSetsCollection_ID = 0
else:
bpy.context.scene.mlpLayerSetsCollection_ID = currentSelected -1
return {'FINISHED'}
def execute(self, context):
bpy.ops.ed.undo_push()
self.deleteLayerSet()
return {'FINISHED'}
class VTOOLS_OP_AddPaintingSet(bpy.types.Operator):
bl_idname = "vtoolpt.createpaintingset"
bl_label = "Add Painting Set"
bl_description = "Add a new painting set"
bl_options = {'REGISTER', 'UNDO'}
def addLayerSet(self,pName):
newLayerSet = None
if bpy.data.node_groups.find(pName) == -1:
bpy.ops.vtoolpt.collectpaintingsets()
mainTree = bpy.context.object.active_material.node_tree
newLayerSet = bpy.context.object.active_material.node_tree
newLayerSet = mainTree.nodes.new(type="ShaderNodeGroup")
newLayerSet.node_tree = bpy.data.node_groups[pName].copy()
newLayerSet.name = "layerSet"
newLayerSet.label = "layerSet"
return newLayerSet
def execute(self, context):
bpy.ops.ed.undo_push()
newSet = self.addLayerSet(bpy.context.scene.vt_layerSetNodeType)
addLayerSetTree(newSet)
newSet.location[0] = 200*len(bpy.context.scene.mlpLayerSetsCollection)
return {'FINISHED'}
class VTOOLS_OP_DuplicatePaintingSet(bpy.types.Operator):
bl_idname = "vtoolpt.duplicatepaintingset"
bl_label = "Duplicate Painting Set"
bl_description = "Duplicate the selected painting set"
bl_options = {'REGISTER', 'UNDO'}
def duplicateLayerSet(self,pLayerSetNode):
newLayerSet = None
if pLayerSetNode != None:
mainTree = bpy.context.object.active_material.node_tree
newLayerSet = mainTree.nodes.new(type="ShaderNodeGroup")
newLayerSet.node_tree = bpy.data.node_groups[pLayerSetNode.node_tree.name].copy()
newLayerSet.name = "layerSet"
newLayerSet.label = "Copy_" + pLayerSetNode.label
return newLayerSet
def makeSetUnique(self, pLayerSetNode):
for n in pLayerSetNode.node_tree.nodes:
if n.type == "GROUP":
if n.node_tree.name.find(bpy.context.scene.vt_paintLayerNodeType) != -1:
n.node_tree = bpy.data.node_groups[n.node_tree.name].copy()
def execute(self, context):
bpy.ops.ed.undo_push()
layerSetNode = getSelectedLayerSetNode()
if layerSetNode != None:
newSet = self.duplicateLayerSet(layerSetNode)
addLayerSetTree(newSet)
newSet.location[0] = 200*len(bpy.context.scene.mlpLayerSetsCollection)
self.makeSetUnique(newSet)
return {'FINISHED'}
def register():
bpy.utils.register_class(VTOOLS_OP_AddPaintingSet)
bpy.utils.register_class(VTOOLS_OP_DeletePaintingSet)
bpy.utils.register_class(VTOOLS_OP_CollectPaintingSets)
bpy.utils.register_class(VTOOLS_OP_DuplicatePaintingSet)
return {'FINISHED'}
def unregister():
bpy.utils.unregister_class(VTOOLS_OP_AddPaintingSet)
bpy.utils.unregister_class(VTOOLS_OP_DeletePaintingSet)
bpy.utils.unregister_class(VTOOLS_OP_CollectPaintingSets)
bpy.utils.unregister_class(VTOOLS_OP_DuplicatePaintingSet)
return {'FINISHED'}
classes = (
VTOOLS_OP_AddPaintingSet,
)