Commit dc8f25cc authored by cutealien's avatar cutealien

Fix several compile-troubles with Collada reported by several people. Also...

Fix several compile-troubles with Collada reported by several people. Also improve some internal function names. Should fix Bugtracker entry 3428843.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4163 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 098dc32a
...@@ -301,7 +301,7 @@ void CColladaMeshWriter::makeMeshNames(irr::scene::ISceneNode * node) ...@@ -301,7 +301,7 @@ void CColladaMeshWriter::makeMeshNames(irr::scene::ISceneNode * node)
if ( !Meshes.find(mesh) ) if ( !Meshes.find(mesh) )
{ {
ColladaMesh cm; ColladaMesh cm;
cm.Name = uniqueNameForMesh(mesh); cm.Name = nameForMesh(mesh);
Meshes.insert(mesh, cm); Meshes.insert(mesh, cm);
} }
} }
...@@ -380,7 +380,7 @@ void CColladaMeshWriter::writeNodeLights(irr::scene::ISceneNode * node) ...@@ -380,7 +380,7 @@ void CColladaMeshWriter::writeNodeLights(irr::scene::ISceneNode * node)
const video::SLight& lightData = lightNode->getLightData(); const video::SLight& lightData = lightNode->getLightData();
ColladaLight cLight; ColladaLight cLight;
cLight.Name = uniqueNameForLight(node); cLight.Name = nameForLightNode(node);
LightNodes.insert(node, cLight); LightNodes.insert(node, cLight);
Writer->writeElement(L"light", false, L"id", cLight.Name.c_str()); Writer->writeElement(L"light", false, L"id", cLight.Name.c_str());
...@@ -500,8 +500,8 @@ void CColladaMeshWriter::writeSceneNode(irr::scene::ISceneNode * node ) ...@@ -500,8 +500,8 @@ void CColladaMeshWriter::writeSceneNode(irr::scene::ISceneNode * node )
if ( !node || !getProperties() || !getProperties()->isExportable(node) ) if ( !node || !getProperties() || !getProperties()->isExportable(node) )
return; return;
// Collada doesn't require to set the id, but some other tools have problems if none exists, so we just add it). // Collada doesn't require to set the id, but some other tools have problems if none exists, so we just add it.
irr::core::stringw nameId(uniqueNameForNode(node)); irr::core::stringw nameId(nameForNode(node));
Writer->writeElement(L"node", false, L"id", nameId.c_str()); Writer->writeElement(L"node", false, L"id", nameId.c_str());
Writer->writeLineBreak(); Writer->writeLineBreak();
...@@ -576,7 +576,7 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 ...@@ -576,7 +576,7 @@ bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32
Writer->writeElement(L"library_materials", false); Writer->writeElement(L"library_materials", false);
Writer->writeLineBreak(); Writer->writeLineBreak();
irr::core::stringw meshname(uniqueNameForMesh(mesh)); irr::core::stringw meshname(nameForMesh(mesh));
writeMeshMaterials(meshname, mesh); writeMeshMaterials(meshname, mesh);
Writer->writeClosingTag(L"library_materials"); Writer->writeClosingTag(L"library_materials");
...@@ -787,29 +787,39 @@ irr::core::stringw CColladaMeshWriter::toRef(const irr::core::stringw& source) c ...@@ -787,29 +787,39 @@ irr::core::stringw CColladaMeshWriter::toRef(const irr::core::stringw& source) c
return ref; return ref;
} }
irr::core::stringw CColladaMeshWriter::uniqueNameForMesh(const scene::IMesh* mesh) const irr::core::stringw CColladaMeshWriter::nameForMesh(const scene::IMesh* mesh) const
{ {
irr::core::stringw name(L"mesh"); irr::core::stringw name(L"mesh");
name += irr::core::stringw((long)mesh); name += nameForPtr(mesh);
return name; return name;
} }
irr::core::stringw CColladaMeshWriter::uniqueNameForLight(const scene::ISceneNode* lightNode) const irr::core::stringw CColladaMeshWriter::nameForLightNode(const scene::ISceneNode* lightNode) const
{ {
irr::core::stringw name(L"light"); // (prefix, because xs::ID can't start with a number) irr::core::stringw name(L"light"); // (prefix, because xs::ID can't start with a number)
name += irr::core::stringw((long)lightNode); name += nameForPtr(lightNode);
return name; return name;
} }
irr::core::stringw CColladaMeshWriter::uniqueNameForNode(const scene::ISceneNode* node) const irr::core::stringw CColladaMeshWriter::nameForNode(const scene::ISceneNode* node) const
{ {
irr::core::stringw name(L"node"); // (prefix, because xs::ID can't start with a number) irr::core::stringw name(L"node"); // (prefix, because xs::ID can't start with a number)
name += irr::core::stringw((long)node); name += nameForPtr(node);
if ( node ) if ( node )
{
name += irr::core::stringw(node->getName()); name += irr::core::stringw(node->getName());
name = toNCName(name);
}
return name; return name;
} }
irr::core::stringw CColladaMeshWriter::nameForPtr(const void* ptr) const
{
wchar_t buf[32];
swprintf(buf, 32, L"%p", ptr);
return irr::core::stringw(buf);
}
irr::core::stringw CColladaMeshWriter::minTexfilterToString(bool bilinear, bool trilinear) const irr::core::stringw CColladaMeshWriter::minTexfilterToString(bool bilinear, bool trilinear) const
{ {
if ( trilinear ) if ( trilinear )
...@@ -844,7 +854,10 @@ bool CColladaMeshWriter::isXmlNameStartChar(wchar_t c) const ...@@ -844,7 +854,10 @@ bool CColladaMeshWriter::isXmlNameStartChar(wchar_t c) const
|| (c >= 0x3001 && c <= 0xD7FF) || (c >= 0x3001 && c <= 0xD7FF)
|| (c >= 0xF900 && c <= 0xFDCF) || (c >= 0xF900 && c <= 0xFDCF)
|| (c >= 0xFDF0 && c <= 0xFFFD) || (c >= 0xFDF0 && c <= 0xFFFD)
|| (c >= 0x10000 && c <= 0xEFFFF); #if __SIZEOF_WCHAR_T__ == 4 || __WCHAR_MAX__ > 0x10000
|| (c >= 0x10000 && c <= 0xEFFFF)
#endif
;
} }
bool CColladaMeshWriter::isXmlNameChar(wchar_t c) const bool CColladaMeshWriter::isXmlNameChar(wchar_t c) const
...@@ -859,13 +872,13 @@ bool CColladaMeshWriter::isXmlNameChar(wchar_t c) const ...@@ -859,13 +872,13 @@ bool CColladaMeshWriter::isXmlNameChar(wchar_t c) const
} }
// Restrict the characters to a set of allowed characters in xs::NCName. // Restrict the characters to a set of allowed characters in xs::NCName.
irr::core::stringw CColladaMeshWriter::pathToNCName(const irr::io::path& path) const irr::core::stringw CColladaMeshWriter::toNCName(const irr::core::stringw& oldString, const irr::core::stringw& prefix) const
{ {
irr::core::stringw result(L"_NCNAME_"); // ensure id starts with a valid char and reduce chance of name-conflicts irr::core::stringw result(prefix); // help to ensure id starts with a valid char and reduce chance of name-conflicts
if ( path.empty() ) if ( oldString.empty() )
return result; return result;
result.append( irr::core::stringw(path) ); result.append( oldString );
// We replace all characters not allowed by a replacement char // We replace all characters not allowed by a replacement char
const wchar_t REPLACMENT = L'-'; const wchar_t REPLACMENT = L'-';
...@@ -879,6 +892,7 @@ irr::core::stringw CColladaMeshWriter::pathToNCName(const irr::io::path& path) c ...@@ -879,6 +892,7 @@ irr::core::stringw CColladaMeshWriter::pathToNCName(const irr::io::path& path) c
return result; return result;
} }
// Restrict the characters to a set of allowed characters in xs::NCName.
irr::core::stringw CColladaMeshWriter::pathToURI(const irr::io::path& path) const irr::core::stringw CColladaMeshWriter::pathToURI(const irr::io::path& path) const
{ {
irr::core::stringw result; irr::core::stringw result;
...@@ -1000,7 +1014,7 @@ void CColladaMeshWriter::writeMaterialEffect(const irr::core::stringw& meshname, ...@@ -1000,7 +1014,7 @@ void CColladaMeshWriter::writeMaterialEffect(const irr::core::stringw& meshname,
// <init_from>internal_texturename</init_from> // <init_from>internal_texturename</init_from>
Writer->writeElement(L"init_from", false); Writer->writeElement(L"init_from", false);
irr::io::path p(FileSystem->getRelativeFilename(layer.Texture->getName().getPath(), Directory)); irr::io::path p(FileSystem->getRelativeFilename(layer.Texture->getName().getPath(), Directory));
Writer->writeText(pathToNCName(p).c_str()); Writer->writeText(toNCName(irr::core::stringw(p)).c_str());
Writer->writeClosingTag(L"init_from"); Writer->writeClosingTag(L"init_from");
Writer->writeLineBreak(); Writer->writeLineBreak();
...@@ -1605,7 +1619,7 @@ void CColladaMeshWriter::writeLibraryImages() ...@@ -1605,7 +1619,7 @@ void CColladaMeshWriter::writeLibraryImages()
{ {
irr::io::path p(FileSystem->getRelativeFilename(LibraryImages[i]->getName().getPath(), Directory)); irr::io::path p(FileSystem->getRelativeFilename(LibraryImages[i]->getName().getPath(), Directory));
//<image name="rose01"> //<image name="rose01">
irr::core::stringw ncname(pathToNCName(p)); irr::core::stringw ncname( toNCName(irr::core::stringw(p)) );
Writer->writeElement(L"image", false, L"id", ncname.c_str(), L"name", ncname.c_str()); Writer->writeElement(L"image", false, L"id", ncname.c_str(), L"name", ncname.c_str());
Writer->writeLineBreak(); Writer->writeLineBreak();
// <init_from>../flowers/rose01.jpg</init_from> // <init_from>../flowers/rose01.jpg</init_from>
......
...@@ -88,12 +88,13 @@ protected: ...@@ -88,12 +88,13 @@ protected:
inline irr::core::stringw toString(const irr::video::E_TEXTURE_CLAMP clamp) const; inline irr::core::stringw toString(const irr::video::E_TEXTURE_CLAMP clamp) const;
inline irr::core::stringw toString(const irr::scene::E_COLLADA_TRANSPARENT_FX opaque) const; inline irr::core::stringw toString(const irr::scene::E_COLLADA_TRANSPARENT_FX opaque) const;
inline irr::core::stringw toRef(const irr::core::stringw& source) const; inline irr::core::stringw toRef(const irr::core::stringw& source) const;
irr::core::stringw uniqueNameForMesh(const scene::IMesh* mesh) const; irr::core::stringw nameForMesh(const scene::IMesh* mesh) const;
irr::core::stringw uniqueNameForLight(const scene::ISceneNode* lightNode) const; irr::core::stringw nameForLightNode(const scene::ISceneNode* lightNode) const;
irr::core::stringw uniqueNameForNode(const scene::ISceneNode* node) const; irr::core::stringw nameForNode(const scene::ISceneNode* node) const;
irr::core::stringw nameForPtr(const void* ptr) const;
irr::core::stringw minTexfilterToString(bool bilinear, bool trilinear) const; irr::core::stringw minTexfilterToString(bool bilinear, bool trilinear) const;
irr::core::stringw magTexfilterToString(bool bilinear, bool trilinear) const; irr::core::stringw magTexfilterToString(bool bilinear, bool trilinear) const;
irr::core::stringw pathToNCName(const irr::io::path& path) const; irr::core::stringw toNCName(const irr::core::stringw& oldString, const irr::core::stringw& prefix=irr::core::stringw(L"_NC_")) const;
irr::core::stringw pathToURI(const irr::io::path& path) const; irr::core::stringw pathToURI(const irr::io::path& path) const;
inline bool isXmlNameStartChar(wchar_t c) const; inline bool isXmlNameStartChar(wchar_t c) const;
inline bool isXmlNameChar(wchar_t c) const; inline bool isXmlNameChar(wchar_t c) const;
......
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