1

It's 1am, and I googled every outdated site on the net, I give up.

In 2.79 I had a code:

mesh = bpy.data.meshes.new(mesh_nev)
mesh.uv_textures.new()
...
mesh.uv_textures[0].data[i].image = meshhez_tartozo_texturak[textúraindex]
...
mesh.uv_layers[0].data[o * 3].uv = (u,v)

what is no longer working for me in 2.81 and I find no good info on the net how I can do this right now. Can someone please help me out?

Thank you!

Zéiksz
  • 1,959
  • 5
  • 23
  • 32

1 Answers1

2

That code worked in 2.79?

Please when posting code in future make sure you leave in all relevant lines. eg in question what is o, i, u, v

Very little difference between this answer and the following, real toss up between answering and closing as duplicate, which I'll leave for others. Quicker to answer and hence confirm in 2.82.

Get/Set coordinates for UV vertices using Python

Add uv_layer to mesh, add uv-coords, with python

Add a new layer (same). Notice if a new layer is added, but there is an existing layer, it will not be index 0. Will be the last, or easier keep the reference returned.

>>> me.uv_layers.new(
new()
UVLoopLayers.new(name="UVMap", do_init=True)
Add a UV map layer to Mesh

get or set the active layer, it can be None a gotcha in answers to links above.

>>> me.uv_layers.active
bpy.data.meshes['Cube'].uv_layers["UVMap"]

>>> me.uv_layers.active = None

Silly example adds random UV (a scribbly mess) to each UV

enter image description here

import bpy
from random import random
context = bpy.context

ob = context.object
me = ob.data
uvlayer = me.uv_layers.new() # default naem and do_init

me.uv_layers.active = uvlayer

for face in me.polygons:
    for vert_idx, loop_idx in zip(face.vertices, face.loop_indices):
        uvlayer.data[loop_idx].uv = (random(), random()) # ie UV coord for each face with vert  me.vertices[vert_idx]
batFINGER
  • 84,216
  • 10
  • 108
  • 233