# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/plugins/COLLADA/DaeHelpers.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.org                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    00029 /*                                                                                    */
    00030 /**************************************************************************************/
    00031
    00032 #ifndef DaHelpers_INCLUDE_ONCE
    00033 #define DaHelpers_INCLUDE_ONCE
    00034
    00035 // needs to be but here because the awesome geniouses that programmed collada-dom 2.3 cleverly decided to use the same macro names as OpenGL, see domTypes.h
    00036 #ifdef _MSC_VER
    00037   #pragma warning(disable:4100)
    00038   #pragma warning(disable:4355)
    00039   #pragma warning(disable:4512)
    00040 #endif
    00041   #include <dae.h>
    00042   #include <dae/domAny.h>
    00043   #include <dom.h>
    00044   #include <dom/domCOLLADA.h>
    00045   #include <dom/domProfile_COMMON.h>
    00046 #ifdef _MSC_VER
    00047   #pragma warning(default:4100)
    00048   #pragma warning(default:4355)
    00049   #pragma warning(default:4512)
    00050 #endif
    00051
    00052 #include <vlGraphics/Actor.hpp>
    00053 #include <vlGraphics/Geometry.hpp>
    00054 #include <vlGraphics/Effect.hpp>
    00055 #include <vlGraphics/Shader.hpp>
    00056 #include <vlGraphics/Light.hpp>
    00057 #include <vlGraphics/MultiDrawElements.hpp>
    00058 #include <vlCore/glsl_math.hpp>
    00059
    00060 namespace vl
    00061 {
    00062   namespace Dae
    00063   {
    00064     //-----------------------------------------------------------------------------
    00065     typedef enum { PT_UNKNOWN, PT_LINES, PT_LINE_STRIP, PT_POLYGONS, PT_POLYLIST, PT_TRIANGLES, PT_TRIFANS, PT_TRISTRIPS } EPrimitiveType;
    00066     //-----------------------------------------------------------------------------
    00067     typedef enum { OM_A_ONE, OM_RGB_ZERO } EOpaqueMode;
    00068     //-----------------------------------------------------------------------------
    00069     typedef enum
    00070     {
    00071       IS_UNKNOWN,
    00072       IS_BINORMAL,
    00073       IS_COLOR,
    00074       IS_CONTINUITY,
    00075       IS_IMAGE,
    00076       IS_INPUT,
    00077       IS_IN_TANGENT,
    00078       IS_INTERPOLATION,
    00079       IS_INV_BIND_MATRIX,
    00080       IS_JOINT,
    00081       IS_LINEAR_STEPS,
    00082       IS_MORPHS_TARGET,
    00083       IS_MORPH_WEIGHT,
    00084       IS_NORMAL,
    00085       IS_OUTPUT,
    00086       IS_OUT_TANGENT,
    00087       IS_POSITION,
    00088       IS_TANGENT,
    00089       IS_TEXBINORMAL,
    00090       IS_TEXCOORD,
    00091       IS_TEXTANGENT,
    00092       IS_UV,
    00093       IS_VERTEX,
    00094       IS_WEIGHT
    00095     } EInputSemantic;
    00096     //-----------------------------------------------------------------------------
    00098     struct Vert
    00099     {
    00100       static const int MAX_ATTRIBS = 8;
    00101
    00102       Vert()
    00103       {
    00104         memset(mAttribIndex, 0xFF, sizeof(mAttribIndex));
    00105         mIndex = (size_t)-1;
    00106       }
    00107
    00108       bool operator<(const Dae::Vert& other) const
    00109       {
    00110         for(int i=0; i<MAX_ATTRIBS; ++i)
    00111         {
    00112           if (mAttribIndex[i] != other.mAttribIndex[i])
    00113             return mAttribIndex[i] < other.mAttribIndex[i];
    00114         }
    00115         return false;
    00116       }
    00117
    00118       size_t mAttribIndex[MAX_ATTRIBS];
    00119       size_t mIndex;
    00120     };
    00121     //-----------------------------------------------------------------------------
    00123     struct Source: public Object
    00124     {
    00125       Source()
    00126       {
    00127         mFloatSource = NULL;
    00128         mIntSource   = NULL;
    00129         mBoolSource  = NULL;
    00130         mFieldsMask = 0;
    00131         mStride     = 0;
    00132         mOffset     = 0;
    00133         mCount      = 0;
    00134         mDataSize   = 0;
    00135       }
    00136
    00138       void init(domFloat_arrayRef data_src, domUint count, domUint stride, domUint offset, size_t fields_mask)
    00139       {
    00140         mFloatSource = data_src;
    00141         mIntSource   = NULL;
    00142         mBoolSource  = NULL;
    00143         mCount       = (size_t)count;
    00144         mStride      = (size_t)stride;
    00145         mOffset      = (size_t)offset;
    00146         mFieldsMask  = fields_mask;
    00147
    00148         // count the number of scalars that will be read.
    00149         mDataSize = 0;
    00150         for(size_t i=0; i<32; ++i)
    00151           if (mFieldsMask & (1<<i))
    00152             mDataSize++;
    00153       }
    00154
    00156       void init(domInt_arrayRef data_src, domUint count, domUint stride, domUint offset, size_t fields_mask)
    00157       {
    00158         mFloatSource = NULL;
    00159         mIntSource   = data_src;
    00160         mBoolSource  = NULL;
    00161         mCount       = (size_t)count;
    00162         mStride      = (size_t)stride;
    00163         mOffset      = (size_t)offset;
    00164         mFieldsMask  = fields_mask;
    00165
    00166         // count the number of scalars that will be read.
    00167         mDataSize = 0;
    00168         for(size_t i=0; i<32; ++i)
    00169           if (mFieldsMask & (1<<i))
    00170             mDataSize++;
    00171       }
    00172
    00174       void init(domBool_arrayRef data_src, domUint count, domUint stride, domUint offset, size_t fields_mask)
    00175       {
    00176         mFloatSource = NULL;
    00177         mIntSource   = NULL;
    00178         mBoolSource  = data_src;
    00179         mCount       = (size_t)count;
    00180         mStride      = (size_t)stride;
    00181         mOffset      = (size_t)offset;
    00182         mFieldsMask  = fields_mask;
    00183
    00184         // count the number of scalars that will be read.
    00185         mDataSize = 0;
    00186         for(size_t i=0; i<32; ++i)
    00187           if (mFieldsMask & (1<<i))
    00188             mDataSize++;
    00189       }
    00190
    00192       void readData(size_t n, float* output)
    00193       {
    00194         size_t read_pos = mOffset + n * mStride;
    00195
    00196         size_t pos = 0;
    00197
    00198         if(mFloatSource)
    00199         {
    00200           VL_CHECK( (n < mCount) || (read_pos < mFloatSource->getValue().getCount() - mDataSize) )
    00201           for(size_t i=0; i<32 && i<mStride; ++i)
    00202             if (mFieldsMask & (1<<i))
    00203               output[pos++] = (float)mFloatSource->getValue()[read_pos+i];
    00204         }
    00205         else
    00206         if(mIntSource)
    00207         {
    00208           VL_CHECK( (n < mCount) || (read_pos < mIntSource->getValue().getCount() - mDataSize) )
    00209           for(size_t i=0; i<32 && i<mStride; ++i)
    00210             if (mFieldsMask & (1<<i))
    00211               output[pos++] = (float)mIntSource->getValue()[read_pos+i];
    00212         }
    00213         else
    00214         if(mBoolSource)
    00215         {
    00216           VL_CHECK( (n < mCount) || (read_pos < mBoolSource->getValue().getCount() - mDataSize) )
    00217           for(size_t i=0; i<32 && i<mStride; ++i)
    00218             if (mFieldsMask & (1<<i))
    00219               output[pos++] = (float)mBoolSource->getValue()[read_pos+i];
    00220         }
    00221       }
    00222
    00224       size_t count() const { return mCount; }
    00225
    00227       size_t dataSize() const { return mDataSize; }
    00228
    00229     protected:
    00230       size_t mFieldsMask;
    00231       size_t mDataSize;
    00232       domFloat_arrayRef mFloatSource;
    00233       domInt_arrayRef  mIntSource;
    00234       domBool_arrayRef mBoolSource;
    00235       size_t mStride;
    00236       size_t mOffset;
    00237       size_t mCount;
    00238     };
    00239     //-----------------------------------------------------------------------------
    00241     struct Input: public Object
    00242     {
    00243       Input()
    00244       {
    00245         mSemantic = Dae::IS_UNKNOWN;
    00246         mOffset = 0;
    00247         mSet = 0;
    00248       }
    00249
    00250       ref<Dae::Source> mSource;
    00251       Dae::EInputSemantic mSemantic;
    00252       size_t mOffset;
    00253       size_t mSet;
    00254     };
    00255     //-----------------------------------------------------------------------------
    00257     struct Primitive: public Object
    00258     {
    00259       Primitive()
    00260       {
    00261         mType = Dae::PT_UNKNOWN;
    00262         mCount = 0;
    00263         mIndexStride = 0;
    00264       }
    00265
    00266       Dae::EPrimitiveType mType;
    00267       std::string mMaterial;
    00268       std::vector< ref<Dae::Input> > mChannels;
    00269       size_t mCount;
    00270       std::vector<domPRef> mP;
    00271       size_t mIndexStride;
    00272       ref<Geometry> mGeometry;
    00273     };
    00274     //-----------------------------------------------------------------------------
    00276     struct Mesh: public Object
    00277     {
    00278       std::vector< ref<Dae::Input> > mVertexInputs;
    00279       std::vector< ref<Dae::Primitive> > mPrimitives;
    00280     };
    00281     //-----------------------------------------------------------------------------
    00283     struct Node: public Object
    00284     {
    00285       Node()
    00286       {
    00287         mTransform = new Transform;
    00288       }
    00289
    00290       ref<Transform> mTransform;
    00291       std::vector< ref<Dae::Node> > mChildren;
    00292       std::vector< ref<Dae::Mesh> > mMesh;
    00293       std::vector< ref<Actor> > mActors;
    00294     };
    00295     //-----------------------------------------------------------------------------
    00297     struct Surface: public Object
    00298     {
    00299       // mic fixme: for the moment we only support 2D images.
    00300       ref<Image> mImage; // <init_from>
    00301     };
    00302     //-----------------------------------------------------------------------------
    00304     struct Sampler2D: public Object
    00305     {
    00306       Sampler2D()
    00307       {
    00308         // default values if no tags are found.
    00309         mMinFilter = TPF_LINEAR;
    00310         mMagFilter = TPF_LINEAR;
    00311         mWrapS     = TPW_REPEAT;
    00312         mWrapT     = TPW_REPEAT;
    00313       }
    00314
    00315       ref<Dae::Surface> mDaeSurface;    // <source>
    00316       vl::ETexParamFilter mMinFilter; // <minfilter>
    00317       vl::ETexParamFilter mMagFilter; // <magfilter>
    00318       vl::ETexParamWrap   mWrapS;     // <wrap_s>
    00319       vl::ETexParamWrap   mWrapT;     // <wrap_t>
    00320
    00321       ref<Texture> mTexture; // actual VL texture implementing the sampler
    00322     };
    00323     //-----------------------------------------------------------------------------
    00325     struct NewParam: public Object
    00326     {
    00327       ref<Dae::Sampler2D> mDaeSampler2D;
    00328       ref<Dae::Surface> mDaeSurface;
    00329       fvec4 mFloat4;
    00330     };
    00331     //-----------------------------------------------------------------------------
    00333     struct ColorOrTexture: public Object
    00334     {
    00335       fvec4 mColor;
    00336       ref<Dae::Sampler2D> mSampler;
    00337       std::string mTexCoord;
    00338     };
    00339     //-----------------------------------------------------------------------------
    00341     struct TechniqueCOMMON: public Object
    00342     {
    00343       TechniqueCOMMON()
    00344       {
    00345         mMode = Unknown;
    00346
    00347         mEmission.mColor     = fvec4(0, 0, 0, 1);
    00348         mAmbient.mColor      = fvec4(0, 0, 0, 1);
    00349         mDiffuse.mColor      = fvec4(1, 0, 1, 1);
    00350         mSpecular.mColor     = fvec4(0, 0, 0, 1);
    00351         mShininess    = 40;
    00352
    00353         mReflective.mColor   = fvec4(1, 1, 1, 1);
    00354         mReflectivity = 0;
    00355
    00356         mTransparent.mColor  = fvec4(0, 0, 0, 1);
    00357         mOpaqueMode   = Dae::OM_A_ONE;
    00358         mTransparency = 1;
    00359
    00360         mIndexOfRefraction = 0;
    00361
    00362         mBlendingOn = false;
    00363       }
    00364
    00365       enum { Unknown, Blinn, Phong, Lambert } mMode;
    00366
    00367       Dae::EOpaqueMode mOpaqueMode;
    00368
    00369       Dae::ColorOrTexture mEmission;
    00370       Dae::ColorOrTexture mAmbient;
    00371       Dae::ColorOrTexture mDiffuse;
    00372       Dae::ColorOrTexture mSpecular;
    00373       float mShininess;
    00374       Dae::ColorOrTexture mReflective;
    00375       float mReflectivity;
    00376       Dae::ColorOrTexture mTransparent;
    00377       float mTransparency;
    00378       float mIndexOfRefraction;
    00379       bool mBlendingOn;
    00380     };
    00381     //-----------------------------------------------------------------------------
    00383     struct Effect: public Object
    00384     {
    00385       Effect()
    00386       {
    00387         mDoubleSided = false;
    00388       }
    00389
    00390       std::vector<ref<Dae::NewParam> > mNewParams;
    00391       ref<Dae::TechniqueCOMMON> mDaeTechniqueCOMMON;
    00392       bool mDoubleSided;
    00393     };
    00394     //-----------------------------------------------------------------------------
    00396     struct Material: public Object
    00397     {
    00398       ref<Dae::Effect> mDaeEffect;
    00399     };
    00400     //-----------------------------------------------------------------------------
    00401   }
    00402 }
    00403
    00404 #endif

Visualization Library v2011.09.1162 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu Jan 26 2012 00:43:40.
Permission is granted to use this page to write and publish articles regarding Visualization Library.