Commit 78e936aa authored by cutealien's avatar cutealien

Simplify the IColladaMeshWriterNames interface somewhat and improve documentation.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4270 dfc29bdd-3216-0410-991c-e03cc46cb475
parent f09f35e0
...@@ -131,94 +131,45 @@ namespace scene ...@@ -131,94 +131,45 @@ namespace scene
}; };
//! Callback interface to use custom names on collada writing. //! Callback interface to use custom names on collada writing.
/** Many names and id's have to be unique in collada. By default /** You can either modify names and id's written to collada or you can use
Irrlicht guarantees for example by using using pointer-values in the name. this interface to just find out which names are used on writing.
This works for most tools, but occasionally you might need another naming scheme
to make it easier finding names again for further processing.
*/ */
class IColladaMeshWriterNames : public virtual IReferenceCounted class IColladaMeshWriterNames : public virtual IReferenceCounted
{ {
public: public:
IColladaMeshWriterNames() : MeshToNC(true), NodeToNC(true), NCNamePrefix(L"_NC_") {}
virtual ~IColladaMeshWriterNames () {} virtual ~IColladaMeshWriterNames () {}
//! Return a unique name for the given mesh //! Return a unique name for the given mesh
/** Note that names really must be unique here per mesh-pointer, so mostly it's a good idea to return /** Note that names really must be unique here per mesh-pointer, so
the nameForMesh from IColladaMeshWriter::getDefaultNameGenerator(). mostly it's a good idea to return the nameForMesh from
IColladaMeshWriter::getDefaultNameGenerator(). Also names must follow
the xs::NCName standard to be valid, you can run them through
IColladaMeshWriter::toNCName to ensure that.
*/ */
virtual irr::core::stringw nameForMesh(const scene::IMesh* mesh) = 0; virtual irr::core::stringw nameForMesh(const scene::IMesh* mesh) = 0;
//! Return a unique name for the given node //! Return a unique name for the given node
/** Note that names really must be unique here per node-pointer, so mostly it's a good idea to return /** Note that names really must be unique here per node-pointer, so
the nameForNode from IColladaMeshWriter::getDefaultNameGenerator(). mostly it's a good idea to return the nameForNode from
IColladaMeshWriter::getDefaultNameGenerator(). Also names must follow
the xs::NCName standard to be valid, you can run them through
IColladaMeshWriter::toNCName to ensure that.
*/ */
virtual irr::core::stringw nameForNode(const scene::ISceneNode* node) = 0; virtual irr::core::stringw nameForNode(const scene::ISceneNode* node) = 0;
//! Return a name for the material //! Return a name for the material
/** There is one material created in the writer for each unique name. So you can use this to control /** There is one material created in the writer for each unique name.
the number of materials which get written. For example Irrlicht does by default write one material for each So you can use this to control the number of materials which get written.
material instanced by a node. So if you know that in your application material instances per node are identical For example Irrlicht does by default write one material for each material
between different nodes you can reduce the number of exported materials using that knowledge by using identical instanced by a node. So if you know that in your application material
names for such shared materials. */ instances per node are identical between different nodes you can reduce
virtual irr::core::stringw nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node) = 0; the number of exported materials using that knowledge by using identical
names for such shared materials.
//! Ensure meshnames follow the xs::NCName format (so this will change names!) Names must follow the xs::NCName standard to be valid, you can run them
/** Names need to have a certain format in collada, like not starting with numbers, through IColladaMeshWriter::toNCName to ensure that.
and avoiding certain special characters.
*/ */
void SetConvertMeshNameToNC(bool doConvert) virtual irr::core::stringw nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node) = 0;
{
MeshToNC = doConvert;
}
//! Check if meshnames are forced to follow the xs::NCName format
bool GetConvertMeshNameToNC() const
{
return MeshToNC;
}
//! Ensure nodenames follow the xs::NCName format (so this will change names!)
void SetConvertNodeNameToNC(bool doConvert)
{
NodeToNC = doConvert;
}
//! Check if nodenames are forced to follow the xs::NCName format
bool GetConvertNodeNameToNC() const
{
return NodeToNC;
}
//! Ensure materialnames follow the xs::NCName format (so this will change names!)
void SetConvertMaterialNameToNC(bool doConvert)
{
MaterialToNC = doConvert;
}
//! Check if materialnames are forced to follow the xs::NCName format
bool GetConvertMaterialNameToNC() const
{
return MaterialToNC;
}
//! When conversion to NCName's is enforced resulting names will have this prefix
void SetNCNamePrefix(const irr::core::stringw& prefix)
{
NCNamePrefix = prefix;
}
//! Get the NCName prefix
const irr::core::stringw& getNCNamePrefix() const
{
return NCNamePrefix;
}
protected:
bool MeshToNC;
bool NodeToNC;
bool MaterialToNC;
irr::core::stringw NCNamePrefix;
}; };
...@@ -342,6 +293,10 @@ namespace scene ...@@ -342,6 +293,10 @@ namespace scene
return DefaultNameGenerator; return DefaultNameGenerator;
} }
//! Restrict the characters of oldString a set of allowed characters in xs::NCName and add the prefix.
/** A tool function to help when using a custom name generator to generative valid names for collada names and id's. */
virtual irr::core::stringw toNCName(const irr::core::stringw& oldString, const irr::core::stringw& prefix=irr::core::stringw(L"_NC_")) const = 0;
protected: protected:
// NOTE: You usually should also call setProperties with the same paraemter when using setDefaultProperties // NOTE: You usually should also call setProperties with the same paraemter when using setDefaultProperties
......
...@@ -135,18 +135,18 @@ IMesh* CColladaMeshWriterProperties::getMesh(irr::scene::ISceneNode * node) ...@@ -135,18 +135,18 @@ IMesh* CColladaMeshWriterProperties::getMesh(irr::scene::ISceneNode * node)
return 0; return 0;
} }
CColladaMeshWriterNames::CColladaMeshWriterNames()
CColladaMeshWriterNames::CColladaMeshWriterNames(IColladaMeshWriter * writer)
: ColladaMeshWriter(writer)
{ {
SetConvertMeshNameToNC(true);
SetConvertNodeNameToNC(true);
SetConvertMaterialNameToNC(true);
} }
irr::core::stringw CColladaMeshWriterNames::nameForMesh(const scene::IMesh* mesh) irr::core::stringw CColladaMeshWriterNames::nameForMesh(const scene::IMesh* mesh)
{ {
irr::core::stringw name(L"mesh"); irr::core::stringw name(L"mesh");
name += nameForPtr(mesh); name += nameForPtr(mesh);
return name; return ColladaMeshWriter->toNCName(name);
} }
irr::core::stringw CColladaMeshWriterNames::nameForNode(const scene::ISceneNode* node) irr::core::stringw CColladaMeshWriterNames::nameForNode(const scene::ISceneNode* node)
...@@ -162,7 +162,7 @@ irr::core::stringw CColladaMeshWriterNames::nameForNode(const scene::ISceneNode* ...@@ -162,7 +162,7 @@ irr::core::stringw CColladaMeshWriterNames::nameForNode(const scene::ISceneNode*
{ {
name += irr::core::stringw(node->getName()); name += irr::core::stringw(node->getName());
} }
return name; return ColladaMeshWriter->toNCName(name);
} }
irr::core::stringw CColladaMeshWriterNames::nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node) irr::core::stringw CColladaMeshWriterNames::nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node)
...@@ -180,11 +180,14 @@ irr::core::stringw CColladaMeshWriterNames::nameForMaterial(const video::SMateri ...@@ -180,11 +180,14 @@ irr::core::stringw CColladaMeshWriterNames::nameForMaterial(const video::SMateri
if ( !useMeshMaterial ) if ( !useMeshMaterial )
{ {
strMat += nameForNode(node); strMat += L"node";
strMat += nameForPtr(node);
strMat += irr::core::stringw(node->getName());
} }
strMat += nameForMesh(mesh); strMat += L"mesh";
strMat += nameForPtr(mesh);
strMat += materialId; strMat += materialId;
return strMat; return ColladaMeshWriter->toNCName(strMat);
} }
irr::core::stringw CColladaMeshWriterNames::nameForPtr(const void* ptr) const irr::core::stringw CColladaMeshWriterNames::nameForPtr(const void* ptr) const
...@@ -219,7 +222,7 @@ CColladaMeshWriter::CColladaMeshWriter( ISceneManager * smgr, video::IVideoDrive ...@@ -219,7 +222,7 @@ CColladaMeshWriter::CColladaMeshWriter( ISceneManager * smgr, video::IVideoDrive
setProperties(p); setProperties(p);
p->drop(); p->drop();
CColladaMeshWriterNames * nameGenerator = new CColladaMeshWriterNames(); CColladaMeshWriterNames * nameGenerator = new CColladaMeshWriterNames(this);
setDefaultNameGenerator(nameGenerator); setDefaultNameGenerator(nameGenerator);
setNameGenerator(nameGenerator); setNameGenerator(nameGenerator);
nameGenerator->drop(); nameGenerator->drop();
...@@ -926,10 +929,7 @@ irr::core::stringw CColladaMeshWriter::nameForMesh(const scene::IMesh* mesh) con ...@@ -926,10 +929,7 @@ irr::core::stringw CColladaMeshWriter::nameForMesh(const scene::IMesh* mesh) con
IColladaMeshWriterNames * nameGenerator = getNameGenerator(); IColladaMeshWriterNames * nameGenerator = getNameGenerator();
if ( nameGenerator ) if ( nameGenerator )
{ {
if ( nameGenerator->GetConvertMeshNameToNC() ) return nameGenerator->nameForMesh(mesh);
return toNCName(nameGenerator->nameForMesh(mesh), nameGenerator->getNCNamePrefix());
else
return nameGenerator->nameForMesh(mesh);
} }
return irr::core::stringw(L"missing_name_generator"); return irr::core::stringw(L"missing_name_generator");
} }
...@@ -939,10 +939,7 @@ irr::core::stringw CColladaMeshWriter::nameForNode(const scene::ISceneNode* node ...@@ -939,10 +939,7 @@ irr::core::stringw CColladaMeshWriter::nameForNode(const scene::ISceneNode* node
IColladaMeshWriterNames * nameGenerator = getNameGenerator(); IColladaMeshWriterNames * nameGenerator = getNameGenerator();
if ( nameGenerator ) if ( nameGenerator )
{ {
if ( nameGenerator->GetConvertNodeNameToNC() ) return nameGenerator->nameForNode(node);
return toNCName(nameGenerator->nameForNode(node), nameGenerator->getNCNamePrefix());
else
return nameGenerator->nameForNode(node);
} }
return irr::core::stringw(L"missing_name_generator"); return irr::core::stringw(L"missing_name_generator");
} }
...@@ -952,10 +949,7 @@ irr::core::stringw CColladaMeshWriter::nameForMaterial(const video::SMaterial & ...@@ -952,10 +949,7 @@ irr::core::stringw CColladaMeshWriter::nameForMaterial(const video::SMaterial &
IColladaMeshWriterNames * nameGenerator = getNameGenerator(); IColladaMeshWriterNames * nameGenerator = getNameGenerator();
if ( nameGenerator ) if ( nameGenerator )
{ {
if ( nameGenerator->GetConvertMaterialNameToNC() ) return nameGenerator->nameForMaterial(material, materialId, mesh, node);
return toNCName(nameGenerator->nameForMaterial(material, materialId, mesh, node), nameGenerator->getNCNamePrefix());
else
return nameGenerator->nameForMaterial(material, materialId, mesh, node);
} }
return irr::core::stringw(L"missing_name_generator"); return irr::core::stringw(L"missing_name_generator");
} }
......
...@@ -19,7 +19,6 @@ namespace io ...@@ -19,7 +19,6 @@ namespace io
} }
namespace scene namespace scene
{ {
//! Callback interface for properties which can be used to influence collada writing //! Callback interface for properties which can be used to influence collada writing
// (Implementer note: keep namespace labels here to make it easier for users copying this one) // (Implementer note: keep namespace labels here to make it easier for users copying this one)
class CColladaMeshWriterProperties : public virtual IColladaMeshWriterProperties class CColladaMeshWriterProperties : public virtual IColladaMeshWriterProperties
...@@ -59,12 +58,14 @@ namespace scene ...@@ -59,12 +58,14 @@ namespace scene
class CColladaMeshWriterNames : public virtual IColladaMeshWriterNames class CColladaMeshWriterNames : public virtual IColladaMeshWriterNames
{ {
public: public:
CColladaMeshWriterNames(); CColladaMeshWriterNames(IColladaMeshWriter * writer);
virtual irr::core::stringw nameForMesh(const scene::IMesh* mesh); virtual irr::core::stringw nameForMesh(const scene::IMesh* mesh);
virtual irr::core::stringw nameForNode(const scene::ISceneNode* node); virtual irr::core::stringw nameForNode(const scene::ISceneNode* node);
virtual irr::core::stringw nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node); virtual irr::core::stringw nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node);
protected: protected:
irr::core::stringw nameForPtr(const void* ptr) const; irr::core::stringw nameForPtr(const void* ptr) const;
private:
IColladaMeshWriter * ColladaMeshWriter;
}; };
...@@ -88,6 +89,8 @@ public: ...@@ -88,6 +89,8 @@ public:
//! writes a mesh //! writes a mesh
virtual bool writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags=EMWF_NONE); virtual bool writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags=EMWF_NONE);
// Restrict the characters of oldString a set of allowed characters in xs::NCName and add the prefix.
virtual irr::core::stringw toNCName(const irr::core::stringw& oldString, const irr::core::stringw& prefix=irr::core::stringw(L"_NC_")) const;
protected: protected:
...@@ -108,7 +111,6 @@ protected: ...@@ -108,7 +111,6 @@ protected:
irr::core::stringw nameForPtr(const void* ptr) 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 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