All pastes #838499 Raw Edit

Problem with Material.New()

public text v1 · immutable
#838499 ·published 2007-12-30 12:55 UTC
rendered paste body
import Blender
from Blender import Scene, Object, Mesh, Mathutils, Material
import random
from random import *


scene = Blender.Scene.GetCurrent()



red = Material.New()
red.rgbCol= 255,0,0 
red.setAlpha(1.0)
red.setRef(0.8)
red.setSpec(0.5)

colorin = Material.New()
colorin.rgbCol= [0,100,100]
colorin.setAlpha(1.0)
colorin.setRef(0.8)
colorin.setSpec(0.5)


contador  = 0



#0x032947 -> 3, 41, 71
#0x951516 -> 149, 21, 22
#0x98bb67 -> 152, 187, 103
#0x017487 -> 1, 116, 135
#0xd4cb62 -> 212,203, 98

def nuevo_color (r,g,b):

    c = Material.New()
    c.rgbCol= [r,g,b]
    c.setAlpha(1.0)
    c.setRef(0.8)
    c.setSpec(0.5)

    return c

colores = [red,colorin]

print "Orign:"
print colores

colores = []
#colores = [red,colorin]

colores  = [Material.New(),Material.New(),Material.New(),Material.New(),Material.New()]
colores[0].rgbCol = [3,41,71]
colores[1].rgbCol = [149,21,22]
colores[2].rgbCol = [152,187,103]
colores[3].rgbCol = [1,115,135]
colores[4].rgbCol = [211,203,98]


print "Con Append:"
print colores

a = 0

def cubo ():

    global colores, a
    
    if (a == 0 ):
        a = 1
        print colores
        print len(colores[0])
        
    cubeMesh = Mesh.Primitives.Cube(.5)
    cubeMesh.materials = [colores[randint(0,len(colores)-1)]]
    cubeNew = scene.objects.new(cubeMesh, "Cube"+str(contador))
    cubeNew.setLocation(random()*10, random()*10, 0)
    cubeNew.setSize(1, 1, 1)
    #cubeNew.RotX = 45



def cilindro ():
    cylinderMesh = Mesh.Primitives.Cylinder(32,2,0.5)
    cylinderMesh.materials = [red]
    cylinderNew = scene.objects.new(cylinderMesh, "Cylinder")
    cylinderNew.setLocation(3, 3, 0)



for i in range (0,100):
    cubo()

#Mostramos los nuevos elementos por pantalla
Blender.Redraw()