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 textures file names is UTF8


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Plugins [osgPlugins]
View previous topic :: View next topic  
Author Message
WalkingCat
Newbie


Joined: 01 Nov 2012
Posts: 10

PostPosted: Wed Nov 14, 2012 5:56 am    Post subject:
FBX textures file names is UTF8
Reply with quote

According to my tests, by exporting fbx files from 3DS Max,
the external texture file names stored in the fbx file is actually UTF-8.

It means, KFbxFileTexture::GetFileName returns an UTF-8 string,
if the string contains complex characters like Chinese/Janpanese/Korean etc,
osgDB::readImageFile() cant found the file.

I suggest the fbx plugin to convert the file name from UTF-8 to current
code page before passing it to readImageFile, its not always the corret CP,
but its the best we can try here.
Back to top
View user's profile Send private message
WalkingCat
Newbie


Joined: 01 Nov 2012
Posts: 10

PostPosted: Wed Nov 14, 2012 6:04 am    Post subject:
Reply with quote

Actually, the official Autodesk documents says the same:

http://download.autodesk.com/global/docs/fbxsdk2012/en_us/files/GUID-D3844B1D-4E74-4C64-AD79-14B00EB1FE4-42.htm

Quote:
FBX SDK uses UTF-8 strings internally.


and you should use KString and its macros to deal with strings in fbx sdk.

http://download.autodesk.com/global/docs/fbxsdk2012/en_us/files/GUID-6766AFC0-4F25-4436-A5EE-BCDAFC6CB58-34.htm
Back to top
View user's profile Send private message
WalkingCat
Newbie


Joined: 01 Nov 2012
Posts: 10

PostPosted: Wed Nov 14, 2012 6:38 am    Post subject:
Reply with quote

OK, I tried modify the file \src\osgPlugins\fbx\fbxMaterialToOsgStateSet.cpp and changed this function, it seems to work !

but I guess there are other places to change right ?
actually any string got from fbx sdk should be converted from utf8 to ansi before used in osg.

Code:
osg::ref_ptr<osg::Texture2D>
FbxMaterialToOsgStateSet::fbxTextureToOsgTexture(const KFbxFileTexture* fbx)
{
    ImageMap::iterator it = _imageMap.find(fbx->GetFileName());
    if (it != _imageMap.end())
        return it->second;
    osg::ref_ptr<osg::Image> pImage = NULL;

    // Warning: fbx->GetRelativeFileName() is relative TO EXECUTION DIR
    //          fbx->GetFileName() is as stored initially in the FBX
   char* fileName = NULL; KFbxUTF8ToAnsi(fbx->GetFileName(), fileName);
   char* relativeFileName = NULL; KFbxUTF8ToAnsi(fbx->GetRelativeFileName(), relativeFileName);

    if ((pImage = osgDB::readImageFile(osgDB::concatPaths(_dir, fileName), _options)) ||                // First try "export dir/name"
        (pImage = osgDB::readImageFile(fileName, _options)) ||                                        // Then try  "name" (if absolute)
        (pImage = osgDB::readImageFile(osgDB::concatPaths(_dir, relativeFileName), _options)))        // Else try  "current dir/name"
    {
        osg::ref_ptr<osg::Texture2D> pOsgTex = new osg::Texture2D;
        pOsgTex->setImage(pImage.get());
        pOsgTex->setWrap(osg::Texture2D::WRAP_S, convertWrap(fbx->GetWrapModeU()));
        pOsgTex->setWrap(osg::Texture2D::WRAP_T, convertWrap(fbx->GetWrapModeV()));
        _imageMap.insert(std::make_pair(fbx->GetFileName(), pOsgTex.get()));
        return pOsgTex;
    }
    else
    {
        return NULL;
    }

   delete fileName;
   delete relativeFileName;
}
Back to top
View user's profile Send private message
WalkingCat
Newbie


Joined: 01 Nov 2012
Posts: 10

PostPosted: Wed Nov 14, 2012 6:52 am    Post subject:
Reply with quote

Well, I just found this option OSG_USE_UTF8_FILENAMES, so I guess my changes are not needed if this option is on, but still better when its off, so, may still worth considering. Razz
Back to top
View user's profile Send private message
WalkingCat
Newbie


Joined: 01 Nov 2012
Posts: 10

PostPosted: Wed Dec 05, 2012 7:11 pm    Post subject:
FBX textures file names is UTF8
Reply with quote

Actually, the official Autodesk documents says the same:

http://download.autodesk.com/global/docs/fbxsdk2012/en_us/files/GUID-D3844B1D-4E74-4C64-AD79-14B00EB1FE4-42.htm


Quote:
FBX SDK uses UTF-8 strings internally.


and you should use KString and its macros to deal with strings in fbx sdk.

http://download.autodesk.com/global/docs/fbxsdk2012/en_us/files/GUID-6766AFC0-4F25-4436-A5EE-BCDAFC6CB58-34.htm

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51087#51087







------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
WalkingCat
Newbie


Joined: 01 Nov 2012
Posts: 10

PostPosted: Wed Dec 05, 2012 7:11 pm    Post subject:
FBX textures file names is UTF8
Reply with quote

According to my tests, by exporting fbx files from 3DS Max,
the external texture file names stored in the fbx file is actually UTF-8.

It means, KFbxFileTexture::GetFileName returns an UTF-8 string,
if the string contains complex characters like Chinese/Janpanese/Korean etc,
osgDB::readImageFile() cant found the file.

I suggest the fbx plugin to convert the file name from UTF-8 to current
code page before passing it to readImageFile, its not always the corret CP,
but its the best we can try here.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51086#51086







------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
WalkingCat
Newbie


Joined: 01 Nov 2012
Posts: 10

PostPosted: Wed Dec 05, 2012 7:11 pm    Post subject:
FBX textures file names is UTF8
Reply with quote

OK, I tried modify the file \src\osgPlugins\fbx\fbxMaterialToOsgStateSet.cpp and changed this function, it seems to work !

but I guess there are other places to change right ?
actually any string got from fbx sdk should be converted from utf8 to ansi before used in osg.


Code:
osg::ref_ptr<osg::Texture2D>
FbxMaterialToOsgStateSet::fbxTextureToOsgTexture(const KFbxFileTexture* fbx)
{
ImageMap::iterator it = _imageMap.find(fbx->GetFileName());
if (it != _imageMap.end())
return it->second;
osg::ref_ptr<osg::Image> pImage = NULL;

// Warning: fbx->GetRelativeFileName() is relative TO EXECUTION DIR
// fbx->GetFileName() is as stored initially in the FBX
char* fileName = NULL; KFbxUTF8ToAnsi(fbx->GetFileName(), fileName);
char* relativeFileName = NULL; KFbxUTF8ToAnsi(fbx->GetRelativeFileName(), relativeFileName);

if ((pImage = osgDB::readImageFile(osgDB::concatPaths(_dir, fileName), _options)) || // First try "export dir/name"
(pImage = osgDB::readImageFile(fileName, _options)) || // Then try "name" (if absolute)
(pImage = osgDB::readImageFile(osgDB::concatPaths(_dir, relativeFileName), _options))) // Else try "current dir/name"
{
osg::ref_ptr<osg::Texture2D> pOsgTex = new osg::Texture2D;
pOsgTex->setImage(pImage.get());
pOsgTex->setWrap(osg::Texture2D::WRAP_S, convertWrap(fbx->GetWrapModeU()));
pOsgTex->setWrap(osg::Texture2D::WRAP_T, convertWrap(fbx->GetWrapModeV()));
_imageMap.insert(std::make_pair(fbx->GetFileName(), pOsgTex.get()));
return pOsgTex;
}
else
{
return NULL;
}

delete fileName;
delete relativeFileName;
}



------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51088#51088







------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
WalkingCat
Newbie


Joined: 01 Nov 2012
Posts: 10

PostPosted: Wed Dec 05, 2012 7:11 pm    Post subject:
FBX textures file names is UTF8
Reply with quote

Well, I just found this option OSG_USE_UTF8_FILENAMES, so I guess my changes are not needed if this option is on, but still better when its off, so, may still worth considering. :P

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51089#51089







------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
allinebetts (Alline Betts)
Newbie


Joined: 23 Dec 2012
Posts: 1
Location: San Diego, CA

PostPosted: Sun Dec 23, 2012 12:01 pm    Post subject:
Reply with quote

Very fine and helpful post. I like to use 3D max. So fine.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Plugins [osgPlugins] 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 Change color of node read from dxf file dhhabyc General 4 Sat Nov 17, 2018 12:58 pm View latest post
No new posts Osgdem created terrains not displayin... D.J. Caldwell General 3 Wed Oct 24, 2018 7:32 pm View latest post
No new posts How to actually play animation in osg... Warren93 General 3 Tue Oct 23, 2018 1:23 pm View latest post
No new posts Load an obj file and mapping a given ... aaa3d General 3 Mon Aug 06, 2018 2:27 pm View latest post
No new posts osgconv osgjs bug file not found memory_thrasher Plugins [osgPlugins] 2 Tue Jul 31, 2018 5:21 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