blender/release/scripts/templates_py/operator_mesh_uv.py

51 lines
1.0 KiB
Python
Raw Normal View History

2010-07-08 16:24:24 +00:00
import bpy
import bmesh
2010-01-14 10:50:58 +00:00
2010-01-14 10:50:58 +00:00
def main(context):
obj = context.active_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
2010-01-14 10:50:58 +00:00
uv_layer = bm.loops.layers.uv.verify()
bm.faces.layers.tex.verify() # currently blender needs both layers.
2010-01-14 10:50:58 +00:00
# adjust UVs
for f in bm.faces:
for l in f.loops:
luv = l[uv_layer]
if luv.select:
2010-01-14 10:50:58 +00:00
# apply the location of the vertex as a UV
luv.uv = l.vert.co.xy
2010-01-14 10:50:58 +00:00
bmesh.update_edit_mesh(me)
2010-01-14 10:50:58 +00:00
2010-01-14 10:50:58 +00:00
class UvOperator(bpy.types.Operator):
"""UV Operator description"""
2010-01-14 10:50:58 +00:00
bl_idname = "uv.simple_operator"
bl_label = "Simple UV Operator"
2010-01-14 10:50:58 +00:00
@classmethod
def poll(cls, context):
return (context.mode == 'EDIT_MESH')
2010-01-14 10:50:58 +00:00
def execute(self, context):
main(context)
return {'FINISHED'}
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__":
register()
# test call
2010-01-14 10:50:58 +00:00
bpy.ops.uv.simple_operator()