root/OpenSceneGraph/trunk/src/osgPlugins/dae/domSourceReader.h @ 13041

Revision 13041, 4.4 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * Copyright 2006 Sony Computer Entertainment Inc.
3 *
4 * Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
5 * file except in compliance with the License. You may obtain a copy of the License at:
6 * http://research.scea.com/scea_shared_source_license.html
7 *
8 * Unless required by applicable law or agreed to in writing, software distributed under the License
9 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10 * implied. See the License for the specific language governing permissions and limitations under the
11 * License.
12 */
13
14#ifndef _DOM_SRC_CONV_H_
15#define _DOM_SRC_CONV_H_
16
17#include <osg/Array>
18#include <osg/Notify>
19
20class domSource;
21
22namespace osgDAE {
23
24/**
25@class domSourceReader
26Converts a source to an OSG vector array as soon as you call a getter, so calling simple precision version \c getArray<osg::Vec3Array>() will force getArray<osg::Vec3dArray>() to return NULL, and vice-versa (for a Vec3 array in the example).
27@brief Convert sources from DAE to OSG arrays
28*/
29class domSourceReader
30{
31public:
32    enum ArrayType {None,Float,Vec2,Vec3,Vec4,Vec2d,Vec3d,Vec4d,Matrix,String};
33
34public:
35
36    domSourceReader();
37    explicit domSourceReader( domSource *src );
38
39    ArrayType getArrayType(bool enableDoublePrecision) const { if (srcInit) const_cast<domSourceReader*>(this)->convert(enableDoublePrecision); return m_array_type; };
40
41    template <class OsgArrayType>
42    inline OsgArrayType * getArray();
43
44    int getCount(bool enableDoublePrecision) const { if (srcInit) const_cast<domSourceReader*>(this)->convert(enableDoublePrecision); return m_count; };
45
46#define ASSERT_TYPE(type)       if (type!=m_array_type) { OSG_WARN<<"Wrong array type requested ("#type" != "<<m_array_type<<")"<<std::endl; }
47
48    float getFloat( int index ) { ASSERT_TYPE( Float ); return (*m_float_array)[index]; };
49
50    osg::Vec2 const& getVec2( int index ) { ASSERT_TYPE( Vec2 ); return (*m_vec2_array)[index]; };
51
52    osg::Vec3 const& getVec3( int index ) { ASSERT_TYPE( Vec3 ); return (*m_vec3_array)[index]; };
53
54    osg::Vec4 const& getVec4( int index ) { ASSERT_TYPE( Vec4 ); return (*m_vec4_array)[index]; };
55
56    osg::Vec2d const& getVec2d( int index ) { ASSERT_TYPE( Vec2d ); return (*m_vec2d_array)[index]; };
57
58    osg::Vec3d const& getVec3d( int index ) { ASSERT_TYPE( Vec3d ); return (*m_vec3d_array)[index]; };
59
60    osg::Vec4d const& getVec4d( int index ) { ASSERT_TYPE( Vec4d ); return (*m_vec4d_array)[index]; };
61
62    osg::Matrixf const& getMatrix( int index ) { ASSERT_TYPE( Matrix ); return (*m_matrix_array)[index]; };
63
64#undef ASSERT_TYPE
65
66protected:
67
68    ArrayType m_array_type;
69    int m_count;
70
71    domSource * srcInit;        ///< Source used before initialization by convert(), NULL otherwise
72    //bool initialized;
73    void convert(bool doublePrecision);
74
75    osg::ref_ptr<osg::FloatArray> m_float_array;
76    osg::ref_ptr<osg::Vec2Array> m_vec2_array;
77    osg::ref_ptr<osg::Vec3Array> m_vec3_array;
78    osg::ref_ptr<osg::Vec4Array> m_vec4_array;
79    osg::ref_ptr<osg::Vec2dArray> m_vec2d_array;
80    osg::ref_ptr<osg::Vec3dArray> m_vec3d_array;
81    osg::ref_ptr<osg::Vec4dArray> m_vec4d_array;
82    osg::ref_ptr<osg::MatrixfArray> m_matrix_array;
83};
84
85template <>
86inline osg::FloatArray* domSourceReader::getArray<osg::FloatArray>()
87{
88    if (srcInit)
89        convert(false);
90    return m_float_array.get();
91}
92
93template <>
94inline osg::Vec2Array* domSourceReader::getArray<osg::Vec2Array>()
95{
96    if (srcInit)
97        convert(false);
98    return m_vec2_array.get();
99}
100
101template <>
102inline osg::Vec3Array* domSourceReader::getArray<osg::Vec3Array>()
103{
104    if (srcInit)
105        convert(false);
106    return m_vec3_array.get();
107}
108
109template <>
110inline osg::Vec4Array* domSourceReader::getArray<osg::Vec4Array>()
111{
112    if (srcInit)
113        convert(false);
114    return m_vec4_array.get();
115}
116
117template <>
118inline osg::Vec2dArray* domSourceReader::getArray<osg::Vec2dArray>()
119{
120    if (srcInit)
121        convert(true);
122    return m_vec2d_array.get();
123}
124
125template <>
126inline osg::Vec3dArray* domSourceReader::getArray<osg::Vec3dArray>()
127{
128    if (srcInit)
129        convert(true);
130    return m_vec3d_array.get();
131}
132
133template <>
134inline osg::Vec4dArray* domSourceReader::getArray<osg::Vec4dArray>()
135{
136    if (srcInit)
137        convert(true);
138    return m_vec4d_array.get();
139}
140
141template <>
142inline osg::MatrixfArray* domSourceReader::getArray<osg::MatrixfArray>()
143{
144    if (srcInit)
145        convert(false);
146    return m_matrix_array.get();
147}
148
149}
150
151#endif
Note: See TracBrowser for help on using the browser.