BGE: Fix T38030: wrong vertex index returned by KX_PolyProxy

Fix T38030.
In c++ source we use one list for triangles and an other for quads, but KX_PolyProxy doesn't care about that and return the vertex offset in its list. So we just have to compute the offset of each RAS_DisplayArray to its previous to have an absolute vertex index.

Reviewers: moguri, campbellbarton, kupoman, agoose77, brita_, hg1

Reviewed By: agoose77, hg1

Projects: #game_engine

Maniphest Tasks: T38030

Differential Revision: https://developer.blender.org/D1324
This commit is contained in:
Porteries Tristan 2015-06-20 14:21:31 +02:00
parent 6b3a43ccb4
commit 2a305580b2
Notes: blender-bot 2023-02-14 11:24:03 +01:00
Referenced by issue #38030, KX_PolyProxy has incorrect getVertexIndex results
7 changed files with 47 additions and 16 deletions

View File

@ -140,21 +140,21 @@ PyObject *KX_PolyProxy::pyattr_get_v1(void *self_v, const KX_PYATTRIBUTE_DEF *at
{
KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
return PyLong_FromLong(self->m_polygon->GetVertexOffset(0));
return PyLong_FromLong(self->m_polygon->GetVertexOffsetAbsolute(0));
}
PyObject *KX_PolyProxy::pyattr_get_v2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
return PyLong_FromLong(self->m_polygon->GetVertexOffset(1));
return PyLong_FromLong(self->m_polygon->GetVertexOffsetAbsolute(1));
}
PyObject *KX_PolyProxy::pyattr_get_v3(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
return PyLong_FromLong(self->m_polygon->GetVertexOffset(2));
return PyLong_FromLong(self->m_polygon->GetVertexOffsetAbsolute(2));
}
PyObject *KX_PolyProxy::pyattr_get_v4(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
@ -163,7 +163,7 @@ PyObject *KX_PolyProxy::pyattr_get_v4(void *self_v, const KX_PYATTRIBUTE_DEF *at
if (3 < self->m_polygon->VertexCount())
{
return PyLong_FromLong(self->m_polygon->GetVertexOffset(3));
return PyLong_FromLong(self->m_polygon->GetVertexOffsetAbsolute(3));
}
return PyLong_FromLong(0);
}
@ -243,7 +243,7 @@ KX_PYMETHODDEF_DOC(KX_PolyProxy, getVertexIndex,
}
if (index < m_polygon->VertexCount())
{
return PyLong_FromLong(m_polygon->GetVertexOffset(index));
return PyLong_FromLong(m_polygon->GetVertexOffsetAbsolute(index));
}
return PyLong_FromLong(0);
}

View File

@ -287,6 +287,16 @@ void RAS_MeshSlot::AddPolygonVertex(int offset)
m_endindex++;
}
void RAS_MeshSlot::UpdateDisplayArraysOffset()
{
unsigned int offset = 0;
for (unsigned short i = 0; i < m_displayArrays.size(); ++i) {
RAS_DisplayArray *darray = m_displayArrays[i];
darray->m_offset = offset;
offset += darray->m_vertex.size();
}
}
void RAS_MeshSlot::SetDeformer(RAS_Deformer* deformer)
{
if (deformer && m_pDeformer != deformer) {

View File

@ -80,6 +80,13 @@ public:
class RAS_DisplayArray
{
public:
/** The offset relation to the previous RAS_DisplayArray.
* For the user vertex are one big list but in C++ source
* it's two different lists if we use quads and triangles.
* So to fix that we add an offset.
* This value is set in UpdateDisplayArraysOffset().
*/
unsigned int m_offset;
vector<RAS_TexVert> m_vertex;
vector<unsigned short> m_index;
/* LINE currently isn't used */
@ -165,6 +172,9 @@ public:
int AddVertex(const RAS_TexVert& tv);
void AddPolygonVertex(int offset);
/// Update offset of each display array
void UpdateDisplayArraysOffset();
/* optimization */
bool Split(bool force=false);
bool Join(RAS_MeshSlot *target, MT_Scalar distance);

View File

@ -465,6 +465,23 @@ void RAS_MeshObject::RemoveFromBuckets(void *clientobj)
}
}
void RAS_MeshObject::EndConversion()
{
#if 0
m_sharedvertex_map.clear(); // SharedVertex
vector<vector<SharedVertex> > shared_null(0);
shared_null.swap( m_sharedvertex_map ); /* really free the memory */
#endif
for (std::list<RAS_MeshMaterial>::iterator it = m_materials.begin();
it != m_materials.end();
++it)
{
RAS_MeshSlot *ms = it->m_baseslot;
ms->UpdateDisplayArraysOffset();
}
}
//void RAS_MeshObject::Transform(const MT_Transform& trans)
//{
//m_trans.translate(MT_Vector3(0,0,1));//.operator *=(trans);

View File

@ -132,13 +132,7 @@ public:
virtual void AddMeshUser(void *clientobj, SG_QList *head, RAS_Deformer* deformer);
void RemoveFromBuckets(void *clientobj);
void EndConversion() {
#if 0
m_sharedvertex_map.clear(); // SharedVertex
vector<vector<SharedVertex> > shared_null(0);
shared_null.swap( m_sharedvertex_map ); /* really free the memory */
#endif
}
void EndConversion();
/* colors */
void DebugColor(unsigned int abgr);

View File

@ -62,9 +62,9 @@ RAS_TexVert *RAS_Polygon::GetVertex(int i)
return &m_darray->m_vertex[m_offset[i]];
}
int RAS_Polygon::GetVertexOffset(int i)
unsigned int RAS_Polygon::GetVertexOffsetAbsolute(unsigned short i)
{
return m_offset[i];
return m_offset[i] + m_darray->m_offset;
}
/*

View File

@ -72,8 +72,8 @@ public:
RAS_TexVert* GetVertex(int i);
void SetVertexOffset(int i, unsigned short offset);
int GetVertexOffset(int i);
unsigned int GetVertexOffsetAbsolute(unsigned short i);
// each bit is for a visible edge, starting with bit 1 for the first edge, bit 2 for second etc.
// - Not used yet!
/* int GetEdgeCode();