2006-01-31 19:47:52 +00:00
|
|
|
#!BPY
|
|
|
|
""" Registration info for Blender menus: <- these words are ignored
|
2006-12-12 07:28:20 +00:00
|
|
|
Name: 'UV Copy from Active'
|
2006-01-31 19:47:52 +00:00
|
|
|
Blender: 242
|
2006-01-31 20:57:05 +00:00
|
|
|
Group: 'Object'
|
2006-01-31 19:47:52 +00:00
|
|
|
Tip: 'Copy UV coords from a mesh to another that has same vertex indices'
|
|
|
|
"""
|
|
|
|
|
2006-01-31 20:57:05 +00:00
|
|
|
__author__ = "Toni Alatalo, Martin Poirier et. al."
|
2008-04-23 14:04:05 +00:00
|
|
|
__url__ = ("blender", "blenderartists.org")
|
2006-01-31 20:57:05 +00:00
|
|
|
__version__ = "0.2 01/2006"
|
2006-01-31 19:47:52 +00:00
|
|
|
|
|
|
|
__bpydoc__ = """\
|
|
|
|
This script copies UV coords from a mesh to another (version of the same mesh).
|
2006-12-12 07:28:20 +00:00
|
|
|
All target meshes must have the same number of faces at the active
|
2006-01-31 19:47:52 +00:00
|
|
|
"""
|
|
|
|
|
2007-05-20 17:30:30 +00:00
|
|
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
# ***** END GPL LICENCE BLOCK *****
|
|
|
|
|
2006-01-31 19:47:52 +00:00
|
|
|
import Blender
|
2006-01-31 20:57:05 +00:00
|
|
|
|
2006-12-12 07:28:20 +00:00
|
|
|
def face_key(me):
|
|
|
|
'''
|
|
|
|
Returns the face lengths for this mesh
|
|
|
|
only copy between meshes that have matching face_key's
|
|
|
|
'''
|
|
|
|
return tuple([len(f) for f in me.faces])
|
2006-01-31 20:57:05 +00:00
|
|
|
|
2006-12-12 07:28:20 +00:00
|
|
|
def main():
|
|
|
|
scene = Blender.Scene.GetCurrent()
|
|
|
|
|
|
|
|
source_ob = scene.objects.active
|
|
|
|
|
|
|
|
if not source_ob or source_ob.type != 'Mesh':
|
|
|
|
Blender.Draw.PupMenu("Error%t|No active object to copy UVs from.")
|
|
|
|
return
|
|
|
|
|
|
|
|
source_me = source_ob.getData(mesh=1)
|
|
|
|
|
|
|
|
target_mes = [ ob.getData(mesh=1) for ob in scene.objects.context if ob != source_ob if ob.type == 'Mesh']
|
|
|
|
|
|
|
|
# remove double meshes
|
|
|
|
target_mes = dict([(me.name, me) for me in target_mes])
|
|
|
|
target_mes = target_mes.values()
|
|
|
|
|
|
|
|
if not target_mes:
|
|
|
|
Blender.Draw.PupMenu("Error%t|No selected object(s) to copy UVs to.")
|
|
|
|
return
|
|
|
|
|
|
|
|
source_me = source_ob.getData(mesh=1)
|
|
|
|
|
|
|
|
if not source_me.faceUV:
|
|
|
|
Blender.Draw.PupMenu("Error%t|Active mesh has no UVs.")
|
|
|
|
return
|
|
|
|
|
|
|
|
if not target_mes:
|
|
|
|
Blender.Draw.PupMenu("Error%t|no selected object other than the source, hence no target defined.")
|
|
|
|
return
|
|
|
|
error = False
|
|
|
|
|
|
|
|
source_face_key = face_key(source_me)
|
|
|
|
source_faces = source_me.faces
|
|
|
|
|
|
|
|
fail_count = 0
|
|
|
|
|
|
|
|
for target in target_mes:
|
|
|
|
if len(source_me.faces) != len(target.faces):
|
|
|
|
print '\ttarget "%s" facelen does not match "%s".' % (target.name, source_me.name)
|
|
|
|
error = True
|
|
|
|
fail_count +=1
|
|
|
|
else:
|
|
|
|
# slow but worth comparing
|
|
|
|
if source_face_key != face_key(target):
|
|
|
|
print '\t\terror, face len dosnt match for ob "%s" next mesh...' % target.name
|
|
|
|
error = True
|
|
|
|
fail_count +=1
|
|
|
|
else:
|
|
|
|
target_faces = target.faces
|
|
|
|
|
|
|
|
# Add uvs if there not there
|
|
|
|
target.faceUV = True
|
|
|
|
|
2006-12-15 20:22:59 +00:00
|
|
|
for i, f_source in enumerate(source_faces):
|
2006-12-12 07:28:20 +00:00
|
|
|
target_faces[i].uv = f_source.uv
|
2006-12-15 20:22:59 +00:00
|
|
|
|
|
|
|
target.update()
|
2006-12-12 07:28:20 +00:00
|
|
|
|
|
|
|
msg = 'Copied UVs to %d of %d mesh(s)' % (len(target_mes)-fail_count, len(target_mes))
|
|
|
|
|
|
|
|
if error:
|
|
|
|
msg += "|Could not copy some UV's, see console."
|
|
|
|
|
|
|
|
Blender.Draw.PupMenu('UV Copy Finished%t|' + msg)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|