Fixed some more material and effect problems, and a mem leak. Tried to get transparency to work.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1205 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
6d7357c3c5
commit
fd753b6b6a
|
@ -673,6 +673,7 @@ void CColladaFileLoader::readNodeSection(io::IXMLReaderUTF8* reader, scene::ISce
|
||||||
{
|
{
|
||||||
nodeprefab = new CScenePrefab(readId(reader));
|
nodeprefab = new CScenePrefab(readId(reader));
|
||||||
p->Childs.push_back(nodeprefab);
|
p->Childs.push_back(nodeprefab);
|
||||||
|
Prefabs.push_back(nodeprefab); // in order to delete them later on
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the node
|
// read the node
|
||||||
|
@ -1268,8 +1269,8 @@ void CColladaFileLoader::readEffect(io::IXMLReaderUTF8* reader, SColladaEffect *
|
||||||
Effects.push_back(SColladaEffect());
|
Effects.push_back(SColladaEffect());
|
||||||
effect = &Effects.getLast();
|
effect = &Effects.getLast();
|
||||||
effect->Id = readId(reader);
|
effect->Id = readId(reader);
|
||||||
|
effect->Transparency = 1.f;
|
||||||
}
|
}
|
||||||
video::SColorf transparency;
|
|
||||||
while(reader->read())
|
while(reader->read())
|
||||||
{
|
{
|
||||||
if (reader->getNodeType() == io::EXN_ELEMENT)
|
if (reader->getNodeType() == io::EXN_ELEMENT)
|
||||||
|
@ -1299,9 +1300,6 @@ void CColladaFileLoader::readEffect(io::IXMLReaderUTF8* reader, SColladaEffect *
|
||||||
if (reader->getNodeType() == io::EXN_ELEMENT)
|
if (reader->getNodeType() == io::EXN_ELEMENT)
|
||||||
{
|
{
|
||||||
const core::stringc node = reader->getNodeName();
|
const core::stringc node = reader->getNodeName();
|
||||||
#ifdef COLLADA_READER_DEBUG
|
|
||||||
os::Printer::log("COLLADA reading effect technique part", reader->getNodeName());
|
|
||||||
#endif
|
|
||||||
if (emissionNode == node || ambientNode == node ||
|
if (emissionNode == node || ambientNode == node ||
|
||||||
diffuseNode == node || specularNode == node ||
|
diffuseNode == node || specularNode == node ||
|
||||||
reflectiveNode == node || transparentNode == node )
|
reflectiveNode == node || transparentNode == node )
|
||||||
|
@ -1327,16 +1325,13 @@ void CColladaFileLoader::readEffect(io::IXMLReaderUTF8* reader, SColladaEffect *
|
||||||
effect->Mat.SpecularColor = color;
|
effect->Mat.SpecularColor = color;
|
||||||
else
|
else
|
||||||
if (transparentNode == node)
|
if (transparentNode == node)
|
||||||
transparency = colorf;
|
effect->Transparency = colorf.a;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (reader->getNodeType() == io::EXN_ELEMENT &&
|
if (reader->getNodeType() == io::EXN_ELEMENT &&
|
||||||
textureNodeName == reader->getNodeName())
|
textureNodeName == reader->getNodeName())
|
||||||
{
|
{
|
||||||
const core::stringc tname = reader->getAttributeValue("texture");
|
const core::stringc tname = reader->getAttributeValue("texture");
|
||||||
#ifdef COLLADA_READER_DEBUG
|
|
||||||
os::Printer::log("COLLADA reading effect technique texture", tname.c_str());
|
|
||||||
#endif
|
|
||||||
effect->Mat.setTexture(0, getTextureFromImage(tname));
|
effect->Mat.setTexture(0, getTextureFromImage(tname));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1364,11 +1359,7 @@ void CColladaFileLoader::readEffect(io::IXMLReaderUTF8* reader, SColladaEffect *
|
||||||
effect->Mat.Shininess = f;
|
effect->Mat.Shininess = f;
|
||||||
else
|
else
|
||||||
if (transparencyNode == node)
|
if (transparencyNode == node)
|
||||||
{
|
effect->Transparency *= f;
|
||||||
transparency.r *= f;
|
|
||||||
transparency.g *= f;
|
|
||||||
transparency.b *= f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (reader->getNodeType() == io::EXN_ELEMENT)
|
if (reader->getNodeType() == io::EXN_ELEMENT)
|
||||||
|
@ -1432,25 +1423,8 @@ void CColladaFileLoader::readEffect(io::IXMLReaderUTF8* reader, SColladaEffect *
|
||||||
if (effect->Mat.DiffuseColor == video::SColor(0) &&
|
if (effect->Mat.DiffuseColor == video::SColor(0) &&
|
||||||
effect->Mat.AmbientColor != video::SColor(0))
|
effect->Mat.AmbientColor != video::SColor(0))
|
||||||
effect->Mat.DiffuseColor = effect->Mat.AmbientColor;
|
effect->Mat.DiffuseColor = effect->Mat.AmbientColor;
|
||||||
if (transparency.r > 0.0f || transparency.g > 0.0f || transparency.b > 0.0f)
|
if (effect->Transparency != 1.0f)
|
||||||
{
|
effect->Mat.MaterialType = irr::video::EMT_TRANSPARENT_VERTEX_ALPHA;
|
||||||
effect->Mat.setFlag(irr::video::EMF_BACK_FACE_CULLING,false);
|
|
||||||
effect->Mat.setFlag(irr::video::EMF_ZWRITE_ENABLE,false);
|
|
||||||
effect->Mat.setFlag(irr::video::EMF_BACK_FACE_CULLING,false);
|
|
||||||
effect->Mat.MaterialType = irr::video::EMT_TRANSPARENT_ADD_COLOR;
|
|
||||||
video::SColorf ambient(effect->Mat.AmbientColor);
|
|
||||||
ambient.r *= transparency.r;
|
|
||||||
ambient.g *= transparency.g;
|
|
||||||
ambient.b *= transparency.b;
|
|
||||||
ambient.a *= transparency.a;
|
|
||||||
effect->Mat.AmbientColor = ambient.toSColor();
|
|
||||||
video::SColorf diffuse(effect->Mat.DiffuseColor);
|
|
||||||
diffuse.r *= transparency.r;
|
|
||||||
diffuse.g *= transparency.g;
|
|
||||||
diffuse.b *= transparency.b;
|
|
||||||
diffuse.a *= transparency.a;
|
|
||||||
effect->Mat.DiffuseColor = diffuse.toSColor();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1460,22 +1434,25 @@ const SColladaMaterial * CColladaFileLoader::findMaterial(const core::stringc &
|
||||||
SColladaMaterial matToFind;
|
SColladaMaterial matToFind;
|
||||||
matToFind.Id = materialName;
|
matToFind.Id = materialName;
|
||||||
s32 mat = Materials.binary_search(matToFind);
|
s32 mat = Materials.binary_search(matToFind);
|
||||||
if (mat < 0)
|
if (mat == -1)
|
||||||
return 0;
|
return 0;
|
||||||
// instance the material effect if needed
|
// instantiate the material effect if needed
|
||||||
if (Materials[mat].InstanceEffectId.size() > 0)
|
if (Materials[mat].InstanceEffectId.size() > 0)
|
||||||
{
|
{
|
||||||
// do a quick lookup in the effects
|
// do a quick lookup in the effects
|
||||||
SColladaEffect effectToFind;
|
SColladaEffect effectToFind;
|
||||||
effectToFind.Id = Materials[mat].InstanceEffectId;
|
effectToFind.Id = Materials[mat].InstanceEffectId;
|
||||||
s32 effect = Effects.binary_search(effectToFind);
|
s32 effect = Effects.binary_search(effectToFind);
|
||||||
if (effect >= 0)
|
if (effect != -1)
|
||||||
{
|
{
|
||||||
// found the effect, instance by copying into the material
|
// found the effect, instantiate by copying into the material
|
||||||
Materials[mat].Mat = Effects[effect].Mat;
|
Materials[mat].Mat = Effects[effect].Mat;
|
||||||
// and indicate the material is instanced by removing the effect ref
|
Materials[mat].Transparency = Effects[effect].Transparency;
|
||||||
|
// and indicate the material is instantiated by removing the effect ref
|
||||||
Materials[mat].InstanceEffectId = "";
|
Materials[mat].InstanceEffectId = "";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return &Materials[mat];
|
return &Materials[mat];
|
||||||
}
|
}
|
||||||
|
@ -1513,9 +1490,19 @@ void CColladaFileLoader::readBindMaterialSection(io::IXMLReaderUTF8* reader, con
|
||||||
{
|
{
|
||||||
core::array<irr::scene::IMeshBuffer*> & toBind
|
core::array<irr::scene::IMeshBuffer*> & toBind
|
||||||
= MeshesToBind[MaterialsToBind[materialReference]];
|
= MeshesToBind[MaterialsToBind[materialReference]];
|
||||||
|
SMesh tmpmesh;
|
||||||
for (u32 i = 0; i < toBind.size(); ++i)
|
for (u32 i = 0; i < toBind.size(); ++i)
|
||||||
{
|
{
|
||||||
toBind[i]->getMaterial() = material->Mat;
|
toBind[i]->getMaterial() = material->Mat;
|
||||||
|
if (material->Transparency!=1.0f)
|
||||||
|
tmpmesh.addMeshBuffer(toBind[i]);
|
||||||
|
}
|
||||||
|
if (material->Transparency!=1.0f)
|
||||||
|
{
|
||||||
|
#ifdef COLLADA_READER_DEBUG
|
||||||
|
os::Printer::log("COLLADA found transparency material", core::stringc(material->Transparency).c_str());
|
||||||
|
#endif
|
||||||
|
SceneManager->getMeshManipulator()->setVertexColorAlpha(&tmpmesh, core::floor32(material->Transparency*255.0f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2109,7 +2096,15 @@ void CColladaFileLoader::readPolygonSection(io::IXMLReaderUTF8* reader,
|
||||||
|
|
||||||
const SColladaMaterial* m = findMaterial(materialName);
|
const SColladaMaterial* m = findMaterial(materialName);
|
||||||
if (m)
|
if (m)
|
||||||
|
{
|
||||||
buffer->getMaterial() = m->Mat;
|
buffer->getMaterial() = m->Mat;
|
||||||
|
if (m->Transparency != 1.0f)
|
||||||
|
{
|
||||||
|
SMesh tmpmesh;
|
||||||
|
tmpmesh.addMeshBuffer(buffer);
|
||||||
|
SceneManager->getMeshManipulator()->setVertexColorAlpha(&tmpmesh,core::floor32(m->Transparency*255.0f));
|
||||||
|
}
|
||||||
|
}
|
||||||
// add future bind reference for the material
|
// add future bind reference for the material
|
||||||
core::stringc materialReference = geometryId+"/"+materialName;
|
core::stringc materialReference = geometryId+"/"+materialName;
|
||||||
if (!MaterialsToBind.find(materialReference))
|
if (!MaterialsToBind.find(materialReference))
|
||||||
|
@ -2404,7 +2399,7 @@ video::SColorf CColladaFileLoader::readColorNode(io::IXMLReaderUTF8* reader)
|
||||||
result.r = color[0];
|
result.r = color[0];
|
||||||
result.g = color[1];
|
result.g = color[1];
|
||||||
result.b = color[2];
|
result.b = color[2];
|
||||||
result.a = 1.0f-color[3];
|
result.a = color[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -2488,6 +2483,9 @@ core::stringc CColladaFileLoader::readId(io::IXMLReaderUTF8* reader)
|
||||||
//! create an Irrlicht texture from the reference
|
//! create an Irrlicht texture from the reference
|
||||||
video::ITexture* CColladaFileLoader::getTextureFromImage(core::stringc uri)
|
video::ITexture* CColladaFileLoader::getTextureFromImage(core::stringc uri)
|
||||||
{
|
{
|
||||||
|
#ifdef COLLADA_READER_DEBUG
|
||||||
|
os::Printer::log("COLLADA searching texture", uri.c_str());
|
||||||
|
#endif
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
uriToId(uri);
|
uriToId(uri);
|
||||||
|
@ -2520,7 +2518,12 @@ video::ITexture* CColladaFileLoader::getTextureFromImage(core::stringc uri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Parameters.getAttributeType(uri.c_str())==io::EAT_STRING)
|
if (Parameters.getAttributeType(uri.c_str())==io::EAT_STRING)
|
||||||
|
{
|
||||||
uri = Parameters.getAttributeAsString(uri.c_str());
|
uri = Parameters.getAttributeAsString(uri.c_str());
|
||||||
|
#ifdef COLLADA_READER_DEBUG
|
||||||
|
os::Printer::log("COLLADA now searching texture", uri.c_str());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2568,7 +2571,8 @@ void CColladaFileLoader::readParameter(io::IXMLReaderUTF8* reader)
|
||||||
if ((initFromName == reader->getNodeName()) ||
|
if ((initFromName == reader->getNodeName()) ||
|
||||||
(sourceSectionName == reader->getNodeName()))
|
(sourceSectionName == reader->getNodeName()))
|
||||||
{
|
{
|
||||||
Parameters.addString(reader->getNodeData(), name.c_str());
|
reader->read();
|
||||||
|
Parameters.addString(name.c_str(), reader->getNodeData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -120,6 +120,7 @@ struct SColladaMaterial
|
||||||
video::SMaterial Mat;
|
video::SMaterial Mat;
|
||||||
core::stringc Id;
|
core::stringc Id;
|
||||||
core::stringc InstanceEffectId;
|
core::stringc InstanceEffectId;
|
||||||
|
f32 Transparency;
|
||||||
|
|
||||||
inline bool operator< (const SColladaMaterial & other) const
|
inline bool operator< (const SColladaMaterial & other) const
|
||||||
{
|
{
|
||||||
|
@ -132,6 +133,7 @@ struct SColladaEffect
|
||||||
{
|
{
|
||||||
video::SMaterial Mat;
|
video::SMaterial Mat;
|
||||||
core::stringc Id;
|
core::stringc Id;
|
||||||
|
f32 Transparency;
|
||||||
|
|
||||||
inline bool operator< (const SColladaEffect & other) const
|
inline bool operator< (const SColladaEffect & other) const
|
||||||
{
|
{
|
||||||
|
@ -362,7 +364,6 @@ private:
|
||||||
class IColladaPrefab : public virtual IReferenceCounted
|
class IColladaPrefab : public virtual IReferenceCounted
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! creates an instance of this prefab
|
//! creates an instance of this prefab
|
||||||
virtual scene::ISceneNode* addInstance(scene::ISceneNode* parent,
|
virtual scene::ISceneNode* addInstance(scene::ISceneNode* parent,
|
||||||
scene::ISceneManager* mgr) = 0;
|
scene::ISceneManager* mgr) = 0;
|
||||||
|
|
Loading…
Reference in New Issue