2010-07-08 16:24:24 +00:00
|
|
|
import bpy
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
if not mesh.active_uv_texture:
|
|
|
|
bpy.ops.mesh.uv_texture_add()
|
|
|
|
|
|
|
|
# adjust UVs
|
|
|
|
for i, uv in enumerate(mesh.active_uv_texture.data):
|
|
|
|
uvs = uv.uv1, uv.uv2, uv.uv3, uv.uv4
|
|
|
|
for j, v_idx in enumerate(mesh.faces[i].verts):
|
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-01-31 14:46:28 +00:00
|
|
|
uvs[j][:] = mesh.verts[v_idx].co.xy
|
2010-01-14 10:50:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
if is_editmode:
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
|
|
|
|
|
|
|
|
class UvOperator(bpy.types.Operator):
|
|
|
|
''''''
|
|
|
|
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
|
|
|
|
|
|
|
def poll(self, context):
|
|
|
|
obj = context.active_object
|
|
|
|
return (obj and obj.type == 'MESH')
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
main(context)
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
bpy.types.register(UvOperator)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
bpy.ops.uv.simple_operator()
|