How do you add Ztransp and some alpha value to the a material?
i added a mat like this
ob = bpy.context.scene.objects[name] # Get object named “Mesh” in scene
myMesh = ob.data
print (‘ob=’,ob)
Create a material
Materialname1=‘FirstMat’
mat = bpy.data.materials.new(Materialname1)
mat.alpha = 0
rgbCol = [0.2,0.4,0.5]
mat.diffuse_color = (1.0, 0.0, 1.0) # This diffuse color will take a Magenta color
the material slots hold materials, the faces have an index that says which material slot they will use.
to assign your material to the faces you need to know the index of the slot it’s in and then set the face to use it I haven’t tested the following!
your mesh object is myMesh, your material is mat:
matindex= myMesh.materials.index(mat)
for f in myMesh.faces:
f.material_index = matindex
not to certain about finding the material index, you may need to go through the texture slots on teh object instead…
once you know that the faces are using the material then just turn on glsl display…and set rendering to textured…
textures with alpha can be assigned to the faces in the UV editor and set mesh flags set to use alpha, this means you can see the transparency in solid view (when" solid tex" is enabled) but that’s a different story… I’m not sure the face flags can be set properly yet in 2.5
ob = bpy.context.scene.objects["Mesh"] # Get object named "Mesh" in scene
myMesh = ob.data
# Create a material
Materialname1='FirstMat'
mat = bpy.data.materials.new(Materialname1)
mat.alpha = 0.2
mat.transparency = True
rgbCol = [0.2,0.4,0.5]
mat.diffuse_color = (1.0, 0.0, 1.0) # This diffuse color will take a Magenta color
# Add it
myMesh.add_material(mat)
# viewport transparency
ob.draw_transparent = True
True.
Totally did not see, that it’s not beeing used.
Btw:
If you want the complete object smooth, you might as well use just one line: bpy.ops.object.shade_smooth()
and get rid of switching to/from editmode.
Well I was a bit sloppy there.
New objects will have all verts selected when switching to editmode.
But of course you can’t assume that this is always the case (everything selected).
(only problem left: what if we were already in editmode)
As I said, I don’t know (yet) how to select verts/faces that belong to a specific material.
Everything so far I’ve learnt mostly by switching to the scripting-layout in blender and looking at the commands from the Report console while messing around.