Unfortunately it works only for meshes. ManualObjects are ignored.
Now I think about to extend the code for usage with ManualObject.
Currently the raycasting method uses the helper function GetMeshInformation(), which returns all vertices of a mesh.
Now I wonder how it works.
So first I come up with general questions.
Code: Select all
for (int i = 0; i < static_cast<int>(index_count); i += 3)
{
// check for a hit against this triangle
std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(ray, vertices[indices[i]],
vertices[indices[i+1]], vertices[indices[i+2]], true, false);
// ...
}
This should be fine for the rendering type OT_TRIANGLE_LIST.
But what happens if the mesh contain other rendering types? (e.g. OT_TRIANGLE_STRIP or OT_LINE_LIST)
For other rendering types I suppose that the "group of 3" assumptions fails.
The result would be wrong results.
Or in worst case the loop throws a OutOfRange exception.
Example:
* A mesh that contains one triangle and one line
* --> 5 vertices are in the vertex list
* first loop do access to indices[0], indices[1] and indices[2]
* i becomes 3 and the second loop starts
* second loop do access to indices[3], indices[4] and indices[5]
* --> CRASH, because indices[5] does not exists
What do you think?
Is my assumption correct or did I misunderstand something?
If I'm right, it would cause problems when a mesh contains lines.
Is it correct?
An other question:
For my application I want to extend the code for detecting ManualObjects.
I suppose the "logic" should be similar, but I know too less about the internals of ManualObject.
Many of my ManualObjects are a mixture of lines and triangles. Additionally I use mixes rendering types for each of them. (e.g. OT_TRIANGLE_LIST, OT_TRIANGLE_STRIP)
Some of my MOs contains different parts, created by blocks of ManualObject.::begin() ... ManualObject::end().
Are such "block" definitions similar to SubMeshes or is there no hierarchy for ManualObjects?
If all vertices are in one "flat" vertex list -- How I can figure out, which 3-pair vertices are "triangle groups".
I know, I can convert all ManualObjects to Meshes. Then I can detect them with the current code.
But some of my MOs I would prefer to keep them as MOs, because I add more triangles/lines on-the-fly.