Commit ac6e07f8 authored by cutealien's avatar cutealien

Make ColladaMeshWriter more flexible by giving user more control over several settings.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3850 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 71d1c79d
// Copyright (C) 2002-2011 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __IRR_I_COLLADA_MESH_WRITER_H_INCLUDED__
#define __IRR_I_COLLADA_MESH_WRITER_H_INCLUDED__
#include "IMeshWriter.h"
#include "SMaterial.h"
namespace irr
{
namespace io
{
class IWriteFile;
} // end namespace io
namespace scene
{
// Lighting models - more or less the way Collada categorizes materials
enum E_COLLADA_TECHNIQUE_FX
{
//! Blinn-phong which is default for opengl and dx fixed function pipelines.
//! But several well-known renderers don't support it and prefer phong.
ECTF_BLINN,
//! Phong shading, default in many external renderers.
ECTF_PHONG,
//! diffuse shaded surface that is independent of lighting.
ECTF_LAMBERT,
// constantly shaded surface that is independent of lighting.
ECTF_CONSTANT
};
//! Callback interface for properties which can be used to influence collada writing
class IColladaMeshWriterProperties : public virtual IReferenceCounted
{
public:
virtual ~IColladaMeshWriterProperties () {}
//! Which lighting model should be used in the technique (FX) section when exporting effects (materials)
virtual E_COLLADA_TECHNIQUE_FX getTechniqueFx(const video::SMaterial& material) const = 0;
//! Which texture index should be used when setting the emissive texture
/** \return the index to the texture-layer or -1 if that texture should never be exported */
virtual s32 getEmissiveTextureIdx(const video::SMaterial& material) const = 0;
//! Which texture index should be used when setting the ambient texture
/** \return the index to the texture-layer or -1 if that texture should never be exported */
virtual s32 getAmbientTextureIdx(const video::SMaterial& material) const = 0;
//! Which texture index should be used when setting the diffuse texture
/** \return the index to the texture-layer or -1 if that texture should never be exported */
virtual s32 getDiffuseTextureIdx(const video::SMaterial& material) const = 0;
//! Which texture index should be used when setting the specular texture
/** \return the index to the texture-layer or -1 if that texture should never be exported */
virtual s32 getSpecularTextureIdx(const video::SMaterial& material) const = 0;
};
//! Interface for writing meshes
class IColladaMeshWriter : public IMeshWriter
{
public:
IColladaMeshWriter() : Properties(0), DefaultProperties(0), WriteTextures(true), WriteScene(false)
{
}
//! Destructor
virtual ~IColladaMeshWriter()
{
if ( Properties )
Properties->drop();
if ( DefaultProperties )
DefaultProperties->drop();
}
//! Set if texture information should be written
virtual void setWriteTextures(bool write)
{
WriteTextures = write;
}
//! Get if texture information should be written
virtual bool getWriteTextures() const
{
return WriteTextures;
}
//! Set if a default scene should be written
/** Many collada readers fail to read a mesh if the collada files doesn't contain a scene as well.
The scene is doing an instantiation of the mesh.
*/
virtual void setWriteScene(bool write)
{
WriteScene = write;
}
//! Get if a default scene should be written
virtual bool getWriteScene() const
{
return WriteScene;
}
//! Set properties to use by the meshwriter instead of it's default properties.
/** Overloading properties with an own class allows modifying the writing process in certain ways.
By default properties are set to the DefaultProperties. */
virtual void setProperties(IColladaMeshWriterProperties * p)
{
if ( p == Properties )
return;
if ( p )
p->grab();
if ( Properties )
Properties->drop();
Properties = p;
}
//! Get properties which are currently used.
virtual IColladaMeshWriterProperties * getProperties()
{
return Properties;
}
//! Return the original default properties of the writer.
/** You can use this pointer in your own properties to access and return default values. */
IColladaMeshWriterProperties * getDefaultProperties() const
{
return DefaultProperties;
}
protected:
// NOTE: you should also call setProperties
virtual void setDefaultProperties(IColladaMeshWriterProperties * p)
{
if ( p == DefaultProperties )
return;
if ( p )
p->grab();
if ( DefaultProperties )
DefaultProperties->drop();
DefaultProperties = p;
}
private:
IColladaMeshWriterProperties * Properties;
IColladaMeshWriterProperties * DefaultProperties;
bool WriteTextures;
bool WriteScene;
};
} // end namespace
} // end namespace
#endif
...@@ -112,6 +112,7 @@ ...@@ -112,6 +112,7 @@
#include "IMeshManipulator.h" #include "IMeshManipulator.h"
#include "IMeshSceneNode.h" #include "IMeshSceneNode.h"
#include "IMeshWriter.h" #include "IMeshWriter.h"
#include "IColladaMeshWriter.h"
#include "IMetaTriangleSelector.h" #include "IMetaTriangleSelector.h"
#include "IOSOperator.h" #include "IOSOperator.h"
#include "IParticleSystemSceneNode.h" // also includes all emitters and attractors #include "IParticleSystemSceneNode.h" // also includes all emitters and attractors
......
This diff is collapsed.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef __IRR_C_COLLADA_MESH_WRITER_H_INCLUDED__ #ifndef __IRR_C_COLLADA_MESH_WRITER_H_INCLUDED__
#define __IRR_C_COLLADA_MESH_WRITER_H_INCLUDED__ #define __IRR_C_COLLADA_MESH_WRITER_H_INCLUDED__
#include "IMeshWriter.h" #include "IColladaMeshWriter.h"
#include "S3DVertex.h" #include "S3DVertex.h"
#include "IVideoDriver.h" #include "IVideoDriver.h"
...@@ -19,10 +19,35 @@ namespace io ...@@ -19,10 +19,35 @@ namespace io
namespace scene namespace scene
{ {
//! Callback interface for properties which can be used to influence collada writing
class CColladaMeshWriterProperties : public virtual IColladaMeshWriterProperties
{
public:
//! Which lighting model should be used in the technique (FX) section when exporting effects (materials)
virtual E_COLLADA_TECHNIQUE_FX getTechniqueFx(const video::SMaterial& material) const;
//! Which texture index should be used when setting the emissive texture
/** \return the index to the texture-layer or -1 if that texture should never be exported */
virtual s32 getEmissiveTextureIdx(const video::SMaterial& material) const;
//! Which texture index should be used when setting the ambient texture
/** \return the index to the texture-layer or -1 if that texture should never be exported */
virtual s32 getAmbientTextureIdx(const video::SMaterial& material) const;
//! Which texture index should be used when setting the diffuse texture
/** \return the index to the texture-layer or -1 if that texture should never be exported */
virtual s32 getDiffuseTextureIdx(const video::SMaterial& material) const;
//! Which texture index should be used when setting the specular texture
/** \return the index to the texture-layer or -1 if that texture should never be exported */
virtual s32 getSpecularTextureIdx(const video::SMaterial& material) const;
};
//! class to write meshes, implementing a COLLADA (.dae, .xml) writer //! class to write meshes, implementing a COLLADA (.dae, .xml) writer
/** This writer implementation has been originally developed for irrEdit and then /** This writer implementation has been originally developed for irrEdit and then
merged out to the Irrlicht Engine */ merged out to the Irrlicht Engine */
class CColladaMeshWriter : public IMeshWriter class CColladaMeshWriter : public IColladaMeshWriter
{ {
public: public:
...@@ -47,9 +72,12 @@ protected: ...@@ -47,9 +72,12 @@ protected:
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 pathToNCName(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;
void writeColorElement(const video::SColor & col); void writeColorElement(const video::SColor & col);
bool writeTextureSampler(const video::SMaterial & material, video::E_COLOR_MATERIAL cm);
void writeFxElement(const video::SMaterial & material, E_COLLADA_TECHNIQUE_FX techFx);
struct SComponentGlobalStartPos struct SComponentGlobalStartPos
{ {
...@@ -85,3 +113,4 @@ protected: ...@@ -85,3 +113,4 @@ protected:
#endif #endif
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