[Bf-python] OB button pushing, making material visible

alex mole nal at blueyonder.co.uk
Thu Mar 25 00:11:13 CET 2004


Hi Nicolas

The problem is that you're setting the Object's material, when by 
default blender uses the Mesh's material. If instead you use:

me.addMaterial(mat)

then it should work.

One other thing that might crop up later, is that if you use UV mapping 
and you want to see the texture in the interactive 3D view, you need to 
set the texture's Image to each face in the mesh. For instance [this 
exact code is untested, but you should get the idea ;)]:

img = mat.getTextures()[0].tex.image
for f in me.faces:
	f.image = img


Hope that helps!


Alex


nicolas bonnand wrote:
> Hello,
> 
> I try to understand Object, Texture and Material creation
> but I'am stuck with the final step
> 
> 1) In the following simple  script, I generate a simple mesh
> with 3 vertices
> 
> 2) Then I apply a textured material to this triangle
> 
> 3 ) But, at the end, why  (??) do I need to manually push the "OB" button
> ("links material to object" ) to be able to see
> the cloud texture of the triangle ???????
> 
> Isn't it the role of the setMaterials method
> to link the material to the object ????
> 
> What method should I use to establish this link ?
> 
> I'm using blender 2.32.
> 
> I've studied the following documentation but couldn't find
> a complete example with object+material+texture creation.
> http://www.blender.org/modules/documentation/232PythonDoc/
> 
> Any help appreciated.
> 
> Regards
> 
> Nicolas
> 
> #------------------------------------
> from Blender import Texture,Material,NMesh,Draw
> 
> #new mesh
> me= NMesh.GetRaw()
> 
> #vertices
> me.verts.append(NMesh.Vert(1.0,0.0,0.0))
> me.verts.append(NMesh.Vert(1.0,1.0,0.0))
> me.verts.append(NMesh.Vert(0.0,1.0,0.0))
> 
> #face f=NMesh.Face()
> f.v.append(me.verts[0])
> f.v.append(me.verts[1])
> f.v.append(me.verts[2])
> 
> me.faces.append(f)
> o=NMesh.PutRaw(me,"MY_OBJ",1)
> 
> #create texture
> t=Texture.New("MY_TEXT")
> t.setType('Clouds')
> 
> #create material
> mat = Material.New("MY_MAT")
> 
> mat.setTexture(0, t,Texture.TexCo.ORCO,Texture.MapTo.COL)
> o.setMaterials([mat])
> 
> # Here I'm obliged to push the OB button in order
> # to be able to see the material on the triangle
> 
> # It's OK when I create only one triangle, but it becomes boring
> # after the 1000th ...
> 
> 
> #------------------------------------
> 
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://www.blender.org/mailman/listinfo/bf-python
> 
> 
> 



More information about the Bf-python mailing list