OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

FBX plugin improvement regarding texture support


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Submission
View previous topic :: View next topic  
Author Message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Fri Jan 19, 2018 11:39 am    Post subject:
FBX plugin improvement regarding texture support
Reply with quote

Hi,
based on my experience during the last months I noticed that many times some authoring software tends to export FBX models using FbxLayeredTexture instead of FbxFileTexture even if only 1 texture is really used. When loading such models with the current version of the FBX plugin, the model would look un-textured.

I'd like to propose to support FbxLayeredTexture along with FbxFileTexture properties, I've already a modified version of the fbxMaterialToOsgStateSet.cpp file in order to read at least the first layer of a layered texture.

My idea is to replace this:

Code:
            int lNbTex = lProperty.GetSrcObjectCount<FbxFileTexture>();
            for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++)
            {
                FbxFileTexture* lTexture = FbxCast<FbxFileTexture>(lProperty.GetSrcObject<FbxFileTexture>(lTextureIndex));
                if (lTexture)
                {
                    result.diffuseTexture = fbxTextureToOsgTexture(lTexture);
                    result.diffuseChannel = lTexture->UVSet.Get();
                    result.diffuseScaleU = lTexture->GetScaleU();
                    result.diffuseScaleV = lTexture->GetScaleV();
                }

                //For now only allow 1 texture
                break;
            }


with this (for every supported channel, not only the diffuse one of course):

Code:
        // check if layered textures are used...
        int layeredTextureCount = lProperty.GetSrcObjectCount<FbxLayeredTexture>();
        if(layeredTextureCount)
        {
            FbxLayeredTexture* layered_texture = FbxCast<FbxLayeredTexture>(lProperty.GetSrcObject<FbxLayeredTexture>(0));
            int lNbTex = layered_texture->GetSrcObjectCount<FbxFileTexture>();

            if(lNbTex)
            {
                // at least 1 texture, use 1st...
                for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++)
                {
                    FbxFileTexture* lTexture = FbxCast<FbxFileTexture>(layered_texture->GetSrcObject<FbxFileTexture>(lTextureIndex));
                    if (lTexture)
                    {
                        result.diffuseTexture = fbxTextureToOsgTexture(lTexture);
                        result.diffuseChannel = lTexture->UVSet.Get();
                        result.diffuseScaleU = lTexture->GetScaleU();
                        result.diffuseScaleV = lTexture->GetScaleV();
                    }

                    //For now only allow 1 texture
                    break;
                }
            }
            else
                OSG_WARN << "FBX: Missing Textures in FbxLayeredTexture." << std::endl;
        }
        else
        {
            int lNbTex = lProperty.GetSrcObjectCount<FbxFileTexture>();
            for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++)
            {
                FbxFileTexture* lTexture = FbxCast<FbxFileTexture>(lProperty.GetSrcObject<FbxFileTexture>(lTextureIndex));
                if (lTexture)
                {
                    result.diffuseTexture = fbxTextureToOsgTexture(lTexture);
                    result.diffuseChannel = lTexture->UVSet.Get();
                    result.diffuseScaleU = lTexture->GetScaleU();
                    result.diffuseScaleV = lTexture->GetScaleV();
                }

                //For now only allow 1 texture
                break;
            }
        }




What do you think?

Alessandro
Back to top
View user's profile Send private message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Mon Jan 22, 2018 10:59 am    Post subject:
Reply with quote

Hi,
regarding the (initial) support of layered textures in the FBX plugin, my proposal is attached to this message.

Let me know what you think and if we can merge the file. Thanks.

Cheers,
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11360

PostPosted: Tue Jan 23, 2018 1:07 pm    Post subject:
FBX plugin improvement regarding texture support
Reply with quote

Hi Alessandro,

I just had quick look at the differences between your code and the
original code, there are a great number of changes required to handle
just one aspect of different source data. The code also has repeated
comments of //For now only allow 1 texture which is a sure indication
that the code isn't yet fully functional.

I haven't yet reviewed the StateSetContent class that is being set by
this convert function, my guess is that this is a bit too limited and
need to be improved to handle multiple textures as per the source
data, and then for the code that unpacks the various ways textures can
be sourced and assigned in a reusable ways so that there isn't these
repeated blocks with tiny differences in them. Instead there should
be some helper methods, or perhaps functors to help improve code reuse
and avoid these mega long methods.

Once this is done it should be easier to slot in the different ways
that textures can be specified.

BTW, I'm not the original author of this code and don't have access to
a modelling tool that provides FBX files so I'm having to learn stuff
just from the source code and review whether it makes sense form a
high level.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Tue Jan 23, 2018 2:26 pm    Post subject:
Reply with quote

Hi Robert,
yes, I agree that is quite a lot of code and also that each block seems to repeat over and over, but even though I could have somehow refactored the code I still think that the method would not be as readable as the original and would not be considerable shorter because of the many checks that should be added. Also, considering the time I could spend on this, I tried to keep the changes with respect to the original code as minimal as possible.

Moreover, I thought that when one would decide to add complete support for layered textures then each block would, presumably, differ a lot with respect to the others and also with the code that currently looks similar (the simple "file texture" case), so one would have to 'roll back' to the proposed initial implementation and then start adding things afterwards.

These were the reasons for me to opt for the cumbersome repeating blocks, even the comments were intentionally duplicated because they still make sense when the layered texture contains exactly 1 texture.

For sure the proposed solution is not the optimal implementation, I saw it more like a 'workaround' and as a starting point for someone that could be willing to keep adding support for layered textures... anyway there's no hurry to merge this until eventually a more complete support will be added from scratch.

If I manage to find more time I will also consider to refactor the code myself and come back with a new solution, just cannot plan it now Smile

Cheers,
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11360

PostPosted: Tue Jan 23, 2018 3:25 pm    Post subject:
FBX plugin improvement regarding texture support
Reply with quote

HI Alessandro,

I have a further look at fbxMaterialToSOsgStateSet.h + .cpp and it's
pretty clear to me that it needs to be refactored before any further
modifications are done. There is so much in the header and the ,cpp
that is repeated when it should have been written with written
differently.

The right way to do it would be to have a class to wrap all the
texture properties then have an instance of this for each of the
diffuse, opacity etc. This would result in far less code and greater
clarity.

I can't tackle this right away, but once I've cleared my present work
enough I'll return to this.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Tue Jan 23, 2018 4:49 pm    Post subject:
Reply with quote

Ok, thank you Robert.

I will be glad to help and contribute of course.

Cheers,
Alessandro
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Submission All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Loading a SilverLining environment ma... Kanpachi General 2 Wed Feb 14, 2018 4:34 pm View latest post
No new posts problem setting texture min/mag filter antiro42 General 8 Mon Feb 12, 2018 7:51 am View latest post
No new posts How to convert all ive texture units ... Bruce Cui Plugins [osgPlugins] 0 Tue Feb 06, 2018 3:15 am View latest post
No new posts iOS/OSX: avfoundation plugin not repo... a.terenzi Plugins [osgPlugins] 2 Fri Jan 19, 2018 8:50 am View latest post
No new posts removing texture from stateset Trajce Nikolov NICK General 3 Sat Jan 13, 2018 8:39 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP