Skip to content
Snippets Groups Projects
Commit 31315311 authored by Adam Wiseman's avatar Adam Wiseman
Browse files

Fixed the broken mesh functions.

parent aab64350
No related branches found
No related tags found
No related merge requests found
...@@ -20,12 +20,11 @@ ...@@ -20,12 +20,11 @@
bl_info = { bl_info = {
'name': 'Copy Attributes Menu', 'name': 'Copy Attributes Menu',
'author': 'Bassam Kurdali, Fabian Fricke, wiseman303', 'author': 'Bassam Kurdali, Fabian Fricke, Adam Wiseman',
'version': (0, 4, 6), 'version': (0, 4, 7),
"blender": (2, 6, 1), 'blender': (2, 6, 3),
'location': 'View3D > Ctrl-C', 'location': 'View3D > Ctrl-C',
'description': 'Copy Attributes Menu from Blender 2.4', 'description': 'Copy Attributes Menu from Blender 2.4',
"warning": "some mesh functions broken",
'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.6/Py/' 'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.6/Py/'
'Scripts/3D_interaction/Copy_Attributes_Menu', 'Scripts/3D_interaction/Copy_Attributes_Menu',
'tracker_url': 'https://projects.blender.org/tracker/index.php?' 'tracker_url': 'https://projects.blender.org/tracker/index.php?'
...@@ -607,16 +606,24 @@ class MESH_MT_CopyFaceSettings(bpy.types.Menu): ...@@ -607,16 +606,24 @@ class MESH_MT_CopyFaceSettings(bpy.types.Menu):
vc = len(mesh.vertex_colors) > 1 vc = len(mesh.vertex_colors) > 1
layout = self.layout layout = self.layout
layout.operator(MESH_OT_CopyFaceSettings.bl_idname, op = layout.operator(MESH_OT_CopyFaceSettings.bl_idname,
text="Copy Material")['mode'] = 'MAT' text="Copy Material")
op['layer'] = ''
op['mode'] = 'MAT'
if mesh.uv_textures.active: if mesh.uv_textures.active:
layout.operator(MESH_OT_CopyFaceSettings.bl_idname, op = layout.operator(MESH_OT_CopyFaceSettings.bl_idname,
text="Copy Image")['mode'] = 'IMAGE' text="Copy Image")
layout.operator(MESH_OT_CopyFaceSettings.bl_idname, op['layer'] = ''
text="Copy UV Coords")['mode'] = 'UV' op['mode'] = 'IMAGE'
op = layout.operator(MESH_OT_CopyFaceSettings.bl_idname,
text="Copy UV Coords")
op['layer'] = ''
op['mode'] = 'UV'
if mesh.vertex_colors.active: if mesh.vertex_colors.active:
layout.operator(MESH_OT_CopyFaceSettings.bl_idname, op = layout.operator(MESH_OT_CopyFaceSettings.bl_idname,
text="Copy Vertex Colors")['mode'] = 'VCOL' text="Copy Vertex Colors")
op['layer'] = ''
op['mode'] = 'VCOL'
if uv or vc: if uv or vc:
layout.separator() layout.separator()
if uv: if uv:
...@@ -683,55 +690,70 @@ class MESH_OT_CopyFaceSettings(bpy.types.Operator): ...@@ -683,55 +690,70 @@ class MESH_OT_CopyFaceSettings(bpy.types.Operator):
return context.mode == 'EDIT_MESH' return context.mode == 'EDIT_MESH'
def execute(self, context): def execute(self, context):
mode = getattr(self, 'mode', '')
if not mode in ('MAT', 'VCOL', 'IMAGE', 'UV'):
self.report({'ERROR'}, "No mode specified or invalid mode.")
return self._end(context, {'CANCELLED'})
layername = getattr(self, 'layer', '')
mesh = context.object.data mesh = context.object.data
mode = getattr(self, 'mode', 'MODE')
layername = getattr(self, 'layer', None)
# Switching out of edit mode updates the selected state of faces and # Switching out of edit mode updates the selected state of faces and
# makes the data from the uv texture and vertex color layers available. # makes the data from the uv texture and vertex color layers available.
bpy.ops.object.editmode_toggle() bpy.ops.object.editmode_toggle()
polys = mesh.polygons
if mode == 'MAT': if mode == 'MAT':
from_data = mesh.polygons to_data = from_data = polys
to_data = from_data
else: else:
if mode == 'VCOL': if mode == 'VCOL':
layers = mesh.vertex_colors layers = mesh.vertex_colors
act_layer = mesh.vertex_colors.active act_layer = mesh.vertex_colors.active
else: elif mode == 'IMAGE':
layers = mesh.uv_textures layers = mesh.uv_textures
act_layer = mesh.uv_textures.active act_layer = mesh.uv_textures.active
elif mode == 'UV':
layers = mesh.uv_layers
act_layer = mesh.uv_layers.active
if not layers or (layername and not layername in layers): if not layers or (layername and not layername in layers):
return _end({'CANCELLED'}) self.report({'ERROR'}, "Invalid UV or color layer.")
return self._end(context, {'CANCELLED'})
from_data = layers[layername or act_layer.name].data from_data = layers[layername or act_layer.name].data
to_data = act_layer.data to_data = act_layer.data
from_face = from_data[mesh.polygons.active] from_index = polys.active
for f in mesh.polygons: for f in polys:
if f.select: if f.select:
if to_data != from_data: if to_data != from_data:
from_face = from_data[f.index] # Copying from another layer.
# from_face is to_face's counterpart from other layer.
from_index = f.index
elif f.index == from_index:
# Otherwise skip copying a face to itself.
continue
if mode == 'MAT': if mode == 'MAT':
f.material_index = from_face.material_index f.material_index = polys[from_index].material_index
continue continue
to_face = to_data[f.index] elif mode == 'IMAGE':
if to_face is from_face: to_data[f.index].image = from_data[from_index].image
continue continue
if mode == 'VCOL': if len(f.loop_indices) != len(polys[from_index].loop_indices):
to_face.color1 = from_face.color1 self.report({'WARNING'}, "Different number of vertices.")
to_face.color2 = from_face.color2 for i in range(len(f.loop_indices)):
to_face.color3 = from_face.color3 to_vertex = f.loop_indices[i]
to_face.color4 = from_face.color4 from_vertex = polys[from_index].loop_indices[i]
elif mode in {'UV', 'IMAGE'}: if mode == 'VCOL':
attr = mode.lower() to_data[to_vertex].color = from_data[from_vertex].color
setattr(to_face, attr, getattr(from_face, attr)) elif mode == 'UV':
return _end({'FINISHED'}) to_data[to_vertex].uv = from_data[from_vertex].uv
return self._end(context, {'FINISHED'})
def _end(retval):
# Clean up by returning to edit mode like it was before.
bpy.ops.object.editmode_toggle() def _end(self, context, retval):
return(retval) if context.mode != 'EDIT_MESH':
# Clean up by returning to edit mode like it was before.
bpy.ops.object.editmode_toggle()
return(retval)
def register(): def register():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment