Commit: 2a305580b2c76af62c129fbca043466ab010c2df
Author: Porteries Tristan
Date:   Sat Jun 20 14:21:31 2015 +0200
Branches: master
https://developer.blender.org/rB2a305580b2c76af62c129fbca043466ab010c2df

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

===================================================================

M       source/gameengine/Ketsji/KX_PolyProxy.cpp
M       source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
M       source/gameengine/Rasterizer/RAS_MaterialBucket.h
M       source/gameengine/Rasterizer/RAS_MeshObject.cpp
M       source/gameengine/Rasterizer/RAS_MeshObject.h
M       source/gameengine/Rasterizer/RAS_Polygon.cpp
M       source/gameengine/Rasterizer/RAS_Polygon.h

===================================================================

diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp 
b/source/gameengine/Ketsji/KX_PolyProxy.cpp
index ccc10eb..4454543 100644
--- a/source/gameengine/Ketsji/KX_PolyProxy.cpp
+++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp
@@ -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);
 }
diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp 
b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
index 4b5fc65..2078fc9 100644
--- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
+++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
@@ -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) {
diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.h 
b/source/gameengine/Rasterizer/RAS_MaterialBucket.h
index 007fdf2..1eee99f 100644
--- a/source/gameengine/Rasterizer/RAS_MaterialBucket.h
+++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.h
@@ -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);
diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp 
b/source/gameengine/Rasterizer/RAS_MeshObject.cpp
index 54b15f0..4360464 100644
--- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp
+++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp
@@ -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);
diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.h 
b/source/gameengine/Rasterizer/RAS_MeshObject.h
index 4f352379..a6f1a1c 100644
--- a/source/gameengine/Rasterizer/RAS_MeshObject.h
+++ b/source/gameengine/Rasterizer/RAS_MeshObject.h
@@ -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);
diff --git a/source/gameengine/Rasterizer/RAS_Polygon.cpp 
b/source/gameengine/Rasterizer/RAS_Polygon.cpp
index 1f23df9..3274ded 100644
--- a/source/gameengine/Rasterizer/RAS_Polygon.cpp
+++ b/source/gameengine/Rasterizer/RAS_Polygon.cpp
@@ -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;
 }
 
 /*
diff --git a/source/gameengine/Rasterizer/RAS_Polygon.h 
b/source/gameengine/Rasterizer/RAS_Polygon.h
index b18477a..597e80f 100644
--- a/source/gameengine/Rasterizer/RAS_Polygon.h
+++ b/source/gameengine/Rasterizer/RAS_Polygon.h
@@ -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();

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to