Mesh vs OpenGEX vs glTF

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


User avatar
spookyboo
Silver Sponsor
Silver Sponsor
Posts: 1141
Joined: Tue Jul 06, 2004 5:57 am
x 151
Contact:

Re: Mesh vs OpenGEX vs glTF

Post by spookyboo »

Image
Image
https://ibb.co/bCSKWG
https://ibb.co/bKdhkb
Materials come out pretty good in most of the cases. Most models are also ok (some models are distorted, but perhaps this is because a few things are not 100% implemented yet). The plugin loads regular gLTF files, but also binaries and base64 embedded (although loading them is very sloooow).
The HLMS editor itself does not support animation, but I will add this to the plugin to have at least a full feature set.
User avatar
devxkh
Halfling
Posts: 84
Joined: Tue Aug 02, 2016 6:07 pm
Location: Germany
x 12

Re: Mesh vs OpenGEX vs glTF

Post by devxkh »

too bad, looks like you won't share your gltf loader source?
https://github.com/spookyboo/HLMSEditor ... Import.dll

So i will have to continue writing my own. :(

anyway, good job!
My little OGRE engine -> FrankE WIP
User avatar
spookyboo
Silver Sponsor
Silver Sponsor
Posts: 1141
Joined: Tue Jul 06, 2004 5:57 am
x 151
Contact:

Re: Mesh vs OpenGEX vs glTF

Post by spookyboo »

Not true: https://github.com/spookyboo/glTFImportPlugin
Btw. the code is not heavy optimized, but is only for offline conversion
User avatar
devxkh
Halfling
Posts: 84
Joined: Tue Aug 02, 2016 6:07 pm
Location: Germany
x 12

Re: Mesh vs OpenGEX vs glTF

Post by devxkh »

spookyboo wrote:Not true: https://github.com/spookyboo/glTFImportPlugin
Btw. the code is not heavy optimized, but is only for offline conversion
Sry, didn't find that. Cool, even as ogre plugin. awesome! thx , will take a look at your material loader :)
My little OGRE engine -> FrankE WIP
User avatar
devxkh
Halfling
Posts: 84
Joined: Tue Aug 02, 2016 6:07 pm
Location: Germany
x 12

Re: Mesh vs OpenGEX vs glTF

Post by devxkh »

ok after a quick look in my lunch break, it looks like you are loading the gltf file and convert it to Ogre material and mesh?
So it's not a direct loader into ogre.
Why not using assimp for loading and conversion? It supports already compression.
Is there an advantage of ogre mesh files opposite to gltf mesh files?
Seems like i have to continue my direct loader -_-
My little OGRE engine -> FrankE WIP
User avatar
spookyboo
Silver Sponsor
Silver Sponsor
Posts: 1141
Joined: Tue Jul 06, 2004 5:57 am
x 151
Contact:

Re: Mesh vs OpenGEX vs glTF

Post by spookyboo »

The plugin indeed does a conversion and is not a direct loader, which makes the task a bit easier. Direct loading is not really needed for my HLMS Editor. I created the plugin from scratch because Assimp does not create 2.1 (Pbs) materials as far as I know.
Current status is that it manages to load most of the models, but some specific models still gives me a headache. The polly model for example is not textured. Maybe this is because of the min/max values in the accessor; I'm still searching what these values actually mean and how to implement them. Mapping the wrapS/wrapT values to addressing mode in the sampler is also not really straightforward and animation is still on my todo.

My question to the forum visitors is to download the HLMS Editor (binaries see in my signature) and test it with a few models. Please provide me some feedback about the material mapping from gLTF to Ogre Pbs. In general it looks ok, but it may need some tweaks here and there. Lighting in HLMS Editor needs some improvements, because the materials look a bit dull in the current light.
User avatar
spookyboo
Silver Sponsor
Silver Sponsor
Posts: 1141
Joined: Tue Jul 06, 2004 5:57 am
x 151
Contact:

Re: Mesh vs OpenGEX vs glTF

Post by spookyboo »

Ok, the gLTF -> Ogre plugin is almost done, but I'm still struggling with animation. In the Ogre skeleton xml I need to determine the bone pose matrix for each bone (the <bones> element). I have the local transformation of each bone (represented by the TRS elements of a gLTF node and converted to a Mat4), I calculated the transformation of each bone in respect to its parent and I have the inverse bind matrix of each bone. My naive interpretation was that the bone pose matrix was the product of either 'local transformation * inverse bind matrix' or 'calculated transformation * inverse bind matrix' (I wasn't sure which one to use). This doesn't work.
I tried all kinds of variations, but I'm stuck. I reviewed the code a couple of times to see whether the mistake was somewhere else, but I'm convinced it is in the animation pose math. The animation does run, but the model is totally distorted (it is fine without animation). I hope someone can shed some light on this matter.
Btw. The code is in Github: https://github.com/spookyboo/glTFImportPlugin
The issue is in https://github.com/spookyboo/glTFImport ... reator.cpp (just search for the TODO TODO)
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Mesh vs OpenGEX vs glTF

Post by dark_sylinc »

Mmm... all of what you're posting sounds strange.

Animation formats rarely even know about bind-space matrices, since this can be automatically calculated using math.
Most animation formats I've seen deal in pose space, i.e. _getDerivedPosition / Orientation / Scale; rather than bind space.

Bind space is used for sending the matrices to GPU.

Edit: Btw gLTFSkin.h is missing from the repo.
User avatar
spookyboo
Silver Sponsor
Silver Sponsor
Posts: 1141
Joined: Tue Jul 06, 2004 5:57 am
x 151
Contact:

Re: Mesh vs OpenGEX vs glTF

Post by spookyboo »

Hmm. Oke. But apparently the pose space isn't the same as the TRS values in the joint. The export does contain inverseBindMatrices though. See JSON snippet:

Code: Select all

"skins": [
  {
    "inverseBindMatrices": 82,
    "skeleton": 2,
    "joints": [2, 11, 12, 19, 20, 16, 13, 17, 14, 18, 15, 7, 3, 8, 4, 9, 5, 10, 6],
    "name": "Armature"
  }
],
82 refers to an accessor, which refers to a location of these matrices in binary data
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Mesh vs OpenGEX vs glTF

Post by dark_sylinc »

My advice is that you make two cubes in blender, one on top of the other in the Y axis, join them (Select both, then Ctrl+J).
Then add two bones, one bone for each cube; and perform a simple 90° rotation animation.

Then export to gltf.

That way you'll spot the problem immediately.
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: Mesh vs OpenGEX vs glTF

Post by Crashy »

I'm currently working on a glTF -> Ogre converter, and I had difficulties undestanding the use of the inverseBindMatrix too, but now I understand.

Some context for other people:
glTF file only holds a list of nodes, which may be interpreted as bones if they're related to a skin.
As every node, they have a transform relative to their parent. At first I thought this transform was the bind pose. Well, it may be, and in most cases it'll be the bind pose I guess, but the specifications tell that the skin also contains a list of "inverse bind matrix".

How to use them ? I must admit the light came from the godot source code (https://github.com/godotengine/godot/bl ... r_gltf.cpp )

I build the skeleton by recursively parsing the glTF scengraph. For each node, I do this:

Code: Select all

        Vector3 position = Vector3::ZERO;
        Vector3 scale = Vector3::UNIT_SCALE;
        Quaternion orientation = Quaternion::IDENTITY;
        bindMatrices[nodeToSkinIndex[currentNode]].decomposition(position, scale, orientation); //bindMatrix = inverseBindMatrix.inverseAffine()
        bone = skeleton->createBone(node.name.size() == 0 ? std::to_string(skeleton->getNumBones()) : node.name);

        parentBone->addChild(bone);

        bone->setPosition(parentBone->convertWorldToLocalPosition(position));
        bone->setOrientation(parentBone->convertWorldToLocalOrientation(orientation));
        bone->setScale(scale);//scale not handled properly for the moment
Ultimately, don't forget to call this after the animation creation, or everything will be distorted

Code: Select all

animation->setUseBaseKeyFrame(true);
The result(hiccup due to capture timings)
Image
reference image from the glTF repository:
Image

So, as a conclusion:
-If the "default" bone transform is giving the bind pose, inverseBindMatrix is useless in Ogre.
-If not, then don't even mind about default bone transform, and just use the inverseBindMatrix to configure the pose.

//EDIT: there is still an issue, the animation is not 100% accurate, I'm looking for a solution.
Follow la Moustache on Twitter or on Facebook
Image
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: Mesh vs OpenGEX vs glTF

Post by Crashy »

And here it is, I hope this is correct this time.

The "animation->setUseBaseKeyFrame(true)" call was a false positive, in fact animation weren't correct with that.

The distortion issue comes from the fact Ogre consider keyframes as delta from the binding pose, but in glTF it's absolute local transforms.
So when building keyframes, we need to make them relative to pose:

Code: Select all

//in Ogre, animations are deltas to pose !
key->setRotation(bone->getOrientation().Inverse()*keyframe.second.orientation);
key->setTranslate(bone->getPosition() - keyframe.second.position);
key->setScale(keyframe.second.scale);
I still don't know how to properly handle scale, but scaling bones has always been a problem to me.
Image
Follow la Moustache on Twitter or on Facebook
Image
User avatar
Ybalrid
Halfling
Posts: 89
Joined: Thu Jul 10, 2014 6:52 pm
Location: France
x 31
Contact:

Re: Mesh vs OpenGEX vs glTF

Post by Ybalrid »

Crashy's solution for parsing the key-frames working for my loader for 2.1 too ;-)

Image
Ogre_glTF Ogre v2-1 GLTF2 loader : topic link github repo
BtOgre21 Fork of btOgre, for Ogre v2-1 : topic link github repo
OIS Current maintainer : Official repository
Annwvyn VR focused game engine using Ogre : https://github.com/Ybalrid/Annwvyn https://annwvyn.org/
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: Mesh vs OpenGEX vs glTF

Post by Crashy »

I have now fixed scaling issues with the sample model Monster.gltf, which has scaled bones.
Here is how I manage the scale at bone creation:

Code: Select all

bone->setPosition(parentBone->convertWorldToLocalPosition(position));
bone->setOrientation(parentBone->convertWorldToLocalOrientation(orientation));
bone->setScale(parentBone->_getDerivedScale()/scale);
And when building the animation keyframe:

Code: Select all

key->setRotation(bone->getOrientation().Inverse()*keyframe.second.orientation);
key->setTranslate(bone->getPosition() - keyframe.second.position);
key->setScale(keyframe.second.scale /bone->getScale());
Follow la Moustache on Twitter or on Facebook
Image
Post Reply