Commit 4c58865f authored by hybrid's avatar hybrid

Use deferred texture resolution to relax the element order required in Collada...

Use deferred texture resolution to relax the element order required in Collada files. Even though the standard forces a certain order, many files come in a different one. This fix allows for proper texture reading in those files, but won't fix the loader to an arbitrary order handling.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3291 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 8de33dd4
......@@ -1438,8 +1438,7 @@ void CColladaFileLoader::readEffect(io::IXMLReaderUTF8* reader, SColladaEffect *
if (reader->getNodeType() == io::EXN_ELEMENT &&
textureNodeName == reader->getNodeName())
{
const core::stringc tname = reader->getAttributeValue("texture");
effect->Mat.setTexture(0, getTextureFromImage(tname));
effect->Textures.push_back(reader->getAttributeValue("texture"));
break;
}
else
......@@ -1548,6 +1547,10 @@ void CColladaFileLoader::readEffect(io::IXMLReaderUTF8* reader, SColladaEffect *
const SColladaMaterial* CColladaFileLoader::findMaterial(const core::stringc& materialName)
{
#ifdef COLLADA_READER_DEBUG
os::Printer::log("COLLADA find material", materialName);
#endif
// do a quick lookup in the materials
SColladaMaterial matToFind;
matToFind.Id = materialName;
......@@ -1565,6 +1568,7 @@ const SColladaMaterial* CColladaFileLoader::findMaterial(const core::stringc& ma
{
// found the effect, instantiate by copying into the material
Materials[mat].Mat = Effects[effect].Mat;
Materials[mat].Mat.setTexture(0, getTextureFromImage(Effects[effect].Textures[0]));
Materials[mat].Transparency = Effects[effect].Transparency;
// and indicate the material is instantiated by removing the effect ref
Materials[mat].InstanceEffectId = "";
......@@ -2749,7 +2753,7 @@ core::stringc CColladaFileLoader::readId(io::IXMLReaderUTF8* reader)
video::ITexture* CColladaFileLoader::getTextureFromImage(core::stringc uri)
{
#ifdef COLLADA_READER_DEBUG
os::Printer::log("COLLADA searching texture", uri.c_str());
os::Printer::log("COLLADA searching texture", uri);
#endif
video::IVideoDriver* driver = SceneManager->getVideoDriver();
for (;;)
......
......@@ -131,9 +131,10 @@ struct SColladaMaterial
//! Collada effect (materials, shaders, and programs)
struct SColladaEffect
{
video::SMaterial Mat;
core::stringc Id;
f32 Transparency;
core::array<core::stringc> Textures;
video::SMaterial Mat;
inline bool operator< (const SColladaEffect & other) const
{
......@@ -355,7 +356,9 @@ private:
core::array<SColladaMaterial> Materials;
core::array<SColladaInput> Inputs;
core::array<SColladaEffect> Effects;
//! meshbuffer reference ("geomid/matname") -> index into MeshesToBind
core::map<core::stringc,u32> MaterialsToBind;
//! Array of buffers for each material binding
core::array< core::array<irr::scene::IMeshBuffer*> > MeshesToBind;
io::CAttributes Parameters;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment