1

Using Blender 2.49's Python API I'm creating a mesh. I have a list of vertices and a list of face indices.

e.g.

mesh = bpy.data.meshes.new('mesh')
mesh.verts.extend(mVerts)
mesh.faces.extend(mFaces)

I've noticed MVert's uvco property and MFace's uv property, and added some random values, but I can't see any change when I render.

Regarding uvco, the documentation mentions:

Note: These are not seen in the UV editor and they are not a part of UV a UVLayer.

I tried this with the new mesh selected:

import Blender
from Blender import *
import random

scn = Scene.GetCurrent()
ob = scn.objects.active
o = ob.getData()

for v in o.verts:
    v.uvco = (random.random(),random.random(),random.random())
    print v.uvco

for f in o.faces:
    r = (random.random(),random.random())
    for i in range(0,4):
        f.uv.append(r)
        print f.uv

I can see the values change in Terminal, but I don't see any change when I render. If I reselect the object, the previous face uvs are gone.

Can anyone explain how are UVs set using the Blender 2.49 Python API ?

Thanks

George Profenza
  • 50,687
  • 19
  • 144
  • 218

1 Answers1

2

Try simply replacing this line:

o = ob.getData()

with

o = ob.getData(mesh=True)

Due to the historic development of Blender Python API, an ordinary call to blender_object.getData gives you a copy of an object's mesh data, that while can be modified, is not "live" on the displayed object. (Actually it is even an "NMesh" - a class that differs from the living "Mesh" class).

With the optional parameter "mesh=True" passed to the getData method you get back the living mesh of the object, and changes therein have effect (that can be seen upon an update forced with after a Blender.Redraw()).

I never tried UV things, however, so there might be more things to it, but I believe this is your issue.

jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • I didn't know about (mesh=True). Might the right track. Now I get this error: 'ValueError: face has no texture values' I've manually applied a texture and tried again, but I get the same error. Any hints ? – George Profenza Jul 14 '10 at 13:23
  • done! must not be in edit mode while modifying uvs. Thanks @jsbueno – George Profenza Jul 15 '10 at 09:50