Page 1 of 1

[fixed] Parsing .X files

Posted: Mon Nov 25, 2013 2:33 pm
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;
    ...
}
 

Re: [bug] Parsing .X files

Posted: Tue Nov 26, 2013 9:42 am
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.

Re: [bug] Parsing .X files

Posted: Tue Nov 26, 2013 3:26 pm
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

Re: [bug] Parsing .X files

Posted: Fri Jan 23, 2015 9:39 pm
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

Re: [bug] Parsing .X files

Posted: Fri Jan 23, 2015 9:45 pm
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.

Re: [bug] Parsing .X files

Posted: Sat Jan 24, 2015 12:24 pm
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.

Re: [bug] Parsing .X files

Posted: Fri Oct 30, 2015 6:29 pm
by robmar
Anyone knows if this got sorted?

Re: [bug] Parsing .X files

Posted: Fri Oct 30, 2015 8:51 pm
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.

Re: [bug] Parsing .X files

Posted: Sat Oct 31, 2015 12:20 am
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...

Re: [bug] Parsing .X files

Posted: Sun Nov 01, 2015 9:00 pm
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.

Re: [fixed] Parsing .X files

Posted: Wed Nov 04, 2015 2:44 am
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.