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
5
#ifndef __IRR_I_COLLADA_MESH_WRITER_H_INCLUDED__
6
#define __IRR_I_COLLADA_MESH_WRITER_H_INCLUDED__
8
#include "IMeshWriter.h"
9
#include "ISceneNode.h"
10
#include "IAnimatedMesh.h"
11
#include "SMaterial.h"
22
//! Lighting models - more or less the way Collada categorizes materials
23
enum E_COLLADA_TECHNIQUE_FX
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.
28
//! Phong shading, default in many external renderers.
30
//! diffuse shaded surface that is independent of lighting.
32
// constantly shaded surface that is independent of lighting.
36
//! How to interpret the opacity in collada
37
enum E_COLLADA_TRANSPARENT_FX
39
//! default - only alpha channel of color or texture is used.
42
//! Alpha values for each RGB channel of color or texture are used.
46
//! Color names collada uses in it's color samplers
47
enum E_COLLADA_COLOR_SAMPLER
57
//! Irrlicht colors which can be mapped to E_COLLADA_COLOR_SAMPLER values
58
enum E_COLLADA_IRR_COLOR
60
//! Don't write this element at all
63
//! Check IColladaMeshWriterProperties for custom color
66
//! Use SMaterial::DiffuseColor
69
//! Use SMaterial::AmbientColor
72
//! Use SMaterial::EmissiveColor
75
//! Use SMaterial::SpecularColor
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
84
virtual ~IColladaMeshWriterProperties () {}
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
135
//! Interface for writing meshes
136
class IColladaMeshWriter : public IMeshWriter
140
IColladaMeshWriter() : Properties(0), DefaultProperties(0), WriteTextures(true), WriteDefaultScene(false), AmbientLight(0.f, 0.f, 0.f, 1.f)
145
virtual ~IColladaMeshWriter()
149
if ( DefaultProperties )
150
DefaultProperties->drop();
153
//! writes a scene starting with the given node
154
virtual bool writeScene(io::IWriteFile* file, scene::ISceneNode* root) = 0;
157
//! Set if texture information should be written
158
virtual void setWriteTextures(bool write)
160
WriteTextures = write;
163
//! Get if texture information should be written
164
virtual bool getWriteTextures() const
166
return WriteTextures;
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)
174
virtual void setWriteDefaultScene(bool write)
176
WriteDefaultScene = write;
179
//! Get if a default scene should be written
180
virtual bool getWriteDefaultScene() const
182
return WriteDefaultScene;
185
//! Sets ambient color of the scene to write
186
virtual void setAmbientLight(const video::SColorf &ambientColor)
188
AmbientLight = ambientColor;
191
//! Return ambient light of the scene which is written
192
virtual video::SColorf getAmbientLight() const
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)
202
if ( p == Properties )
211
//! Get properties which are currently used.
212
virtual IColladaMeshWriterProperties * getProperties()
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
221
return DefaultProperties;
225
// NOTE: you should also call setProperties
226
virtual void setDefaultProperties(IColladaMeshWriterProperties * p)
228
if ( p == DefaultProperties )
232
if ( DefaultProperties )
233
DefaultProperties->drop();
234
DefaultProperties = p;
238
IColladaMeshWriterProperties * Properties;
239
IColladaMeshWriterProperties * DefaultProperties;
241
bool WriteDefaultScene;
242
video::SColorf AmbientLight;