[Bf-python] Disco ball tutorial

Lone Wolf lone_wolf at ureach.com
Thu Apr 22 21:12:03 CEST 2004


I'm putting together a simple blender/python tutorial to help
newbies with coloring faces. I far as I know, one does not
already exist. In order to finish the tut, it would be nice if I
could get three questions answered (see the bottom of this
message). Anyway, I posted this on elYsiun for almost a week.
Over 100 people have looked at it, but nobody offered an answer
to my questions. Here is what I posted on elYsiun ...

............................................................

I think I've pretty much figured out how to assign color to
faces (thanks locash and Willian). So, I am putting together a
tutorial to help others. I confess that I am probably not the
best person to do this, because I've just learned it myself. To
make sure I'm on the right track, I thought I'd post a script
I've put together for a disco ball. Disco pretty much died in
the US in the 70s, but it still has a following in Europe. So...


import math 
from math import * 
import Blender 
from Blender import NMesh, Material 

#Get the Object, Mesh 
mySphere = Blender.Object.Get('Sphere') 
me=NMesh.GetRaw('Sphere') 

#Set up materials 

mat1=Material.New('red') 
mat1.setRGBCol(1,0,0) 
mat1.setAdd(1.0) 
me.addMaterial(mat1) 

mat2=Material.New('blue') 
mat2.setRGBCol(0,0,1) 
mat2.setAdd(1.0) 
me.addMaterial(mat2) 

mat3=Material.New('green') 
mat3.setRGBCol(0,1,0) 
mat3.setAdd(1.0) 
me.addMaterial(mat3) 

mat4=Material.New('yellow') 
mat4.setRGBCol(1,1,0) 
mat4.setAdd(1.0) 
me.addMaterial(mat4) 

mat5=Material.New('purple') 
mat5.setRGBCol(1,0,1) 
mat5.setAdd(1.0) 
me.addMaterial(mat5) 

mat6=Material.New('white') 
mat6.setRGBCol(1,1,1) 
mat6.setAdd(1.0) 
me.addMaterial(mat6) 

#Assign materials 
for n in range(0,10,1): 
     for i in range(0,80,1): 
       
               rotation = n*80 + i 
               mySphere.setEuler(0,rotation/5,0) 

               f=me.faces[i] 
               f.mat = (i+n)%6 

               me.update() 
               Blender.Redraw() 
    
# done 

I'm planning to introduce the tutorial in stages: first just one
color on one face of the ball, followed by six colors, followed
by six colors that alternate, and finally putting the spin on
the ball. 

I'm still bothered by three things however: 

(1) Each time I run the script, it adds 6 new materials.
Therefore, if I run it the second time, there are 12 materials,
and then after that the material list reaches its max (16) and
the script won't run at all. Is there a way to delete the
materials at the end of the script ... or at least make sure
that the same materials aren't created over and over. 

(2) It looks like all the faces on the entire mesh are redrawn
each time a single face is updated. This has to slow things down
a great deal. Is there a good way to make just the changed face
update? 

(3) The ball starts out entirely red (the color of the first
material), then gradually gets filled in with other colors. Is
there a way make the ball start out with multi colored faces
already in place? 

Anybody out there have good answers or suggestions for the
tutorial?

...........................................................
I hate to keep posting here because I know you guys are doing
serious development work, but could someone *please* take a few
minutes to look at this? THANKS :) :) :)




________________________________________________
Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag



More information about the Bf-python mailing list