[2.1][Addon] glTF loader plugin for Ogre v2-1

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
User avatar
Ybalrid
Halfling
Posts: 82
Joined: Thu Jul 10, 2014 6:52 pm
Location: France
x 23
Contact:

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Ybalrid » Wed Oct 31, 2018 12:41 am

The code that loads node transform seems to have some issues...

master branch has a first fix. Rotation data was never actually loaded because a quaternion as 4 attributes, and it was only doing it if the size of the data was 3. (@Slicky the scale vector was fine, so it probably crept under the radar when you were testing :wink:)

Also, it was testing once if the different vectors were of the right size, to load everything, but it it wasn't, the different array were still initialized to zero, and assigned in the struct, meaning that you could have transform with
  • a translation of (0,0,0) (not a big deal)
  • a scale of (0,0,0) (oops. Invisible object)
  • a null quaternion (0,0,0,0) (oops, you just broke the maths, and triggered a pretty nasty and weird assert in debug in the code that use cpu intrinsic to go faster...) :mrgreen:
This is fixed. Also, there's no need to check for the size of theses things in tiny_gltf nodes, this is error-prone. The library's guaranties that a position/scale is of size 3, or is empty, and same goes for an orientation, but with size 4.

Now, for the actual transform, it is pulling the first node of the scene, and that's the node where the mesh is attached, so that's the local transform of that node. But, it may still be different as what you would expect because the actual position of the model in the scene would be dependent on parents of that node. I have an issue with one sample file (Cesium_man) where it seems that this node doesn't define a transform, but the object still should be rotated by -HALF_PI around X to look "normal".

So to get that transform information, it still needs to apply all the transform from the root node to the node that owns the mesh inside the gltf hierarchy.

Edit: Actually, it seems that there's 2 ways the local transform of a node can be described in glTF : by a local matrix, or by the 2 vectors/ one quaternion way.

For some reason, the translation/rotation/scales of nodes exposed by tiny_gltf doesn't seem to be actually populated, but the local matrix is. So it's just matter of loading the arry in a Ogre::Matrix4 (the constructor I recently contributed to Ogre permit to do that jut by giving a pointer to the float array), transpose it (because nobody can agree between row/column major), and call "decomposition".

Something that uses this in the case the transform wasn't applied by the translate/scale/rotate method will be soon live on the master branch.
0 x
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/

Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Owl53 » Thu Nov 01, 2018 10:58 pm

Sorry for the basic question, but this is something that I am currently unfamiliar with. Just to confirm that my understanding of the process is correct; if you were using a modelling program, say Maya, would a plugin for Maya need to be downloaded and installed to export as glTF, then it can be loaded into Ogre using your plugin?

Since reading your thread, I have read up on glTF and understand why it is being used increasingly commonly, but I just wanted to make sure I understand how I would go about using this format in the future.

Thanks
0 x

Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 537
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 12

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Slicky » Thu Nov 01, 2018 11:10 pm

Yes you generally need a plugin to the modelling program to export to gltf. There are quite a few available for different modelers. I think the Khronos site has a list.
0 x

Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Owl53 » Thu Nov 01, 2018 11:14 pm

Slicky wrote:
Thu Nov 01, 2018 11:10 pm
Yes you generally need a plugin to the modelling program to export to gltf. There are quite a few available for different modelers. I think the Khronos site has a list.
I've found the list of available exporters you mentioned, thank you for the confirmation!
0 x

User avatar
Ybalrid
Halfling
Posts: 82
Joined: Thu Jul 10, 2014 6:52 pm
Location: France
x 23
Contact:

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Ybalrid » Thu Nov 01, 2018 11:56 pm

Owl53 wrote:
Thu Nov 01, 2018 10:58 pm
Sorry for the basic question, but this is something that I am currently unfamiliar with. Just to confirm that my understanding of the process is correct; if you were using a modelling program, say Maya, would a plugin for Maya need to be downloaded and installed to export as glTF, then it can be loaded into Ogre using your plugin?
This is exactly that! :D

If you want more details:

The "TF" in glTF means "transmission format". It's an open-standard to describe 3D assets, but not like collada was. It's not to exchange "authoring" files (eg = "projects files" for 3D modeling programs), but to describe "content" to be consumed by real-time applications, like game engines. The idea is that gltf is a no-frills, explicit, compact binary format for that. (In "opengl" speak, you could upload all the buffers from the asset directly, and use the metadata to setup the VAO/VBO/EBOs for a model)

What you do is that you export a glTF file (and in our case, preferable the "binary" version of the format : .glb from any kind of modeling software. I don't know if Maya has the functionality from scratch or if you need a plugin, but that's the idea.

I started working on this project because I was frustrated by the current "Blender to Ogre" exporter, and that I haven't seen a good, simple way to get just a model with a PBR material (metal-roughness workflow) applied to it from Blender, to a file that would "just work" with Ogre. And it seemed to me that it was "more useful" at the time to build a glTF loader that to try to work on a blender exporter...

By the way, this plugin could be used to create a "glTF to Ogre .mesh" program if somebody really wants it. Once the model is loaded into Ogre, you could just re-serialize the mesh to disk, same for the HlmsPbsDatablock, you could write a JSON output, and same for the textures.

If anything is unclear, do not hesitate to ask questions.
1 x
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/

Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 537
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 12

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Slicky » Fri Nov 02, 2018 8:45 am

Also there is an online .glb creator that works well if you have all the files but no binary.
0 x

User avatar
Zonder
Ogre Magi
Posts: 1129
Joined: Mon Aug 04, 2008 7:51 pm
Location: Manchester - England
x 21

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Zonder » Fri Nov 02, 2018 10:06 am

Thought I would look up the online tool found these:

Collada, Obj -> glTF + glb
http://52.4.31.236/convertmodel.html

Various -> glTF (three.js based) has some limitations
https://blackthread.io/gltf-converter/

glTF -> glb
https://sbtron.github.io/makeglb/
1 x
There are 10 types of people in the world: Those who understand binary, and those who don't...

Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Owl53 » Fri Nov 02, 2018 11:26 am

Slicky wrote:
Fri Nov 02, 2018 8:45 am
Also there is an online .glb creator that works well if you have all the files but no binary.
Ybalrid wrote:
Thu Nov 01, 2018 11:56 pm
Owl53 wrote:
Thu Nov 01, 2018 10:58 pm
Sorry for the basic question, but this is something that I am currently unfamiliar with. Just to confirm that my understanding of the process is correct; if you were using a modelling program, say Maya, would a plugin for Maya need to be downloaded and installed to export as glTF, then it can be loaded into Ogre using your plugin?
This is exactly that! :D

If you want more details:

The "TF" in glTF means "transmission format". It's an open-standard to describe 3D assets, but not like collada was. It's not to exchange "authoring" files (eg = "projects files" for 3D modeling programs), but to describe "content" to be consumed by real-time applications, like game engines. The idea is that gltf is a no-frills, explicit, compact binary format for that. (In "opengl" speak, you could upload all the buffers from the asset directly, and use the metadata to setup the VAO/VBO/EBOs for a model)

What you do is that you export a glTF file (and in our case, preferable the "binary" version of the format : .glb from any kind of modeling software. I don't know if Maya has the functionality from scratch or if you need a plugin, but that's the idea.

I started working on this project because I was frustrated by the current "Blender to Ogre" exporter, and that I haven't seen a good, simple way to get just a model with a PBR material (metal-roughness workflow) applied to it from Blender, to a file that would "just work" with Ogre. And it seemed to me that it was "more useful" at the time to build a glTF loader that to try to work on a blender exporter...

By the way, this plugin could be used to create a "glTF to Ogre .mesh" program if somebody really wants it. Once the model is loaded into Ogre, you could just re-serialize the mesh to disk, same for the HlmsPbsDatablock, you could write a JSON output, and same for the textures.

If anything is unclear, do not hesitate to ask questions.
I had read similar to a lot of that, but an additional perspective is always welcome so thanks to you both for the additional information!
0 x

User avatar
Ybalrid
Halfling
Posts: 82
Joined: Thu Jul 10, 2014 6:52 pm
Location: France
x 23
Contact:

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Ybalrid » Fri Nov 02, 2018 7:32 pm

So, I finished the little cleanups I've talked about. I'm happy with the new getModelData() method, so I just tagged the new version 0.2 on github! :D
1 x
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/

Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 537
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 12

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Slicky » Fri Nov 02, 2018 7:33 pm

Cool will check it out.
0 x

User avatar
Ybalrid
Halfling
Posts: 82
Joined: Thu Jul 10, 2014 6:52 pm
Location: France
x 23
Contact:

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Ybalrid » Wed Jan 30, 2019 1:45 am

Small update : plugin should be able to load glTF assets that uses Draco geometry compression
1 x
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/

rujialiu
Goblin
Posts: 213
Joined: Mon May 09, 2016 8:21 am
x 20

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by rujialiu » Wed Jan 30, 2019 3:24 am

Ybalrid wrote:
Wed Jan 30, 2019 1:45 am
Small update : plugin should be able to load glTF assets that uses Draco geometry compression
Awesome!!! I like draco.
BTW: Are you planing to port your addon to Ogre 2.2? It will remove WIP label and several active users here already started porting some time ago 8-)
0 x

User avatar
Ybalrid
Halfling
Posts: 82
Joined: Thu Jul 10, 2014 6:52 pm
Location: France
x 23
Contact:

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by Ybalrid » Tue Feb 05, 2019 2:15 pm

rujialiu wrote:
Wed Jan 30, 2019 3:24 am
Ybalrid wrote:
Wed Jan 30, 2019 1:45 am
Small update : plugin should be able to load glTF assets that uses Draco geometry compression
Awesome!!! I like draco.
BTW: Are you planing to port your addon to Ogre 2.2? It will remove WIP label and several active users here already started porting some time ago 8-)
The only piece of that plugin that should need rework for 2.2 is the texture loading code AFAIK. It's on the TODOlist, but I cannot give any timeline on that. I'll keep you guys up to date on when I start working on it. Probably won't start before I start porting one of my silly projects to 2.2 ;-)

If you look at the code, the current way texture and materials are loaded to be created by Ogre is a bit backwards anyway... It needs some refactoring anyhow, but I figured since I'm going to port it to 2.2 at some point, I will not do that work 2 times :mrgreen:
0 x
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/

rujialiu
Goblin
Posts: 213
Joined: Mon May 09, 2016 8:21 am
x 20

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by rujialiu » Today, 2019 3:42 am

Ybalrid wrote:
Tue Feb 05, 2019 2:15 pm
The only piece of that plugin that should need rework for 2.2 is the texture loading code AFAIK. It's on the TODOlist, but I cannot give any timeline on that. I'll keep you guys up to date on when I start working on it. Probably won't start before I start porting one of my silly projects to 2.2 ;-)

If you look at the code, the current way texture and materials are loaded to be created by Ogre is a bit backwards anyway... It needs some refactoring anyhow, but I figured since I'm going to port it to 2.2 at some point, I will not do that work 2 times :mrgreen:
Just gently remind you that Ogre 2.2 is no longer WIP 8-)
0 x

rujialiu
Goblin
Posts: 213
Joined: Mon May 09, 2016 8:21 am
x 20

Re: [2.1][Addon] glTF loader plugin for Ogre v2-1

Post by rujialiu » Today, 2019 4:09 am

rujialiu wrote:
Today, 2019 3:42 am
Just gently remind you that Ogre 2.2 is no longer WIP 8-)
hmm... maybe waiting a bit long is better. According to your latest blog:
And the only real missing feature is the loading of morph targets animations. Currently Ogre 2.x does not support animation targets in the v2-1 or v2-2 branches. I know somebody was working on this some time ago, and had support for that in OpenGL and metal, but last time I’ve checked this person had closed his pull request.
Now that morph animations branch is merge into Ogre 2.1, but not Ogre 2.2 yet. The reason is discribed here:
https://bitbucket.org/sinbad/ogre/pull- ... tions/diff
0 x

Post Reply