Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-01-14 17:06:27 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-01-14 17:06:27 +0300
commit231d29ccce00d746b9666f52d453613c57195e80 (patch)
treefa3cc38a6ab16c9fd751b0cf902d71636c34bdd4 /release
parent6a0a5b54ec2525c05d43cb56346b5577f16287df (diff)
Join as UVs.... (copies matching UVs to another object with the same topology)
nice that it uses foreach_get/set for fast array copying from python. note: this is getting out of hand, we beed some central panel/interface for copying mesh data about - shapes, UVs weights etc. at the moment they are accessed from all different places.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/op/object.py59
-rw-r--r--release/scripts/ui/space_view3d.py1
2 files changed, 60 insertions, 0 deletions
diff --git a/release/scripts/op/object.py b/release/scripts/op/object.py
index dd95c6f51a6..1cf46d514c7 100644
--- a/release/scripts/op/object.py
+++ b/release/scripts/op/object.py
@@ -320,7 +320,66 @@ class ShapeTransfer(bpy.types.Operator):
return self._main(ob_act, objects, self.properties.mode, self.properties.use_clamp)
+class JoinUVs(bpy.types.Operator):
+ '''Copy UV Layout to objects with matching geometry'''
+ bl_idname = "object.join_uvs"
+ bl_label = "Join as UVs"
+
+ def poll(self, context):
+ obj = context.active_object
+ return (obj and obj.type == 'MESH')
+
+ def _main(self, context):
+ import array
+ obj = context.active_object
+ mesh = obj.data
+
+ is_editmode = (obj.mode == 'EDIT')
+ if is_editmode:
+ bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
+
+ len_faces = len(mesh.faces)
+
+ uv_array = array.array('f', [0.0] * 8) * len_faces # seems to be the fastest way to create an array
+ mesh.active_uv_texture.data.foreach_get("uv_raw", uv_array)
+
+ objects = context.selected_editable_objects[:]
+
+ for obj_other in objects:
+ if obj_other.type == 'MESH':
+ obj_other.data.tag = False
+
+ for obj_other in objects:
+ if obj_other != obj and obj_other.type == 'MESH':
+ mesh_other = obj_other.data
+ if mesh_other != mesh:
+ if mesh_other.tag == False:
+ mesh_other.tag = True
+
+ if len(mesh_other.faces) != len_faces:
+ self.report({'WARNING'}, "Object: %s, Mesh: '%s' has %d faces, expected %d\n" % (obj_other.name, mesh_other.name, len(mesh_other.faces), len_faces))
+ else:
+ uv_other = mesh_other.active_uv_texture
+ if not uv_other:
+ mesh_other.uv_texture_add() # should return the texture it adds
+ uv_other = mesh_other.active_uv_texture
+
+ # finally do the copy
+ uv_other.data.foreach_set("uv_raw", uv_array)
+
+ if is_editmode:
+ bpy.ops.object.mode_set(mode='EDIT', toggle=False)
+
+ def execute(self, context):
+ self._main(context)
+ return {'FINISHED'}
+
+if __name__ == "__main__":
+ bpy.ops.uv.simple_operator()
+
+
bpy.types.register(SelectPattern)
bpy.types.register(SubdivisionSet)
bpy.types.register(Retopo)
bpy.types.register(ShapeTransfer)
+bpy.types.register(JoinUVs)
diff --git a/release/scripts/ui/space_view3d.py b/release/scripts/ui/space_view3d.py
index e17d068b586..101fb6f7acc 100644
--- a/release/scripts/ui/space_view3d.py
+++ b/release/scripts/ui/space_view3d.py
@@ -656,6 +656,7 @@ class VIEW3D_MT_object(bpy.types.Menu):
layout.separator()
layout.operator("object.join_shapes")
+ layout.operator("object.join_uvs")
layout.operator("object.join")
layout.separator()