[fixed] Parsing .X files

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Alin
Posts: 2
Joined: Mon Nov 25, 2013 1:38 pm
Contact:

[fixed] Parsing .X files

Post by Alin »

Version 1.8.1 will fail to parse binary format X file when it use DeclData. In debug mode the engine will report: "No closing brace in DeclData", the reason is the parser forgot read the opening brace when it start parsing the DeclData block.
This bug can be fixed by modifying CXMeshFileLoader.cpp, add readHeadOfDataObject() at the beginning of the if block in CXMeshFileLoader::parseDataObjectMesh

Code: Select all

 
if (objectName == "DeclData")
{
    if (!readHeadOfDataObject())  //add this
       return false;
    ...
}
 
Last edited by Alin on Tue Nov 26, 2013 3:39 pm, edited 1 time in total.
X File Exporter: http://www.cgdev.net/
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: [bug] Parsing .X files

Post by hybrid »

Do you have some example mesh failing here? In case it's not a free mesh, you can send it also by private mail. Just to make sure that we have some mesh in our test repository.
In any way, it sounds as if alo 1.8.0 would fail on such a mesh then, as we have no changes in the .x loader code I suppose.
Alin
Posts: 2
Joined: Mon Nov 25, 2013 1:38 pm
Contact:

Re: [bug] Parsing .X files

Post by Alin »

Hi hybrid,

A simple mesh with no texture:
http://www.cgdev.net/test/plane_bin.X

More complex samples with animations can be found on this page:
http://www.cgdev.net/download.php

You don't need to download the exporter because these zip files already contain a binary X file.

Alin
X File Exporter: http://www.cgdev.net/
rabbit
Posts: 15
Joined: Wed Sep 02, 2009 12:39 pm
Location: Sydney, Australia

Re: [bug] Parsing .X files

Post by rabbit »

I think I have something of value to add.

I was looking over the code which processes the DeclData block and it appears that it doesn't handle tangents or bi-normals. It collects some information and then does nothing with them.

The reason it does this is because the mesh vertices are stored using the irr::video::S3DVertex structure; where there are no fields for this sort of information. There is a better structure S3DVertexTangents which should probably be used in its place.
If you take a look at the SXMesh structure (found in CXMeshLoader.h) you'll see the vertex format is declared as 'core::array<video::S3DVertex> Vertices;'.

I was trying to build a Bi-normal / Tangent / Normal matrix for a NormalMap Shader. Now I am not sure how to proceed; guess I'll have to find a work around.

I am looking into this now too because I am hoping to generate a Binormal/Tangent/Normal matrix. Inspecting the parser
Last edited by rabbit on Fri Jan 23, 2015 9:47 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9694
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [bug] Parsing .X files

Post by CuteAlien »

I fear we are all in the same situation as you - only way to figure it out is understanding what's going on in the .x loader. The original authors are all no longer active.
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
rabbit
Posts: 15
Joined: Wed Sep 02, 2009 12:39 pm
Location: Sydney, Australia

Re: [bug] Parsing .X files

Post by rabbit »

There is a work around though.

// Mesh
irr::scene::IMesh* pMesh = 0;
// Mesh Scene Node
irr::scene::IMeshSceneNode* pMeshSceneNode = 0;

// Create a mesh
pMesh = pGame->getSceneManager()->getMesh("media/meshes/NormalMapTest.x");

// NOTE: This is 100% necessary without it the normal map screws up
irr::scene::ISkinnedMesh* pSkinnedMesh = (irr::scene::ISkinnedMesh*)pMesh;
pSkinnedMesh->convertMeshToTangents();

The tangent comes into the vertex shader in 'gl_MultiTexCoord1' (value passed from COpenGLDriver.cpp) and then to make your uniform TBN Matrix, you need the bi-normal which is the cross product between the normal and the tangent.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: [bug] Parsing .X files

Post by robmar »

Anyone knows if this got sorted?
CuteAlien
Admin
Posts: 9694
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [bug] Parsing .X files

Post by CuteAlien »

Good question, I think there have been a few changes for .X, but don't know about this one. Probably got lost. I'll put it on my todo.
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
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: [bug] Parsing .X files

Post by robmar »

There was another fix, where a buffer overflow can occur, and I couldn't see that one either. Its in one of my posts, but I can look it up if needed.

The fix from Alin I tested, but it didn't work with DeclData type .X files, not the ASCII ones anyway, and I doubt the binary.

I see that the main changes for 1.8.1 related to some type of .x texture support, but haven't had a good look.

Also that the const specifier on the class had been changed to some _IRRLICT_ type specifier, no idea what that change is about...
CuteAlien
Admin
Posts: 9694
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [bug] Parsing .X files

Post by CuteAlien »

Fix probably didn't make much of a difference in most cases. But for his test-case it removes the warning, so I've applied it.
If you have other problems please make a new bugreport and include a test-model with all data.
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
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: [fixed] Parsing .X files

Post by Mel »

THANK GOODNESS! this fix has "fixed" the troubles that i had with Irr and the KWX Exporter. The curious part is that other X files were loaded properly.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply