KX_MeshProxy(SCA_IObject)

base class — SCA_IObject

class bge.types.KX_MeshProxy(SCA_IObject)

A mesh object.

You can only change the vertex properties of a mesh object, not the mesh topology.

To use mesh objects effectively, you should know a bit about how the game engine handles them.

  1. Mesh Objects are converted from Blender at scene load.
  2. The Converter groups polygons by Material. This means they can be sent to the renderer efficiently. A material holds:
    1. The texture.
    2. The Blender material.
    3. The Tile properties
    4. The face properties - (From the “Texture Face” panel)
    5. Transparency & z sorting
    6. Light layer
    7. Polygon shape (triangle/quad)
    8. Game Object
  3. Vertices will be split by face if necessary. Vertices can only be shared between faces if:
    1. They are at the same position
    2. UV coordinates are the same
    3. Their normals are the same (both polygons are “Set Smooth”)
    4. They are the same color, for example: a cube has 24 vertices: 6 faces with 4 vertices per face.

The correct method of iterating over every KX_VertexProxy in a game object

from bge import logic

cont = logic.getCurrentController()
object = cont.owner

for mesh in object.meshes:
   for m_index in range(len(mesh.materials)):
      for v_index in range(mesh.getVertexArrayLength(m_index)):
         vertex = mesh.getVertex(m_index, v_index)
         # Do something with vertex here...
         # ... eg: color the vertex red.
         vertex.color = [1.0, 0.0, 0.0, 1.0]
materials
Type:list of KX_BlenderMaterial or KX_PolygonMaterial types
numPolygons
Type:integer
numMaterials
Type:integer
getMaterialName(matid)

Gets the name of the specified material.

Parameters:matid (integer) – the specified material.
Returns:the attached material name.
Return type:string
getTextureName(matid)

Gets the name of the specified material’s texture.

Parameters:matid (integer) – the specified material
Returns:the attached material’s texture name.
Return type:string
getVertexArrayLength(matid)

Gets the length of the vertex array associated with the specified material.

There is one vertex array for each material.

Parameters:matid (integer) – the specified material
Returns:the number of verticies in the vertex array.
Return type:integer
getVertex(matid, index)

Gets the specified vertex from the mesh object.

Parameters:
  • matid (integer) – the specified material
  • index (integer) – the index into the vertex array.
Returns:

a vertex object.

Return type:

KX_VertexProxy

getPolygon(index)

Gets the specified polygon from the mesh.

Parameters:index (integer) – polygon number
Returns:a polygon object.
Return type:KX_PolyProxy
transform(matid, matrix)

Transforms the vertices of a mesh.

Parameters:
  • matid (integer) – material index, -1 transforms all.
  • matrix (4x4 matrix [[float]]) – transformation matrix.
transformUV(matid, matrix, uv_index=-1, uv_index_from=-1)

Transforms the vertices UV’s of a mesh.

Parameters:
  • matid (integer) – material index, -1 transforms all.
  • matrix (4x4 matrix [[float]]) – transformation matrix.
  • uv_index (integer) – optional uv index, -1 for all, otherwise 0 or 1.
  • uv_index_from (integer) – optional uv index to copy from, -1 to transform the current uv.

Previous topic

KX_LightObject(KX_GameObject)

Next topic

KX_MouseFocusSensor(SCA_MouseSensor)