Raycasting to the polygon level [solved]

Problems building or running the engine, queries about how to use features etc.
gabrielrodriguez
Gnoblar
Posts: 1
Joined: Mon Nov 30, 2009 8:26 pm

Re: Raycasting to the polygon level [solved]

Post by gabrielrodriguez » Sun Apr 18, 2010 11:35 am

Hey Guys,

Just a quick doubt. Is there a particular performance reason why m_pray_scene_query (a RaySceneQuery object) is declared globally outside the RaycastFromPoint function?.
0 x

mikademus
Halfling
Posts: 54
Joined: Wed Jun 25, 2008 6:38 pm

Re: Raycasting to the polygon level [solved]

Post by mikademus » Sun May 09, 2010 10:28 pm

There is a bug in the Wiki code. GetMeshInformation did not take into consideration that SubMeshes' indexData member could have startIndex > 0. This is the fixed code.

Code: Select all

                size_t offset = submesh->useSharedVertices ? shared_offset : current_offset;
                size_t index_start = index_data->indexStart;
                size_t last_index = numTris*3 + index_start;

                if (use32bitindexes)
                    for (size_t k = index_start; k < last_index; ++k)
                    {
                        indices[index_offset++] = pLong[k] + static_cast<unsigned long>( offset );
                    }

                else
                    for (size_t k = index_start; k < last_index; ++k)
                    {
                        indices[ index_offset++ ] = static_cast<unsigned long>( pShort[k] ) +
                            static_cast<unsigned long>( offset );
                    }
I have updated the Wiki code. Please help test this for stability.
0 x

User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
Contact:

Re: Raycasting to the polygon level [solved]

Post by Beauty » Thu Oct 27, 2011 4:06 pm

mikademus, your thoughts about indexStart are interesting.
Nevertheless I suppose that your code would cause a crash if indexStart is larger than 0.

The amount of triangles is defined by this line:

Code: Select all

size_t numTris = index_data->indexCount / 3; 
You added these condition variables:

Code: Select all

size_t index_start = index_data->indexStart;
// The loop break condition you calculate by this:
size_t last_index = numTris*3 + index_start;
This means the break condition is equal to:

Code: Select all

size_t last_index = (index_data->indexCount / 3) * 3 + index_data->indexStart;
// Which is equal to:
size_t last_index = index_data->indexCount + index_data->indexStart;
The problem:
When index_data->indexStart is larger than 0,
then "last_index" is larger than the size of "index_data".

In this case the loop code would try to access to a non existing value of the array.
The result would be a crash (out of "range exception"):

Code: Select all

    for (size_t k = index_start; k < last_index; ++k)
    {
        indices[index_offset++] = ...  // CRASH
    }

So I would suggest to change the loop condition to:

Code: Select all

                          k < index_data->indexCount
By the way - What's the reason that the Ogre developers added index_data->indexStart?


An other topic:
For me it seems so that the polygon raycasting only works for render type OT_TRIANGLE_LIST.
If a mesh contains an other "triangle definition style" or lines or points, then the code can return wrong results.
Or a crash happens when the size of the index list is not divisible by 3.
Details and improvement suggestions I published in this topic.
0 x
Help to add information to the wiki. Also tiny edits will let it grow ... :idea:
Add your country to your profile ... it's interesting to know from where of the world you are.

JDX_John
Gnome
Posts: 397
Joined: Sat Nov 08, 2008 1:59 pm

Re: Raycasting to the polygon level [solved]

Post by JDX_John » Fri Dec 30, 2011 6:13 pm

I noted that the wiki version doesn't compile:
error C2039: 'getWorldPosition' : is not a member of 'Ogre::SceneNode'
error C2039: 'getWorldOrientation' : is not a member of 'Ogre::Node'
In:

Code: Select all

				getMeshInformation(pentity->getMesh(), vertex_count, vertices, index_count, indices,             
					pentity->getParentNode()->getWorldPosition(),
					pentity->getParentNode()->getWorldOrientation(),
					pentity->getParentNode()->_getDerivedScale());
I assume Ogre API changed and we should use:

Code: Select all

					pentity->getParentNode()->_getDerivedPosition(),
					pentity->getParentNode()->_getDerivedOrientation(),
But I wanted to make sure before I update the wiki.
0 x

User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
Contact:

Re: Raycasting to the polygon level [solved]

Post by Beauty » Fri Dec 30, 2011 8:51 pm

Thanks for your note.
You are right, the API changed and unfortunately the getWorldXxx() functions were removed. (Although it's title is more clear than getDerivedXxx)
It would be great if you update the wiki.

Two months ago I re-wrote the polygon raycasting code from the scratch.
Now it supports all rendering types and can detect ManualObjects, too.
Also I suppose that the code is more performant than the current one of the wiki.
An almost complete "preview version" I posted here:
http://www.ogre3d.org/forums/viewtopic. ... 83#p446083
If you like, you can have a look. It's attached to the linked post.
When I tested/polished my code, I will publish it again. Suscribe the linked topic (at the page bottom) and you will get a message when the day comes.

By the way:
I created an other topic called IndexData::indexStart - questions/usage.
There I got an answer from Sinbad about the background.
Details are here: http://www.ogre3d.org/forums/viewtopic. ... 69#p446069
0 x
Help to add information to the wiki. Also tiny edits will let it grow ... :idea:
Add your country to your profile ... it's interesting to know from where of the world you are.

JDX_John
Gnome
Posts: 397
Joined: Sat Nov 08, 2008 1:59 pm

Re: Raycasting to the polygon level [solved]

Post by JDX_John » Sat Dec 31, 2011 4:06 pm

Beauty wrote:Two months ago I re-wrote the polygon raycasting code from the scratch.
Now it supports all rendering types and can detect ManualObjects, too.
Also I suppose that the code is more performant than the current one of the wiki.
An almost complete "preview version" I posted here:
http://www.ogre3d.org/forums/viewtopic. ... 83#p446083
I had seen that topic, but had not realised it supported the Mesh version as well as MO... I thought you had written a MO version of the Mesh version only.

In your version, do you support all the other extensions to the original, like animations, etc?
0 x

User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
Contact:

Re: Raycasting to the polygon level [solved]

Post by Beauty » Sun Jan 01, 2012 3:48 am

Yes, it also support entity/mesh detection.
I don't need it for my application, but I wanted to write an almost complete detection class, because this is useful for many Ogre users.

Also animation is supported.
In an other topic I had a discussion related to animantion. My code should process both: software based and hardware based animations.

The IndexData::indexStart feature is currently not included, because I didn't know the background when I wrote it.
Now I know and want to add it optionally. (Even if an application uses this very special feature, it can be useful to recognize all vertices instead of the reduced co-domain. Look to the indexStart topic for details.)
I suppose in normal cases the indexStart feature is not needed. It's only needed if an Ogre programmer creates entities by code or his own mesh tool, which uses this very special feature. When you load meshes from files (which are created by a common Ogre exporter), the indexStart feature isn't needed.

On the wiki page is a modified code of GetMeshInformation():
The versions of GetMeshInformation() fails on 64 bit machines using GCC.
I compared the codes line by line and found only one difference.
Because of the lack of documentation I added a note to the wiki:
Difference:
  • Changed type of "indices" from long (uint64) to uint32
Well, I didn't recognized this difference and don't know if my code would run with 64bit GCC.
But it should be easy to modify my code to get it run.
Additionally a "common Ogre user" needs to port my code from C# to C++ :mrgreen:
This should be easy, too, because the code is similar to C++. (My code is C#, because I use Mogre.)
If anybody do so, please publish the result. If you add differences, please write down the details.

Feedback is always welcome.
0 x
Help to add information to the wiki. Also tiny edits will let it grow ... :idea:
Add your country to your profile ... it's interesting to know from where of the world you are.

User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
Contact:

Re: Raycasting to the polygon level [solved]

Post by Beauty » Sun Jan 01, 2012 4:41 am

I looked to the "adapted version 2" again and added further "important" notes to the wiki page:
Difference:
  • Changed type of "indices" from long (uint64) to uint32
Important:
  • Every sub mesh can contain up to 2^32 indices.
  • If the whole mesh has more than 2^32 indices, the code will crash at: ''indices = new Ogre::uint32[index_count]''
  • In this code is no security check or special treatment for "uint32 overflow".
  • Suggestion: Use this modified code only if really needed.
0 x
Help to add information to the wiki. Also tiny edits will let it grow ... :idea:
Add your country to your profile ... it's interesting to know from where of the world you are.

JDX_John
Gnome
Posts: 397
Joined: Sat Nov 08, 2008 1:59 pm

Re: Raycasting to the polygon level [solved]

Post by JDX_John » Mon Jan 02, 2012 7:02 pm

Another question - I have it working nicely but when I inspected the results of the Ray Query, I noted it contained results for cameras as well as entities. Obviously these get ignored but it didn't seem ideal. I even changed my init code but this made no difference:

Code: Select all

		m_query = m_sceneManager.createRayQuery(Ray(),SceneManager::ENTITY_TYPE_MASK);
Is there a simple fix to this minor issue?
0 x

User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
Contact:

Re: Raycasting to the polygon level [solved]

Post by Beauty » Mon Jan 02, 2012 8:39 pm

Sorry, I have no idea for this behaviour.
I would check if result == entity and if not, then go on with the next result.
0 x
Help to add information to the wiki. Also tiny edits will let it grow ... :idea:
Add your country to your profile ... it's interesting to know from where of the world you are.

User avatar
PsyCowboy
Halfling
Posts: 74
Joined: Fri Apr 24, 2009 8:01 am

Re: Raycasting to the polygon level [solved]

Post by PsyCowboy » Wed May 09, 2012 3:35 pm

I would like to retrieve information about uv mapping in the GetMeshInformation function.

Does somebody has any clue about where this information can be found? Do you think this is possible?
0 x

Post Reply