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
};
//! Callback interface to use custom names on collada writing.
/** Many names and id's have to be unique in collada. By default
Irrlicht guarantees for example by using using pointer-values in the name.
This works for most tools, but occasionally you might need another naming scheme
to make it easier finding names again for further processing.
/** You can either modify names and id's written to collada or you can use
this interface to just find out which names are used on writing.
*/
class IColladaMeshWriterNames : public virtual IReferenceCounted
{
public:
IColladaMeshWriterNames() : MeshToNC(true), NodeToNC(true), NCNamePrefix(L"_NC_") {}
virtual ~IColladaMeshWriterNames () {}
//! 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
the nameForMesh from IColladaMeshWriter::getDefaultNameGenerator().
/** Note that names really must be unique here per mesh-pointer, so
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;
//! 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
the nameForNode from IColladaMeshWriter::getDefaultNameGenerator().
/** Note that names really must be unique here per node-pointer, so
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;
//! 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
the number of materials which get written. For example Irrlicht does by default write one material for each
material instanced by a node. So if you know that in your application material instances per node are identical
between different nodes you can reduce the number of exported materials using that knowledge by using identical
names for such shared materials. */
virtual irr::core::stringw nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node) = 0;
//! Ensure meshnames follow the xs::NCName format (so this will change names!)
/** Names need to have a certain format in collada, like not starting with numbers,
and avoiding certain special characters.
/** There is one material created in the writer for each unique name.
So you can use this to control the number of materials which get written.
For example Irrlicht does by default write one material for each material
instanced by a node. So if you know that in your application material
instances per node are identical between different nodes you can reduce
the number of exported materials using that knowledge by using identical
names for such shared materials.
Names must follow the xs::NCName standard to be valid, you can run them
through IColladaMeshWriter::toNCName to ensure that.
*/
void SetConvertMeshNameToNC(bool doConvert)
{
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;
virtual irr::core::stringw nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node) = 0;
};
......@@ -342,6 +293,10 @@ namespace scene
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:
// 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)
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 name(L"mesh");
name += nameForPtr(mesh);
return name;
return ColladaMeshWriter->toNCName(name);
}
irr::core::stringw CColladaMeshWriterNames::nameForNode(const scene::ISceneNode* node)
......@@ -162,7 +162,7 @@ irr::core::stringw CColladaMeshWriterNames::nameForNode(const scene::ISceneNode*
{
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)
......@@ -180,11 +180,14 @@ irr::core::stringw CColladaMeshWriterNames::nameForMaterial(const video::SMateri
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;
return strMat;
return ColladaMeshWriter->toNCName(strMat);
}
irr::core::stringw CColladaMeshWriterNames::nameForPtr(const void* ptr) const
......@@ -219,7 +222,7 @@ CColladaMeshWriter::CColladaMeshWriter( ISceneManager * smgr, video::IVideoDrive
setProperties(p);
p->drop();
CColladaMeshWriterNames * nameGenerator = new CColladaMeshWriterNames();
CColladaMeshWriterNames * nameGenerator = new CColladaMeshWriterNames(this);
setDefaultNameGenerator(nameGenerator);
setNameGenerator(nameGenerator);
nameGenerator->drop();
......@@ -926,10 +929,7 @@ irr::core::stringw CColladaMeshWriter::nameForMesh(const scene::IMesh* mesh) con
IColladaMeshWriterNames * nameGenerator = getNameGenerator();
if ( nameGenerator )
{
if ( nameGenerator->GetConvertMeshNameToNC() )
return toNCName(nameGenerator->nameForMesh(mesh), nameGenerator->getNCNamePrefix());
else
return nameGenerator->nameForMesh(mesh);
return nameGenerator->nameForMesh(mesh);
}
return irr::core::stringw(L"missing_name_generator");
}
......@@ -939,10 +939,7 @@ irr::core::stringw CColladaMeshWriter::nameForNode(const scene::ISceneNode* node
IColladaMeshWriterNames * nameGenerator = getNameGenerator();
if ( nameGenerator )
{
if ( nameGenerator->GetConvertNodeNameToNC() )
return toNCName(nameGenerator->nameForNode(node), nameGenerator->getNCNamePrefix());
else
return nameGenerator->nameForNode(node);
return nameGenerator->nameForNode(node);
}
return irr::core::stringw(L"missing_name_generator");
}
......@@ -952,10 +949,7 @@ irr::core::stringw CColladaMeshWriter::nameForMaterial(const video::SMaterial &
IColladaMeshWriterNames * nameGenerator = getNameGenerator();
if ( nameGenerator )
{
if ( nameGenerator->GetConvertMaterialNameToNC() )
return toNCName(nameGenerator->nameForMaterial(material, materialId, mesh, node), nameGenerator->getNCNamePrefix());
else
return nameGenerator->nameForMaterial(material, materialId, mesh, node);
return nameGenerator->nameForMaterial(material, materialId, mesh, node);
}
return irr::core::stringw(L"missing_name_generator");
}
......
......@@ -19,7 +19,6 @@ namespace io
}
namespace scene
{
//! 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)
class CColladaMeshWriterProperties : public virtual IColladaMeshWriterProperties
......@@ -59,12 +58,14 @@ namespace scene
class CColladaMeshWriterNames : public virtual IColladaMeshWriterNames
{
public:
CColladaMeshWriterNames();
CColladaMeshWriterNames(IColladaMeshWriter * writer);
virtual irr::core::stringw nameForMesh(const scene::IMesh* mesh);
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);
protected:
irr::core::stringw nameForPtr(const void* ptr) const;
private:
IColladaMeshWriter * ColladaMeshWriter;
};
......@@ -88,6 +89,8 @@ public:
//! writes a mesh
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:
......@@ -108,7 +111,6 @@ protected:
irr::core::stringw nameForPtr(const void* ptr) const;
irr::core::stringw minTexfilterToString(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;
inline bool isXmlNameStartChar(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