blender/scripts/templates_py/operator_mesh_uv.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.3 KiB
Python
Raw Permalink 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()
2010-01-14 10:50:58 +00:00
# Adjust UV coordinates.
for face in bm.faces:
for loop in face.loops:
loop_uv = loop[uv_layer]
# Use XY position of the vertex as a uv coordinate.
loop_uv.uv = loop.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):
obj = context.active_object
return obj and obj.type == 'MESH' and obj.mode == 'EDIT'
2010-01-14 10:50:58 +00:00
def execute(self, context):
main(context)
return {'FINISHED'}
def menu_func(self, context):
self.layout.operator(UvOperator.bl_idname, text="Simple UV Operator")
2010-01-14 10:50:58 +00:00
# Register and add to the "UV" menu (required to also use F3 search "Simple UV Operator" for quick access).
def register():
bpy.utils.register_class(UvOperator)
bpy.types.IMAGE_MT_uvs.append(menu_func)
def unregister():
bpy.utils.unregister_class(UvOperator)
bpy.types.IMAGE_MT_uvs.remove(menu_func)
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()