Irrlicht 3D Engine
IColladaMeshWriter.h
Go to the documentation of this file.
00001 // Copyright (C) 2002-2012 Nikolaus Gebhardt
00002 // This file is part of the "Irrlicht Engine".
00003 // For conditions of distribution and use, see copyright notice in irrlicht.h
00004 
00005 #ifndef __IRR_I_COLLADA_MESH_WRITER_H_INCLUDED__
00006 #define __IRR_I_COLLADA_MESH_WRITER_H_INCLUDED__
00007 
00008 #include "IMeshWriter.h"
00009 #include "ISceneNode.h"
00010 #include "IAnimatedMesh.h"
00011 #include "SMaterial.h"
00012 
00013 namespace irr
00014 {
00015 namespace io
00016 {
00017     class IWriteFile;
00018 } // end namespace io
00019 
00020 namespace scene
00021 {
00023     enum E_COLLADA_TECHNIQUE_FX
00024     {
00027         ECTF_BLINN, 
00029         ECTF_PHONG,
00031         ECTF_LAMBERT,
00032         // constantly shaded surface that is independent of lighting. 
00033         ECTF_CONSTANT
00034     };
00035 
00037     enum E_COLLADA_TRANSPARENT_FX
00038     {
00040         ECOF_A_ONE = 0,
00041 
00043         ECOF_RGB_ZERO = 1
00044     };
00045 
00047     enum E_COLLADA_COLOR_SAMPLER
00048     {
00049         ECCS_DIFFUSE,
00050         ECCS_AMBIENT,
00051         ECCS_EMISSIVE,
00052         ECCS_SPECULAR,
00053         ECCS_TRANSPARENT,
00054         ECCS_REFLECTIVE
00055     };
00056 
00058     enum E_COLLADA_IRR_COLOR
00059     {
00061         ECIC_NONE,
00062 
00064         ECIC_CUSTOM,
00065 
00067         ECIC_DIFFUSE,
00068 
00070         ECIC_AMBIENT,
00071 
00073         ECIC_EMISSIVE,
00074 
00076         ECIC_SPECULAR
00077     };
00078 
00080     enum E_COLLADA_GEOMETRY_WRITING
00081     {
00083         ECGI_PER_MESH,  
00084 
00088         ECGI_PER_MESH_AND_MATERIAL
00089     };
00090 
00092     class IColladaMeshWriterProperties  : public virtual IReferenceCounted
00093     {
00094     public:
00095         virtual ~IColladaMeshWriterProperties ()    {}
00096 
00098         virtual E_COLLADA_TECHNIQUE_FX getTechniqueFx(const video::SMaterial& material) const = 0;
00099 
00101 
00104         virtual s32 getTextureIdx(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const = 0;
00105 
00107 
00111         virtual E_COLLADA_IRR_COLOR getColorMapping(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const = 0;
00112 
00114 
00115         virtual video::SColor getCustomColor(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const = 0;
00116 
00118 
00119         virtual E_COLLADA_TRANSPARENT_FX getTransparentFx(const video::SMaterial& material) const = 0;
00120 
00122 
00124         virtual f32 getTransparency(const video::SMaterial& material) const = 0;
00125 
00127 
00129         virtual f32 getReflectivity(const video::SMaterial& material) const = 0;
00130 
00132 
00134         virtual f32 getIndexOfRefraction(const video::SMaterial& material) const = 0;
00135 
00138         virtual bool isExportable(const irr::scene::ISceneNode * node) const = 0;
00139 
00142         // Note: Function is not const because there is no const getMesh() function.
00143         virtual IMesh* getMesh(irr::scene::ISceneNode * node) = 0;
00144 
00146 
00150         virtual bool useNodeMaterial(const scene::ISceneNode* node) const = 0;
00151 
00152     };
00153 
00155 
00158     class IColladaMeshWriterNames  : public virtual IReferenceCounted
00159     {
00160     public:
00161     
00162         virtual ~IColladaMeshWriterNames () {}
00163 
00165 
00174         virtual irr::core::stringw nameForMesh(const scene::IMesh* mesh, int instance) = 0;
00175 
00177 
00183         virtual irr::core::stringw nameForNode(const scene::ISceneNode* node) = 0;
00184 
00186 
00196         virtual irr::core::stringw nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node) = 0;
00197     };
00198 
00199 
00201     class IColladaMeshWriter : public IMeshWriter
00202     {
00203     public:
00204 
00205         IColladaMeshWriter() 
00206             : Properties(0), DefaultProperties(0), NameGenerator(0), DefaultNameGenerator(0)
00207             , WriteTextures(true), WriteDefaultScene(true), ExportSMaterialOnce(true)
00208             , AmbientLight(0.f, 0.f, 0.f, 1.f)
00209             , GeometryWriting(ECGI_PER_MESH)
00210         {
00211         }
00212 
00214         virtual ~IColladaMeshWriter() 
00215         {
00216             if ( Properties )
00217                 Properties->drop();
00218             if ( DefaultProperties )
00219                 DefaultProperties->drop();
00220             if ( NameGenerator )
00221                 NameGenerator->drop();
00222             if ( DefaultNameGenerator )
00223                 DefaultNameGenerator->drop();
00224         }
00225 
00227         virtual bool writeScene(io::IWriteFile* file, scene::ISceneNode* root) = 0;
00228 
00229 
00231         virtual void setWriteTextures(bool write)
00232         {
00233             WriteTextures = write;
00234         }
00235 
00237         virtual bool getWriteTextures() const 
00238         {
00239             return WriteTextures;
00240         }
00241 
00243 
00247         virtual void setWriteDefaultScene(bool write)
00248         {
00249             WriteDefaultScene = write;
00250         }
00251 
00253         virtual bool getWriteDefaultScene() const
00254         {
00255             return WriteDefaultScene;
00256         }
00257 
00259         virtual void setAmbientLight(const video::SColorf &ambientColor)
00260         {
00261             AmbientLight = ambientColor;
00262         }
00263 
00265         virtual video::SColorf getAmbientLight() const
00266         {
00267             return AmbientLight;
00268         }
00269 
00271 
00278         virtual void setGeometryWriting(E_COLLADA_GEOMETRY_WRITING writeStyle) 
00279         {
00280             GeometryWriting = writeStyle;
00281         }
00282 
00284         virtual E_COLLADA_GEOMETRY_WRITING getGeometryWriting() const
00285         {
00286             return GeometryWriting;
00287         }
00288 
00290 
00297         virtual void setExportSMaterialsOnlyOnce(bool exportOnce)
00298         {
00299             ExportSMaterialOnce = exportOnce;
00300         }
00301 
00302         virtual bool getExportSMaterialsOnlyOnce() const
00303         {
00304             return ExportSMaterialOnce;
00305         }
00306 
00308 
00310         virtual void setProperties(IColladaMeshWriterProperties * p)
00311         {
00312             if ( p == Properties )
00313                 return;
00314             if ( p ) 
00315                 p->grab();
00316             if ( Properties )
00317                 Properties->drop();
00318             Properties = p;
00319         }
00320 
00322         virtual IColladaMeshWriterProperties * getProperties() const
00323         {
00324             return Properties;
00325         }
00326 
00328 
00329         IColladaMeshWriterProperties * getDefaultProperties() const 
00330         { 
00331             return DefaultProperties; 
00332         }
00333 
00335         virtual void setNameGenerator(IColladaMeshWriterNames * nameGenerator)
00336         {
00337             if ( nameGenerator == NameGenerator )
00338                 return;
00339             if ( nameGenerator ) 
00340                 nameGenerator->grab();
00341             if ( NameGenerator )
00342                 NameGenerator->drop();
00343             NameGenerator = nameGenerator;
00344         }
00345 
00347         virtual IColladaMeshWriterNames * getNameGenerator() const
00348         {
00349             return NameGenerator;
00350         }
00351 
00353 
00354         IColladaMeshWriterNames * getDefaultNameGenerator() const 
00355         { 
00356             return DefaultNameGenerator; 
00357         }
00358 
00360 
00361         virtual irr::core::stringw toNCName(const irr::core::stringw& oldString, const irr::core::stringw& prefix=irr::core::stringw(L"_NC_")) const = 0;
00362 
00363 
00364     protected:
00365         // NOTE: You usually should also call setProperties with the same paraemter when using setDefaultProperties
00366         virtual void setDefaultProperties(IColladaMeshWriterProperties * p)
00367         {
00368             if ( p == DefaultProperties )
00369                 return;
00370             if ( p ) 
00371                 p->grab();
00372             if ( DefaultProperties )
00373                 DefaultProperties->drop();
00374             DefaultProperties = p;
00375         }
00376 
00377         // NOTE: You usually should also call setNameGenerator with the same paraemter when using setDefaultProperties
00378         virtual void setDefaultNameGenerator(IColladaMeshWriterNames * p)
00379         {
00380             if ( p == DefaultNameGenerator )
00381                 return;
00382             if ( p ) 
00383                 p->grab();
00384             if ( DefaultNameGenerator )
00385                 DefaultNameGenerator->drop();
00386             DefaultNameGenerator = p;
00387         }
00388 
00389     private:
00390         IColladaMeshWriterProperties * Properties;
00391         IColladaMeshWriterProperties * DefaultProperties;
00392         IColladaMeshWriterNames * NameGenerator;
00393         IColladaMeshWriterNames * DefaultNameGenerator;
00394         bool WriteTextures;
00395         bool WriteDefaultScene;
00396         bool ExportSMaterialOnce;
00397         video::SColorf AmbientLight;
00398         E_COLLADA_GEOMETRY_WRITING GeometryWriting;
00399     };
00400 
00401 
00402 } // end namespace
00403 } // end namespace
00404 
00405 #endif