Page MenuHome

BGE: Fix T38030: wrong vertex index returned by KX_PolyProxy
ClosedPublic

Authored by Porteries Tristan (panzergame) on May 24 2015, 2:11 PM.

Details

Summary

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.

Diff Detail

Repository
rB Blender
Branch
ge_poly_vertex_index

Event Timeline

Add function GetVertexOffsetAbsolute.

I don't know if that would mess up the mesh, but wouldn't it better to calculate the correct vertex offset before it will be set with SetVertexOffset().

source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
292

unsigned int

source/gameengine/Rasterizer/RAS_MaterialBucket.h
89

Unsigned short is maybe the value range is to small for big meshes. Should be changed to Unsigned int.

source/gameengine/Rasterizer/RAS_MeshObject.h
134–135

I think this cloud be deleted. If you want to keep it, move it into RAS_MeshObject.cpp in RAS_MeshObject::EndConversion().

source/gameengine/Rasterizer/RAS_Polygon.h
74–75

Look like that GetVertexOffset() is now unused, because GetVertexOffsetAbsolute() is now used instead. One of the methods should be deleted.
I prefer to keep GetVertexOffset() and modify the code to return the absolute offset.

Forget the comment about SetVertexOffset().

We can't set the array offset with SetVertexOffset because this function is called for each polygon during the array construction and we will get incorrect index.
[EDIT : i didn't see your last comment]

source/gameengine/Rasterizer/RAS_Polygon.h
74–75

I think that it's useful to keep the function GetVertexOffset(), It can be used later for mesh generation ect …

Use unsigned int instead of unsigned short for offset, move comment block of EndConversion in the .cpp.

source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
293

You need to change the iterator to unsigned int too.

Note:
I don't made a comment on this line because it was obviously for me that this need to be changed too. I don't want to make a comment for every line that need to be changed too.

source/gameengine/Rasterizer/RAS_Polygon.cpp
65–68

GetVertexOffset() is now not unused anywhere. One of the methods should be deleted.
I prefer to delete GetVertexOffsetAbsolute() and keep GetVertexOffset() and modify the code to return the absolute offset (return m_offset[i] + m_darray->m_offset;). Then the modifications in KX_PolyProxy.cpp are not necessary.
Don't forget to change the the return type to unsigned int .

70

unsigned int for the return type.

Porteries Tristan (panzergame) marked 3 inline comments as done.Jun 4 2015, 1:37 PM
Porteries Tristan (panzergame) added inline comments.
source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
293

why ? the 'i' value is the current vertex array index, it can't be more than 2 (Line, Tri, Quad).

source/gameengine/Rasterizer/RAS_Polygon.cpp
65–68

What do you think to rewrite the function ? :
GetVertexOffset(int index, bool absolute=true)

source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
293

I am sorry, I don't checked what the maximum value of m_displayArrays is. In that case you can leave unsigned short.

source/gameengine/Rasterizer/RAS_Polygon.cpp
65–68

I think we don't need to do this. There is actually no usage for getting a non absolute vertex offset.
We should not keep unused or add unused functionality to methods.

int RAS_Polygon::GetVertexOffset(int i)
{
    return m_offset[i] + m_darray->m_offset;
}

You can also keep your new GetVertexOffsetAbsolute(), and delete the old one, if you like the new method name more.

Remove function GetVertexOffset and use unsigned int instead of int for returned value and unsigned short for the function argument.

Thomas Szepe (hg1) edited edge metadata.

Looks good to me.

This revision is now accepted and ready to land.Jun 4 2015, 6:10 PM

Looking at the original T38030 problem:

  • why make a new function? People will still use the old function and think it doesn't work properly sometimes. Why would one use the old vs this new function?
  • does this fix the problem with mixed materials as well?

pointed a few typos.

I see now that it was supposed to be a function rename, not a new function.
Are we sure about the name change? How about SetVertexOffset ? does it need to consider the different lists too?

(This is not at all my area, I'm just trying to help. I really can't give feedback on the overall solution as I don't know the design)

source/gameengine/Rasterizer/RAS_MaterialBucket.h
85

lists not listes

175

display

179

avoid doing cleanup mixed with functional changes. (not ultra important, though. for next time)

Angus Hollands (agoose77) edited edge metadata.

Provided it solves the test case, and all pending comments are addressed, I'm happy with this revision.

Porteries Tristan (panzergame) edited edge metadata.

Fix some comment message and remove cleanup.

source/gameengine/Rasterizer/RAS_Polygon.cpp
65–68

To be clear : i prefer keep the name "GetVertexOffsetAbsolute" and not "GetVertexOffset" because we have a setter named "SetVertexoffset" and a getter with the same name must be return the same value, but here is not the case.