import Blender
from Blender import Mesh, Scene
from Blender import Material,Texture
#print spacers
print
print
print
print "------------------------------------"
print
#set the mesh size - ex: .5 (small and distinct) or 1 (large and sigular)
size = .5
#create meshes
mesh1 = Mesh.Primitives.Cube(size)
mat = Material.New('Material')
mesh1.materials.append(mat)
#mat.rgbCol = [sliderR.val, sliderG.val, sliderB.val]
mat.setRGBCol([1.0,0.2,0.4])
#mat.setRGBCol=([1.0,0.2,0.4])
mat.setSpecCol([1.0,1.0,0.8])
mat.setMirCol([0.8,0.9,0.7])
mat.setAlpha(1.0)
mat.setRef(0.8)
mat.setSpec(0.5)
mat.setHardness(50)
#get the scene
scene = Scene.GetCurrent()
#link object to the scene
meshob = scene.objects.new(mesh1)
#set location
meshob.setLocation(0,0,0)
#all objects in the scene
oblist = list(scene.objects)
print "
All objects in the scene:
", oblist
#only mesh objects in the scene
oblist = [ ob for ob in oblist if ob.type == 'Mesh']
#reorder the list - not required
oblist.reverse()
print "
Only mesh objects in the scene:
", oblist
#join 1st object in list to remaining objects in list (slice)
oblist[0].join(oblist[1:])
print "
First object:
", oblist[0]
print "
Remaining objects:
", oblist[1:]
#unlink the "remaining" objects from the scene
for i in range(1, len(oblist)):
scene.objects.unlink(oblist[i])
#update the scene
scene.update(0)
#redraw
Blender.Redraw()
try this one it is very simple and should work but is not!
lg 03 is interesting cause there is a lot of other variables that you can set
like mirror trnasp reflec ect…
now i was able to make another one work with mesh
import Blender as B
from Blender import Mesh, Scene
from Blender import Material,Texture
# vertices
p1 = [0,0,0]
p2 = [1,0,0]
p3 = [0.5, 1, 1]
verts = [p1,p2,p3]
faces = [0,1,2]
# create Object
ob = B.Object.New('Mesh', 'MeshOb')
# create ObData
me = B.Mesh.New('myMesh')
# add vertices
me.verts.extend( verts )
# create faces
me.faces.extend( faces )
# first object in selection list
#ob = B.Object.GetSelected()[0]
# get the Mesh version of our cube, not NMesh
#me = B.Mesh.Get( ob.data.name )
# create some materials this add 3 materials to the object one red blue and green
red1 = B.Material.New('Red1')
red1.rgbCol = 1,0,0 # red, green, blue values
green1 = B.Material.New('Green1')
green1.rgbCol = 0,1,0 # red, green, blue values
blue1 = B.Material.New('Blue1')
blue1.rgbCol = 0,0,1 # red, green, blue values
# add the material list to our ObData
me.materials = [red1, green1, blue1 ]
# set the face materials of our cube
# we can set all faces the same color like this
for f in me.faces:
f.mat = 0
################################################
#create new meshes cube
size=2
mesh1 = Mesh.Primitives.Cube(size)
#mat = Material.New('Material')
mat = Material.New('Material')
mesh1.materials.append(mat)
mesh1.materials = [red1, green1, blue1 ]
#for f in mesh1.faces:
# f.mat = 0
# Different faces color
for i in range(len(mesh1.faces)):
mesh1.faces[i].mat = i % 3
#get the scene
scene = Scene.GetCurrent()
#link object to the scene
meshob = scene.objects.new(mesh1)
#set location
meshob.setLocation(4,4,0)
ob.link( me )
scene = B.Scene.GetCurrent()
scene.link( ob )
B.Redraw(-1)
now this wseems to work but
i dont’ have the name of other variables for the mirror tranps ect…!
and this has been deprecated and replace by Mesh object!
1 -
this seems to be an intneresting way to save space in a script i’m preparaing
in script example you’v given to me for color and materials textures
call to function is :
mixedCube = makeCube(4,0,“mixedCube”,mixedMesh,localScene)
then this function creates an object and ob
but use an internal name for it
def makeCube(x,y,name,passedMesh,passedScene):
ob = Object.New("Mesh",name)
ob.LocX=x
ob.LocY=y
ob.link(passedMesh)
passedScene.link(ob)
return ob
would it be possible to pass a name for the new object in parameters
or may be change ti afterward to another name?
2 - the "mesh1.setMaterials([mat_mat,mat_granit ]) command "
exist only for Nmesh which is deprecated and replaced by another Mesh object