Jump to content
The Dark Mod Forums
Sign in to follow this  
rich_is_bored

MD3 models?

Recommended Posts

I was working my way through the code and noticed the game supports loading MD3 models. I can't believe Doom 3 has been around for 12 years and nobody played around with this. Vertex animation is a bit dated but it still has valid use cases.

 

Of course I was immediately sidetracked. I had to track down an exporter for Blender and try it.

 

Nothing complicated. Just a sphere with a wave modifier on it. I've packaged it up if anyone would like to tinker. It's testmd3.pk4.

 

If you load the model you'll note that it doesn't animate. But there's a bit of code in Model_md3.cpp that's of interest...

    // TODO: these need set by an entity

    frame = ent->shaderParms[SHADERPARM_MD3_FRAME];            // probably want to keep frames < 1000 or so

    oldframe = ent->shaderParms[SHADERPARM_MD3_LASTFRAME];

    backlerp = ent->shaderParms[SHADERPARM_MD3_BACKLERP];

These shaderparm references translate into parms 8, 9, and 10. I have determined that setting shaderparm 8 changes the current frame. You can see for yourself by loading the model with "testModel models/test.md3" and advancing frames with "testShaderParm 8 [frame]".

 

Anyway. Just sharing my findings. Maybe I'll figure it out a way to make use of this eventually.

Share this post


Link to post
Share on other sites

I think Arcturus did some fake cloth physics by baking animation to models then used animation commands to swap models.

This seems to be a better way to achieve that. This may also come in handy for water effects.

 

Edit:

 

I might be remembering wrong. All I can find is a baked bone animation:

 

http://forums.thedarkmod.com/topic/16469-model-request-furniture-covered-in-sheets/page-3?do=findComment&comment=353012

 

still, using vertex animation instead should reduce the amount of calculation needed for these effects as I gather.

(At the expense of more storage and memory.)

Share this post


Link to post
Share on other sites

Yes, I tried to overcome lack of vertex animation by baking cloth physics to bones. Rather tedious. I recall Motorsep trying to hire someone to write a Blender script for that (?)

Share this post


Link to post
Share on other sites

I recall back on the D3W forums der_ton wrote an experimental MD5 exporter that baked vertex animation by creating a bone for every vertex. It's funny looking back on it as we were clearly shoving a square peg into a round hole.

 

At any rate, I initially was going to use a Q3 character model for testing purposes since they could be found everywhere. But then I saw how they are split into three separate MD3s, paired with a CFG, and the code doesn't appear to reflect this. I'm fine with that however. MD5 is far superior for character models with fewer keyframes, support for frame events, interpolation, ect. We'd only be using MD3 for props like grass, fabric, and spider webs blowing in the wind.

Share this post


Link to post
Share on other sites

This is very nice.

 

I'll see if I can apply it to the surface of the Fire Elemental for 2.06, which would be a nice improvement. I imagine I'll be picking up a few changes for the FE as people start to put it into their maps.

 

Thanks!

Share this post


Link to post
Share on other sites

Very nice work.

 

I may add that such effects can be achieved using vertex shaders either. The question would be which way is easier and less performance consuming, though.

 

As md5 is most probably a successor of md3, I am wondering whether the same stuff could be achieved with normal md5's either.

Share this post


Link to post
Share on other sites

Very nice work.

 

I may add that such effects can be achieved using vertex shaders either. The question would be which way is easier and less performance consuming, though.

 

As md5 is most probably a successor of md3, I am wondering whether the same stuff could be achieved with normal md5's either.

 

Very nice work indeed!!

 

You can achive something similar to this with Md5 but only using bones and is more time consuming.

 

Btw i knew that idtech 4 add a MD3 loader but i always thought it was old legacy code that didn't worked!

 

I also assume modern exporters for this old format aren't plenty?

Edited by HMart

Share this post


Link to post
Share on other sites

@Obsttorte

 

I'm sure a vertex shader would be better for performance. My concern is the custom shaders we call from our materials are executed after interaction.vfp. Will you see any changes to vertex positions if they are rendered before they are moved?

Share this post


Link to post
Share on other sites

(AFAIK) Yes, currently you'd need to distort _currentRender or jump through hoops re-rendering the whole lighting pipeline

to make that work.

 

That said, perhaps I can look into changing the place in the pipeline where vertex arb can be

inserted. Ideally we'd do what the shadow.vp does and write to the VBO before the lighting process begins.

Share this post


Link to post
Share on other sites

@Obsttorte

 

I'm sure a vertex shader would be better for performance. My concern is the custom shaders we call from our materials are executed after interaction.vfp. Will you see any changes to vertex positions if they are rendered before they are moved?

I played around with vertex shaders moving vertices and it works. I've used it to create water waves.

Share this post


Link to post
Share on other sites

I'm trying to wrap my head around this.

    {
        setShaderParm(8, currentFrame);
        currentFrame = (currentFrame + 1) % numFrames;
        sys.waitFrame();
    }

Does this depend on current FPS? I made a test md3 with two frames. I want to play one frame per second. I also would like to animate texture so that first image is displayed exactly at frame one and second image at frame two. I could add sixty of these: sys.waitFrame();

 

 

    {
        setShaderParm(8, currentFrame);
        currentFrame = (currentFrame + 1) % numFrames;
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
        sys.waitFrame();
    }

 

That will play at roughly 1 FPS.

I use this material:

anim_test
{
    noshadows
    noimpact
    nonsolid
    {
        if ( (time * 1) % 2 == 0 )
        blend blend
        alpha 1
        map    textures/anim_test/anim_test_01.tga
    }
    {
        if ( (time * 1) % 2 == 1 )
        blend blend
        alpha 1
        map    textures/anim_test/anim_test_02.tga
    }
}

Time means seconds here?

If I set up the script and material like this they both play at roughly 1 FPS but never exactly in sync. Do I get it right that one is dependent on FPS and other not?

Share this post


Link to post
Share on other sites

;) Water is transparent...

 

The arb programs work as long as you are doing some sort of transparency. You can hack them back to opaque of course.

Depends on how much juggling you wanna do:

 

http://wiki.thedarkmod.com/index.php?title=Making_Semi-transparent_textures

 

If I can dig out the files related to the water I could check whether it works with opaque surfaces either.

Found the files and testet it. It works.

 

Note that the vertex shader only affects the visual representation, not the physics (= collision). But I'm not sure whether the md3 examples above would do so either.

 

However, in case of moving cobwebs (why is it called like that, aren't those spiderwebs?) or waves you don't expect them to be solid anyways (unless you want to make a FM where the player can walk over water, preferable after he had turned it into wine :P ).

Share this post


Link to post
Share on other sites

@Arcturus

 

Yes, the scriptobject as currently constructed is linked to FPS. To base it on a set duration instead you would use...

sys.wait(X);

... where X is the number of seconds.

 

I'm sure you've noticed that the engine does not interpolate between keyframes? I figured smooth playback was preferable so I coupled playback to FPS.

 

In your case, why not export two static models each with their own material? Then you can toggle their visibility on or off at 1 FPS and you won't have to worry about sync issues. The script events you're interested in are "show" and "hide".

 

@Bikerdude

 

Hold that thought. If Obsttorte's shader works nobody will need to model anything.

 

@Obsttorte

 

If you could put those files into a package and make it available somewhere I'd like to see it.

Share this post


Link to post
Share on other sites

I used 2 frames just as an example. What I really want to do is to have an ocean with 50 frames that plays at 24-30 FPS. I want to bake normalmap for each frame so I would like them to align, although it's not super important. At 60 FPS I would need twice as many frames for a nice loop and I thought that would be an overkill.

 

I used sys.wait(1); and they still don't synchronize perfectly.

Share this post


Link to post
Share on other sites

Here's a 50-frame md3 waves animation with animated texture.

 

 

I used this experimental shader by SteveL with addition of specular reflections. It looks great on the shore. Too bad that further away all the reflections and refractions are masked leaving only the diffusemaps.

Share this post


Link to post
Share on other sites

I used this experimental shader by SteveL with addition of specular reflections. It looks great on the shore. Too bad that further away all the reflections and refractions are masked leaving only the diffusemaps.

This is amazing, would it be possible to get the edges of the water where is touches another brush/shader to foam-up -

 

- https://forum.unity3d.com/threads/release-calm-water.381288/

 

Edited by Bikerdude

Share this post


Link to post
Share on other sites
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...