문제

For a school project, I need to load a DirectX model (.x file) into my (OpenScene)graph. I have a BeeGee.x file (DirectX 3D model) and a BeeGee.dds file (texture). Here's a short sample of my code in charge of constructing the graph:

osg::ref_ptr<osg::Group> root = new osg::Group;

osg::ref_ptr<osg::MatrixTransform>  t1 = new osg::MatrixTransform;
root->addChild(t1.get());

// What I want to do but not working
osg::ref_ptr<osg::Node> plane= osgDB::readNodeFile( "BeeGee.x" );
t1->addChild(plane);
...

Is it possible to use osgDB::readNodeFile with DirectX 3D model? Thanks for your help

도움이 되었습니까?

해결책 2

Yes it is, apparently osgDB uses the file extension to load the proper plugin.

However, I'm not sure how well supported the .x file format is. I've been able to load a single model from the DX SDK (it wasn't pretty):

C:\OpenSceneGraph\bin>osgviewer.exe --window 10 10 600 600 "C:\Program Files\DXSDK\Samples\Media\Tiny\tiny.x"

Other attempts lead to a dark-blue background with nothing going on (and most of the attempts yield no errors either).

So, it's possible, but how your model should be made is unclear.

다른 팁

I tried again and it worked! For the record, here is my working code:

osg::ref_ptr<osg::Node> plane = osgDB::readNodeFile( "GeeBee2.x" );
osg::Image *img_plane = osgDB::readImageFile("Images/GeeBee.dds");
osg::Texture2D *tex_plane = new osg::Texture2D;
tex_plane ->setImage(img_plane);
plane->getOrCreateStateSet()->setTextureAttributeAndModes(0, tex_plane );
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top