Commit d79c5132 authored by cutealien's avatar cutealien

Fix color writing in ColladaMeshWriter (Collada needs floats not integers).

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3822 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 60616873
...@@ -170,70 +170,22 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 ...@@ -170,70 +170,22 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
s32 attridx = attributes->findAttribute("Emissive"); s32 attridx = attributes->findAttribute("Emissive");
if ( attridx >= 0 ) if ( attridx >= 0 )
{ {
Writer->writeElement(L"emission", false); writeColorAttribute(L"emission", attributes, attridx);
Writer->writeLineBreak();
Writer->writeElement(L"color", false);
Writer->writeLineBreak();
str = attributes->getAttributeAsString(attridx);
str.replace(',',' ');
Writer->writeText(core::stringw(str.c_str()).c_str());
Writer->writeClosingTag(L"color");
Writer->writeLineBreak();
Writer->writeClosingTag(L"emission");
Writer->writeLineBreak();
} }
attridx = attributes->findAttribute("Ambient"); attridx = attributes->findAttribute("Ambient");
if ( attridx >= 0 ) if ( attridx >= 0 )
{ {
Writer->writeElement(L"ambient", false); writeColorAttribute(L"ambient", attributes, attridx);
Writer->writeLineBreak();
Writer->writeElement(L"color", false);
Writer->writeLineBreak();
str = attributes->getAttributeAsString(attridx);
str.replace(',',' ');
Writer->writeText(core::stringw(str.c_str()).c_str());
Writer->writeClosingTag(L"color");
Writer->writeLineBreak();
Writer->writeClosingTag(L"ambient");
Writer->writeLineBreak();
} }
attridx = attributes->findAttribute("Diffuse"); attridx = attributes->findAttribute("Diffuse");
if ( attridx >= 0 ) if ( attridx >= 0 )
{ {
Writer->writeElement(L"diffuse", false); writeColorAttribute(L"diffuse", attributes, attridx);
Writer->writeLineBreak();
Writer->writeElement(L"color", false);
Writer->writeLineBreak();
str = attributes->getAttributeAsString(attridx);
str.replace(',',' ');
Writer->writeText(core::stringw(str.c_str()).c_str());
Writer->writeClosingTag(L"color");
Writer->writeLineBreak();
Writer->writeClosingTag(L"diffuse");
Writer->writeLineBreak();
} }
attridx = attributes->findAttribute("Specular"); attridx = attributes->findAttribute("Specular");
if ( attridx >= 0 ) if ( attridx >= 0 )
{ {
Writer->writeElement(L"specular", false); writeColorAttribute(L"specular", attributes, attridx);
Writer->writeLineBreak();
Writer->writeElement(L"color", false);
Writer->writeLineBreak();
str = attributes->getAttributeAsString(attridx);
str.replace(',',' ');
Writer->writeText(core::stringw(str.c_str()).c_str());
Writer->writeClosingTag(L"color");
Writer->writeLineBreak();
Writer->writeClosingTag(L"specular");
Writer->writeLineBreak();
} }
attridx = attributes->findAttribute("Shininess"); attridx = attributes->findAttribute("Shininess");
if ( attridx >= 0 ) if ( attridx >= 0 )
...@@ -241,7 +193,6 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 ...@@ -241,7 +193,6 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
Writer->writeElement(L"shininess", false); Writer->writeElement(L"shininess", false);
Writer->writeLineBreak(); Writer->writeLineBreak();
Writer->writeElement(L"float", false); Writer->writeElement(L"float", false);
Writer->writeLineBreak();
Writer->writeText(core::stringw(attributes->getAttributeAsString(attridx).c_str()).c_str()); Writer->writeText(core::stringw(attributes->getAttributeAsString(attridx).c_str()).c_str());
...@@ -761,24 +712,48 @@ bool CColladaMeshWriter::hasSecondTextureCoordinates(video::E_VERTEX_TYPE type) ...@@ -761,24 +712,48 @@ bool CColladaMeshWriter::hasSecondTextureCoordinates(video::E_VERTEX_TYPE type)
irr::core::stringw CColladaMeshWriter::toString(const irr::core::vector3df& vec) const irr::core::stringw CColladaMeshWriter::toString(const irr::core::vector3df& vec) const
{ {
core::stringw str; c8 tmpbuf[255];
str += vec.X; snprintf(tmpbuf, 255, "%f %f %f", vec.X, vec.Y, vec.Z);
str += " "; core::stringw str = tmpbuf;
str += vec.Y;
str += " ";
str += vec.Z;
return str; return str;
} }
irr::core::stringw CColladaMeshWriter::toString(const irr::core::vector2df& vec) const irr::core::stringw CColladaMeshWriter::toString(const irr::core::vector2df& vec) const
{ {
core::stringw str; c8 tmpbuf[255];
str += vec.X; snprintf(tmpbuf, 255, "%f %f", vec.X, vec.Y);
str += " "; core::stringw str = tmpbuf;
str += vec.Y;
return str;
}
inline irr::core::stringw CColladaMeshWriter::toString(const irr::video::SColorf& colorf) const
{
c8 tmpbuf[255];
snprintf(tmpbuf, 255, "%f %f %f %f", colorf.getRed(), colorf.getGreen(), colorf.getBlue(), colorf.getAlpha());
core::stringw str = tmpbuf;
return str; return str;
} }
void CColladaMeshWriter::writeColorAttribute(wchar_t * parentTag, io::IAttributes* attributes, s32 attridx)
{
Writer->writeElement(parentTag, false);
Writer->writeLineBreak();
Writer->writeElement(L"color", false);
irr::core::stringw str( toString(attributes->getAttributeAsColorf(attridx)) );
Writer->writeText(str.c_str());
Writer->writeClosingTag(L"color");
Writer->writeLineBreak();
Writer->writeClosingTag(parentTag);
Writer->writeLineBreak();
}
} // end namespace } // end namespace
} // end namespace } // end namespace
......
...@@ -41,6 +41,8 @@ protected: ...@@ -41,6 +41,8 @@ protected:
bool hasSecondTextureCoordinates(video::E_VERTEX_TYPE type) const; bool hasSecondTextureCoordinates(video::E_VERTEX_TYPE type) const;
inline irr::core::stringw toString(const irr::core::vector3df& vec) const; inline irr::core::stringw toString(const irr::core::vector3df& vec) const;
inline irr::core::stringw toString(const irr::core::vector2df& vec) const; inline irr::core::stringw toString(const irr::core::vector2df& vec) const;
inline irr::core::stringw toString(const irr::video::SColorf& colorf) const;
inline void writeColorAttribute(wchar_t * parentTag, io::IAttributes* attributes, s32 attridx);
struct SComponentGlobalStartPos struct SComponentGlobalStartPos
{ {
......
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