1

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

Lucas
  • 1,833
  • 1
  • 18
  • 19
  • What is wrong with my question? I just want to know how to load a DirectX 3D model (.x file) in my c++ program using OpenSceneGraph library. I'm using Visual Studio to compile my program. – Lucas Feb 06 '14 at 07:44
  • @sashoalm This is not a duplicate as this question here is specifically for OSG, while the other does not specify any engine. – Vaillancourt Feb 06 '14 at 13:22
  • @Lucas I'll have to agree with @CaptainObvlious; you don't actually *ask* anything. You just state facts. Your only question up to now is *What is wrong with my question?* What have you tried up to now that did not work? What's your code and what is your model? – Vaillancourt Feb 06 '14 at 13:38
  • @AlexandreVaillancourt Thanks for your comprehension. I'm not really familiar with asking questions on stackoverflow. What I'm trying to do is attach a 3D DirectX Model to an OSG node into my c++ program. All I have is a .x file representing a plane 3D model and a .dds texture file. I added some of my code in the question. – Lucas Feb 06 '14 at 18:22

2 Answers2

1

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 );
Lucas
  • 1,833
  • 1
  • 18
  • 19
  • You might want to add what you did different in your model to achieve this! – Vaillancourt Feb 07 '14 at 14:30
  • 1
    Actually I didn't touch to the model. What I did is just add the GeeBee.x and GeeBee.dds files in the OSG dataset folder in order for OSG to retrieve the file when running readNodeFile and readImageFile. – Lucas Feb 07 '14 at 15:42
0

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.

Vaillancourt
  • 1,380
  • 1
  • 11
  • 42