Author Topic: Skeletal Animation Idea?  (Read 62155 times)

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Skeletal Animation Idea?
« on: February 06, 2007, 01:52:36 am »
I was just thinking of this. Please tell me if its possible - not if its plausible - I like to do strange things:)....
Its just an example of what I might try...

----
Export model in OBJ format...
----
Make a quick app, to create a list of vertex coords for each "bone".
Perhaps using the pickPolygon to select a few.
----
Save those coords in an xml file.
Also save any skeletal movements.
----
Load actual model in jpct.
----
At load time...
Get mesh somehow, and create a new one, finding the object space coords(same as in modeler? would think so)...
Rotate them around the already found(guessed;)) bone pivots,
and save as a new mesh.
----
Put all the meshes into a keyframe animation like you would with multiple 3ds files, as we once discussed.

Is this possible?


If it is, I would like to make a generic bone editor, and a skeletal-like api,
that could be used if needed.
I do not know how others achieve this effect, but I see it as this:

SimpleVectors,
Rotation Around Pivot(with parent/child)
Storage(in xml) of each bone, its parent/children, and the connected vertexes.
For each mesh vertex, apply rotations.
Make keyframe animation from skeletal stages.

Some form of this is the only thing missing from the jpct features.
It need not be included by default, but as another jar, if needed.

I'd like to do this myself, as my contribution:)
How would I know which vertex is which? Well, by its original coordinate:)
doubles might cause trouble, but I don't own a model that has vertexes in the EXACT same place:)
The bone editor could be programmed to point out these double vertexes, so i dont think its a problem.



Now, whats the point of this? Well, you could get the data for the model, and do the same for clothing, and be able to make a new skeleton animation, without having to manually mess around with all of the clothing sets you've made! I have no idea why I needed to point that out. Its obvious;)

Still, if this is even a tiny possibility, it would be great! An MMORPG game would benefit from such dynamic animation, and it wouldnt have to be blocky.

I heard rolz used a kind of skeleton system by making each limb an object, and rotating them.
It would be like that, but the limbs could be connected, and not hinge-like(I am assuming here, unless you found a way to join the arms with the torso, etc).
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Offline halcor

  • byte
  • *
  • Posts: 28
    • View Profile
Skeletal Animation Idea?
« Reply #1 on: February 06, 2007, 10:12:00 am »
Maybe you can use Blender to make your skeletal animation and write a Python script (if there isn't one already) that exports bones (Blender Python API for reference how to do that, but shouldn't be hard) in some format.

You then load the hierarchy of bones, mesh rest position and data for each vertex which bone it belongs to. Then you can implement IVertexController that for given frame of the bone animation calculates actual vertex positions (I have very vague idea how you do this exactly, however).

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Skeletal Animation Idea?
« Reply #2 on: February 06, 2007, 11:20:22 am »
Sounds good:)

Thanks for responding!

I am beginning to think it is possible to manipulate the vertexes in the way
I would require.

EDIT:
I wonder if there is something already in jpct that allows you to rotate a SimpleVector, around a pivot SimpleVector, in object space:)

This looks like my friend:

Code: [Select]

rotateAxis(SimpleVector axis, float angle)
Rotates the matrix around an arbitrary axis.
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Skeletal Animation Idea?
« Reply #3 on: February 06, 2007, 12:55:50 pm »
XML Export Prototypes...

Code: [Select]

<skeleton>
<bone name="arm" x="0" y="0" z="0">
<bone name="wrist" x="10" y="10" z="10">
</bone>
</bone>
</skeleton>

This is how the bones are stored. Nested to show parents.

Code: [Select]

<vertexgroups>
<group name="arm">
<vertex  x="0" y="0" z="0" />
<vertex  x="2" y="0" z="3" />
<vertex  x="3" y="2" z="1" />
</group>
<group name="wrist">
<vertex  x="7" y="5" z="0" />
<vertex  x="6" y="5" z="5" />
<vertex  x="5" y="5" z="1" />
</group>
</vertexgroups>

This is how a models vertexes could be mapped into an xml file.

Code: [Select]

<animation>
<sequence name="walking">
<keyframe id="1">
<bone name="arm" rotx="3" roty="2" rotz="1" />
<bone name="wrist" rotx="39" roty="92" rotz="91" />
</keyframe>
<keyframe id="2">
<bone name="arm" rotx="4" roty="5" rotz="6" />
</keyframe>
</sequence>
</animation>

This is how the animation sequences could be stored.
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Skeletal Animation Idea?
« Reply #4 on: February 06, 2007, 01:27:30 pm »
How might I "pick" a polygon's vertex using Interact2D?

I know I can get the polygon selected, but is there a way to then get the vertex data?

Perhaps I could get the polygon's position in object space, and then run through
the list of vertexes stolen from VertexController, and highlight the closest vertex to the mouse position? Yes, that might work.

Perhaps if I apply the world transformation onto the object space vertex, before
picking.

EDIT:
I think ive found a way to get the vertexed(just vertex 0 for now)...

Code: [Select]

public SimpleVector getClosestVertex(int mouseX,int mouseY)
{
SimpleVector td = Interact2D.reproject2D3D(camera,frameBuffer,mouseX,mouseY);
int[] res = Interact2D.pickPolygon(world.getVisibilityList(),td);

if (res == null)
return null;

Object3D obj = world.getObject(Interact2D.getObjectID(res));  

PolygonManager polygonManager = obj.getPolygonManager();

SimpleVector vertex =
polygonManager.getTransformedVertex(Interact2D.getPolygonID(res), 0);//0-2

return vertex;
}
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Skeletal Animation Idea?
« Reply #5 on: February 06, 2007, 04:39:52 pm »
You may use a simple screen space based algorithm to get the nearest vertex by projecting all three vertices into screen space (using a combination of the PolygonManager and Interact2D) and find the vertex which is closest to the mouse pointer. Should be quite easy to do...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Skeletal Animation Idea?
« Reply #6 on: February 06, 2007, 04:42:21 pm »
Quote from: "cyberkilla"
This looks like my friend:

Code: [Select]

rotateAxis(SimpleVector axis, float angle)
Rotates the matrix around an arbitrary axis.
It depends...is rotates around an axis, but still asumes the origin as a rotation oivot. If you don't want that, you would have to subtract the actual pivot from the SimpleVector, do the rotation and add the pivot again. You wrap this in a small method and never think about it again...  :wink:

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Skeletal Animation Idea?
« Reply #7 on: February 06, 2007, 04:47:07 pm »
BTW: I like the rotz-Attribute in the xml-example. Of course it's rotation-z, but rotz in german means snot... :lol:

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Skeletal Animation Idea?
« Reply #8 on: February 06, 2007, 05:20:51 pm »
Fantastic!

It is looking quite plausible now!

Im currently working on the import/export api, baring in mind that I would like others to be able to use it.

So, effectively, for my whole game, the source code is now covered in snot :)

I am using software mode in the editor, because it will cause the least trouble.

Screenshots soon. Its a heck of a lot simpler than I thought it was.
Im only doing rotational movement - the specs I have found, include actual translations, but that does not make sense to me! That isnt very bone-like;)

EDIT:
I cannot decide what to call the bone points:)

This is the way I am doing it...
Each bone has an EndPoint Vector. Basically, the end position of it.
The start position is actually the EndPoint of the parent.

Also, the parent endpoint is the pivot of the child bone.
Makes sense to me(EG. A wrist bone rotates around the pivot of the arm its attached to).

End Point is a satisfactory terminology for now;)
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Skeletal Animation Idea?
« Reply #9 on: February 06, 2007, 06:45:30 pm »
Egon, if you had any spare time(for me, i mean;)), that "rotation around a point" code would be appreciated.
You do not need to though. I haven't even tried it yet. I've just finished all of the importing and exporting code.

Im using "Vertex Groups", which can be bound to "Bones" with the same name.
Just like blender.
Means you can reuse the skeleton, which is, of course, the whole point :wink: .

My next job is the vertex selection in the editor. This will be interesting:)
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Skeletal Animation Idea?
« Reply #10 on: February 06, 2007, 07:00:41 pm »
Well, like so:

Code: [Select]

 SimpleVector pivot=new SimpleVector(...); // The rotation pivot
 SimpleVector vertex=new SimpleVector(...); // The vertex to rotate
 vertex=vertex.calcSub(pivot); // move vertex into "pivot"-space
 vertex.rotate?(...); // Do the rotation
 vertex.add(pivot); // ...move back into former space

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Skeletal Animation Idea?
« Reply #11 on: February 06, 2007, 07:19:31 pm »
Oh, that simple? I actually understand that:)
Thanks;)

Here! The vertex selection works!



EDIT:
My next task it to allow the positioning/building of the bone structure.
The classes are in order. It is just the graphical part remaining.

Then, I can bind the vertex groups to the structure, and im almost done!

I suggest a vertex weight system. Just a number for each vertex, to dictate how much of the rotation should be attributed to it.

I mean, if there are 5 vertexes next to the rotating joint, they should be warped
depending on their "weights", and the distance from the pivot.

http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Skeletal Animation Idea?
« Reply #12 on: February 07, 2007, 01:51:47 pm »
Im drawing the bones over the top, in 2d, because it gives an "xray"-like feeling.
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Skeletal Animation Idea?
« Reply #13 on: February 07, 2007, 05:49:18 pm »
Looks great. Actually, the real purpose of the IVertexController/PolygonManager was to make such things possible...it's just that no one volunteered until now... :wink:

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Skeletal Animation Idea?
« Reply #14 on: February 07, 2007, 06:54:28 pm »
I hope to have it done soon:)

I do have some problems with the "3d cursor".
Obviously, I could use some sliders to position to cursor, but id rather
have the mouse like they do in blender.

I notice, in Blender, you can turn the model around, and it will move the 3 cursor
along different axis.

I could just have multiple windows, I suppose. Yes, I will try that;)
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG