Commit 87f86371 authored by cutealien's avatar cutealien

- add overloaded map::getValue which can return a reference

- simplified IColladaMeshWriterProperties interface
- ColladaMeshWriter can now write complete scenes as well as just writing single meshes.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3859 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 7d101163
......@@ -6,6 +6,8 @@
#define __IRR_I_COLLADA_MESH_WRITER_H_INCLUDED__
#include "IMeshWriter.h"
#include "ISceneNode.h"
#include "IAnimatedMesh.h"
#include "SMaterial.h"
namespace irr
......@@ -63,7 +65,18 @@ namespace scene
ECOF_TRANSPARENT_SPECULAR = 16
};
//! For mapping irrlicht textures indices to collada color-types
enum E_COLLADA_COLOR_SAMPLER
{
ECCS_DIFFUSE,
ECCS_AMBIENT,
ECCS_EMISSIVE,
ECCS_SPECULAR,
ECCS_TRANSPARENT
};
//! Callback interface for properties which can be used to influence collada writing
//! NOTE: Interface is still work in process and might change some more before 1.8 release
class IColladaMeshWriterProperties : public virtual IReferenceCounted
{
public:
......@@ -72,27 +85,11 @@ namespace scene
//! 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 writing 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 writing 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 writing 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 writing 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;
//! Which texture index should be used when writing the transparent texture
/** Note: By default the alpha channel is used, if you want to use RGB you have to set
the ECOF_RGB_ZERO flag in getTransparentFx.
\return the index to the texture-layer or -1 if that texture should never be exported */
virtual s32 getTransparentTextureIdx( const video::SMaterial& material) const = 0;
//! Which texture index should be used when writing the texture of the given sampler color.
/** \return the index to the texture-layer or -1 if that texture should never be exported
Note: for ECCS_TRANSPARENT by default the alpha channel is used, if you want to use RGB you have to set
also the ECOF_RGB_ZERO flag in getTransparentFx. */
virtual s32 getTextureIdx(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const = 0;
//! Return the settings for transparence
virtual E_COLLADA_TRANSPARENT_FX getTransparentFx(const video::SMaterial& material) const = 0;
......@@ -101,6 +98,14 @@ namespace scene
/** This value is additional to transparent settings, if both are set they will be multiplicated.
\return 1.0 for fully transparent, 0.0 for not transparent and not written at all when < 0.f */
virtual f32 getTransparency(const video::SMaterial& material) const = 0;
//! Should node be used in scene export?
//! By default all visible nodes are exported.
virtual bool isExportable(const irr::scene::ISceneNode * node) const = 0;
//! Return the mesh for the given node. If it has no mesh or shouldn't export it's mesh return 0
//! then only the transformation matrix of the node will be used.
virtual IMesh* getMesh(irr::scene::ISceneNode * node) = 0;
};
......@@ -109,8 +114,7 @@ namespace scene
{
public:
IColladaMeshWriter() : Properties(0), DefaultProperties(0), WriteTextures(true), WriteScene(false)
IColladaMeshWriter() : Properties(0), DefaultProperties(0), WriteTextures(true), WriteDefaultScene(false)
{
}
......@@ -123,6 +127,10 @@ namespace scene
DefaultProperties->drop();
}
//! writes a scene starting with the given node
virtual bool writeScene(io::IWriteFile* file, scene::ISceneNode* root) = 0;
//! Set if texture information should be written
virtual void setWriteTextures(bool write)
{
......@@ -135,19 +143,20 @@ namespace scene
return WriteTextures;
}
//! Set if a default scene should be written
//! Set if a default scene should be written when writing meshes.
/** 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.
When using writeScene this flag is ignored (as we have scene there already)
*/
virtual void setWriteScene(bool write)
virtual void setWriteDefaultScene(bool write)
{
WriteScene = write;
WriteDefaultScene = write;
}
//! Get if a default scene should be written
virtual bool getWriteScene() const
virtual bool getWriteDefaultScene() const
{
return WriteScene;
return WriteDefaultScene;
}
//! Set properties to use by the meshwriter instead of it's default properties.
......@@ -194,7 +203,7 @@ namespace scene
IColladaMeshWriterProperties * Properties;
IColladaMeshWriterProperties * DefaultProperties;
bool WriteTextures;
bool WriteScene;
bool WriteDefaultScene;
};
......
......@@ -58,6 +58,12 @@ class map
return Value;
}
ValueTypeRB& getValue()
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return Value;
}
KeyTypeRB getKey() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
......
This diff is collapsed.
......@@ -7,6 +7,7 @@
#include "IColladaMeshWriter.h"
#include "S3DVertex.h"
#include "irrMap.h"
#include "IVideoDriver.h"
namespace irr
......@@ -26,27 +27,9 @@ namespace scene
//! 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
//! Which texture index should be used when writing the texture of the given sampler color.
/** \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;
//! Which texture index should be used when writing the transparent texture
/** Note: By default the alpha channel is used, if you want to use RGB you have to set
the ECOF_RGB_ZERO flag in getTransparentFx.
\return the index to the texture-layer or -1 if that texture should never be exported */
virtual s32 getTransparentTextureIdx( const video::SMaterial& material) const;
virtual s32 getTextureIdx(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const;
//! Return the settings for transparence
virtual E_COLLADA_TRANSPARENT_FX getTransparentFx(const video::SMaterial& material) const;
......@@ -55,6 +38,12 @@ namespace scene
/** This value is additional to transparent settings, if both are set they will be multiplicated.
\return 1.0 for fully transparent, 0.0 for not transparent and not written at all when < 0.f */
virtual f32 getTransparency(const video::SMaterial& material) const;
//! Should node be used in scene export? By default all visible nodes are exported.
virtual bool isExportable(const irr::scene::ISceneNode * node) const;
//! Return the mesh for the given nod. If it has no mesh or shouldn't export it's mesh return 0.
virtual IMesh* getMesh(irr::scene::ISceneNode * node);
};
......@@ -71,21 +60,15 @@ public:
//! Returns the type of the mesh writer
virtual EMESH_WRITER_TYPE getType() const;
//! writes a scene starting with the given node
virtual bool writeScene(io::IWriteFile* file, scene::ISceneNode* root);
//! writes a mesh
virtual bool writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags=EMWF_NONE);
protected:
enum E_COLLADA_COLOR_SAMPLER
{
ECS_DIFFUSE,
ECS_AMBIENT,
ECS_EMISSIVE,
ECS_SPECULAR,
ECS_TRANSPARENT
};
bool hasSecondTextureCoordinates(video::E_VERTEX_TYPE type) const;
inline irr::core::stringw toString(const irr::core::vector3df& vec) const;
inline irr::core::stringw toString(const irr::core::vector2df& vec) const;
......@@ -93,6 +76,9 @@ protected:
inline irr::core::stringw toString(const irr::video::ECOLOR_FORMAT format) 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 toRef(const irr::core::stringw& source) const;
irr::core::stringw uniqueNameForMesh(const scene::IMesh* mesh) const;
irr::core::stringw uniqueNameForNode(const scene::ISceneNode* node) const;
irr::core::stringw minTexfilterToString(bool bilinear, bool trilinear) const;
irr::core::stringw magTexfilterToString(bool bilinear, bool trilinear) const;
irr::core::stringw pathToNCName(const irr::io::path& path) const;
......@@ -100,10 +86,25 @@ protected:
inline bool isXmlNameStartChar(wchar_t c) const;
inline bool isXmlNameChar(wchar_t c) const;
s32 getTextureIdx(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs);
void writeAsset();
void makeMeshNames(irr::scene::ISceneNode * node);
void writeNodeMaterials(irr::scene::ISceneNode * node);
void writeNodeEffects(irr::scene::ISceneNode * node);
void writeNodeGeometries(irr::scene::ISceneNode * node);
void writeSceneNode(irr::scene::ISceneNode * node);
void writeMeshMaterials(const irr::core::stringw& meshname, scene::IMesh* mesh);
void writeMeshEffects(const irr::core::stringw& meshname, scene::IMesh* mesh);
void writeMaterialEffect(const irr::core::stringw& meshname, const irr::core::stringw& materialname, const video::SMaterial & material);
void writeMeshGeometry(const irr::core::stringw& meshname, scene::IMesh* mesh);
void writeMeshInstanceGeometry(const irr::core::stringw& meshname, scene::IMesh* mesh);
void writeLibraryImages();
void writeColorElement(const video::SColor & col);
bool writeTextureSampler(s32 textureIdx);
void writeFxElement(const video::SMaterial & material, E_COLLADA_TECHNIQUE_FX techFx);
bool writeTextureSampler(const irr::core::stringw& meshname, s32 textureIdx);
void writeFxElement(const irr::core::stringw& meshname, const video::SMaterial & material, E_COLLADA_TECHNIQUE_FX techFx);
void writeFloatElement(irr::f32 value);
void writeRotateElement(const irr::core::vector3df& axis, irr::f32 angle);
void writeScaleElement(const irr::core::vector3df& scale);
void writeTranslateElement(const irr::core::vector3df& translate);
struct SComponentGlobalStartPos
{
......@@ -131,6 +132,20 @@ protected:
io::IXMLWriter* Writer;
core::array<video::ITexture*> LibraryImages;
io::path Directory;
struct ColladaMesh
{
ColladaMesh() : MaterialWritten(false), EffectWritten(false), GeometryWritten(false)
{
}
irr::core::stringw Name;
bool MaterialWritten;
bool EffectWritten;
bool GeometryWritten;
};
typedef core::map<IMesh*, ColladaMesh>::Node MeshNode;
core::map<IMesh*, ColladaMesh> Meshes;
};
......
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