1
KX_MeshProxy(SCA_IObject)
2
=========================
6
base class --- :class:`SCA_IObject`
8
.. class:: KX_MeshProxy(SCA_IObject)
12
You can only change the vertex properties of a mesh object, not the mesh topology.
14
To use mesh objects effectively, you should know a bit about how the game engine handles them.
16
#. Mesh Objects are converted from Blender at scene load.
17
#. The Converter groups polygons by Material. This means they can be sent to the renderer efficiently. A material holds:
20
#. The Blender material.
21
#. The Tile properties
22
#. The face properties - (From the "Texture Face" panel)
23
#. Transparency & z sorting
25
#. Polygon shape (triangle/quad)
28
#. Vertices will be split by face if necessary. Vertices can only be shared between faces if:
30
#. They are at the same position
31
#. UV coordinates are the same
32
#. Their normals are the same (both polygons are "Set Smooth")
33
#. They are the same color, for example: a cube has 24 vertices: 6 faces with 4 vertices per face.
35
The correct method of iterating over every :class:`KX_VertexProxy` in a game object
37
.. code-block:: python
41
cont = logic.getCurrentController()
44
for mesh in object.meshes:
45
for m_index in range(len(mesh.materials)):
46
for v_index in range(mesh.getVertexArrayLength(m_index)):
47
vertex = mesh.getVertex(m_index, v_index)
48
# Do something with vertex here...
49
# ... eg: color the vertex red.
50
vertex.color = [1.0, 0.0, 0.0, 1.0]
52
.. attribute:: materials
54
:type: list of :class:`KX_BlenderMaterial` or :class:`KX_PolygonMaterial` types
56
.. attribute:: numPolygons
60
.. attribute:: numMaterials
64
.. method:: getMaterialName(matid)
66
Gets the name of the specified material.
68
:arg matid: the specified material.
70
:return: the attached material name.
73
.. method:: getTextureName(matid)
75
Gets the name of the specified material's texture.
77
:arg matid: the specified material
79
:return: the attached material's texture name.
82
.. method:: getVertexArrayLength(matid)
84
Gets the length of the vertex array associated with the specified material.
86
There is one vertex array for each material.
88
:arg matid: the specified material
90
:return: the number of verticies in the vertex array.
93
.. method:: getVertex(matid, index)
95
Gets the specified vertex from the mesh object.
97
:arg matid: the specified material
99
:arg index: the index into the vertex array.
101
:return: a vertex object.
102
:rtype: :class:`KX_VertexProxy`
104
.. method:: getPolygon(index)
106
Gets the specified polygon from the mesh.
108
:arg index: polygon number
110
:return: a polygon object.
111
:rtype: :class:`PolyProxy`
113
.. method:: transform(matid, matrix)
115
Transforms the vertices of a mesh.
117
:arg matid: material index, -1 transforms all.
119
:arg matrix: transformation matrix.
120
:type matrix: 4x4 matrix [[float]]
122
.. method:: transformUV(matid, matrix, uv_index=-1, uv_index_from=-1)
124
Transforms the vertices UV's of a mesh.
126
:arg matid: material index, -1 transforms all.
128
:arg matrix: transformation matrix.
129
:type matrix: 4x4 matrix [[float]]
130
:arg uv_index: optional uv index, -1 for all, otherwise 0 or 1.
131
:type uv_index: integer
132
:arg uv_index_from: optional uv index to copy from, -1 to transform the current uv.
133
:type uv_index_from: integer