Raycast to the polygon level after animation transform

Problems building or running the engine, queries about how to use features etc.
Post Reply
sms1986
Gnoblar
Posts: 24
Joined: Thu Jun 12, 2008 8:17 pm

Raycast to the polygon level after animation transform

Post by sms1986 »

I found this old thread about this issue:
http://www.ogre3d.org/forums/viewtopic.php?f=2&t=23440

Recently an user wrote over there:
CurlyHairedGenius wrote:I know this is kind of an old thread...
I would like to use this method for some collision detection, but I noticed it does not take into account the animation transforms.
Is there a way to raycast to the polygon level at the current animation state.
I think there should be a way to redo the GetMeshInformation function but I'm not exactly sure on the particulars.
I was thinking it could be done at the entity level instead of the mesh level something along the lines of:

Ogre::VertexData * vData = ent->_getHardwareVertexAnimVertexData();
const Ogre::VertexElement* pElem = vData->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
Ogre::HardwareVertexBufferSharedPtr vBuf = vData->vertexBufferBinding->getBuffer(pElem->getSource());
unsigned char* vert = static_cast<unsigned char*>(vBuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));

I am pretty new to ogre and I feel like I know this is incomplete...
Does anyone have any ideas on how to raycast to the polygon level after the animation transforms?
I tried to get some help in that topic but maybe due the [solved] on the title nobody is reading that.

As CurlyHairedGenius said, I tried to modify GetMeshInformation method to use _getHardwareVertexAnimVertexData or _getSkelAnimVertexData but apparently both fail on the assertions tests:
assert (mHardwareVertexAnimVertexData && "Not vertex animated or has no shared vertex data!"); and assert (mSkelAnimVertexData && "Not software skinned or has no shared vertex data!"); respectively.

I don't know why these assertions fail because, in each case, the entity used returns true on hasVertexAnimation or hasSkeleton so they should have mHardwareVertexAnimVertexData or mSkelAnimVertexData initialized right?

I am new to ogre and appreciate any help.
User avatar
gerds
Goblin
Posts: 260
Joined: Mon Sep 01, 2003 3:59 am
Location: London, United Kingdom
x 1

Re: Raycast to the polygon level after animation transform

Post by gerds »

I'm not sure exactly what your problem is but I do know that you will have to request that the animations are calculated in software (ie: Ogre::Entity::addSoftwareAnimationRequest) and you will also have to perform your raycasting after the animations have been updated (if you want them to be accurate to the frame).
void Ogre::Entity::addSoftwareAnimationRequest ( bool normalsAlso )

Add a request for software animation.


Remarks:
Tells the entity to perform animation calculations for skeletal/vertex animations in software, regardless of the current setting of isHardwareAnimationEnabled(). Software animation will be performed any time one or more requests have been made. If 'normalsAlso' is 'true', then the entity will also do software blending on normal vectors, in addition to positions. This advanced method useful for situations in which access to actual mesh vertices is required, such as accurate collision detection or certain advanced shading techniques. When software animation is no longer needed, the caller of this method should always remove the request by calling removeSoftwareAnimationRequest(), passing the same value for 'normalsAlso'.
sms1986
Gnoblar
Posts: 24
Joined: Thu Jun 12, 2008 8:17 pm

Re: Raycast to the polygon level after animation transform

Post by sms1986 »

gerds wrote:I'm not sure exactly what your problem is but I do know that you will have to request that the animations are calculated in software (ie: Ogre::Entity::addSoftwareAnimationRequest) and you will also have to perform your raycasting after the animations have been updated (if you want them to be accurate to the frame).
void Ogre::Entity::addSoftwareAnimationRequest ( bool normalsAlso )

Add a request for software animation.


Remarks:
Tells the entity to perform animation calculations for skeletal/vertex animations in software, regardless of the current setting of isHardwareAnimationEnabled(). Software animation will be performed any time one or more requests have been made. If 'normalsAlso' is 'true', then the entity will also do software blending on normal vectors, in addition to positions. This advanced method useful for situations in which access to actual mesh vertices is required, such as accurate collision detection or certain advanced shading techniques. When software animation is no longer needed, the caller of this method should always remove the request by calling removeSoftwareAnimationRequest(), passing the same value for 'normalsAlso'.
My problem is that when I use that GetMeshInformation method I'm getting the vertices positions of the not animated mesh, but I have an animation running...

I understood what you said but now how should I retrieve the vertex data in that GetMeshInformation method after calling Entity addSoftwareAnimationRequest?

Take a look at a piece of that code:
( http://www.ogre3d.org/wiki/index.php/Ra ... ygon_level )

Code: Select all

Ogre::SubMesh* submesh = mesh->getSubMesh(i);

        Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;

        if((!submesh->useSharedVertices)||(submesh->useSharedVertices && !added_shared))
        {
            if(submesh->useSharedVertices)
            {
                added_shared = true;
                shared_offset = current_offset;
            }

            const Ogre::VertexElement* posElem =
                vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);

            Ogre::HardwareVertexBufferSharedPtr vbuf =
                vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());

            unsigned char* vertex =
                static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
Thanks!
sms1986
Gnoblar
Posts: 24
Joined: Thu Jun 12, 2008 8:17 pm

Re: Raycast to the polygon level after animation transform

Post by sms1986 »

Nobody? :/
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: Raycast to the polygon level after animation transform

Post by Wolfmanfx »

Digg deeper just yesterday i read a thread about this where they generate a collision mesh after each transformation but this is only working if you use software skinning not with hardware skinning.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Raycast to the polygon level after animation transform

Post by jacmoe »

sms1986 wrote:Nobody? :/
Just build that information each frame, and you should be all set. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
GantZ
Kobold
Posts: 33
Joined: Thu Jan 31, 2008 9:23 pm
Location: France

Re: Raycast to the polygon level after animation transform

Post by GantZ »

I've ran into the same problem , and use addSoftwareAnimationRequest as gerds have mention.

I've just call addSoftwareAnimationRequest on the entity creation and get the vertex data using _getSkelAnimVertexData. i think calling _getSkelAnimVertexData make sense only if you use addSoftwareAnimationRequest before. it work ok in my case and i get the correct data. i use mogre, but i don't think it's different in c++. to have more information of how it work, i suggest you to read this thread since it have help me as well .

http://www.ogre3d.org/forums/viewtopic. ... ionRequest
mogre community irc channel at : irc://freenode/#mogre

Image
sms1986
Gnoblar
Posts: 24
Joined: Thu Jun 12, 2008 8:17 pm

Re: Raycast to the polygon level after animation transform

Post by sms1986 »

GantZ wrote:I've ran into the same problem , and use addSoftwareAnimationRequest as gerds have mention.

I've just call addSoftwareAnimationRequest on the entity creation and get the vertex data using _getSkelAnimVertexData. i think calling _getSkelAnimVertexData make sense only if you use addSoftwareAnimationRequest before. it work ok in my case and i get the correct data. i use mogre, but i don't think it's different in c++. to have more information of how it work, i suggest you to read this thread since it have help me as well .

http://www.ogre3d.org/forums/viewtopic. ... ionRequest
Wow, thanks a lot man! It's working now!

I saw the GetEntityInformation method (in the link you posted) and I made a little modification in my GetMeshInformation.

I changed this:

Code: Select all

		if (entity && entity->hasSkeleton()) {
			vertex_data = entity->_getSkelAnimVertexData();
		} else {	
			vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
		}
by

Code: Select all

		if (entity && entity->hasSkeleton()) {
			vertex_data = submesh->useSharedVertices ? entity->_getSkelAnimVertexData() : entity->getSubEntity(i)->_getSkelAnimVertexData();
		} else {	
			vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
		}
And it works fine even without calling entity->addSoftwareAnimationRequest before.
(does somebody know why?)

Here is the whole code:

Code: Select all

void Render::getMeshInformation(const MESH* const mesh, size_t &vertex_count, VECTOR* &vertices, size_t &index_count, unsigned long* &indices, const VECTOR &position, const QUATERNION &orient, const VECTOR &scale, const API_RENDER_OBJECT *entity) {
	bool added_shared = false;
	size_t current_offset = 0;
	size_t shared_offset = 0;
	size_t next_offset = 0;
	size_t index_offset = 0;

	vertex_count = index_count = 0;

	// Calculate how many vertices and indices we're going to need
	for ( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i) {
		Ogre::SubMesh* submesh = mesh->getSubMesh(i);
		// We only need to add the shared vertices once
		if (submesh->useSharedVertices) {
			if (!added_shared) {
				vertex_count += mesh->sharedVertexData->vertexCount;
				added_shared = true;
			}
		} else {
			vertex_count += submesh->vertexData->vertexCount;
		}
		// Add the indices
		index_count += submesh->indexData->indexCount;
	}

	// Allocate space for the vertices and indices
	vertices = new Ogre::Vector3[vertex_count];
	indices = new unsigned long[index_count];

	added_shared = false;

	// Run through the submeshes again, adding the data into the arrays
	for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i) {
		Ogre::SubMesh* submesh = mesh->getSubMesh(i);

		Ogre::VertexData* vertex_data;
		
		/**/
		if (entity && entity->hasSkeleton()) {
			vertex_data = submesh->useSharedVertices ? entity->_getSkelAnimVertexData() : entity->getSubEntity(i)->_getSkelAnimVertexData();
		} else {	
			vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
		}
		
		//Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
				
		if ((!submesh->useSharedVertices) || (submesh->useSharedVertices && !added_shared)) {
			if (submesh->useSharedVertices) {
				added_shared = true;
				shared_offset = current_offset;
			}

			const Ogre::VertexElement* posElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);

			Ogre::HardwareVertexBufferSharedPtr vbuf = vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());

			unsigned char* vertex = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));

			// There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double
			//  as second argument. So make it float, to avoid trouble when Ogre::Real will
			//  be comiled/typedefed as double:
			//Ogre::Real* pReal;
			float* pReal;

			for (size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize()) {
				posElem->baseVertexPointerToElement(vertex, &pReal);
				Ogre::Vector3 pt(pReal[0], pReal[1], pReal[2]);
				vertices[current_offset + j] = (orient * (pt * scale)) + position;
			}
            
			vbuf->unlock();
			next_offset += vertex_data->vertexCount;
		}

		Ogre::IndexData* index_data = submesh->indexData;
		size_t numTris = index_data->indexCount / 3;
		Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
        
		bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);

		unsigned long* pLong = static_cast<unsigned long*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
		unsigned short* pShort = reinterpret_cast<unsigned short*>(pLong);

		size_t offset = (submesh->useSharedVertices)? shared_offset : current_offset;

		if (use32bitindexes) {
			for ( size_t k = 0; k < numTris*3; ++k) {
				indices[index_offset++] = pLong[k] + static_cast<unsigned long>(offset);
			}
		} else {
			for ( size_t k = 0; k < numTris*3; ++k) {
				indices[index_offset++] = static_cast<unsigned long>(pShort[k]) + static_cast<unsigned long>(offset);
			}
		}

		ibuf->unlock();
		current_offset = next_offset;
	}
}
User avatar
GantZ
Kobold
Posts: 33
Joined: Thu Jan 31, 2008 9:23 pm
Location: France

Re: Raycast to the polygon level after animation transform

Post by GantZ »

sms1986 wrote: it works fine even without calling entity->addSoftwareAnimationRequest before.
(does somebody know why?)
that's weird because according to the api
VertexData* Ogre::Entity::_getSkelAnimVertexData ( void ) const

Advanced method to get the temporarily blended skeletal vertex information for entities which are software skinned.

Remarks:
Internal engine will eliminate software animation if possible, this information is unreliable unless added request for software animation via addSoftwareAnimationRequest.

Note:
The positions/normals of the returned vertex data is in object space.
http://www.ogre3d.org/docs/api/html/cla ... 94a6d6853e

i have never try to get the data without calling addSoftwareAnimationRequest to see if the result differ, though.
mogre community irc channel at : irc://freenode/#mogre

Image
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Raycast to the polygon level after animation transform

Post by jacmoe »

It will only work if your model is not using hardware skinning.
If it is, good luck getting the skeletal animation data without an addSoftwareAnimationRequest request. :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
sms1986
Gnoblar
Posts: 24
Joined: Thu Jun 12, 2008 8:17 pm

Re: Raycast to the polygon level after animation transform

Post by sms1986 »

jacmoe wrote:It will only work if your model is not using hardware skinning.
If it is, good luck getting the skeletal animation data without an addSoftwareAnimationRequest request. :)
How can I know if my model is using hardware skinning?
Where or how can I choose use hardware skinning or not?
Thanks!
User avatar
GantZ
Kobold
Posts: 33
Joined: Thu Jan 31, 2008 9:23 pm
Location: France

Re: Raycast to the polygon level after animation transform

Post by GantZ »

you have an example on the ogresdk. see the skeletal animation sample and the example_basic.cg file
mogre community irc channel at : irc://freenode/#mogre

Image
sms1986
Gnoblar
Posts: 24
Joined: Thu Jun 12, 2008 8:17 pm

Re: Raycast to the polygon level after animation transform

Post by sms1986 »

GantZ wrote:you have an example on the ogresdk. see the skeletal animation sample and the example_basic.cg file
Thanks :)
User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
x 39
Contact:

Re: Raycast to the polygon level after animation transform

Post by Beauty »

I wrote a new class for polygon raycasts.
Now I want to extend it for animation support.

In the wiki is a modified GetMeshInformation() code for this usage:
http://www.ogre3d.org/tikiwiki/Raycasti ... ed_version

I suppose it contains the code snippets of this forum topic. Because of the problems with SoftwareVertexAnimation stuff, I added this note to the wiki page:
Note:
This code can cause problems, if the animated model uses hardware skinning.
Look to this forum topic for details.
If my note is wrong, please correct me.

Here is the animation related code from the wiki page:

Code: Select all

   bool useSoftwareBlendingVertices = entity->hasSkeleton();
 
   if (useSoftwareBlendingVertices)
   {
      entity->_updateAnimation();
   }

Code: Select all

      //When there is animation:
      if(useSoftwareBlendingVertices)
         vertex_data = submesh->useSharedVertices ? entity->_getSkelAnimVertexData() : entity->getSubEntity(i)->_getSkelAnimVertexData();
      else
         vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
What's about this code?
Does is cause trouble when a model uses hardware skinning?
Or is it already improved?
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
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Raycast to the polygon level after animation transform

Post by jacmoe »

The code was written to allow software animation with hardware skinned entities.

However, and this is important:

You need to issue a software animation request first!
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Raycast to the polygon level after animation transform

Post by jacmoe »

By the way: the modified version is from OgreOpcode, not Rumi - and it has worked flawlessly since 2005/2006 (IIRC)
It was written by me and Baxissimo.
Based on the original and some KingPrawnVindaloo code. :wink:
We needed exact polygonal data, also for hardware animated entities.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Raycast to the polygon level after animation transform

Post by jacmoe »

Would be nice if you guys would stop creating yet another version...
Why not just update the original thing?? :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
x 39
Contact:

Re: Raycast to the polygon level after animation transform

Post by Beauty »

I have a question about this code:


Code: Select all

   bool useSoftwareBlendingVertices = entity->hasSkeleton();
 
   if (useSoftwareBlendingVertices)
   {
      entity->_updateAnimation();
   }
This code checks Entity::hasSkeleton().
I suppose it would be better to check for Entity::hasVertexAnimation().
Is it right?


API descriptions:
Entity::hasSkeleton() wrote:Returns whether or not this entity is skeletally animated.
Entity::hasVertexAnimation() wrote:Returns whether or not this entity is either morph or pose animated.
Last edited by Beauty on Thu Nov 24, 2011 6:01 pm, edited 1 time in total.
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
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Raycast to the polygon level after animation transform

Post by jacmoe »

Start with this:

Code: Select all

		if (mEntity->hasSkeleton()) {
			mEntity->addSoftwareAnimationRequest(false);
		}
The code you quoted assumes that we are using software animation if the entity has a skeleton.

And when we're done, we need to turn it off:

Code: Select all

		if (mEntity && mEntity->hasSkeleton())
		{
			mEntity->removeSoftwareAnimationRequest(false);
		}
If the original Rumi version could be updated to take that into account.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
x 39
Contact:

Re: Raycast to the polygon level after animation transform

Post by Beauty »

jacmoe wrote:By the way: the modified version is from OgreOpcode, not Rumi - and it has worked flawlessly since 2005/2006 (IIRC)
It was written by me and Baxissimo.
Based on the original and some KingPrawnVindaloo code.
This note was not done by me, but I will update the wiki page.
jacmoe wrote:You need to issue a software animation request first!
Good note.
You mean Entity::getSoftwareAnimationRequests()?
Or shall I call Entity::addSoftwareAnimationRequest() instead?
I'm not shure how to use it, because I have no animation knowledge.

Ogre API
Entity::getSoftwareAnimationRequests() wrote: Returns the number of requests that have been made for software animation.

Remarks:
If non-zero then software animation will be performed in updateAnimation regardless of the current setting of isHardwareAnimationEnabled or any internal optimise for eliminate software animation. Requests for software animation are made by calling the addSoftwareAnimationRequest() method.
Entity::addSoftwareAnimationRequest wrote: Add a request for software animation.

Remarks:
Tells the entity to perform animation calculations for skeletal/vertex animations in software, regardless of the current setting of isHardwareAnimationEnabled(). Software animation will be performed any time one or more requests have been made. If 'normalsAlso' is 'true', then the entity will also do software blending on normal vectors, in addition to positions. This advanced method useful for situations in which access to actual mesh vertices is required, such as accurate collision detection or certain advanced shading techniques. When software animation is no longer needed, the caller of this method should always remove the request by calling removeSoftwareAnimationRequest(), passing the same value for 'normalsAlso'.
jacmoe wrote:Would be nice if you guys would stop creating yet another version...
Perhaps the authors were was afraid to add other problems by updates. (As I saw, this problem happened at the polygon raycasting method related to indexStart. Somewhere I posted details about.)
Also I recognized that there are different parameters for the modified versions.
It was not easy to figure out the code differences.
So you are right. One updated code is better than multiple ones with only slightly differences.
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
x 39
Contact:

Re: Raycast to the polygon level after animation transform

Post by Beauty »

Just for information:
Now I found my bug report. The bug was created by updating the GetMeshInformation() method in the wiki. It' related to vertex buffer::indexStart.
Details I posted here: http://www.ogre3d.org/forums/viewtopic. ... 04#p443304

So it's an example how code can get more buggy by updates. Well, in most cases updates are useful. I just want to say, sometimes it's good to have a backup of the previous version. 8)

By the way:
There is still an unanswered question about indexStart.
I want to regard this property in my polygon query code.
jacmoe, it's one more chance to spread your specialist knowledge again. :mrgreen:
IndexData::indexStart - questions/usage
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
x 39
Contact:

Re: Raycast to the polygon level after animation transform

Post by Beauty »

thanks, jacmoe.

How often do I need to call ...SoftwareAnimationRequest() ?
* For each ray query
* Or only once per mesh in the whole application lifetime

For the second case perhaps it could be useful to memorize, which meshed are still "prepared" for ray query to prevent redundant calls. On the other hand - maybe it doesn't cares if I call it multiple time (e.g. by internal flags or too tiny CPU load).
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
x 39
Contact:

Re: Raycast to the polygon level after animation transform

Post by Beauty »

jacmoe wrote:And when we're done, we need to turn it off:
What you mean with "when we are done"?
After animation update or after checking all vertices?
So which case is better?

1)

Code: Select all

Boolean isAnimated = entity.HasSkeleton;
if (isAnimated)
{
    entity.AddSoftwareAnimationRequest(false);
    entity._updateAnimation();
    entity.RemoveSoftwareAnimationRequest(false);
}

// query all vertices here
2)

Code: Select all

Boolean isAnimated = entity.HasSkeleton;
if (isAnimated)
{
    entity.AddSoftwareAnimationRequest(false);
    entity._updateAnimation();
}

// query all vertices here

if (isAnimated)
    entity.RemoveSoftwareAnimationRequest(false);
jacmoe wrote: If the original Rumi version could be updated to take that into account.
I will do it when I know how to add the code correctly.
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
x 39
Contact:

Re: Raycast to the polygon level after animation transform

Post by Beauty »

I think I found the answer in an other topic. (So it should be case 2)
sinbad wrote:You can't call addSoftwareAnimationRequest / removeSoftwareAnimationRequest like that, because the animation data is not updated at that point (_updateAnimation() will do something at most once per frame, it tries not to update the animation if nothing has changed). addSoftwareAnimationRequest simply registers the intention to access the animation results in software, thus cusing Ogre to perform some calculations in software always and to store the results. It must be done before the animation is updated (which typically happens at frame update time unless you manually trigger it earlier), and you should not remove it until you never want to access the results in software again. Chances are that something else (like frame rendering) is triggering the animation update for that frame while the software request is still off, and thus your animation update request is doing nothing. Leave it on all the time if you intend to access it every frame.

This feature deals with both skeletal and pose animation. As a general rule, if you can avoid having to pull the animation results back in software, do. It's much faster to let the GPU do the animation without the CPU getting involved.
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.
Post Reply