Issue Loading DirectX (.x) File

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
nullReference
Posts: 17
Joined: Mon Jan 08, 2018 2:45 pm

Issue Loading DirectX (.x) File

Post by nullReference »

I'm having an issue exporting my scene from blender as .x file and loading it into irrlicht. Everything loads correctly from what I can tell, however the results are...umm..botched (for lack of a better term). Totally possible I have missed a step somewhere along the lines or have something setup incorrectly on my end. Basically all I have done is modify the quake3 map example code to read my map.x file instead of the quake map. Has anyone else run into this issue before that would be able to point me in the right direction? I have taken several detailed screenshots of my settings and what the scene looks like in blender and what is output by irrlicht. I have also included my code (although it's really just the quake3 map example):

Image
Image
Image
Image
Image

Code: Select all

 
#include <irrlicht.h>
#include <iostream>
 
using namespace irr;
 
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
//#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
 
 
int main()
{
 
    IrrlichtDevice *device =
        createDevice(video::EDT_OPENGL, core::dimension2d<u32>(1280, 720));
 
    if (device == 0)
        return 1; // could not create selected driver.
 
 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
 
 
    //device->getFileSystem()->addFileArchive("data/maps/map-20kdm2.pk3");
 
 
    scene::IAnimatedMesh* mesh = smgr->getMesh("data/maps/wl/map.x");
    scene::ISceneNode* node = 0;
 
    if (mesh)
        //node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
            node = smgr->addMeshSceneNode(mesh->getMesh(0));
 
 
    //if (node)
    //  node->setposition(core::vector3df(-1300, -144, -1249));
 
 
    //! Key map added to allow multiple keys for actions such as
    //! movement. ie Arrow keys & W,S,A,D.
    SKeyMap keyMap[8];
    keyMap[0].Action = EKA_MOVE_FORWARD;
    keyMap[0].KeyCode = KEY_UP;
    keyMap[1].Action = EKA_MOVE_FORWARD;
    keyMap[1].KeyCode = KEY_KEY_W;
 
    keyMap[2].Action = EKA_MOVE_BACKWARD;
    keyMap[2].KeyCode = KEY_DOWN;
    keyMap[3].Action = EKA_MOVE_BACKWARD;
    keyMap[3].KeyCode = KEY_KEY_S;
 
    keyMap[4].Action = EKA_STRAFE_LEFT;
    keyMap[4].KeyCode = KEY_LEFT;
    keyMap[5].Action = EKA_STRAFE_LEFT;
    keyMap[5].KeyCode = KEY_KEY_A;
 
    keyMap[6].Action = EKA_STRAFE_RIGHT;
    keyMap[6].KeyCode = KEY_RIGHT;
    keyMap[7].Action = EKA_STRAFE_RIGHT;
    keyMap[7].KeyCode = KEY_KEY_D;
 
    smgr->addCameraSceneNodeFPS(0, 100.0f, 0.5f, -1, keyMap, 8);
    device->getCursorControl()->setVisible(false);
 
 
    int lastFPS = -1;
 
    while (device->run())
    {
        if (device->isWindowActive())
        {
            driver->beginScene(true, true, video::SColor(255, 200, 200, 200));
            smgr->drawAll();
            driver->endScene();
 
            int fps = driver->getFPS();
 
            if (lastFPS != fps)
            {
                core::stringw str = L"Irrlicht Engine - Quake 3 Map example [";
                str += driver->getName();
                str += "] FPS:";
                str += fps;
 
                device->setWindowCaption(str.c_str());
                lastFPS = fps;
            }
        }
        else
            device->yield();
    }
 
 
    device->drop();
    return 0;
}
 
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Issue Loading DirectX (.x) File

Post by devsh »

It's most probably the option "Export Selected Only" since you have multiple textures I guess you have multiple separate objects in the blend.
nullReference
Posts: 17
Joined: Mon Jan 08, 2018 2:45 pm

Re: Issue Loading DirectX (.x) File

Post by nullReference »

devsh wrote:It's most probably the option "Export Selected Only" since you have multiple textures I guess you have multiple separate objects in the blend.
That is correct. I have multiple objects with multiple textures. However, when I export I have all objects selected that I want to export. Also, in the irrlicht render it appears only two of the objects are showing up, and in the wrong location, without textures applied.
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Issue Loading DirectX (.x) File

Post by Arclamp »

What does it look like when setting the material to wireframe in Irrlicht?

If its all there then it maybe your normals... In Blender, sometimes just resetting all normals (Ctrl-N) isn't enough, because of bizarre geometry (maybe non-manifold???), so you need to turn normals on in a viewport from the N toolbar somewhere and then either split your meshes into logical chunks Blender can recognise or flip the faces manually where needed.

Just a thought...
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Issue Loading DirectX (.x) File

Post by Arclamp »

Oh, maybe also in Blender, try using Ctrl-A to apply transforms???
nullReference
Posts: 17
Joined: Mon Jan 08, 2018 2:45 pm

Re: Issue Loading DirectX (.x) File

Post by nullReference »

Arclamp wrote:What does it look like when setting the material to wireframe in Irrlicht?

If its all there then it maybe your normals... In Blender, sometimes just resetting all normals (Ctrl-N) isn't enough, because of bizarre geometry (maybe non-manifold???), so you need to turn normals on in a viewport from the N toolbar somewhere and then either split your meshes into logical chunks Blender can recognise or flip the faces manually where needed.

Just a thought...
You might be onto something. I actually ran into an issue similar to this a few years back when loading models into libgdx (had completely forgot about that until reading your post). Turned out I had internal faces causing the issue. I will go back through my blender scene and see if I can find any non-manifold geometry. Will also try wireframe material in irrlicht. Thanks! :)
nullReference
Posts: 17
Joined: Mon Jan 08, 2018 2:45 pm

Re: Issue Loading DirectX (.x) File

Post by nullReference »

The reason I couldn't see any textures applied to models was because I did not turn off lighting via:

Code: Select all

node->setMaterialFlag(irr::video::EMF_LIGHTING, false);
After doing so I see the following:

Image

Something is still up with normals/textures as they appear to be applied on the opposite side of the object face. When I choose to export right-handed, the textures look as such:
Image
Image

So they look to now be on the correct side of the face, however they are still not being applied correctly, almost as if the uv map coordinates are switched around? :?: Also, as can be seen from the screenshots, all objects are being added at the origin instead of their designated positions, and with incorrect scale. If I export the scene from blender as an obj and select positive Z as forward, everything renders as expected:

Image

Therefore wouldn't this tell me that positions, tranforms, scale, rotation, etc are all correctly applied within blender? Does no one else have this issue using .x format? Is there a different format I should stick with? I plan on having animated characters which is why I am trying to use .x for everything (for consistency).
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Issue Loading DirectX (.x) File

Post by Arclamp »

For static models I use dae nowadays as I kept getting texture problems with x from Blender
nullReference
Posts: 17
Joined: Mon Jan 08, 2018 2:45 pm

Re: Issue Loading DirectX (.x) File

Post by nullReference »

Arclamp wrote:For static models I use dae nowadays as I kept getting texture problems with x from Blender
What format are you using for animated models (skeletal rigs)?
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Issue Loading DirectX (.x) File

Post by Arclamp »

b3d, a.k.a. Blitz3D

I think this is the one... https://github.com/alrusdi/blender-b3d-exporter
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Issue Loading DirectX (.x) File

Post by CuteAlien »

Could be a problem on X-Format loader. I tend to use .obj for static models.

edit: For b3d I copied the SuperTuxKart Blender exporter recently to Irrlicht (as STK no longer had it in their current repository). It can now be found in trunk/tools/Exporters/Blender/B3DExport.py
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Issue Loading DirectX (.x) File

Post by CuteAlien »

I experimented a little bit with a quick test-model, but could not reproduce the problems. Export should be left-handed as in your first screenshot. Maybe something with multiple materials or so (I only used a single texture right now). Can you send me your model? Then I can try if I can reproduce it with that one.
edit: I do have some difference to Blender when using transparency in textures - but might be lighting settings.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
mant
Posts: 125
Joined: Sun Jan 27, 2013 3:38 pm

Re: Issue Loading DirectX (.x) File

Post by mant »

Use B3D instead. Both static and animated mesh work.

http://www.rtsoft.com/forums/showthread ... ort-script
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Issue Loading DirectX (.x) File

Post by CuteAlien »

Yeah, B3D probably is better. But I would still be interested in the broken model - as it might be something which is easy to fix in Irrlicht if I just had an example for it.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
mant
Posts: 125
Joined: Sun Jan 27, 2013 3:38 pm

Re: Issue Loading DirectX (.x) File

Post by mant »

I think .X exporter of Blender sucks. Remember that I also made posts about this? After exporting from Blender, I run MeshConvert.exe from DirectX SDK to convert it to binary then problems gone. Unfortunately MeshConvert doesn't support animated mesh. But I never mind .X any more, just use B3D.
Post Reply