2010-07-08 16:24:24 +00:00
|
|
|
import bpy
|
2013-05-05 05:54:29 +00:00
|
|
|
import bmesh
|
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
|
2013-05-05 05:54:29 +00:00
|
|
|
me = obj.data
|
|
|
|
bm = bmesh.from_edit_mesh(me)
|
2010-01-14 10:50:58 +00:00
|
|
|
|
2013-05-05 05:54:29 +00:00
|
|
|
uv_layer = bm.loops.layers.uv.verify()
|
2013-05-05 18:41:45 +00:00
|
|
|
bm.faces.layers.tex.verify() # currently blender needs both layers.
|
2010-01-14 10:50:58 +00:00
|
|
|
|
|
|
|
# adjust UVs
|
2013-05-05 05:54:29 +00:00
|
|
|
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
|
2013-05-05 05:54:29 +00:00
|
|
|
luv.uv = l.vert.co.xy
|
2010-01-14 10:50:58 +00:00
|
|
|
|
2013-05-05 05:54:29 +00:00
|
|
|
bmesh.update_edit_mesh(me)
|
2010-01-14 10:50:58 +00:00
|
|
|
|
2010-08-02 03:30:07 +00:00
|
|
|
|
2010-01-14 10:50:58 +00:00
|
|
|
class UvOperator(bpy.types.Operator):
|
2012-07-01 07:55:44 +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):
|
2013-05-05 05:54:29 +00:00
|
|
|
return (context.mode == 'EDIT_MESH')
|
2010-01-14 10:50:58 +00:00
|
|
|
|
|
|
|
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()
|