-- fixing a last minute bug: scripts w/o guis that called the file selector were
   not being checked for errors, which could cause crash dumps upon exiting.
-- docs: updates for Draw (fixed example) and Material (added tex related methods docs)

Scripts:
-- added some more scripts, all I could get in shape in time (at least they export / import back).
   Only tested on linux.
This commit is contained in:
Willian Padovani Germano
2004-01-28 19:16:50 +00:00
parent abe7425f3c
commit bdc624452b
13 changed files with 1966 additions and 57 deletions

View File

@@ -12,63 +12,66 @@ scrollbar, plus support for text drawing. It also includes keyboard keys and
mouse button code values in its dictionary (print dir(Blender.Draw)).
Example::
import Blender
from Blender import Draw, BGL
#
mystring = ""
mymsg = ""
toggle = 0
#
def event(evt, val): # the function to handle input events
global mystring, mymsg
import Blender
from Blender import Draw, BGL
if not val: # val = 0: it's a key/mbutton release
if evt in [Draw.LEFTMOUSE, Draw.MIDDLEMOUSE, Draw.RIGHTMOUSE]:
mymsg = "You released a mouse button."
Draw.Redraw(1)
return
mystring = ""
mymsg = ""
toggle = 0
if evt == Draw.ESCKEY:
Draw.Exit() # exit when user presses ESC
return
def event(evt, val): # the function to handle input events
global mystring, mymsg
elif Draw.AKEY <= evt <= Draw.ZKEY: mystring += chr(evt)
elif evt == Draw.SPACEKEY: mystring += ' '
elif evt == Draw.BACKSPACEKEY and len(mystring):
mystring = mystring[:-1]
else: return # this is important: only re-register if an event was caught
if not val: # val = 0: it's a key/mbutton release
if evt in [Draw.LEFTMOUSE, Draw.MIDDLEMOUSE, Draw.RIGHTMOUSE]:
mymsg = "You released a mouse button."
Draw.Redraw(1)
return
Draw.Register(gui, event, button_event) # re-register to stay in the loop
#
def button_event(evt): # the function to handle Draw Button events
global mymsg, toggle
if evt == 1:
mymsg = "You pressed the toggle button."
toggle = 1 - toggle
Draw.Redraw(1)
else:
Draw.Register(gui, event, button_event)
#
def gui(): # the function to draw the screen
global mystring, mymsg, toggle
if len(mystring) > 90: mystring = ""
BGL.glClearColor(0,0,1,1)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
BGL.glColor3f(1,1,1)
Draw.Toggle("Toggle", 1, 10, 10, 55, 20, toggle,"A toggle button")
BGL.glRasterPos2i(72, 16)
if toggle: toggle_state = "down"
else: toggle_state = "up"
Draw.Text("The toggle button is %s." % toggle_state, "small")
BGL.glRasterPos2i(10, 230)
Draw.Text("Type letters from a to z, ESC to leave.")
BGL.glRasterPos2i(20, 200)
Draw.Text(mystring)
BGL.glColor3f(1,0.4,0.3)
BGL.glRasterPos2i(340, 70)
Draw.Text(mymsg, "tiny")
#
Draw.Register(gui, event, button_event) # registering the 3 callbacks
if evt == Draw.ESCKEY:
Draw.Exit() # exit when user presses ESC
return
elif Draw.AKEY <= evt <= Draw.ZKEY: mystring += chr(evt)
elif evt == Draw.SPACEKEY: mystring += ' '
elif evt == Draw.BACKSPACEKEY and len(mystring):
mystring = mystring[:-1]
else: return # no need to redraw if nothing changed
Draw.Redraw(1)
def button_event(evt): # the function to handle Draw Button events
global mymsg, toggle
if evt == 1:
mymsg = "You pressed the toggle button."
toggle = 1 - toggle
Draw.Redraw(1)
def gui(): # the function to draw the screen
global mystring, mymsg, toggle
if len(mystring) > 90: mystring = ""
BGL.glClearColor(0,0,1,1)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
BGL.glColor3f(1,1,1)
Draw.Toggle("Toggle", 1, 10, 10, 55, 20, toggle,"A toggle button")
BGL.glRasterPos2i(72, 16)
if toggle: toggle_state = "down"
else: toggle_state = "up"
Draw.Text("The toggle button is %s." % toggle_state, "small")
BGL.glRasterPos2i(10, 230)
Draw.Text("Type letters from a to z, ESC to leave.")
BGL.glRasterPos2i(20, 200)
Draw.Text(mystring)
BGL.glColor3f(1,0.4,0.3)
BGL.glRasterPos2i(340, 70)
Draw.Text(mymsg, "tiny")
Draw.Register(gui, event, button_event) # registering the 3 callbacks
@note: The example above was fixed to call Draw.Register only once. It's
not necessary to re-register the callbacks, they will stay until Draw.Exit
is called. It's enough to redraw the screen when a relevant event is caught.
Apologies for the confusion.
@warn: Inside the windowing loop (after Draw.Register() has been executed and
before Draw.Exit() is called), don't use the redraw functions from other

View File

@@ -117,6 +117,8 @@ class Material:
that range: if val < Min, then val = Min, if val > Max, then val = Max.
"""
import Texture
def getName():
"""
Get the name of this Material object.
@@ -471,3 +473,30 @@ class Material:
@type nrings: int
@param nrings: The new value in [0, 24].
"""
def setTexture(index, texture, texco, mapto):
"""
Assign a Blender Texture object to slot number 'number'.
@type index: int
@param index: material's texture index in [0, 7].
@type texture: Blender Texture
@param texture: a Blender Texture object.
@type texco: int
@param texco: optional or'ed bitflag -- defaults to TexCo.ORCO. See TexCo var in L{Texture}.
@type mapto: int
@param mapto: optional or'ed bitflag -- defaults to MapTo.COL. See MapTo var in L{Texture}.
"""
def clearTexture(index):
"""
Clear the ith (given by 'index') texture channel of this material.
@type index: int
@param index: material's texture channel index in [0, 7].
"""
def getTextures ():
"""
Get this Material's Texture list.
@rtype: list
@return: a list of Blender Textures. None is returned for each empty texture slot.
"""