Chrono Compendium

Kajar Laboratories - Fan Works and Submissions => Chrono Cross Modification => Topic started by: utunnels on July 19, 2016, 06:02:22 am

Title: Convert joints to bones(done)
Post by: utunnels on July 19, 2016, 06:02:22 am
Currently the models are posed using the hard way, that is calculating the new positions of all vertex using the joint and vertex group data.

I think the original armature code was done by Hypergeek? It did created normal looking bones, though the vertex groups are not connected to correct bones. That is because the last joint can't form a bone itself, so does the first joint of the model which is usually used to move the entire model.

CC joints
(http://i.imgur.com/TEku7h0.png)

Bones
(http://i.imgur.com/g6FQDue.png)


Title: Re: Convert joints to bones, possible?
Post by: alfadorredux on July 19, 2016, 08:15:06 am
For that example to come out right in terms of which vertex groups are connected to what, it almost looks like you need to add an extra joint right at the wrist to solve the "last joint" problem--let's call it A. Then your bones become 13-A in the hand (blue), A-12 in the forearm (green), and 12-11 in the upper arm (red), and all the attachments make sense.

Aren't the same joints in fairly consistent positions inside the data for all the models? That should make it possible to interpolate extras in the same locations for everyone. (Worst case, it might be necessary to flag some joint locations somehow.)

Also, I wonder if the existence of the two shoulder joints isn't due to the original animation code's insistence on rotating each joint in only one direction at a time, as I seem to recall was the case? That would require one joint to rotate the arm around its long axis and another to move it up and down relative to the model, but I'm not sure if that makes sense from a rigging point of view. That would allow 11 and 10 to be consolidated to one joint.
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 19, 2016, 10:22:08 am
Yes, it seems the double shoulder joint set up is for tranlation and rotation.
Usually joint 10 doesn't rotate, instead joint 11 does.
But the two joints at at exactly the same location.

To form a bone, there must be a head and a tail vector, and they can't be the same one. I was thinking about making small bones(for example, 0.1 in length) for this purpose, but it seems the positions of the tail and head affect the result of the transform, so it is a bit hard to determine.

An extreme approach is using all small bones, which simplifies the logic but I'm not sure if it is possible(and it is too alien for any modeler to use).
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 19, 2016, 12:48:20 pm
For that example to come out right in terms of which vertex groups are connected to what, it almost looks like you need to add an extra joint right at the wrist to solve the "last joint" problem--let's call it A. Then your bones become 13-A in the hand (blue), A-12 in the forearm (green), and 12-11 in the upper arm (red), and all the attachments make sense.
This is how the default pose looks. (http://i.imgur.com/A5TJjWO.png)

An extreme approach is using all small bones, which simplifies the logic but I'm not sure if it is possible(and it is too alien for any modeler to use).
Well I posed every "bone" manually. The result seemed promising...
(http://i.imgur.com/SL3SHJj.png)

But when applied the pose to the mesh, it looked like this.  :o
I think I need some sleep before starting to figure out what went wrong.
(http://i.imgur.com/biiXuSN.png)
Title: Re: Convert joints to bones, possible?
Post by: alfadorredux on July 19, 2016, 08:16:04 pm
Looks to me like the problem there is the shoulder joints 10/11 and 6/7 connecting down to the waist joint 2, rather than to something at shoulder level (maybe joint 3? Or is that too high up?) Alternatively, shift the second "double" joints in towards the center of the body, maybe?
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 19, 2016, 08:55:19 pm
Yeah, sounds like that. Joint 3 is mainly for the head, and joint 2 is for the body.
Some vertices of the shoulders are also connect to joint 2 and they use weight values to adjust how much they are affected by the 2 joints.
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 21, 2016, 02:58:51 am
Well it seems things are not that simple.

Cross models use 2 different sets of position if a vertex group is connected to 2 joints. When a transform is applied, the two vertices calculate individually then combine the final results using the weight values.

However, blender models use only 1 set of vertices.

Cross:
finalV = transformA(V1)*weightA + transformB(V2)*weightB

Blender:
finalV = transformA(V)*weightA + transformB(V)*weightB

I think that is why the shoulders are deformed beyond recognition.
Title: Re: Convert joints to bones, possible?
Post by: alfadorredux on July 21, 2016, 08:00:06 am
Geh. That's a lot more complicated, then.

Shift the second shoulder joint to create a bone that goes all the way to the "spine", then reassign the shoulder vertices? (Assuming that "connected to both arm and waist joint" = "shoulder vertex".)
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 21, 2016, 09:14:44 am
I don't think so. Those vertices do not just belong to one joints, actually, vertices on the elbows and wrists follows the same rules yet they seem OK. Maybe their initial position are along the same axis, while the shoulder and waist vertices are almost perpendicular to each other.

(I hate math)
Title: Re: Convert joints to bones, possible?
Post by: alfadorredux on July 21, 2016, 06:00:51 pm
Blender can now attach the same vertices to more than one bone, according to what turned up when I applied some search-fu to the problem. It seems to depend on assigning the vertices to two or more vertex groups, then assigning each vertex group to a bone (that's from the very end of this section of the manual (http://"https://www.blender.org/manual/rigging/skinning/obdata.html#vertex-groups")). No idea how you'd go about doing that from a loading/conversion script, but it must be possible. So in this case, you'd stick the shoulder vertices to the upper arm and the spine, I guess.
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 21, 2016, 07:46:15 pm
I think you misunderstood me.
It is not about assigning a vertex to 2 bones, which is already done, but Cross actually uses 2 vertex positions before combining the results. Blender(and other 3d software) uses the same vertex.

When not using bones, I can use the final result to create the vertex in the mesh, but if bones are involved the transform should be done after the mesh is created....


Edited:

A possible solution:
1. Create the T-posed mesh using the old way.
2. Posed the bones, but do not link them to the mesh.
3. Created another set of bones using the positions of the posed ones.
4. Link the mesh to the 2nd set of bones and delete the old bones.
5. Find a way to animate the new skeleton.

The first 4 steps are easy. I am now thinking about how to do the 5th step.
Title: Re: Convert joints to bones, possible?
Post by: alfadorredux on July 21, 2016, 08:04:49 pm
Okay, yes, I did misunderstand. Sorry.

I wonder what they used to create this setup in the first place. Some kind of Squeenix studio homebrew?

Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 21, 2016, 08:17:46 pm
Meow, reply edited, sorry.
Cross models are like marionette, a piles of limbs and parts scattered around the central point without the joints/strings.
Title: Re: Convert joints to bones, possible?
Post by: alfadorredux on July 21, 2016, 09:25:15 pm
In a marionette, at least all the parts connect together in a way that kinda-sorta-maybe-almost makes sense. I'm not so sure about the Cross models.  :?

Yeah, I would think that doing up a new set of bones similar to the old ones and transferring the mesh onto them would produce something without these weird brokennesses. Recovering the old animations...well, an animation is just a succession of poses. Screencapping everything pose by pose (ideally from several angles) and then imitating the poses with the rigged model should be possible (but really tedious).
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 21, 2016, 09:51:03 pm
Well, think cross models like normal models in blender. Break down all the vertex groups into individual sub-models (for example, the head and the torso both have a portion of the neck) in the beginning then interpolate them together.

Edit*
Like this (almost).
(http://i.imgur.com/8CANVZW.png)
Title: Re: Convert joints to bones, possible?
Post by: alfadorredux on July 22, 2016, 06:08:06 pm
Actually, you could do an interesting dream or ghost sequence with the model all disarranged like that... :lol:
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 23, 2016, 02:55:08 am
A possible solution:
1. Create the T-posed mesh using the old way.
2. Posed the bones, but do not link them to the mesh.
3. Created another set of bones using the positions of the posed ones.
4. Link the mesh to the 2nd set of bones and delete the old bones.
5. Find a way to animate the new skeleton.

Well this is what I have so far. At least the rotation part is correct(or at least is looks OK).

(http://i.imgur.com/zuxpGbe.png)
Title: Re: Convert joints to bones, possible?
Post by: alfadorredux on July 23, 2016, 07:51:16 am
Definitely an improvement over having his shoulders indented all the way to his hips.  :D

I guess that's the Swallow over there to the side--it looks really odd from that angle.
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 23, 2016, 08:34:38 am
I think the translation part is wrong. The shoulders look slightly dislocated because the joints also move a little other than just rotate. The weapon, however moves a long distance from between his feet to his hands, so it looks ridiculous. Same thing happens to Kid's skirt (I'm surprised it even uses multiple bones).

Well, actually I'm confused because it seems blender uses different coordination system for bones and other objects. When creating the T-posed skeleton, it doesn't matter because all bones are in the center of the global space. But to move them further, it has to be specific.



I also posted a question on stackoverflow.
https://stackoverflow.com/questions/38541723/apply-rotation-and-translation-to-bones



Quote from: https://www.chronocompendium.com/Term/Mdl.html
Since the maximum number of joints in a model is 32, some models lack a weapon bone.
Well it seems the wiki is wrong because battle models can certain have more than 32 joints...
For example, Kid has 39 joints include the weapon (blame the braid and the skirt).
Title: Re: Convert joints to bones, possible?
Post by: alfadorredux on July 23, 2016, 01:28:16 pm
It almost looks like the bone in Serge's left upper arm is curved there, although I suppose it could be just an artifact of the screenshot. I wonder--are the shoulders truly, conceptually translating, or did they just use that as a kind of shorthand for rotating the upper torso, shoulders included? I don't know how you re-rigged this, but if you followed the original pattern, the shoulders aren't connected to the spine at shoulder level, as would be expected based on the way a real human skeleton works... (I may be too hung up on how real human skeletons work. If so, I apologize.)

About the number of joints--I think that line refers only to the overworld models, but it's possible that the reason for some of them not having weapon joints may be due to something other than a joint number restriction (in fact, from the look of it, all of the overworld models should have a couple of unused joint slots, since the max listed is 30, for Leena and Riddel). Maybe those characters just never participate in a sequence where they pull their weapon before a combat has actually started?
Title: Re: Convert joints to bones, possible?
Post by: TheMage on July 23, 2016, 02:32:41 pm




It almost looks like the bone in Serge's left upper arm is curved there, although I suppose it could be just an artifact of the screenshot. I wonder--are the shoulders truly, conceptually translating, or did they just use that as a kind of shorthand for rotating the upper torso, shoulders included? I don't know how you re-rigged this, but if you followed the original pattern, the shoulders aren't connected to the spine at shoulder level, as would be expected based on the way a real human skeleton works...


I wouldn't put it past the developers to take shortcuts around the human skeleton, especially in the 90's, graphics were changing so fast.

Hmm most of this stuff is over my head but out of curiosity how many polygons do the Cross models roughly have? If the conversion of joints to bones is possible would it also be possible to add polygons?

Title: Re: Convert joints to bones, possible?
Post by: alfadorredux on July 23, 2016, 06:19:29 pm
If the conversion of joints to bones is possible would it also be possible to add polygons?

Directly inside the existing game, you mean? In theory, but It's Complicated. You'd need to manipulate section 1 of the .mdl file (http://"https://www.chronocompendium.com/Term/Mdl.html"), adding vertices to the vertex pool and corresponding UV map information (possibly adding constructs, too).

Outside the game? Presumably it would be no different from editing any other 3D model. I don't think we have the means to convert back to Cross's in-game format, though.
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 23, 2016, 07:52:28 pm
In theory, posing is easier than editing the mesh.
For the reason the way cc uses to handle vertices that are connected to 2 joints can not be reverted easily.
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 23, 2016, 08:25:45 pm
I wonder--are the shoulders truly, conceptually translating, or did they just use that as a kind of shorthand for rotating the upper torso, shoulders included? I don't know how you re-rigged this, but if you followed the original pattern, the shoulders aren't connected to the spine at shoulder level, as would be expected based on the way a real human skeleton works... (I may be too hung up on how real human skeletons work. If so, I apologize.)
Some times it takes more than rotation of the upper body to shrug your shoulders, or you need to add extra joints between shoulder and neck, same cost but perhaps not as easy as moving the shoulders directly. And when swinging a weapon we need to adjust the positions of the shoulders otherwise it looks too stiff.

And yes, the shoulders are connected to joint 2 (the joint that controls the upper body). Because only the relative movements of the joints matter, no matter how far aways they are apart. Even though it looks like they connect with the waist, they don't move with the waist (the waist is controled by joint 1).

Quote
About the number of joints--I think that line refers only to the overworld models, but it's possible that the reason for some of them not having weapon joints may be due to something other than a joint number restriction (in fact, from the look of it, all of the overworld models should have a couple of unused joint slots, since the max listed is 30, for Leena and Riddel). Maybe those characters just never participate in a sequence where they pull their weapon before a combat has actually started?
The overworld models don't have weapon bones, or as far as i know. Maybe there is a script to bind weapons to a certain joint when needed. The overworld weapons are also complete models than just mesh. In the other word, weapons used in battle are parts of the character models.

Quote
It almost looks like the bone in Serge's left upper arm is curved there, although I suppose it could be just an artifact of the screenshot.
Yes it is bended for some reason. I compared it to a normal model exported before.
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 25, 2016, 10:18:06 am
OK I found the reason why the weapon and shoulders were in wrong positions.
(I really hate math, I spent the whole day trying to figure it out)

This time the position is correct, but the angle is a bit off. :evil:
(http://i.imgur.com/bhmESJy.png)



Edit*


Oh, well, the reason the angles are wrong is because rotations are relative to the bone itself. So if a bone is created with rotation, the coordinates are also rotated.
How to convert the rotation in 3D to match the new coordinates is currently beyond my sleepy brain.
Title: Re: Convert joints to bones, possible?
Post by: alfadorredux on July 25, 2016, 10:07:13 pm
The simplest thing to do is apply the bone's initial rotation in reverse, then apply the new rotation. I think. The answer's probably in this (http://"http://www.flipcode.com/documents/matrfaq.html") somewhere, but I don't have the time or energy to read it all right now, and I haven't done the kind of vector and matrix math involved in this stuff since university, ~20 years ago. (Typing that makes me feel old, sigh.)
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 25, 2016, 11:57:33 pm
Thanks alfador. Well, to me it is 15 years ago. LOL
Title: Re: Convert joints to bones, possible?
Post by: utunnels on July 26, 2016, 11:01:40 pm
OK, this time it works.
(http://i.imgur.com/xejBgk3.png)(http://i.imgur.com/6i1kPLK.png)



I was confused by euler angles and rotation matrix conversion. Now I know how the code works...
Title: Re: Convert joints to bones(done)
Post by: alfadorredux on July 27, 2016, 07:44:19 am
Looking good!  :D
Title: Re: Convert joints to bones(done)
Post by: prizvel on July 27, 2016, 03:25:07 pm
Nice work!
Title: Re: Convert joints to bones(done)
Post by: utunnels on July 27, 2016, 09:11:28 pm
@alfadorredux

Do you know if there's already a working atim to tim tool? I recall I had something that exports atim data into a fake psx vram block and views it using a psx vram viewer, but I can't remember how did whoever-ripped-the-battle-models convert the textures.
Title: Re: Convert joints to bones(done)
Post by: prizvel on July 28, 2016, 01:15:21 am
@alfadorredux

Do you know if there's already a working atim to tim tool? I recall I had something that exports atim data into a fake psx vram block and views it using a psx vram viewer, but I can't remember how did whoever-ripped-the-battle-models convert the textures.

I usually manually extracted image data and clut data and insert them in ordinary tim . If clut 400 bytes, I save two tim file with different parts of clut 200 bytes each, and combine them in a regular editor.
Title: Re: Convert joints to bones(done)
Post by: utunnels on July 28, 2016, 05:16:38 am
Well I think I can do the copy and paste job for now, until I get bored and write a tool.
Title: Re: Convert joints to bones(done)
Post by: prizvel on July 28, 2016, 07:19:59 am
@alfadorredux

Do you know if there's already a working atim to tim tool? I recall I had something that exports atim data into a fake psx vram block and views it using a psx vram viewer, but I can't remember how did whoever-ripped-the-battle-models convert the textures.

perhaps I can remind you  :) your script?
Title: Re: Convert joints to bones(done)
Post by: utunnels on July 28, 2016, 09:03:48 am
It does not create bmp files.
Title: Re: Convert joints to bones(done)
Post by: prizvel on July 28, 2016, 09:20:35 am
This tools is designed for remap the textures, but slightly changing the code can be used as atim2bmp
Title: Re: Convert joints to bones(done)
Post by: utunnels on July 28, 2016, 09:51:28 am
LOL
You are right. Now I recall this. I thought it was a standalone tool so I missed the files.
Title: Re: Convert joints to bones(done)
Post by: prizvel on July 28, 2016, 10:00:57 am
LOL
You are right. Now I recall this. I thought it was a standalone tool so I missed the files.


:D

In truth I did not understand how he works  :oops:
Title: Re: Convert joints to bones(done)
Post by: utunnels on August 10, 2016, 07:32:30 am
Well I think the first version, despite the shoulders are all junks, is not completely useless, because we can use it to pose the character and output the transform values to make new animations for CC.
The final version, while it's mathematically correct, is not so easy to convert back into CC standard.
Title: Re: Convert joints to bones(done)
Post by: utunnels on September 02, 2016, 11:50:40 pm
(http://i.imgur.com/iLq4CWV.gif)

Kung Fu Serge


I did this by copying Orha's joint rotation values to Serge's corresponding joints.
Again the shoulders are a bit deformed but you usually won't notice it unless you pause the animation.

However, copying Serge's walking animation from his field model is much easier because the skeletons are almost identical.
Title: Re: Convert joints to bones(done)
Post by: EgyLynx on September 03, 2016, 01:02:06 pm
+ :?
Are someone maked Serge to M.U.G.E.N?
These are at it... or can be...
Maybe someone else than me...

Anyway, in my my opinion these are do at for up weak /med punc /kick... ?
Title: Re: Convert joints to bones(done)
Post by: utunnels on September 03, 2016, 08:17:42 pm
Each pc character has 2 attack patterns, and each pattern has its own weak-medium-heavy attacks.
Title: Re: Convert joints to bones(done)
Post by: utunnels on September 19, 2016, 09:42:59 am
I'm trying to export cc animations from blender.
The only problem is that CC uses full -360 to 360 degree range for rotations, while blender uses quaternion/matrix which doesn't have enough information to reverse the process. For example, it can't tell the different between -90 degree and 270 degree. While it makes no different when making gif animations, the game uses some sort of key frame system, so rotation from 180 to 270 and rotation from 180 to -90 are completely different.
OK, I seemed to have find a solution. Blender provides a method to convert matrix to compatible euler.
Title: Re: Convert joints to bones(done)
Post by: utunnels on September 19, 2016, 12:12:22 pm
Did some test on Serge's idle animation, using Greco's animation as the template.
(http://i.imgur.com/A6pMEok.png)
(http://i.imgur.com/gcjeOoM.png)
Title: Re: Convert joints to bones(done)
Post by: IHBP on September 19, 2016, 03:03:22 pm
Looks pretty good,will this be useful in giving characters new weapons or moves or is it just for poses?
Title: Re: Convert joints to bones(done)
Post by: EgyLynx on September 19, 2016, 03:33:00 pm
oh... nice, in deed...
Title: Re: Convert joints to bones(done)
Post by: utunnels on September 19, 2016, 08:21:28 pm
Currently there  is no use. Well, just trying to find a way to make animations.
Maybe a modder can find it useful.
Title: Re: Convert joints to bones(done)
Post by: utunnels on September 20, 2016, 01:06:18 pm
Just keep a note here. Warning: it is long and dry.





Here's how I did that (assume you know python or at least the basis of coding):

0. You need blender 2.49, I know it is old, but for now the script hasn't been updated for new versions.

1. Download the model rips from this topic (https://www.chronocompendium.com/Forums/index.php?topic=12461.0).

2. Check this link for required files: https://drive.google.com/open?id=0B5GvuiubpnUZMTZGZmlySFJqSFU
   
import_ccpose.py is the script to import character poses. You need to edit a few lines.

Change the path below to where you extract your model rips. It should has a "Battle Models" folder, replace the path below to that on your disk.
Code: [Select]
    mdlroot = "D:\\Chrono\\CC Models\\Battle Models\\"
The lines below also need to change if you want to load a model which is not Serge.
Code: [Select]
    imptype = 'battle_model'
    ind = 0

When the script is done, the model you get is deformed, it is normal because we only need the skeleton, the mesh is there for you to have an general idea of how it looks.

Now you can pose the bones in pose mode and action editor, I will not talk about details here. If you check the action editor panel, you will see Serge has 28 animations (DefaultAction, DefaultAction.001, .... , DefaultAction.027), do not rename them.

Check the text editor, there should be 3 texts.
Text: empty, you can paste your script here
import_ccpose.py: the script you just ran
Animation Note: it contains a list, which is important later.

3. To export animations from the blend file, find anim_export_blender2.4.txt from the download link.

Replace the line has animFrames with the contents from Animation Note. The frames are just place holders, it tells the script how many frames each animation has, you can change the numbers to anything and it won't make a difference, as long as the lengths are correct.

Run it in blender, for example, copy and paste the text in the text editor, and run python script. Wait for it to complete, it depends on how good your computer is. On my old home pc, the window may freeze for a while, but on another computer, it finishes in about 1 seceond.

A new text is create if the script finished without errors. It is called Animations.

Note: if you want to copy content of the new text, you'd better click the wrap words button above the text editor panel. Because if you dont, the window will freeze because the line is too long, as far as I know, a good cpu makes little difference here.

4. Final step, edit anim_export_blender2.4.html
(Yeah I know, but I prefer javascript over python when writing complex things. )

Copy the content in the newly generated text Animations, and replace the first two lines of the javascript (namely, frm0 and animSet).

Now edit the line below:
Code: [Select]
pack_anim([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]);
The list contains the animations you want to pack, in this case, 0 to 21 are the animations in Serge's mdl file, when 22 to 27 are his attack animations. Preview the html in a web browser and you get the hex strings you can use in a hex editor.

For example, Serge.mdl stores its animations at 0x5228, copy the hex values and replace the contents behind that position.  For more information on animations, check the wiki page: https://www.chronocompendium.com/Term/Anim.html

Serge's animations are in a drp file (https://www.chronocompendium.com/Term/Chrono_Cross_Player_Character_Battle_Animation_Files_List.html). Seach for "0600000020000000" in the hex editor, that is where the animation data begin.