Topic: access to the mesh bones

Hi, I have a question about Maratis Engine.
if I import a mesh that has several bones, how can I stock them into a MOBone* variable ? (the bones don't appear in the maratis 3d view)

I thought that they were considered like mesh children but they aren't.

Re: access to the mesh bones

Hi !

Hi, I have a question about Maratis Engine.
if I import a mesh that has several bones, how can I stock them into a MOBone* variable ? (the bones don't appear in the maratis 3d view)

What do you mean by "stock them" ?
Otherwise, to get bones from a mesh entity in c++, you can do like that :

MEngine * engine = MEngine::getInstance();
MLevel * level = engine->getLevel();

// get current scene
MScene * scene = level->getCurrentScene();

// get bone 0 from a mesh entity
MOEntity * entity = scene->getEntityByName("MyEntity");
if(entity)
{
    MMesh * mesh = entity->getMesh();
    if(mesh)
    {
        MArmature * armature = mesh->getArmature();
        if(armature)
        {
            MOBone * bone = armature->getBone(0); // get bone 0
        }
    }
}

Re: access to the mesh bones

that's perfect, I didn't see the methode "MArmature *  getArmature (void) " in the MMesh class,
that's all I wanted to know, thanks wink

Re: access to the mesh bones

cool smile
I'm waiting to see what you are working on wink

Re: access to the mesh bones

Hi, I have other questions about bones and Maratis engine wink :

suppose we have a MOBone named Bone0, how can we move him (Euler rotation like in Blender Pose mode, for example ) ?
how can we, with maratis Engine, play, stop and change mesh animations ?
and finally, does animations using shape keys work in maratis ?

Re: access to the mesh bones

Hi,

to move a bone, you have access to all the MObject3d functions (MOBone derive from MObject3d),
for example, the rotation/translation (there is a lot more, you can look at MObject3d.h for more detail) :

bone->setEulerRotation(euler);
bone->addAxisAngleRotation(axis, angle);
bone->setPosition(position);

Be just careful that there is no keyframes associated with the bone, or it will discard your changes.
If you want to remove keyframes for a specific bone, lets say the bone 0 for example, you can do :

MArmatureAnim * armatureAnim = mesh->getArmatureAnim();
if(armatureAnim)
{
    // get bones anim array
    MObject3dAnim * bonesAnim = armatureAnim->getBonesAnim();

    // clear bone 0 keys
    bonesAnim[0].clearPositionKeys();
    bonesAnim[0].clearScaleKeys();
    bonesAnim[0].clearRotationKeys();
}


To play/stop animation (you can look at MOEntity.h for more animation related functions) :

entity->changeAnimation(animationId);


And for shape keys animation, I started working on it and wrote the MMorphingData class,
but I didn't finished to implement it, maybe you can help by studying how to improve the Blender python script exporter
to export Blender shape keys ?

Cheers,
Anaël.

Re: access to the mesh bones

Anaël wrote:

maybe you can help by studying how to improve the Blender python script exporter
to export Blender shape keys ?

thank you for you fast response wink
I am afraid it's quite over my faculties, I am sorry.

I made a very basic behavior to test mesh deforming by moving a bone, but the mesh didn't deform itself, can you see where the problem is, please ?

update methode wrote:

int i =0.0;

void Behavior::update(void)
{
    MEngine * engine = MEngine::getInstance();
    MGame * game = engine->getGame();

    if(! game->isRunning())
    {
        i=0;
        return;
    }
    MOEntity * parent = (MOEntity *) getParentObject();
    MVector3 vector;
    MVector3 vector2;
    MSystemContext * system = engine->getSystemContext();
    MInputContext * input = engine->getInputContext();
                if(input->isKeyPressed("A"))
                {
                i++;
                if (i>360)
                {
                    i=i-360;
                }
                vector2.x=i;
                vector2.y=i;
                vector2.z=0.0;
                parent->setEulerRotation(vector2); // this work perfectly
                }
if(parent)
{
    MMesh* mesh = parent->getMesh();
    if(mesh)
    {
        MArmature * armature = mesh->getArmature();
        if(armature)
        {
            MOBone* bone=armature->getBone(0);
            if(bone)
            { // bone has indeed a no NULL adress here
            if(input->onKeyDown("MOUSE_BUTTON1"))
            {
                vector.x=0.0;
                vector.y=1.0;
                vector.z=1.0;
            bone->addAxisAngleRotation(vector,i); // nothing doing here
            }
            }
        }
    }
}

}

Last edited by Alinor (2011-08-20 12:33:11)

Re: access to the mesh bones

Hi,

"input->onKeyDown("MOUSE_BUTTON1")" is launched only 1 frame just after you press the mouse button (not every frames).
You maybe want to use "isKeyPressed("MOUSE_BUTTON1")".

You maybe also have animation keys that cancel your changes,
try to not export, or delete the Armature Animation file from Blender (.maa),
or use the piece of code I gave you in the previous post to remove keys for a specific bone.

Re: access to the mesh bones

Thanks for the answer, I am sorry but it doesn't work, I probably made a mistake in the mesh creation :

in blender :
I created a plane that I subdivided 5-6 times and a single bone that I extruded 3 times.
I selected the plane and the bone and "ctrl+p -> armature deform with empty group".
and for each bone  I selected some faces that I assigned to the bone.
http://img11.hostingpics.net/pics/541674mara2.png
and I exported this (mesh + armature) in maratis mesh without "armature anim".

In Maratis :
I imported the mesh and gave to it my behavior
http://img11.hostingpics.net/pics/949431mara1.png

do you see an error somewhere, please ?

Last edited by Alinor (2011-08-21 12:28:52)

Re: access to the mesh bones

Look at the .mesh file with a text editor and check that you have armature and bones inside.
Or send me the file.

Also, I looked at your behavior code again,
you do : "bone->addAxisAngleRotation(vector,i);"
but "i" is equal to zero, so it won't add any rotation,

try : "bone->addAxisAngleRotation(vector, 10);"

Re: access to the mesh bones

there isn't further reaction ...

apparently there are well bones in the .mesh file :

armature.mesh wrote:

<Bones num="4">
    <Bone id="0" name="Bone">
        <position x="-2.618241" y="0.000000" z="0.000000" />
        <rotation x="89.999992" y="100.106392" z="0.000001" />
        <scale x="1.000000" y="1.000000" z="1.000000" />
    </Bone>
    <Bone id="1" name="Bone.001">
        <parent id="0" />
        <position x="0.000000" y="1.000094" z="-0.000000" />
        <rotation x="5.679412" y="-179.110901" z="19.974031" />
        <scale x="1.000000" y="1.000000" z="1.000000" />
    </Bone>
    <Bone id="2" name="Bone.002">
        <parent id="1" />
        <position x="0.000000" y="1.355897" z="-0.000000" />
        <rotation x="0.072250" y="0.357129" z="24.149242" />
        <scale x="1.000000" y="1.000000" z="1.000000" />
    </Bone>
    <Bone id="3" name="Bone.003">
        <parent id="2" />
        <position x="0.000000" y="1.801812" z="-0.000000" />
        <rotation x="5.126833" y="-0.721032" z="-7.293643" />
        <scale x="1.000000" y="1.000000" z="1.000000" />
    </Bone>
</Bones>

here is the all .mesh

thanks for helping me wink

Last edited by Alinor (2011-08-21 15:00:32)

Re: access to the mesh bones

Ok, I understood, I forget that when there is no animations,
the armature is not updated.

Just call this after you finish moving your bones and it should work :

armature->processBonesLinking();
armature->updateBonesSkinMatrix();

So, to summary here is a code to rotate a bone :

if(mesh)
{
       MArmature * armature = mesh->getArmature();
       if(armature)
       {
           MOBone * bone = armature->getBone(0); // be sure the bone exist
           bone->addAxisAngleRotation(MVector3(1, 0, 0), 10);
            
           armature->processBonesLinking();
           armature->updateBonesSkinMatrix();
       }
}

Re: access to the mesh bones

this time it's works perfectly, thanks a lot  wink

Last edited by Alinor (2011-08-21 18:22:03)