Page 2 of 2

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

Posted: Wed Oct 31, 2018 12:41 am
by Ybalrid
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.

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

Posted: Thu Nov 01, 2018 10:58 pm
by Owl53
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

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

Posted: Thu Nov 01, 2018 11:10 pm
by Slicky
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.

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

Posted: Thu Nov 01, 2018 11:14 pm
by Owl53
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!

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

Posted: Thu Nov 01, 2018 11:56 pm
by Ybalrid
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.

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

Posted: Fri Nov 02, 2018 8:45 am
by Slicky
Also there is an online .glb creator that works well if you have all the files but no binary.

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

Posted: Fri Nov 02, 2018 10:06 am
by Zonder
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/

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

Posted: Fri Nov 02, 2018 11:26 am
by Owl53
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!

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

Posted: Fri Nov 02, 2018 7:32 pm
by Ybalrid
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

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

Posted: Fri Nov 02, 2018 7:33 pm
by Slicky
Cool will check it out.

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

Posted: Wed Jan 30, 2019 1:45 am
by Ybalrid
Small update : plugin should be able to load glTF assets that uses Draco geometry compression

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

Posted: Wed Jan 30, 2019 3:24 am
by rujialiu
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-)

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

Posted: Tue Feb 05, 2019 2:15 pm
by Ybalrid
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: