Class KX_MeshProxy (2.48)


Methods
getMaterialName getTextureName
getNumMaterials getVertex
getNumPolygons getVertexArrayLength
getPolygon reinstancePhysicsMesh
 
Variables
---------- ----------
 
Constants
---------- ----------

Inherited Methods:  Class PyObjectPlus
isA ----------



Methods



getMaterialName

getMaterialName(matID)

returns the material name.  Returns the value NoMaterial if there isn't a material.

Return type:  string

matID:
Type:   integer.

Note:
A mesh can have more than one material on it.

Note:
If you add a material by UVMapping it without using Blender materials, it returns an empty string.

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get object controller is attached to
owner = controller.getOwner()

# get the mesh
mesh = owner.getMesh()

# get the number of materials on the mesh
numMaterial = mesh.getNumMaterials()

# cycle through all of the materials
for matID in range( 0, numMaterial):

# get the name of the material
matName = mesh.getMaterialName(matID)

# name of material to change
if matName == "MAFront":

# get array length of the material
array = mesh.getVertexArrayLength(matID)
          
# loop through array
for vertNum in range( 0, array):
      
# get vertex
vert = mesh.getVertex( matID, vertNum)
           
#Change the color
color = [1.0, 0.0, 1.0, 1.0]
                      
# change vertex color
vert.setRGBA(color)


Example Blend:


getNumMaterials

getNumMaterials()

Returns the number of materials on the object.

Return type:  integer

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get object the controller is attached to
owner = controller.getOwner()

# get the mesh
mesh = owner.getMesh()

# get the number of the materials
number = mesh.getNumMaterials()

getNumPolygons

getNumPolygons( )

Returns the number of polygons on the object.

Return type:  integer

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get object the controller is attached to
owner = controller.getOwner()

# get the mesh
mesh = owner.getMesh()
# get the number of polygons on the mesh
numPoly = mesh.getNumPolygons()

getPolygon

getPolygon(num)

Returns the polygon

Return type:   KX_PolyProxy

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get object the controller is attached to
owner = controller.getOwner()

# get the mesh
mesh = owner.getMesh()
# get the first polygon on the mesh
poly = mesh.getPolygon(0)

getTextureName

getTextureName(matID)

Returns the name of the texture on a material.

Returns Null if there isn't a texture in the first texture slot

Return type:  string

matID:
Type:   integer

Note:
Only returns the name of the texture in the first texture slot.

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get object the controller is attached to
owner = controller.getOwner()

# get the mesh
mesh = owner.getMesh()

# get the number of materials on the mesh
numMaterial = mesh.getNumMaterials()

# cycle through all of the materials
for matID in range( 0, numMaterial):

# get the name of the 1st texture on each material
textureName = mesh.getTextureName(matID)

getVertex

getVertex(matID, array)

Returns the vertex

Return type:  KX_VertexProxy

matID:
Type:   integer

array:
Type:  interger.

Sample Code


# get controller
controller = GameLogic.getCurrentController()

# get object the controller is attached to
owner = controller.getOwner()

# get the mesh
mesh = owner.getMesh()

# get the number of materials on the mesh
numMaterial = mesh.getNumMaterials()

# cycle through all of the materials
for matID in range( 0, numMaterial):

# get array length of the material
length = mesh.getVertexArrayLength(matID)

# loop through array
for array in range( 0, length):

# get vertex
vert = mesh.getVertex(matID,array)

#Change the color
color = [1.0, 0.0, 1.0, 1.0]

# change vertex color
vert.setRGBA(color)


Example Blend:


getVertexArrayLength

getVertexArrayLength(matID)

Returns the number of vertexes in a material.

Return type:  integer

matID:
Type:   integer

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get object the controller is attached to
owner = controller.getOwner()

# get the mesh
mesh = owner.getMesh()

# get the number of materials on the mesh
numMaterial = mesh.getNumMaterials()

# cycle through all of the materials
for matID in range( 0, numMaterial):

# get array length of the material
length = mesh.getVertexArrayLength(matID)

# loop through array
for array in range( 0, length):

# get vertex
vert = mesh.getVertex(matID,array)

#Change the color
color = [1.0, 0.0, 1.0, 1.0]

# change vertex color
vert.setRGBA(color)


Example Blend:


reinstancePhysicsMesh

reinstancePhysicsMesh()

This updates the physics system with the changed mesh.

Return Type:  bool 

True if the update succeeded.
False if it failed.

Note:
Only one material on the mesh can have collision flags.
 
All collision primitives must be in one vertex array (ie. < 65535 verts)

Mesh bounds must be either a polytope or polyheder.

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get object controller is attached to
owner = controller.getOwner()

# get the mesh
mesh = owner.getMesh()

# update physics system
mesh.reinstancePhysicsMesh()



Blender 3D
Game Engine