[ogre 13] custom skeletons with identical meshes

Problems building or running the engine, queries about how to use features etc.
Post Reply
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

[ogre 13] custom skeletons with identical meshes

Post by loath »

i need to create custom skeletons for identical meshes. i have this working as a prototype but i want to ensure i'm using "supported" APIs as opposed to accidentally hacking this together.

scenario:
say i have a mesh and i want to create two entities. one with skeleton A and another with skeleton B. (both skeletons are identical except each has a different combinations of animations)

1. should i clone the mesh so there is a 1-1 relationship between mesh and skeleton? this produces 3 identical meshes but each with a different skeleton.

Code: Select all

// pseudocode
auto meshA = mesh->clone(); // meshA will use skeletonA
meshA->notifySkeleton (skeletonA);
auto entityA = scene->createEntity (meshA); // entityA uses skeletonA

auto meshB = mesh->clone(); // meshB will use skeletonB
meshB->notifySkeleton (skeletonB); 
auto entityB = scene->createEntity (meshB); // entityB uses skeletonB

2. or can i reuse the same mesh which saves memory and assign the skeleton to the mesh just prior to creating each entity?

Code: Select all

// pseudocode
mesh->notifySkeleton (skeletonA);
auto entityA = scene->createEntity (mesh); // entityA uses skeletonA

mesh->notifySkeleton (skeletonB);
auto entityB = scene->createEntity (mesh); // entityB uses skeletonB

mesh->notifySkeleton (master); // restore the original master skeleton
3. is there a better way to approach this?

thanks!
User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 449
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 156

Re: [ogre 13] custom skeletons with identical meshes

Post by sercero »

Quite a puzzle you posted here, I think that you will have to try both options unless @paroj comes with the answer.

I would venture that option B won't work because the second entity will end up using the same skeleton when you modify the mesh but can't tell for sure.

Another thing: do you really need to separate the animations in different skeletons?

Why not use a single skeleton and only enable the animations you need?
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: [ogre 13] custom skeletons with identical meshes

Post by paroj »

does SkeletonInstance not do exactly what you want?
https://ogrecave.github.io/ogre/api/lat ... ml#details
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [ogre 13] custom skeletons with identical meshes

Post by loath »

sercero wrote: Sun Oct 24, 2021 4:35 am Quite a puzzle you posted here, I think that you will have to try both options unless @paroj comes with the answer.

I would venture that option B won't work because the second entity will end up using the same skeleton when you modify the mesh but can't tell for sure.

Another thing: do you really need to separate the animations in different skeletons?

Why not use a single skeleton and only enable the animations you need?
thanks for the response sercero! both options work so i'm currently going with option B since it's simpler but it obviously feels hacky.

my goal is a torchlight 2 style approach to produce many variations of entities from a small set of mesh parts and animations. for example, using different heads, arms, legs etc. it appears torchlight uses a "master" skeleton (with bones but no animations) and then they apply a set of animations (skeletons with the same bones but a single animation per file) depending on which weapon or equipment you have configured. for example, equipping a gun uses "walk_gun", "attack_gun", "idle_gun" vs using a sword which would use "walk_sword", "attack_sword", "idle_sword".

the goal of "custom" skeletons vs a single "super" skeleton (with all animations) would just be to keep each skeleton as small as possible for memory and performance.
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [ogre 13] custom skeletons with identical meshes

Post by loath »

paroj wrote: Sun Oct 24, 2021 11:34 am does SkeletonInstance not do exactly what you want?
https://ogrecave.github.io/ogre/api/lat ... ml#details
thanks paroj! the only way i see to change the skeleton instance is via the public Entity::_initialise () function which is basically option 2... i.e. it would create a new instance based on calling mesh->getSkeleton ().

Code: Select all

void Entity::_initialise(bool forceReinitialise)
{
        ... code omitted here ...

        if (mMesh->hasSkeleton() && mMesh->getSkeleton())
        {
            mSkeletonInstance = OGRE_NEW SkeletonInstance(mMesh->getSkeleton());
            mSkeletonInstance->load();
            // if mUpdateBoundingBoxFromSkeleton was turned on before the mesh was loaded, and mesh hasn't computed the boneBoundingRadius yet,
            if ( mUpdateBoundingBoxFromSkeleton && mMesh->getBoneBoundingRadius() == Real(0))
            {
                mMesh->_computeBoneBoundingRadius();
            }
        }

        ... code omitted here ...
}
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [ogre 13] custom skeletons with identical meshes

Post by loath »

code review comment of the entity code above:

seems like the mesh should calculate it's bounding radius just once ahead of time and not require the entity to check and potentially do so.

Code: Select all

// if mUpdateBoundingBoxFromSkeleton was turned on before the mesh was loaded, and mesh hasn't computed the boneBoundingRadius yet,
            if ( mUpdateBoundingBoxFromSkeleton && mMesh->getBoneBoundingRadius() == Real(0))
            {
                mMesh->_computeBoneBoundingRadius();
            }
perhaps if you've just called mesh->notifySkeleton (skeleton) or mesh->setSkeletonName() you could then call mesh->_computeBoneBoundingRadius(). you may NOT even want to call it if you know the bones have not changed and don't want to waste performance on a recalculation.

(note that i don't use mesh->setSkeletonName() because it triggers a clear and reinit of the mesh buffers which is wasteful plus my meshes are manually created anyway)

also, instead of calling mesh->hasSkeleton() we could just do:

Code: Select all

auto skeleton = mesh->GetSkeleton();
if (skeleton)
{
	mSkeletonInstance = OGRE_NEW SkeletonInstance(skeleton());
        mSkeletonInstance->load();
        // bounding already calculated
}
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: [ogre 13] custom skeletons with identical meshes

Post by paroj »

loath wrote: Sun Oct 24, 2021 4:13 pm thanks paroj! the only way i see to change the skeleton instance is via the public Entity::_initialise () function which is basically option 2... i.e. it would create a new instance based on calling mesh->getSkeleton ().
yes, that would only work with a "super skeleton", but I think you already were aware of this. I must admit I do not use skeletal animations besides fixing samples.
loath wrote: Sun Oct 24, 2021 4:13 pm the goal of "custom" skeletons vs a single "super" skeleton (with all animations) would just be to keep each skeleton as small as possible for memory and performance.
I think you should benchmark/ measure that. There should be only a cost for active animations and if you split the animations over multiple skeletons the total storage requirement would be the same.

Also, there is this to inject animations from matching skeletons:
https://ogrecave.github.io/ogre/api/lat ... ed0a7eac64
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: [ogre 13] custom skeletons with identical meshes

Post by paroj »

loath wrote: Sun Oct 24, 2021 6:53 pm code review comment of the entity code above:

seems like the mesh should calculate it's bounding radius just once ahead of time and not require the entity to check and potentially do so.
looks like the behavior was introduced on purpose:
https://github.com/OGRECave/ogre/commit ... 20d601419f
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [ogre 13] custom skeletons with identical meshes

Post by loath »

paroj wrote: Mon Oct 25, 2021 12:34 pm
loath wrote: Sun Oct 24, 2021 4:13 pm thanks paroj! the only way i see to change the skeleton instance is via the public Entity::_initialise () function which is basically option 2... i.e. it would create a new instance based on calling mesh->getSkeleton ().
yes, that would only work with a "super skeleton", but I think you already were aware of this. I must admit I do not use skeletal animations besides fixing samples.
loath wrote: Sun Oct 24, 2021 4:13 pm the goal of "custom" skeletons vs a single "super" skeleton (with all animations) would just be to keep each skeleton as small as possible for memory and performance.
I think you should benchmark/ measure that. There should be only a cost for active animations and if you split the animations over multiple skeletons the total storage requirement would be the same.

Also, there is this to inject animations from matching skeletons:
https://ogrecave.github.io/ogre/api/lat ... ed0a7eac64
this is fantastic! must be the approach runic took with torchlight. i'll put this all together and benchmark it to determine the final plan. thanks again!
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [ogre 13] custom skeletons with identical meshes

Post by loath »

paroj wrote: Mon Oct 25, 2021 12:39 pm
loath wrote: Sun Oct 24, 2021 6:53 pm code review comment of the entity code above:

seems like the mesh should calculate it's bounding radius just once ahead of time and not require the entity to check and potentially do so.
looks like the behavior was introduced on purpose:
https://github.com/OGRECave/ogre/commit ... 20d601419f
ah good to know.
Post Reply