-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperators.py
More file actions
133 lines (110 loc) · 4.86 KB
/
operators.py
File metadata and controls
133 lines (110 loc) · 4.86 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
'''
Copy Right Notice
=================
* This file is part of the Blender Addon "Image Mapper" which is distributed under a EULA License.
* Redistribute, resell, or lease of the software is strictly prohibited.
* This software is provided "as is" and without any warranty.
* Changing or Removing this notice is strictly prohibited.
* For full license terms, please visit the following link: <Blender addon marketplace holder>
For support, please contact: mohidoart@gmail.com
(c) 2024 Mohammed Al-Mahdawi.
'''
import bpy
from bpy.props import (IntProperty)
from .utils import unbind_materials, clean_materials, map_materials
class ApplyImageMapping(bpy.types.Operator):
"""Apply Image Mapping based on properties"""
bl_idname = "object.apply_image_mapping"
bl_label = "Apply Mapping"
def execute(self, context):
props = context.scene.image_mapper_properties
# Single Values
mat = props.general_material
obj_name = props.object_name_pattern
rm_cops = props.cleanup_copied_materials
nested_search = props.nested_node_search
# Lists
node_labels = [x.label for x in props.image_node_labels]
expressions = [x.expression for x in props.expressions]
paths = [{'path': bpy.path.abspath(x.file_path), 'deep': x.deep} for x in props.image_files]
# Delete Material Copies
if(props.cleanup_copied_materials):
unbind_materials(mat)
clean_materials(mat)
# Map Materials
map_materials(obj_name, mat, node_labels, paths, expressions, nested_search)
self.report({'INFO'}, "Image Mapping Applied")
return {'FINISHED'}
class AddImagePath(bpy.types.Operator):
"""Add an image file path to the collection."""
bl_idname = "image_mapper.add_image_path"
bl_label = "Add Image File Path"
def execute(self, context):
item = context.scene.image_mapper_properties.image_files.add()
item.file_path = "" # Default or use file browser
self.report({'INFO'}, "Loading Image Files")
return {'FINISHED'}
class RemoveImagePath(bpy.types.Operator):
"""Remove an image file path from the collection."""
bl_idname = "image_mapper.remove_image_path"
bl_label = "Remove Image File Path"
index: IntProperty()
def execute(self, context):
props = context.scene.image_mapper_properties
props.image_files.remove(self.index)
self.report({'INFO'}, "Removing Image Files")
return {'FINISHED'}
class AddExpression(bpy.types.Operator):
"""Add an expression to the collection."""
bl_idname = "image_mapper.add_expression"
bl_label = "Add Expression"
def execute(self, context):
item = context.scene.image_mapper_properties.expressions.add()
item.expression = "" # Default or use file browser
self.report({'INFO'}, "Adding Expression")
return {'FINISHED'}
class RemoveExpression(bpy.types.Operator):
"""Remove an expression from the collection."""
bl_idname = "image_mapper.remove_expression"
bl_label = "Remove Expression"
index: IntProperty()
def execute(self, context):
props = context.scene.image_mapper_properties
props.expressions.remove(self.index)
self.report({'INFO'}, "Removing Expression")
return {'FINISHED'}
class AddNodeLabel(bpy.types.Operator):
"""Add an image node label to the collection."""
bl_idname = "image_mapper.add_node_label"
bl_label = "Add Image Node Label"
def execute(self, context):
item = context.scene.image_mapper_properties.image_node_labels.add()
item.label = "" # Default or use file browser
self.report({'INFO'}, "Adding Image Node Label")
return {'FINISHED'}
class RemoveNodeLabel(bpy.types.Operator):
"""Remove an image node label from the collection."""
bl_idname = "image_mapper.remove_node_label"
bl_label = "Remove Image Node Label"
index: IntProperty()
def execute(self, context):
props = context.scene.image_mapper_properties
props.image_node_labels.remove(self.index)
self.report({'INFO'}, "Removing Image Node Label")
return {'FINISHED'}
def register():
bpy.utils.register_class(ApplyImageMapping)
bpy.utils.register_class(AddImagePath)
bpy.utils.register_class(RemoveImagePath)
bpy.utils.register_class(AddExpression)
bpy.utils.register_class(RemoveExpression)
bpy.utils.register_class(AddNodeLabel)
bpy.utils.register_class(RemoveNodeLabel)
def unregister():
bpy.utils.unregister_class(RemoveImagePath)
bpy.utils.unregister_class(AddImagePath)
bpy.utils.unregister_class(ApplyImageMapping)
bpy.utils.unregister_class(AddExpression)
bpy.utils.unregister_class(RemoveExpression)
bpy.utils.unregister_class(AddNodeLabel)
bpy.utils.unregister_class(RemoveNodeLabel)