Git Product home page Git Product logo

ogre_gltf's Introduction

Ogre_glTF

Project public taskboard

Library and Plugin to use glTF 2.0 resources with Ogre 2.1 licencied under the terms of the MIT licence

Loading an object with a PBR material as HLMS/PBS datablock

DEMO

Loading of an object with skeletal animation

DEMO

Requirements

  • Ogre 2.1 built for source (lattest commit available)
  • C++14 compliant compiler (any modern-ish version of Visual Studio or GCC will do)

CI builds are currently performed on Windows under Visual Studio 2017 and on Linux under g++7

(please, do not attempt to do the thing the travis script does directly under linux, unless you really think extracting random archives inside of / is wise πŸ˜‰)

How to use

  • Get the source code with git clone https://github.com/Ybalrid/Ogre_glTF --recursive
  • Build the library with CMake, using the build subdirectory, and get the Ogre_glTF.dll/libOgre_glTF.so file (instructions below)
  • Point your compiler to the public headers (the /include directory of the repository), or copy them to your project
  • Point Ogre to use Ogre_glTF as a plugin in the same way you'll do to the other (e.g. RenderSystems, using plugin.cfg, ...)
  • You can put binary glTF files (GLB files) inside your resources, like you would do with .mesh/.skeleton/textures files
  • In your code:
//Get access to the gltf loader, and load a GLB file in the resources to an item
//This actually search through the list of installed plugin, keep that pointer somewhere convinient
auto glTFLoader = gltfPluginAccessor::findPlugin()->getLoader(); 

//You can creae an Item for a scene by giving the name of the GLB file to look for in the resources
Ogre::Item* cesiumMan = glTFLoader->getModelData("CesiumMan.glb", glTFLoaderInterface::LoadFrom::ResourceManager).makeItem(smgr);

In case you cloned without --recursive, cd into the Ogre_glTF directory and use git submodule update --init --recursive to download dependencies correctly.

Building the source code

First of all, locally clone this repository. It uses git submodules to get it's dependencies, so you just need to do

git clone --recursive https://github.com/Ybalrid/Ogre_glTF

This project uses CMake. The CMake directory is a simple copy of every cmake script shipped in the Ogre SDK, to make things simpler.

You should get and install Ogre 2.1 from source on your system, some help can be found here: https://forums.ogre3d.org/viewtopic.php?f=25&t=92874

To build the project, you need to have Ogre 2.1 build and "installed" somewhere. Windows users may need to build the INSTALL target of Ogre and then to set the OGRE_HOME variable to the "build/sdk" folder. Linux users, you can make install Ogre in /usr/local

then, do the folliwng (linux) :

cd build
cmake ..                        #execute CMake while pointing at the parent directory
make                            #build the library and the demo program

#to be able to run the demo program as-is, do the following:
cp -r <path to HLMS> .          #add the Hlms shader code that comes with Ogre
cp <path to ogre plugins>/* .   #add the necessary plugins (RenderSystem_GL3+)

On a typical install from Ogre's source code on linux, theses path are /usr/local/share/OGRE/Media/Hlms and /usr/local/lib/OGRE/* respectively

(windows) :

  • Use cmake-gui to generate a Visual Studio solution inside the build using the same version that you built Ogre with. You probably need to set the OGRE_HOME variable.
  • Open the .sln (solution) file into Visual Studio. You'll get 2 projects : Ogre_glTF (the DLL) and Ogre_glTF_TEST (a test program)
  • To make the test program works, copy inside the "build" directory all the .dll (and .pdb if you want to debug) files from Ogre's debug and release binary directories
  • Copy the HLMS libary to the "build" directory

The "test" program is really crude and badly written, it was to validate that some of the features were working during development.

Project details

The goal is to be able to load the geometry, the PBR material and the animations of an object from glTF and use Ogre's classes as if you just got the object as a .mesh from Ogre's resource manager.

The curent code is limitted into loading the first declared mesh in a glTF file, or, if the glTF file has multiple "secenes", and has a "default scene" value, it will take the mesh attached to the fist node of the default scene.

Think of it as replacing .mesh files with binary .glb files, that are a standard format, with clear material/skeleton/animation/textures definitions enclosed, and with official exporters that works according to an industry-standard specification.

I'm wanting to get this functionality working inside my game engine (Annwvyn, a VR application developement framework that uses Ogre), and specifically I want to be able to use the glTF official Blender exporter.

The user facing API hasn't been worked on quite well, the only thing that has been cared on is to follow a pImpl (compillation firewall) pattern to hide to your code the dependencies in this library.

This library is based on tinygltf. https://github.com/syoyo/tinygltf. tinygltf itsefl vendor in some other opensource projects, like stb_image and a json loading library.

Features

This project is currently in developement, here's a list of features that we are working on, ticked items means that the feature is implemented.

  • Load mesh infrmation (index and vertex buffer, including vertex coordinates, normal vectors, texture coordinates) and create an Ogre::Mesh out of it via Ogre::MeshManager and Ogre::VaoManager
  • Load Image information from glTF into Ogre::TextureManager
  • Load PBR material definition form glTF and create coresponding Ogre::HlmsPbsDatablock for them. (Ogre call PBR "PBS", more or less)
  • Load "skin" information from glTF and create corresponding Ogre::Skeleton for the mesh
  • Loop through all the vertex <-> bone assignement to get a valid skeleton configuration
  • Load animation information and create animations from them
  • Load mesh "target" information and create Ogre "morph" target from them (Ogre 2.1 doesn't support them yet)
  • Load .glb files from Ogre's resource manager
  • Load .gltf from Ogre's resource manager (Not really practical as it relies on URIs and path to resources. It is probably easier to manage and more efficient to stick with .glb in an offline workflow)
  • Being able to "load" and "install" this as an actual Ogre plugin

Known issues

  • There's a problem with loading normal map data with the Direct 3D 11 render system of Ogre issue #2
  • There's several little issues with the texture loading. A small refactor would help. See the TODO comments.
  • Library is not "installable" from CMakeLists.txt yet. Users need to get the .dll / .so file accessible to their program, and point their compiler to look for headers the "include" directory
  • Can only load one mesh and it's associated material in a file. Will either load the first one, of the fist node of the default scene, depending if the default scene is set
  • Library only has been tested on an handfull of glTF files, so some corner cases may make it not work.

Contributors

This project is Open Source. If you can improve it in any way, Pull Requests are welcommed!

Here's the list of the contributors that hepled out with this projet:

  • Crashy helped figure out how to correctly bind the skeleton base pauses, and how to get relative transform in the keyframes
  • Matt Chang Fixes in mesh loading
  • jprajala added multi material loading for model files. Fixed bouding box issue where object will have the AABBs of the last loaded primitive. (now bounding box are merged together when model has multiple primitives.)
  • Stig Atle @stig-atle
  • Stuggy Implemented the retreival of node local transform, if you just want a model, but has to apply the scene nodes transform on them
  • MatΓ­as being the main author/maintainer of the Ogre 2.x for awnsering countless silly questions over twitter, gitter and the forums... ^^"

Notes on third party components

tinygltf is an header only library. It is included in this very repository via git submodules. If you are about to clone this repository, you should use git clone --recursive

The library define inside one of it's files the implementation of tinygltf and stb_image. This shouldn't be an issue and your program using ogre_glTF shouldn't be affected by them in any way. Everything is hidden inside a pimpl

If you have issues related with them, please open an issue :)

ogre_gltf's People

Contributors

chchwy avatar jprajala avatar stig-atle avatar stuggy avatar xissburg avatar ybalrid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ogre_gltf's Issues

CMAKE issue.

I'm trying to build the project.
But i'm facing an issue, i built ogre 2.1 but the sdk folder doesn't contain the necessary files.

Am i missing a step in the ogre build?

Here is my build/sdk folder from ogre

β”œβ”€β”€ bin
β”‚Β Β  β”œβ”€β”€ Debug
β”‚Β Β  β”‚Β Β  └── SDL2.dll
β”‚Β Β  └── Release
β”‚Β Β      └── SDL2.dll
β”œβ”€β”€ include
β”‚Β Β  └── SDL2
β”‚Β Β      β”œβ”€β”€ begin_code.h
β”‚Β Β      β”œβ”€β”€ close_code.h
β”‚Β Β      β”œβ”€β”€ SDL.h
β”‚Β Β      β”œβ”€β”€ SDL_assert.h
β”‚Β Β      β”œβ”€β”€ SDL_atomic.h
β”‚Β Β      β”œβ”€β”€ SDL_audio.h
β”‚Β Β      β”œβ”€β”€ SDL_bits.h
β”‚Β Β      β”œβ”€β”€ SDL_blendmode.h
β”‚Β Β      β”œβ”€β”€ SDL_clipboard.h
β”‚Β Β      β”œβ”€β”€ SDL_config.h
β”‚Β Β      β”œβ”€β”€ SDL_config_android.h
β”‚Β Β      β”œβ”€β”€ SDL_config_iphoneos.h
β”‚Β Β      β”œβ”€β”€ SDL_config_macosx.h
β”‚Β Β      β”œβ”€β”€ SDL_config_minimal.h
β”‚Β Β      β”œβ”€β”€ SDL_config_pandora.h
β”‚Β Β      β”œβ”€β”€ SDL_config_psp.h
β”‚Β Β      β”œβ”€β”€ SDL_config_windows.h
β”‚Β Β      β”œβ”€β”€ SDL_config_winrt.h
β”‚Β Β      β”œβ”€β”€ SDL_config_wiz.h
β”‚Β Β      β”œβ”€β”€ SDL_copying.h
β”‚Β Β      β”œβ”€β”€ SDL_cpuinfo.h
β”‚Β Β      β”œβ”€β”€ SDL_egl.h
β”‚Β Β      β”œβ”€β”€ SDL_endian.h
β”‚Β Β      β”œβ”€β”€ SDL_error.h
β”‚Β Β      β”œβ”€β”€ SDL_events.h
β”‚Β Β      β”œβ”€β”€ SDL_filesystem.h
β”‚Β Β      β”œβ”€β”€ SDL_gamecontroller.h
β”‚Β Β      β”œβ”€β”€ SDL_gesture.h
β”‚Β Β      β”œβ”€β”€ SDL_haptic.h
β”‚Β Β      β”œβ”€β”€ SDL_hints.h
β”‚Β Β      β”œβ”€β”€ SDL_joystick.h
β”‚Β Β      β”œβ”€β”€ SDL_keyboard.h
β”‚Β Β      β”œβ”€β”€ SDL_keycode.h
β”‚Β Β      β”œβ”€β”€ SDL_loadso.h
β”‚Β Β      β”œβ”€β”€ SDL_log.h
β”‚Β Β      β”œβ”€β”€ SDL_main.h
β”‚Β Β      β”œβ”€β”€ SDL_messagebox.h
β”‚Β Β      β”œβ”€β”€ SDL_mouse.h
β”‚Β Β      β”œβ”€β”€ SDL_mutex.h
β”‚Β Β      β”œβ”€β”€ SDL_name.h
β”‚Β Β      β”œβ”€β”€ SDL_opengl.h
β”‚Β Β      β”œβ”€β”€ SDL_opengl_glext.h
β”‚Β Β      β”œβ”€β”€ SDL_opengles.h
β”‚Β Β      β”œβ”€β”€ SDL_opengles2.h
β”‚Β Β      β”œβ”€β”€ SDL_opengles2_gl2.h
β”‚Β Β      β”œβ”€β”€ SDL_opengles2_gl2ext.h
β”‚Β Β      β”œβ”€β”€ SDL_opengles2_gl2platform.h
β”‚Β Β      β”œβ”€β”€ SDL_opengles2_khrplatform.h
β”‚Β Β      β”œβ”€β”€ SDL_pixels.h
β”‚Β Β      β”œβ”€β”€ SDL_platform.h
β”‚Β Β      β”œβ”€β”€ SDL_power.h
β”‚Β Β      β”œβ”€β”€ SDL_quit.h
β”‚Β Β      β”œβ”€β”€ SDL_rect.h
β”‚Β Β      β”œβ”€β”€ SDL_render.h
β”‚Β Β      β”œβ”€β”€ SDL_revision.h
β”‚Β Β      β”œβ”€β”€ SDL_rwops.h
β”‚Β Β      β”œβ”€β”€ SDL_scancode.h
β”‚Β Β      β”œβ”€β”€ SDL_shape.h
β”‚Β Β      β”œβ”€β”€ SDL_stdinc.h
β”‚Β Β      β”œβ”€β”€ SDL_surface.h
β”‚Β Β      β”œβ”€β”€ SDL_system.h
β”‚Β Β      β”œβ”€β”€ SDL_syswm.h
β”‚Β Β      β”œβ”€β”€ SDL_test.h
β”‚Β Β      β”œβ”€β”€ SDL_test_assert.h
β”‚Β Β      β”œβ”€β”€ SDL_test_common.h
β”‚Β Β      β”œβ”€β”€ SDL_test_compare.h
β”‚Β Β      β”œβ”€β”€ SDL_test_crc32.h
β”‚Β Β      β”œβ”€β”€ SDL_test_font.h
β”‚Β Β      β”œβ”€β”€ SDL_test_fuzzer.h
β”‚Β Β      β”œβ”€β”€ SDL_test_harness.h
β”‚Β Β      β”œβ”€β”€ SDL_test_images.h
β”‚Β Β      β”œβ”€β”€ SDL_test_log.h
β”‚Β Β      β”œβ”€β”€ SDL_test_md5.h
β”‚Β Β      β”œβ”€β”€ SDL_test_random.h
β”‚Β Β      β”œβ”€β”€ SDL_thread.h
β”‚Β Β      β”œβ”€β”€ SDL_timer.h
β”‚Β Β      β”œβ”€β”€ SDL_touch.h
β”‚Β Β      β”œβ”€β”€ SDL_types.h
β”‚Β Β      β”œβ”€β”€ SDL_version.h
β”‚Β Β      └── SDL_video.h
└── lib
    β”œβ”€β”€ SDL2.lib
    └── SDL2main.lib

Why do some class names begin in lower case?

I am in the process of refactoring, cleaning up and changing a few things in this project, and am also implementing new features. I'll submit a pull request later though I'm not sure all my changes will be welcome.

One thing I'm trying to understand and am feeling the urge to change are certain class names that begin in lower case, e.g. loaderAdapter, modelConverter, materialLoader, skeletonImporter, textureImporter. Why's that and should I just go ahead and capitalize them?

D3D11 Normal map problem

The current code that load the normal map data into a texture is a bit janky. And it's working only with OpenGL.

Here's how it's looking like with the GL3+ RenderSystem

ogre_gltf_test_2018-01-04_02-14-13

And here's what we are currently getting with the D3D11 RenderSystem

ogre_gltf_test_2018-01-04_02-14-30

From what I understand, it seems that Ogre expect the texture to be in an "SNORM" pixel format.

The only info I currently have on the issue is this tweet exchange :

https://twitter.com/matiasgoldberg/status/948332133998874624

The relative section of the code is the Ogre_glTF_textureImporter::getNormalSNORM(int gltfTextureSourceID)method

Refactor glTFLoaderInterface

Currently the interface looks like this :

    ///Plugin accessible interface that plugin users can use
    struct glTFLoaderInterface
    {
        ///Polymorphic dtor
        virtual ~glTFLoaderInterface() = default;

        ///Get you an item from a GLB file loaded inside an Ogre resource group
        virtual Ogre::Item* getItemFromResource(const std::string& name, Ogre::SceneManager* smgr) = 0;

        ///Get you an item and transform from a GLB file loaded inside an Ogre resource group
        virtual ItemAndTransform getItemAndTransformFromResource(const std::string& name, Ogre::SceneManager* smgr) = 0;

        ///Get you an item and transform from a GLB or a GLTF file from the filesystem.
        virtual ItemAndTransform getItemAndTransformFromFileSystem(const std::string& name, Ogre::SceneManager* smgr) =0;

        ///Get you an item from a GLB or a GLTF file from the filesystem.
        virtual Ogre::Item* getItemFromFileSystem(const std::string& fileName, Ogre::SceneManager* smgr) = 0;

        ///Get you a mesh and a material datablock from a GLB in the resource manager
        virtual MeshAndDataBlock getMeshFromResource(const std::string& name) = 0;

        ///Gets you a mesh and a material datablock from GLB or a GLTF file from the filesystem
        virtual MeshAndDataBlock getMeshFromFileSystem(const std::string& name) = 0;
    };

The XXXFileSystem and XXXResource methods are mostly identical. A simple flag could singal where we are supposed to load from.

Returning an Item, or a Mesh, or an Item with a transofrom (or a mesh with a transform,t hat is not possible right now) should be handled better.

Failing to load skeleton

Hello, lovely plugin here. I'm just struggling to load a particular mesh:

Walking2.glb.zip
(However, CesiumMan works fine)

Basically, I am receiving the following assertion from Ogre:
(!pos.isNaN() && "Invalid vector supplied as parameter"), function setPosition, file .../OgreMain/src/OgreOldNode.cpp, line 391.

bone->setPosition(parent->convertWorldToLocalPosition(translation));

It looks like convertWorldToLocalPosition is returning NaN values because the scale of the parent bone is +inf.

If I comment out the following line, the mesh loads fine - however, playing an animation makes everything look awful. I may be mistaken but I believe the scale becomes so small until it reaches a point where _getDerivedScale starts returning +inf.

bone->setScale(parent->_getDerivedScale() / scale);

I'm kinda running out of ideas and would appreciate it if I could be pointed in the right direction

Thanks!

Adapt texture loading code to Ogre 2.2

The current code that loads texture data is both messy and inefficient. There's 2 things that need fixing :

  1. we are loading textures before knowing what material the glTF will use. Thus, we don't know what purpose the textures we load. Some of theses textures differ between how glTF store them and how HLMS PBS need them (eg : metalic-roughness map has to be separated in 2 "one color" texture from the 1 "two color" texture).

  2. current texture loading code is inefficient and messy. It needs cleaning.

Original issue about that problem was #17. But instead of concentrating on fixing the code for Ogre 2.1, we should rewrite it for 2.2, while incorporating the necessary changes.

The Ogre 2.1 code path will still benefit from the change due to the updated texture loading logic, but it is by no mean necessary.

I'm closing issue #17 now, as it is irrelevant from now on.

Mesh boundaries (AABB) aren't set properly

Right now I'm putting a fixed sphere radius, but it's wrong.

There' minimal and maximal values on vertex buffers in glTF, do some reading and see if we can set a AABB with this.

Add custom exception types

There's a number of places that this code throws exceptions by throwing std::runtime_error.

It would be better to throw a custom type that could be caught independently and that would permit to manage the error if the situation permits it.

Theses exception types should inherit from either runtime_error or from Ogre's own exceptions. It would be good if something was printed to the log automatically (I think the Ogre exceptions does that in their ctor)

glTF 2.0 or 1.0

Hi,

Nice job done on your repot!
Could you tell me, does this project allows glTF 2.0 scene loading or only glTF 1.0?

Thanks in advance.

#-- edit after having a look to https://github.com/syoyo/tinygltf
i suppose it's glTF 2.0 compatible.

Skeleton root bone child issue.

I tested a bit tonight with exported cylinder with bones.
It seems as if the gltf file has the mesh as a child to the root bone, so when the loader loads the file it tries to make the mesh as a bone - and fails.
So this means the root bones has two children, mesh and the next bone.

The test scene I used was the sample file that comes with the gltf blender addon.
03_skinned_cylinder.blend

I added some more logging where the children are created, then I printed the name of the child.
You will then see the cylinder appear as the first child like this:

22:25:06: Bone 0 has 2 children
22:25:06: Looping through current child: Cylinder

(Cylinder is the name of the mesh object itself.).

Review the Texture Loader code

The texture loader is maybe ineficient. All textures are loaded as-is and when material request them, some of them are re-computed to be available in Ogre's expected format.

Also, there's Issue #2 to be fixed. This is probably an image format problem.

Test program doesn't stop cleanly

Here's the issues with the "test" program test/main.cpp

  • Program hangs on Windows with the GL render system

  • Program crashes on Windows when closing window on Direct3D render system

  • Everything seems fine on linux

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.