/* * Copyright 2006 Sony Computer Entertainment Inc. * * Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this * file except in compliance with the License. You may obtain a copy of the License at: * http://research.scea.com/scea_shared_source_license.html * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. See the License for the specific language governing permissions and limitations under the * License. */ #ifndef _DOM_SRC_CONV_H_ #define _DOM_SRC_CONV_H_ #include #include class domSource; namespace osgDAE { /** @class domSourceReader Converts a source to an OSG vector array as soon as you call a getter, so calling simple precision version \c getArray() will force getArray() to return NULL, and vice-versa (for a Vec3 array in the example). @brief Convert sources from DAE to OSG arrays */ class domSourceReader { public: enum ArrayType {None,Float,Vec2,Vec3,Vec4,Vec2d,Vec3d,Vec4d,Matrix,String}; public: domSourceReader(); explicit domSourceReader( domSource *src ); ArrayType getArrayType(bool enableDoublePrecision) const { if (srcInit) const_cast(this)->convert(enableDoublePrecision); return m_array_type; }; template inline OsgArrayType * getArray(); int getCount(bool enableDoublePrecision) const { if (srcInit) const_cast(this)->convert(enableDoublePrecision); return m_count; }; #define ASSERT_TYPE(type) if (type!=m_array_type) { OSG_WARN<<"Wrong array type requested ("#type" != "< m_float_array; osg::ref_ptr m_vec2_array; osg::ref_ptr m_vec3_array; osg::ref_ptr m_vec4_array; osg::ref_ptr m_vec2d_array; osg::ref_ptr m_vec3d_array; osg::ref_ptr m_vec4d_array; osg::ref_ptr m_matrix_array; }; template <> inline osg::FloatArray* domSourceReader::getArray() { if (srcInit) convert(false); return m_float_array.get(); } template <> inline osg::Vec2Array* domSourceReader::getArray() { if (srcInit) convert(false); return m_vec2_array.get(); } template <> inline osg::Vec3Array* domSourceReader::getArray() { if (srcInit) convert(false); return m_vec3_array.get(); } template <> inline osg::Vec4Array* domSourceReader::getArray() { if (srcInit) convert(false); return m_vec4_array.get(); } template <> inline osg::Vec2dArray* domSourceReader::getArray() { if (srcInit) convert(true); return m_vec2d_array.get(); } template <> inline osg::Vec3dArray* domSourceReader::getArray() { if (srcInit) convert(true); return m_vec3d_array.get(); } template <> inline osg::Vec4dArray* domSourceReader::getArray() { if (srcInit) convert(true); return m_vec4d_array.get(); } template <> inline osg::MatrixfArray* domSourceReader::getArray() { if (srcInit) convert(false); return m_matrix_array.get(); } } #endif