Archived

This topic is now archived and is closed to further replies.

Torquai

rendering an md2 + weapon

Recommended Posts

When I finished my little md2 loader class yeasterday I tried to show more than one objects (ie a tris.md2 and a weapon.md2), but this resulted in a problem. The weapon.md2 does''nt follow the tris in animation or scale (I have scaled the tris down to 0.03f) but I can''t seem to find any scale where the weapon is correct. Also the weapon does''nt fit into place, and I seem to remember a document once (tried finding it again but not luck) that said to translate the weapon into a certain vertex from the tris frame. Can anyone please explain? Thanks in advance -Thomas Leggett tl@removeme@digitalteknik.no

Share this post


Link to post
Share on other sites
Well, you obviously need some kind of attach reference point on the model. That can be a point, a distance vector or a matrix. I never used md2 files, so I don''t know if they provide this point (they should). If not, you''ll have to use some 3D editor to create it yourself.

Once you have that point, you have several options to position your weapon. The most elegant solution is to treat the weapon as a detachable part of the characters skeletal bone structure. If the player picks up a weapon, just add it as a bone to your skeleton by integrating it''s local frame matrix. The best way to organize this internally, is by using a good dynamic scenegraph. This method allows for very nice weapon animation, for example by using inverse kinematics or solid object dynamics.

Now, if I recall correctly, the md2 format uses keyframed vertex animations instead of a bone structure ? In that case, you''ll have to animate your reference attach point together with the keyframed animation. The easiest way is to take an existing vertex of the model, and use it as the attach point. So in summary, for each frame you compute the current vertex animation state of your model, then compute the local coordinate frame matrix for your weapon at the attach vertex, and render the weapon with that matrix loaded. Of course, this will somewhat limit your weapon movements. The best way to handle that, is by throwing out keyframed animations altogether, and using current state-of-the-art skeletal animation instead

Share this post


Link to post
Share on other sites
Yeah, MD2 has no bones, only frames. I decided to use MD2 for simplicity, so I am going to stick with it... The only solution I see for this is too... umm... have as many models as weapons, and whenever the player picls a new weapon, the MD2 will be changed to the MD2 that has that weapon :D

Share this post


Link to post
Share on other sites
quote:
Original post by Raduprv
..And I mean an arbitrary MD2 with an arbitrary weapon.



That''s the problem. An MD2 model can''t handle arbitrary weapons.

If you look at the readme files that usually are comes with the models, you''ll probably see something like "visible weapons support". If the model has visible weapon support, it means that weapon models made specifically for the player model are provided.

If you load in a weapon model, you''ll see that it''s animated all on it''s own..and if you load in a player model and the provided weapon and render them in the same scale and the same world-space coordinates, you''ll see that the weapons follows the model animation smoothly..


-Luctus
Codito, Ergo Sum (Courtesy of ThinkGeek)

[Mail][DreggSoft][Fileformat Guide][n00bs]

Share this post


Link to post
Share on other sites
Hmm, that sounds nice, however, I can''t use that in my engine (at least, not without a lot of work.
See, I load the MD2 file, then trnasform it inot an internal format, to speed up the rendering. And, in that internal format of mine, each frame has a bounding box, and I am rendering the model according to the center of that bounding box on x any y, and the bounding box min has to stay on the ground. This allows for nice effects, for example, when a bird liek creature flips it''s wings, even if it stays in place, it is moved up/down backward/forward, depending on the wings position. So, when I will render the weapon, using my way, most likely it won''t show up correctly...


Height Map Editor | Eternal lands

Share this post


Link to post
Share on other sites