2010-07-08 16:24:24 +00:00
|
|
|
import bpy
|
2010-01-14 10:50:58 +00:00
|
|
|
|
2011-01-26 07:54:27 +00:00
|
|
|
|
2010-01-14 10:50:58 +00:00
|
|
|
def main(context):
|
|
|
|
obj = context.active_object
|
|
|
|
mesh = obj.data
|
|
|
|
|
|
|
|
is_editmode = (obj.mode == 'EDIT')
|
|
|
|
if is_editmode:
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
|
|
|
|
|
2010-08-23 22:16:45 +00:00
|
|
|
if not mesh.uv_textures:
|
|
|
|
uvtex = bpy.ops.mesh.uv_texture_add()
|
2010-11-24 18:37:54 +00:00
|
|
|
else:
|
|
|
|
uvtex = mesh.uv_textures.active
|
2010-01-14 10:50:58 +00:00
|
|
|
|
|
|
|
# adjust UVs
|
2010-08-23 22:16:45 +00:00
|
|
|
for i, uv in enumerate(uvtex.data):
|
2010-01-14 10:50:58 +00:00
|
|
|
uvs = uv.uv1, uv.uv2, uv.uv3, uv.uv4
|
2010-08-18 03:42:26 +00:00
|
|
|
for j, v_idx in enumerate(mesh.faces[i].vertices):
|
2010-07-15 16:56:04 +00:00
|
|
|
if uv.select_uv[j]:
|
2010-01-14 10:50:58 +00:00
|
|
|
# apply the location of the vertex as a UV
|
2010-08-18 03:42:26 +00:00
|
|
|
uvs[j][:] = mesh.vertices[v_idx].co.xy
|
2010-01-14 10:50:58 +00:00
|
|
|
|
|
|
|
if is_editmode:
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
|
|
|
|
|
2010-08-02 03:30:07 +00:00
|
|
|
|
2010-01-14 10:50:58 +00:00
|
|
|
class UvOperator(bpy.types.Operator):
|
2010-08-02 03:30:07 +00:00
|
|
|
'''UV Operator description'''
|
2010-01-14 10:50:58 +00:00
|
|
|
bl_idname = "uv.simple_operator"
|
2010-01-14 10:59:42 +00:00
|
|
|
bl_label = "Simple UV Operator"
|
2010-01-14 10:50:58 +00:00
|
|
|
|
2010-08-09 01:37:09 +00:00
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
2010-01-14 10:50:58 +00:00
|
|
|
obj = context.active_object
|
|
|
|
return (obj and obj.type == 'MESH')
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
main(context)
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
2011-02-12 08:04:32 +00:00
|
|
|
def register():
|
|
|
|
bpy.utils.register_class(UvOperator)
|
|
|
|
|
|
|
|
|
|
|
|
def unregister():
|
|
|
|
bpy.utils.unregister_class(UvOperator)
|
|
|
|
|
|
|
|
|
2010-01-14 10:50:58 +00:00
|
|
|
if __name__ == "__main__":
|
2011-02-12 08:04:32 +00:00
|
|
|
register()
|
|
|
|
|
|
|
|
# test call
|
2010-01-14 10:50:58 +00:00
|
|
|
bpy.ops.uv.simple_operator()
|