blender/release/scripts/templates_py/operator_mesh_uv.py

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

50 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()
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 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()