Commit 9459acf1 authored by cutealien's avatar cutealien

Added IColladaMeshWriterProperties::useNodeMaterial to allow handling custom...

Added IColladaMeshWriterProperties::useNodeMaterial to allow handling custom ISceneNode implementation on export.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4278 dfc29bdd-3216-0410-991c-e03cc46cb475
parent f1aea87c
......@@ -140,7 +140,16 @@ namespace scene
//! Return the mesh for the given node. If it has no mesh or shouldn't export it's mesh
//! you can return 0 in which case only the transformation matrix of the node will be used.
// Note: Function is not const because there is no const getMesh() function.
virtual IMesh* getMesh(irr::scene::ISceneNode * node) = 0;
//! Return if the node has it's own material overwriting the mesh-materials
/** Usually true except for mesh-nodes which have isReadOnlyMaterials set.
This is mostly important for naming (as ISceneNode::getMaterial() already returns the correct material).
You have to override it when exporting custom scenenodes with own materials.
\return true => The node's own material is used, false => ignore node material and use the one from the mesh */
virtual bool useNodeMaterial(const scene::ISceneNode* node) const = 0;
};
//! Callback interface to use custom names on collada writing.
......
......@@ -135,6 +135,26 @@ IMesh* CColladaMeshWriterProperties::getMesh(irr::scene::ISceneNode * node)
return 0;
}
// Check if the node has it's own material overwriting the mesh-materials
bool CColladaMeshWriterProperties::useNodeMaterial(const scene::ISceneNode* node) const
{
if ( !node )
return false;
// TODO: we need some ISceneNode::hasType() function to get rid of those checks
bool useMeshMaterial = ( (node->getType() == ESNT_MESH ||
node->getType() == ESNT_CUBE ||
node->getType() == ESNT_SPHERE ||
node->getType() == ESNT_WATER_SURFACE ||
node->getType() == ESNT_Q3SHADER_SCENE_NODE)
&& static_cast<const IMeshSceneNode*>(node)->isReadOnlyMaterials())
|| (node->getType() == ESNT_ANIMATED_MESH
&& static_cast<const IAnimatedMeshSceneNode*>(node)->isReadOnlyMaterials() );
return !useMeshMaterial;
}
CColladaMeshWriterNames::CColladaMeshWriterNames(IColladaMeshWriter * writer)
......@@ -174,16 +194,8 @@ irr::core::stringw CColladaMeshWriterNames::nameForMaterial(const video::SMateri
{
core::stringw strMat(L"mat");
bool useMeshMaterial = !node ||
( (node->getType() == ESNT_MESH || // TODO: we need some ISceneNode::hasType() function to get rid of those checks
node->getType() == ESNT_CUBE ||
node->getType() == ESNT_SPHERE ||
node->getType() == ESNT_WATER_SURFACE ||
node->getType() == ESNT_Q3SHADER_SCENE_NODE)
&& static_cast<const IMeshSceneNode*>(node)->isReadOnlyMaterials())
|| (node->getType() == ESNT_ANIMATED_MESH && static_cast<const IAnimatedMeshSceneNode*>(node)->isReadOnlyMaterials() );
if ( !useMeshMaterial )
bool nodeMaterial = ColladaMeshWriter->getProperties()->useNodeMaterial(node);
if ( nodeMaterial )
{
strMat += L"node";
strMat += nameForPtr(node);
......@@ -423,9 +435,8 @@ void CColladaMeshWriter::writeNodeMaterials(irr::scene::ISceneNode * node)
IMesh* mesh = getProperties()->getMesh(node);
if ( mesh )
{
MeshNode * n = Meshes.find(mesh);
if ( node->getType() == ESNT_MESH
&& static_cast<IMeshSceneNode*>(node)->isReadOnlyMaterials() )
MeshNode * n = Meshes.find(mesh);
if ( !getProperties()->useNodeMaterial(node) )
{
// no material overrides - write mesh materials
if ( n && !n->getValue().MaterialsWritten )
......@@ -506,8 +517,7 @@ void CColladaMeshWriter::writeNodeEffects(irr::scene::ISceneNode * node)
IMesh* mesh = getProperties()->getMesh(node);
if ( mesh )
{
if ( node->getType() == ESNT_MESH
&& static_cast<IMeshSceneNode*>(node)->isReadOnlyMaterials() )
if ( !getProperties()->useNodeMaterial(node) )
{
// no material overrides - write mesh materials
MeshNode * n = Meshes.find(mesh);
......
......@@ -53,6 +53,9 @@ namespace scene
//! Return the mesh for the given nod. If it has no mesh or shouldn't export it's mesh return 0.
virtual irr::scene::IMesh* getMesh(irr::scene::ISceneNode * node);
//! Return if the node has it's own material overwriting the mesh-materials
virtual bool useNodeMaterial(const scene::ISceneNode* node) const;
};
class CColladaMeshWriterNames : public virtual IColladaMeshWriterNames
......
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