About Store Forum Documentation Contact
Donations:
178$/mo



Post Reply 
How can I get AnimatedSkeleton from Extended Game.Item
Author Message
tipforeveryone Offline
Member

Post: #1
How can I get AnimatedSkeleton from Extended Game.Item
I have an ak47 object which has animated bones (gun's bolt movement)
and here is my custom class which is extended from Game.Item
Code:
class Gun : Game.Item
{
    AnimatedSkeleton animSkel;

    virtual void create(Object &obj){
        super.create(obj);

        //as tutorial, this is how to get animated skeleton from a mesh's skeleton
        animSkel.create(mesh->skeleton(),1.0);

        //but this does not work because below line return an error
      
        if (!mesh->skeleton()) Exit("this mesh has no skeleton");
        //that means my ak47 model does not have skeleton right ?
        //How can I get skeleton of this object?
    }

    virtual bool update(){
        //skel will play my desired animation here
    }
}
(This post was last modified: 06-21-2020 12:58 PM by tipforeveryone.)
06-21-2020 12:56 PM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Member

Post: #2
RE: How can I get AnimatedSkeleton from Extended Game.Item
anyone ? please
06-22-2020 09:46 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Bronze Supporter

Post: #3
RE: How can I get AnimatedSkeleton from Extended Game.Item
Does your gun has skeleton ? You can add skeleton easely thru the game obj editor. I believe you need at least one bone on your obj to be considered skeleton
(This post was last modified: 06-22-2020 05:31 PM by RedcrowProd.)
06-22-2020 05:30 PM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Member

Post: #4
RE: How can I get AnimatedSkeleton from Extended Game.Item
yes it does have animated skeleton, I imported from blender. It works well on preview (while mouse hovering)

This is the gun model with bones
   

and animation is fine with these settings
   

For testing, I copy code from Animation tutorial and replace my gun object and its animation
   

But when I try to implement to my code, it does not work as expected. I will upload my video soon, maybe I did not understand the proper way to use animation for object like Game.Item
06-23-2020 11:12 AM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Member

Post: #5
RE: How can I get AnimatedSkeleton from Extended Game.Item
This how I implement my model
1. Import model into engine from exported fbx (by blender)
2. Create an object class and name it "GUN_CLASS" with some parameters
3. Select GUN_CLASS as class of my model
4. MyGunClass code:
Code:
class MyGunClass : Game.Item
{
    AnimatedSkeleton skel;

    virtual void create(Object &obj){
        super.create(obj);
        skel.create(T.mesh->skeleton(), 1.0);
    }

    virtual bool update(){
        animSkel.updateBegin();
        animSkel.clear();
        animSkel.animate(/*Drag and drop imported animation here*/, Time.time());
        animSkel.updateMatrix();
        animSkel.updateEnd();

        return super.update();
    }
}

5. MyCharacterClass code
Code:
class MyCharacterClass : Game.Chr
{
    ObjectPtr gun_object;
    MyGunClass *my_gun;

    virtual void create(Object &obj){
        super.create(obj);
        gun_object = /*Drag and drop imported model here*/;
        Game.World.objCreate(
            *gun_object,  
            Matrix(wpnModel->scale3(), Vec(0, 1, 1))
        );
        my_gun = &gunList[gunList.elms()-1];
        //Note: gunList was declared in Main
        //Game.ObjMap<MyGunClass> gunList;
    }

    virtual bool update(){
        /*some overriden code here following character tutorial*/
        super.update()
    }
}

6. For debugging, I added this code to display gun's bones to check if it is running animation
Code:
void Draw()
{
   Renderer(Render);
   Renderer.setDepthForDebugDrawing();
   player.currentWeapon.animSkel.draw(RED);
}

and this is what I got, animation is running somehow but, not for the gun, check out this video

https://youtu.be/LPrOfsU-rPY
(This post was last modified: 06-23-2020 03:58 PM by tipforeveryone.)
06-23-2020 03:58 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Bronze Supporter

Post: #6
RE: How can I get AnimatedSkeleton from Extended Game.Item
Well once you declare it to be skel, the update you are doing is for animskel. Can you try using skel instead ?

Hard to see right now im at work on my phone
(This post was last modified: 06-23-2020 05:02 PM by RedcrowProd.)
06-23-2020 05:01 PM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Member

Post: #7
RE: How can I get AnimatedSkeleton from Extended Game.Item
Ah just my typo error, my real code is "animSkel", I rewrite it to "skel" on this post for better reading, therefore the problem is still there, whenever u can check it out, please help, I stuck with this 3 days..
06-24-2020 01:20 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Bronze Supporter

Post: #8
RE: How can I get AnimatedSkeleton from Extended Game.Item
Hi,

It doesnt seems to be working for me either to just call the animation in the animate()

there might be something there that i am missing, nonetheless it says in the func comment to avoid using this one.

if i were you, i would be looking into using either set SkelAnim ( which works well, and that's the way i do it, for longer animation loop, like movement ) or Motion ( for one time trigger animation, like shooting or attacking ).

the tutorial shows how to use motion, if you need help setting up SkelAnim let me know
06-24-2020 01:51 AM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Member

Post: #9
RE: How can I get AnimatedSkeleton from Extended Game.Item
Yes. help me. Give me a look on your code smile I am so new to this engine
06-24-2020 07:28 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Bronze Supporter

Post: #10
RE: How can I get AnimatedSkeleton from Extended Game.Item
pretty simple just have a SkelAnim *SA_YourName=null;

then in your create

SA_YourName= obj.skel.getSkelAnim(UID(youranimUID));

then your update
obj.skel.updateBegin(); // begin update
obj.skel.clear();

obj.skel.animate(SA_YourName, AnimationFlt, 1.0f , true);
obj.skel.animate(SA_YourName2, AnimationFlt, flt_YouranimWeight, true);
obj.skel.animate(SA_YourName3, AnimationFlt, flt_YouranimWeight2, true);
obj.skel.animate(SA_YourName4, AnimationFlt, flt_YouranimWeight3, true);

obj.skel.updateMatrix(obj.matrix()); // update skeleton animation matrixes
obj.skel.updateEnd(); // end update

Note : on this code i use Game.Animatable obj;

but you can do the same with AnimatedSkeleton skel ; // animated skeleton and setting it up correctly with your own matrix ( i just dont see the point, because animatable is what i want smile )
06-25-2020 01:15 AM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Member

Post: #11
RE: How can I get AnimatedSkeleton from Extended Game.Item
Arrggg This drives me crazy, I still can not make my gun animate, even using SkelAnim
Here is my project download link, feel free to adjust, let see you can make it happen :(

https://mega.nz/file/SZsRyQiC#zpz8r8ZgWK...rxAcBfTDus

First press Build and see what happens, Start with CharacterClass, this is before I using SkelAnim
Thank you so much for your support
(This post was last modified: 06-26-2020 01:04 AM by tipforeveryone.)
06-26-2020 01:03 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #12
RE: How can I get AnimatedSkeleton from Extended Game.Item
Code:
virtual bool update()
   {
      {
         animSkel.updateBegin(); // begin update
         animSkel.clear(); // clear skeleton animation
         animSkel.animate(UID(1785919657, 1244929154, 2797312937, 3002806710), Time.time());
         animSkel.updateMatrix(actor.matrix()); // update skeleton animation matrixes
         animSkel.updateEnd(); // end update
      }
      return super.update();
   }
  
   virtual UInt drawPrepare()
   {
      base->mesh()->draw(animSkel);
      
      return 0; //super.drawPrepare();
   }
06-26-2020 04:59 AM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Member

Post: #13
RE: How can I get AnimatedSkeleton from Extended Game.Item
Wow, it works and I understand more about Esentel.!
Thanks admin and RedcrowProd

One more question, I think it is ok to continue this topic like this
How can I play animation 1 time,

example:
if(Ms.bp(0)) skel.animate(animation, 1 time); //mouse click make skel play animation 1 time
06-26-2020 05:48 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Bronze Supporter

Post: #14
RE: How can I get AnimatedSkeleton from Extended Game.Item
use motion, those are especially made for one time animation
06-26-2020 09:16 PM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Member

Post: #15
RE: How can I get AnimatedSkeleton from Extended Game.Item
Can you give me code example, I tried by myself but it does not work, what is the proper way using motion ?
there is no motion tutorial in official tutorial, isn't it?
And how can I use Ms.bp(0) to activate motion?

   
(This post was last modified: 06-27-2020 03:33 AM by tipforeveryone.)
06-27-2020 03:29 AM
Find all posts by this user Quote this message in a reply
Post Reply