-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathop_meshtex_wrap.py
68 lines (51 loc) · 1.95 KB
/
op_meshtex_wrap.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
import bpy
import bmesh
from . import utilities_meshtex
class op(bpy.types.Operator):
bl_idname = "uv.textools_meshtex_wrap"
bl_label = "Wrap Mesh Texture"
bl_description = "Swap UV to XYZ coordinates"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if bpy.context.scene.texToolsSettings.meshtexture_wrap < 1:
return False
if (not bpy.context.active_object) or bpy.context.active_object.mode != 'OBJECT':
return False
if len(bpy.context.selected_objects) > 0:
# Find 1 UV mesh
if utilities_meshtex.find_uv_mesh(bpy.context.selected_objects):
# Find 1 or more meshes to wrap
if len( utilities_meshtex.find_texture_meshes(bpy.context.selected_objects)) > 0:
return True
return False
def execute(self, context):
wrap_meshtex(self)
return {'FINISHED'}
def wrap_meshtex(self):
# Collect UV mesh
obj_uv = utilities_meshtex.find_uv_mesh(bpy.context.selected_objects)
if not obj_uv:
self.report({'ERROR_INVALID_INPUT'}, "No UV mesh found" )
return
# Collect texture meshes
obj_textures = utilities_meshtex.find_texture_meshes( bpy.context.selected_objects )
if len(obj_textures) == 0:
self.report({'ERROR_INVALID_INPUT'}, "No meshes found for mesh textures" )
return
# Setup Thickness? This doesn't seem to be really needed
#utilities_meshtex.uv_mesh_fit(obj_uv, obj_textures)
for obj in obj_textures:
# Delete previous modifiers
for modifier in obj.modifiers:
if modifier.type == 'SURFACE_DEFORM':
obj.modifiers.remove(modifier)
break
# Add mesh modifier
modifier_deform = obj.modifiers.new(name="SurfaceDeform", type='SURFACE_DEFORM')
modifier_deform.target = obj_uv
obj.select_set( state = True, view_layer = None)
bpy.context.view_layer.objects.active = obj
bpy.ops.object.surfacedeform_bind(modifier="SurfaceDeform")
# Apply wrapped morph state
bpy.context.scene.texToolsSettings.meshtexture_wrap = 0