Class BL_BlenderMaterial (2.48)


Methods
getMaterialIndex setBlending
getShader ----------
 
Variables
---------- ----------
 
Constants
---------- ----------
 
Inherited Methods:  Class Value
getName ----------


Methods


getMaterialIndex

getMaterialIndex()

Returns whether or not the material has a material index.

Return Type:  bool
True (1) or False (0)

Note:
For a material to have a material index, either Blender GLSL Materials or Blender MultiTexture Materials must be checked.

Sample Code

# define the main part of the program
def main():

# get the current scene
scene = GameLogic.getCurrentScene()

# get a list of the objects in the scene
objList = scene.getObjectList()

# get object named Cube
objCube = objList["OBCube"]

# only one mesh on this cube
mesh = objCube.getMesh()

# only one material on this mesh
mat = mesh.materials[0]

# Using Blender GLSL Materials or Blender Multitexture Materials?
if hasattr(mat, "getMaterialIndex") == True:

# get shader envelope
shader = mat.getShader()

# did it get the shader envelope?
if shader != None:
       
# set the source and use it
shader.setSource(VertexProgram,FragmentProgram, True)

####### end of main program def

# Import OpenGL code as a string
VertexProgram =

"""

void main()

{

// OpenGL glsl

gl_Position = ftransform();

}


"""


# Import OpenGL code as a string
FragmentProgram =

"""

void main()

{

// Set color to green

gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);

}


"""


# run the program
main()

getShader

getShader()

Returns the shader envelope.  Returns None if there isn't a shader envelope to return.

Return Type:  BL_Shader

Sample Code

# define the main part of the program
def main():

# get the current scene
scene = GameLogic.getCurrentScene()

# get a list of the objects in the scene
objList = scene.getObjectList()

# get object named Cube
objCube = objList["OBCube"]

# only one mesh on this cube
mesh = objCube.getMesh()

# only one material on this mesh
mat = mesh.materials[0]

# Using Blender GLSL Materials or Blender Multitexture Materials?
if hasattr(mat, "getMaterialIndex") == True:

# get shader envelope
shader = mat.getShader()

# did it get the shader envelope?
if shader != None:
       
# set the source and use it
shader.setSource(VertexProgram,FragmentProgram, True)

####### end of main program def

# Import OpenGL code as a string
VertexProgram =

"""

void main()

{

// OpenGL glsl

gl_Position = ftransform();

}


"""


# Import OpenGL code as a string
FragmentProgram =

"""

void main()

{

// Set color to green

gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);

}


"""


# run the program
main()

setBlending

setBlending( source, destination)

Textures are drawn by blending the incoming (source) RGBA color values with the RGBA color values already in the frame buffer (destination)

source:
GameLogic.BL_ZERO
GameLogic.BL_ONE
GameLogic.BL_SRC_COLOR
GameLogic.BL_ONE_MINUS_SRC_COLOR
GameLogic.BL_DST_COLOR
GameLogic.BL_ONE_MINUS_DST_COLOR
GameLogic.BL_SRC_ALPHA
GameLogic.BL_ONE_MINUS_SRC_ALPHA
GameLogic.BL_DST_ALPHA,
GameLogic.BL_ONE_MINUS_DST_ALPHA
GameLogic.BL_SRC_ALPHA_SATURATE

destination:
GameLogic.BL_ZERO
GameLogic.BL_ONE
GameLogic.BL_SRC_COLOR
GameLogic.BL_ONE_MINUS_SRC_COLOR
GameLogic.BL_DST_COLOR
GameLogic.BL_ONE_MINUS_DST_COLOR
GameLogic.BL_SRC_ALPHA
GameLogic.BL_ONE_MINUS_SRC_ALPHA
GameLogic.BL_DST_ALPHA,
GameLogic.BL_ONE_MINUS_DST_ALPHA
GameLogic.BL_SRC_ALPHA_SATURATE

Note:
The code below uses a texture's alpha channel.  The Alpha button on the Texture Face tab doesn't have to be enabled.

Sample Code

# get the currrent controller
controller = GameLogic.getCurrentController()

# get object that owns this controller
obj = controller.getOwner()
 
# There's only one mesh
mesh = obj.getMesh(0)

# And only one material
mat = mesh.materials[0]

# Using Blender GLSL Materials or Blender Multitexture Materials?
if hasattr(mat, "getMaterialIndex") == True:

# set blending of pixels to use texture's alpha channel
mat.setBlending(GameLogic.BL_SRC_ALPHA ,
GameLogic.BL_ONE_MINUS_SRC_ALPHA )


Example Blend:




Blender 3D
Game Engine