MD3 - improve animations support

I did discover a different problem, however… when I loaded 3 models at once instead of 2 using the same technique as in 2, it works flawlessly, which is not the problem of course, but what is, is that the third model I want to render transparency and be like a fish-bowl style space helmet,

so I looked up in the scripting documentation/API about how to enable blending on a render, and saw the class TRenderOptions, and the property Blending, and knew you usually did “Class.property := something”, or in this case “Class.subclass.property := something” as TRenderOptions is a sub-class of TCastleScene,

But unfortunately when I tried something along the lines of “ModelScene3.RenderOptions (RenderOptions without the T specifically is in the documentation as the name of the CastleScene property).Blending := true”, it acted like nothing happened, instead of either correctly making the helmet semitransparent or throwing an error.

Do you know if it is because the new “TSceneSubAnimations” class does not inherit/use the RenderOptions at all from TCastleScene or anything else, or is it because I am not using the syntax to control the blending correctly because I am using the syntax for TCastleScene and not TSceneSubAnimations, so it’s different (although that is very weird if yes, because if the syntax is incorrect I should get a compiler error)?

If it is because I am using it incorrectly, do you know the correct syntax for this?

blendinghelp.zip (65.1 MB)

Unfortunately, I tried around some more, this time by testing how the part I want semi-transparent (the fishbowl helmet) looks just by importing it as a normal scene as a child of TCastleTransform in the scene hiearchy in the editor, and unfortunately it looked exactly the same, even with Blending checked on, and the Blendingoptions trying every single option instead of leaving it at the default “blendsrcAlpha” etc (even though that is what the guidelines recommend explicitly, I just wanted to test if anything else would work).

Because of this, I believe it is probably a problem with the texture/model itself, rather than a problem with the script. Does anybody know with the model I want (named “sandyhead” in the folder), I get it to look semi-transparent in game? In the MD3 editor I use, the Misfit Model 3D app mentioned above, it renders the semi-transparency perfectly, so it’s weird it doesn’t here if you enable blending explicitly and use the exact styles/options the guidelines give you (for reference, I looked up the tutorial on the page about blending in the manual).

Okay, it’s even weirder than I thought… in the model program, Misfit Model 3D, I can preview the alpha blend fine when I’m not in animation mode, but once I get into animation mode, and still make sure to have “alpha blend” view explicitly checked, it stops alpha blending and renders the helmet opaque, just like when I import the model, both using code as in yesterday, as well as importing it normally like I tried today.

Do you guys think that might be part of the problem, although I would wager no because model viewer and editor programs and game engines use different shaders for the texture materials, like they’re independent of one another?

But to recap, the crux/essence of my problem is that a model who looks semi-transparent correctly in the main view of my model editing program, does not look semi-transparent at all, fully opaque, importing it both using code as the example program does, and importing it by adding it as a TCastleScene directly in the user interface.

Does anybody know why this is happening? I make sure to have the proper blending settings as discussed in the manual’s blending section, as mentioned in a previous post of mine above.

Sorry for the delay in answering!

I’m addressing below various things you mention, but long story short: the lack of blending in this particular case was just a missing feature in CGE MD3 importer. It’s now fixed :slight_smile: You don’t need to specify anything non-default to use this blending, you just need latest CGE version. Here’s how your last testcase now renders:

As before, please give a few hours from now for the new engine to be build and available on Download | Castle Game Engine .

And thank you for sending complete projects to reproduce the issues, this allowed me to quickly debug the problems.

I tested your example nonsenseviolation.zip. The access violation is because you do

// ModelScene := TSceneSubAnimations.Create(FreeAtStop);
// ModelScene2 := TSceneSubAnimations.Create(FreeAtStop);
ModelScene.Load(ModelUrl);
ModelScene2.Load(ModelUrl2);

So you call Load method on ModelScene, but you never created ModelScene instance.

You commented out the creation code from my example, but didn’t replace it with anything.

In Pascal, just like in most OOP languages (C#, Java…) you need to create object instances.

Simply add

ModelScene := TCastleScene.Create(FreeAtStop);
ModelScene2 := TCastleScene.Create(FreeAtStop);

before using ModelScene and ModelScene2. If this sounds unclear, read our book about using Pascal and in particular classes, Modern Object Pascal Introduction for Programmers | Castle Game Engine , it talks about how to create and destroy instances a lot :slight_smile:

I don’t know what exactly you mean by “none”, and what you expect the be done in this case. But you can naturally modify the code in split_long_md3_animation_into_logical_pieces/code/gamescenesubanimations.pas to perform any logic you need, I tried to keep it simple :slight_smile:

E.g. you can

  • Just not call PlaySubAnimation if you don’t want to
  • In my code, PlaySubAnimation(nil, ...) will stop the animation
  • In my code, PlaySubAnimation('any non-existent name', ...) will emit a warning and not change the previous animation

You can modify this however you like, and in the end use ForceAnimationPose('animation', ...) call in any way. E.g. you could introduce a method TSceneSubAnimations.ResetSubAnimations like this, to stop animations and reset the model to initial frame:

procedure TSceneSubAnimations.ResetSubAnimations;
begin
  FCurrentSubAnimation := nil;
  ForceAnimationPose('animation', 0, false);
end;

If my original, unmodified example code and data crash for you, please describe in more details how. For me, switching between various models and playing their animations works. Marauder and Basilisk work too :slight_smile: I did show it on https://www.youtube.com/watch?v=DpRGTKqJZ4Y .

You don’t need to turn blending support “on”, it is “on” automatically. You can consult the API docs, in this case for TCastleRenderOptions.Blending ( Castle Game Engine: CastleRenderOptions: Class TCastleRenderOptions ) to see it is declared with default true.

The blending should work equally well for MD3 as well as any other model format, with subanimations or not.

As I stated at the beginning of this answer, we just didn’t use a particular MD3 feature (we didn’t use per-surface shader name, so we didn’t use helmet-specific texture which used blending). This is now fixed :slight_smile: There’s nothing for you to do, keep Scene.RenderOptions.Blending = true (default) to see it.

Since I was playing with MD3 code in CGE already, I decided to add some more improvements:

  • We now read animation.cfg automatically when you load MD3 into TCastleScene.

    So there’s completely no need to use “subanimations” code from split_long_md3_animation_into_logical_pieces example anymore, if you use MD3 file with “animation.cfg” file. Forget about subanimations in this case :slight_smile: You can now just use regular CGE PlayAnimation method, documented e.g. at Writing code to modify scenes and transformations | Manual | Castle Game Engine , to play MD3 animations. You can also enumerate animations using e.g. MyScene.AnimationsList.

    Although the “subanimations” code will still work, it is completely unnecessary for the case of MD3 now, as TCastleScene already defines all animations.

    This also means you can set animation on MD3 in CGE editor, just adjust AutoAnimation. This also means you can play MD3 animations in view3dscene (if you double-click on MD3 model in CGE editor).

  • Optimized reading vertexes and triangles from MD3.


Thank you so much for all the help! The crashing with the examples you gave, which was one of the things you addressed, was because of the buggy modified code, which you also addressed (how ModelScene was never declared in my modified code). It’s a relief to know the blending problem was because of something unsupported in the engine itself, and not because of anything wrong I messed up in like the access violation error.

What I meant, to address one of your questions, by playing subanimation none, is that I wanted it to simply not play any subanimations/stop animating, but you showed me “nil” is the correct parameter word for it.

Also, it’s a relief to know that you made even more improvements to the subanimations script… I thought it was really great as it was, but it’s much better and convenient to be able to play subanimations using the normal “Playanimation” instead of needing to do special code for different types of animations (animations defined in a configuration in this case, that is).

Does anyone know though, on a different note, if there is a way to load a multi-part model and have the engine hook the parts together automatically for you, the way it works with Quake 3 original (like reading the tag_torso and linking the legs and body in the joint named tag_torso), or is that not supported right now because the plan is to use unsegmented/one-piece models only?

I know, like my modified example demonstrations, that you can use multiple one-piece models and just translate and rotate them as appropriate to simulate a multi-part model (it looks intentionally unpolished right now like in the image you attached above, cause it’s just proof of concept; I will fix the position/translation later), but since you want to make MD3 usage more convenient do you think it would be better for everyone to support multi-part models (like lower.md3, upper.md3, etc all in the same folder/directory just like in Quake 3 original)?

Support for MD3 “tags” to attach parts to a bigger model is not implemented.

In principle it is possible to implement it. Hm, I looked at the specs ( Description of MD3 Format (2011 Jul 11) , RtCW:ET Blender Model Tools - Unofficial MD3 Format Specification. ), it could actually be quite simple to add.

( You would then be able to use ExposeTransforms, Attach objects to (animated) bones, like weapon in character’s hand, by ExposeTransforms – Castle Game Engine , to attach any object (maybe another MD3 object, maybe any other CGE transformation and scene) to a given tag. )

Hm, I’ll experiment later today :), if it’s as easy as it seems – we could add it.

( I renamed the forum thread subject to better correspond to our topics, " MD3 - improve animations support". )

Sounds very good, thank you. I was unsure about if it would be spamming, especially if I am new, to start a new support topic for a new issue, but in the future that is always what I should do, to keep things organized and not things mixing with each other and the thread turning into a complicated mess?

And it sounds really great about considering adding the bone support. If you end up implementing it, do you know if you could please give a tutorial/example of how exactly “ExportTransforms” would work with the MD3 bones, just like you gave a demonstration earlier about subanimations?

Okay, never mind, A: it’s Expose not Export, silly me making typos, and B: I can see in the news article that you linked, there is in fact already a clear link to a demonstration, so I will make sure to use it if you end up adding MD3’s supporting it.

Don’t hesitate to create new topics :slight_smile: But also I know that some conversations naturally go over a few inter-connected things, no worries either way :slight_smile:

Hello, have you figured out yet if you can add the tags that combine MD3 models that we discussed above, or will it take longer to figure out?

if the answer is there will be no implementation period, do you know how I can find a method to combine multiple animations at the same time (like running + shooting) inside a single model, or will I just end up having to use the method of manually moving and rotating the seperate pieces so it looks like a cohesive whole?

Because obviously, like any tech question, I made sure to research before asking, but couldn’t find anything about combining multiple animations at the same time, only blending the transition between them (which is not the same thing, they don’t play at the same exact time still), and tried using keywords like “blend” or “combine” in the API reference but came up blank/empty.

Oh yeah, Googling “castle game engine layered animations” too but came up empty

I failed to do it yesterday, due to too little time, too much tasks :slight_smile: It’s still on my TODO list, will try later today. It still looks easy.

In general, you can play multiple animations in the same scene if they touch different bones, see examples/animations/animate_bones_by_code. But this will likely not help you – MD3 animation doesn’t expose any bones now, because the “bones” are encoded in “tags”.

So, it’s best to wait for our “MD3 tags” implementation :slight_smile:

Okay, that makes perfect sense. I know I can just wait, cause I believe gltf with bone/skeletal animations will serve the purpose I want and will take up about the same amount of data, or will it take up more (that’s important, because I want the games I make to be minimal and run on very old PC’s from the early 2000s, as that is what the school I am teaching at has right now?)