~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to include/IColladaMeshWriter.h

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
 
2
// This file is part of the "Irrlicht Engine".
 
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
 
4
 
 
5
#ifndef __IRR_I_COLLADA_MESH_WRITER_H_INCLUDED__
 
6
#define __IRR_I_COLLADA_MESH_WRITER_H_INCLUDED__
 
7
 
 
8
#include "IMeshWriter.h"
 
9
#include "ISceneNode.h"
 
10
#include "IAnimatedMesh.h"
 
11
#include "SMaterial.h"
 
12
 
 
13
namespace irr
 
14
{
 
15
namespace io
 
16
{
 
17
        class IWriteFile;
 
18
} // end namespace io
 
19
 
 
20
namespace scene
 
21
{
 
22
        //! Lighting models - more or less the way Collada categorizes materials
 
23
        enum E_COLLADA_TECHNIQUE_FX
 
24
        {
 
25
                //! Blinn-phong which is default for opengl and dx fixed function pipelines.
 
26
                //! But several well-known renderers don't support it and prefer phong.
 
27
                ECTF_BLINN,     
 
28
                //! Phong shading, default in many external renderers.
 
29
                ECTF_PHONG,
 
30
                //! diffuse shaded surface that is independent of lighting.
 
31
                ECTF_LAMBERT,
 
32
                // constantly shaded surface that is independent of lighting. 
 
33
                ECTF_CONSTANT
 
34
        };
 
35
 
 
36
        //! How to interpret the opacity in collada
 
37
        enum E_COLLADA_TRANSPARENT_FX
 
38
        {
 
39
                //! default - only alpha channel of color or texture is used.
 
40
                ECOF_A_ONE = 0,
 
41
 
 
42
                //! Alpha values for each RGB channel of color or texture are used. 
 
43
                ECOF_RGB_ZERO = 1
 
44
        };
 
45
 
 
46
        //! Color names collada uses in it's color samplers
 
47
        enum E_COLLADA_COLOR_SAMPLER
 
48
        {
 
49
                ECCS_DIFFUSE,
 
50
                ECCS_AMBIENT,
 
51
                ECCS_EMISSIVE,
 
52
                ECCS_SPECULAR,
 
53
                ECCS_TRANSPARENT,
 
54
                ECCS_REFLECTIVE
 
55
        };
 
56
 
 
57
        //! Irrlicht colors which can be mapped to E_COLLADA_COLOR_SAMPLER values
 
58
        enum E_COLLADA_IRR_COLOR
 
59
        {
 
60
                //! Don't write this element at all
 
61
                ECIC_NONE,
 
62
 
 
63
                //! Check IColladaMeshWriterProperties for custom color
 
64
                ECIC_CUSTOM,
 
65
 
 
66
                //! Use SMaterial::DiffuseColor
 
67
                ECIC_DIFFUSE,
 
68
 
 
69
                //! Use SMaterial::AmbientColor
 
70
                ECIC_AMBIENT,
 
71
 
 
72
                //! Use SMaterial::EmissiveColor
 
73
                ECIC_EMISSIVE,
 
74
 
 
75
                //! Use SMaterial::SpecularColor
 
76
                ECIC_SPECULAR
 
77
        };
 
78
 
 
79
        //! Callback interface for properties which can be used to influence collada writing
 
80
        //! NOTE: Interface is still work in process and might change some more before 1.8 release
 
81
        class IColladaMeshWriterProperties  : public virtual IReferenceCounted
 
82
        {
 
83
        public:
 
84
                virtual ~IColladaMeshWriterProperties ()        {}
 
85
 
 
86
                //! Which lighting model should be used in the technique (FX) section when exporting effects (materials)
 
87
                virtual E_COLLADA_TECHNIQUE_FX getTechniqueFx(const video::SMaterial& material) const = 0;
 
88
 
 
89
                //! Which texture index should be used when writing the texture of the given sampler color.
 
90
                /** \return the index to the texture-layer or -1 if that texture should never be exported 
 
91
                        Note: for ECCS_TRANSPARENT by default the alpha channel is used, if you want to use RGB you have to set
 
92
                        also the ECOF_RGB_ZERO flag in getTransparentFx.  */
 
93
                virtual s32 getTextureIdx(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const = 0;
 
94
 
 
95
                //! Return which color from Irrlicht should be used for the color requested by collada
 
96
                /** Note that collada allows exporting either texture or color, not both. 
 
97
                        So color mapping is only checked if we have no valid texture already.
 
98
                        By default we try to return best fits when possible. For example ECCS_DIFFUSE is mapped to ECIC_DIFFUSE.
 
99
                        When ECIC_CUSTOM is returned then the result of getCustomColor will be used. */
 
100
                virtual E_COLLADA_IRR_COLOR getColorMapping(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const = 0;
 
101
 
 
102
                //! Return custom colors for certain color types requested by collada. 
 
103
                /** Only used when getColorMapping returns ECIC_CUSTOM for the same paramters. */
 
104
                virtual video::SColor getCustomColor(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const = 0;
 
105
 
 
106
                //! Return the transparence color interpretation.
 
107
                /** Not this is only about ECCS_TRANSPARENT and does not affect getTransparency. */
 
108
                virtual E_COLLADA_TRANSPARENT_FX getTransparentFx(const video::SMaterial& material) const = 0;
 
109
 
 
110
                //! Transparency value for that material. 
 
111
                /** This value is additional to transparent settings, if both are set they will be multiplicated.
 
112
                \return 1.0 for fully transparent, 0.0 for not transparent and not written at all when < 0.f */
 
113
                virtual f32 getTransparency(const video::SMaterial& material) const = 0;
 
114
 
 
115
                //! Reflectivity value for that material
 
116
                /** The amount of perfect mirror reflection to be added to the reflected light 
 
117
                \return 0.0 - 1.0 for reflectivity and element is not written at all when < 0.f */
 
118
                virtual f32 getReflectivity(const video::SMaterial& material) const = 0;
 
119
 
 
120
                //! Return index of refraction for that material
 
121
                /**     By default we don't write that.
 
122
                \return a value >= 0.f to write <index_of_refraction> when it's < 0 nothing will be written */
 
123
                virtual f32 getIndexOfRefraction(const video::SMaterial& material) const = 0;
 
124
 
 
125
                //! Should node be used in scene export? (only needed for scene-writing, ignored in mesh-writing)
 
126
                //! By default all visible nodes are exported.
 
127
                virtual bool isExportable(const irr::scene::ISceneNode * node) const = 0;
 
128
 
 
129
                //! Return the mesh for the given node. If it has no mesh or shouldn't export it's mesh 
 
130
                //! you can return 0 in which case only the transformation matrix of the node will be used.
 
131
                virtual IMesh* getMesh(irr::scene::ISceneNode * node) = 0;
 
132
        };
 
133
 
 
134
 
 
135
        //! Interface for writing meshes
 
136
        class IColladaMeshWriter : public IMeshWriter
 
137
        {
 
138
        public:
 
139
 
 
140
                IColladaMeshWriter() : Properties(0), DefaultProperties(0), WriteTextures(true), WriteDefaultScene(false), AmbientLight(0.f, 0.f, 0.f, 1.f)
 
141
                {
 
142
                }
 
143
 
 
144
                //! Destructor
 
145
                virtual ~IColladaMeshWriter() 
 
146
                {
 
147
                        if ( Properties )
 
148
                                Properties->drop();
 
149
                        if ( DefaultProperties )
 
150
                                DefaultProperties->drop();
 
151
                }
 
152
 
 
153
                //! writes a scene starting with the given node
 
154
                virtual bool writeScene(io::IWriteFile* file, scene::ISceneNode* root) = 0;
 
155
 
 
156
 
 
157
                //! Set if texture information should be written
 
158
                virtual void setWriteTextures(bool write)
 
159
                {
 
160
                        WriteTextures = write;
 
161
                }
 
162
 
 
163
                //! Get if texture information should be written
 
164
                virtual bool getWriteTextures() const 
 
165
                {
 
166
                        return WriteTextures;
 
167
                }
 
168
 
 
169
                //! Set if a default scene should be written when writing meshes.
 
170
                /** Many collada readers fail to read a mesh if the collada files doesn't contain a scene as well.
 
171
                The scene is doing an instantiation of the mesh.
 
172
                When using writeScene this flag is ignored (as we have scene there already)
 
173
                */
 
174
                virtual void setWriteDefaultScene(bool write)
 
175
                {
 
176
                        WriteDefaultScene = write;
 
177
                }
 
178
 
 
179
                //! Get if a default scene should be written
 
180
                virtual bool getWriteDefaultScene() const
 
181
                {
 
182
                        return WriteDefaultScene;
 
183
                }
 
184
 
 
185
                //! Sets ambient color of the scene to write
 
186
                virtual void setAmbientLight(const video::SColorf &ambientColor)
 
187
                {
 
188
                        AmbientLight = ambientColor;
 
189
                }
 
190
 
 
191
                //! Return ambient light of the scene which is written
 
192
                virtual video::SColorf getAmbientLight() const
 
193
                {
 
194
                        return AmbientLight;
 
195
                }
 
196
 
 
197
                //! Set properties to use by the meshwriter instead of it's default properties.
 
198
                /** Overloading properties with an own class allows modifying the writing process in certain ways. 
 
199
                By default properties are set to the DefaultProperties. */
 
200
                virtual void setProperties(IColladaMeshWriterProperties * p)
 
201
                {
 
202
                        if ( p == Properties )
 
203
                                return;
 
204
                        if ( p ) 
 
205
                                p->grab();
 
206
                        if ( Properties )
 
207
                                Properties->drop();
 
208
                        Properties = p;
 
209
                }
 
210
 
 
211
                //! Get properties which are currently used.
 
212
                virtual IColladaMeshWriterProperties * getProperties()
 
213
                {
 
214
                        return Properties;
 
215
                }
 
216
 
 
217
                //! Return the original default properties of the writer. 
 
218
                /** You can use this pointer in your own properties to access and return default values. */
 
219
                IColladaMeshWriterProperties * getDefaultProperties() const 
 
220
                { 
 
221
                        return DefaultProperties; 
 
222
                }
 
223
 
 
224
        protected:
 
225
                // NOTE: you should also call setProperties
 
226
                virtual void setDefaultProperties(IColladaMeshWriterProperties * p)
 
227
                {
 
228
                        if ( p == DefaultProperties )
 
229
                                return;
 
230
                        if ( p ) 
 
231
                                p->grab();
 
232
                        if ( DefaultProperties )
 
233
                                DefaultProperties->drop();
 
234
                        DefaultProperties = p;
 
235
                }
 
236
 
 
237
        private:
 
238
                IColladaMeshWriterProperties * Properties;
 
239
                IColladaMeshWriterProperties * DefaultProperties;
 
240
                bool WriteTextures;
 
241
                bool WriteDefaultScene;
 
242
                video::SColorf AmbientLight;
 
243
        };
 
244
 
 
245
 
 
246
} // end namespace
 
247
} // end namespace
 
248
 
 
249
#endif