forked from bartvdbraak/blender
f6c323aa42
scene.active_keying_set --> scene.keying_sets.active ...same for active_uv_texture. active_vertex_color, active_keyconfig, - move mesh.add_uv_layer() and mesh.add_vertex_color() into their collections also have them return the newly created layer and dont set the layer active. uvtex = mesh.uv_layers.new(name) vcol = mesh.vertex_colors.new(name)
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
import bpy
|
|
|
|
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.uv_textures:
|
|
uvtex = bpy.ops.mesh.uv_texture_add()
|
|
|
|
# adjust UVs
|
|
for i, uv in enumerate(uvtex.data):
|
|
uvs = uv.uv1, uv.uv2, uv.uv3, uv.uv4
|
|
for j, v_idx in enumerate(mesh.faces[i].vertices):
|
|
if uv.select_uv[j]:
|
|
# apply the location of the vertex as a UV
|
|
uvs[j][:] = mesh.vertices[v_idx].co.xy
|
|
|
|
|
|
if is_editmode:
|
|
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
|
|
|
|
|
|
class UvOperator(bpy.types.Operator):
|
|
'''UV Operator description'''
|
|
bl_idname = "uv.simple_operator"
|
|
bl_label = "Simple UV Operator"
|
|
|
|
@classmethod
|
|
def poll(cls, context):
|
|
obj = context.active_object
|
|
return (obj and obj.type == 'MESH')
|
|
|
|
def execute(self, context):
|
|
main(context)
|
|
return {'FINISHED'}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
bpy.ops.uv.simple_operator()
|