From Tassilo Glander, "I want to submit a fix for the plugin to load .x model files (Direct X).

The current version crashes when encountering global materials, as also reported in the forum by the author of the plugin.

The problem in mesh.cpp (app. ln 247) is, that references to global materials that are given in curly brackets {} are not supported by the reader. However, curly brackets seem to be common, according to Bourke. Unfortunately, I found no specification. However, also the DirectX model viewer that comes with the DirectX-SDK (August 2009) expects curly brackets and refuses models without them.

My fix checks 2 more cases ("{ aMaterial }" -> 3 tokens and "{aMaterial}" -> 1 token), and extracts the material name for the lookup. I don't know if this is the most elegant solution, but the tokenizer seems to split based on white spaces.

You can reproduce the bug with the attached model (box.x), which loads fine in other tools, such as 3DSmax, DeepExploration or the DirectX model viewer. When I remove the curly brackets at the reference of "myGlobalMaterial", it loads in osgviewer, but is not standard conform.
"
This commit is contained in:
Robert Osfield
2010-09-09 10:09:31 +00:00
parent cbc43841e1
commit fa94700e5c

View File

@@ -244,7 +244,20 @@ void Mesh::parseMeshMaterialList(std::istream& fin)
// check for "{ <material name> }" for a
// material which was declared globally
Material * material = _obj->findMaterial(token[0]);
string materialName = token[0];
// could be given as "{ someName }" which more than 1 tokens
if (materialName == "{" && token.size()>1)
{
materialName = token[1];
}
// or could be given as "{someName}" which would be in token[0]
else if (materialName.size() > 2 && materialName[0] == '{' && materialName[materialName.size()-1] == '}')
{
// remove curly brackets
materialName = materialName.substr(1, materialName.size()-2);
}
Material * material = _obj->findMaterial(materialName);
if (material)
{
_materialList->material.push_back(*material);