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

# src/obj_loader.impl.hpp

Go to the documentation of this file.

    00001
    00010 template<typename T>
    00011 void OBJ_Mesh::GetMeshGeometryUnindexed(T* mesh_geometry, T* mesh_normals, T* mesh_texture, T scale) const {
    00012     int index = 0;      //index of the current triangle
    00013     for(std::vector<Face>::const_iterator iter = m_faces.begin(); iter != m_faces.end(); ++iter, ++index) {
    00014         if(mesh_geometry) {
    00015             mesh_geometry[(index*9)]     = static_cast<T>( m_geometry[ (*iter).vert1 * 3 ])    * scale;
    00016             mesh_geometry[(index*9) + 1] = static_cast<T>( m_geometry[ (*iter).vert1 * 3 + 1]) * scale;
    00017             mesh_geometry[(index*9) + 2] = static_cast<T>( m_geometry[ (*iter).vert1 * 3 + 2]) * scale;
    00018             mesh_geometry[(index*9) + 3] = static_cast<T>( m_geometry[ (*iter).vert2 * 3 ])    * scale;
    00019             mesh_geometry[(index*9) + 4] = static_cast<T>( m_geometry[ (*iter).vert2 * 3 + 1]) * scale;
    00020             mesh_geometry[(index*9) + 5] = static_cast<T>( m_geometry[ (*iter).vert2 * 3 + 2]) * scale;
    00021             mesh_geometry[(index*9) + 6] = static_cast<T>( m_geometry[ (*iter).vert3 * 3 ])    * scale;
    00022             mesh_geometry[(index*9) + 7] = static_cast<T>( m_geometry[ (*iter).vert3 * 3 + 1]) * scale;
    00023             mesh_geometry[(index*9) + 8] = static_cast<T>( m_geometry[ (*iter).vert3 * 3 + 2]) * scale;
    00024         }
    00025         if(mesh_normals) {
    00026             mesh_normals[(index*9)]      = static_cast<T>( m_normals[ (*iter).normal1 * 3 ] );
    00027             mesh_normals[(index*9) + 1]  = static_cast<T>( m_normals[ (*iter).normal1 * 3 + 1] );
    00028             mesh_normals[(index*9) + 2]  = static_cast<T>( m_normals[ (*iter).normal1 * 3 + 2] );
    00029             mesh_normals[(index*9) + 3]  = static_cast<T>( m_normals[ (*iter).normal2 * 3] );
    00030             mesh_normals[(index*9) + 4]  = static_cast<T>( m_normals[ (*iter).normal2 * 3 + 1] );
    00031             mesh_normals[(index*9) + 5]  = static_cast<T>( m_normals[ (*iter).normal2 * 3 + 2] );
    00032             mesh_normals[(index*9) + 6]  = static_cast<T>( m_normals[ (*iter).normal3 * 3] );
    00033             mesh_normals[(index*9) + 7]  = static_cast<T>( m_normals[ (*iter).normal3 * 3 + 1] );
    00034             mesh_normals[(index*9) + 8]  = static_cast<T>( m_normals[ (*iter).normal3 * 3 + 2] );
    00035         }
    00036         if(mesh_texture) {
    00037             mesh_texture[(index*9)]      = static_cast<T>( m_texcoords[ (*iter).texture1 * 3 ] );
    00038             mesh_texture[(index*9) + 1]  = static_cast<T>( m_texcoords[ (*iter).texture1 * 3 + 1] );
    00039             mesh_texture[(index*9) + 2]  = static_cast<T>( m_texcoords[ (*iter).texture1 * 3 + 2] );
    00040             mesh_texture[(index*9) + 3]  = static_cast<T>( m_texcoords[ (*iter).texture2 * 3] );
    00041             mesh_texture[(index*9) + 4]  = static_cast<T>( m_texcoords[ (*iter).texture2 * 3 + 1] );
    00042             mesh_texture[(index*9) + 5]  = static_cast<T>( m_texcoords[ (*iter).texture2 * 3 + 2] );
    00043             mesh_texture[(index*9) + 6]  = static_cast<T>( m_texcoords[ (*iter).texture3 * 3] );
    00044             mesh_texture[(index*9) + 7]  = static_cast<T>( m_texcoords[ (*iter).texture3 * 3 + 1] );
    00045             mesh_texture[(index*9) + 8]  = static_cast<T>( m_texcoords[ (*iter).texture3 * 3 + 2] );
    00046         }
    00047     }
    00048 }
    00049
    00050 template<typename T>
    00051 void OBJ_Mesh::GetMeshGeometry(T* mesh_geometry, T* mesh_normals, T* mesh_texture, OBJ_Mesh::Face* mesh_faces, T scale) const {
    00052     int i = 0;
    00053     if(mesh_geometry) {
    00054         for(std::vector<double>::const_iterator iter = m_geometry.begin(); iter != m_geometry.end(); ++iter, ++i) {
    00055             mesh_geometry[i] = static_cast<T>( (*iter) * scale );
    00056         }
    00057     }
    00058     if(mesh_normals) {
    00059         for(std::vector<double>::const_iterator iter = m_normals.begin(); iter != m_normals.end(); ++iter, ++i) {
    00060             mesh_normals[i] = static_cast<T>( *iter );
    00061         }
    00062     }
    00063     if(mesh_texture) {
    00064         for(std::vector<double>::const_iterator iter = m_texcoords.begin(); iter != m_texcoords.end(); ++iter, ++i) {
    00065             mesh_texture[i] = static_cast<T>( *iter );
    00066         }
    00067     }
    00068     if(mesh_faces) {
    00069         for(std::vector<Face>::const_iterator iter = m_faces.begin(); iter != m_faces.end(); ++iter, ++i) {
    00070             mesh_faces[i].vert1           = (*iter).vert1;
    00071             mesh_faces[i].vert2           = (*iter).vert2;
    00072             mesh_faces[i].vert3           = (*iter).vert3;
    00073             mesh_faces[i].normal1         = (*iter).normal1;
    00074             mesh_faces[i].normal2         = (*iter).normal2;
    00075             mesh_faces[i].normal3         = (*iter).normal3;
    00076             mesh_faces[i].texture1        = (*iter).texture1;
    00077             mesh_faces[i].texture2        = (*iter).texture2;
    00078             mesh_faces[i].texture3        = (*iter).texture3;
    00079             mesh_faces[i].smoothing_group = (*iter).smoothing_group;
    00080         }
    00081     }
    00082 }
    00085 template<typename T_1, typename T_2>
    00086 inline void FillVector(std::vector<T_1>* dest, T_2 const* data, int n_data) {
    00087     dest->clear();
    00088     for(int i=0; i<n_data; i++) {
    00089         dest->push_back( static_cast<T_1>(data[i]) );
    00090     }
    00091 }
    00094 template<typename T_1, typename T_2>
    00095 inline void AppendToVector(std::vector<T_1>* dest, T_2 const* data, int n_data) {
    00096     for(int i=0; i<n_data; i++) {
    00097         dest->push_back( static_cast<T_1>(data[i]) );
    00098     }
    00099 }
    00100
    00101 template<typename T>
    00102 void OBJ_Mesh::SetGeometry(T const* data, int n_data) {
    00103     FillVector(&m_geometry, data, n_data);
    00104 }
    00105 template<typename T>
    00106 void OBJ_Mesh::AddGeometry(T const* data, int n_data) {
    00107     AppendToVector(&m_geometry, data, n_data);
    00108 }
    00109 template<typename T>
    00110 void OBJ_Mesh::SetNormals(T const* data, int n_data) {
    00111     FillVector(&m_normals, data, n_data);
    00112 }
    00113 template<typename T>
    00114 void OBJ_Mesh::AddNormals(T const* data, int n_data) {
    00115     AppendToVector(&m_normals, data, n_data);
    00116 }
    00117 template<typename T>
    00118 void OBJ_Mesh::SetTextureData(T const* data, int n_data) {
    00119     FillVector(&m_texcoords, data, n_data);
    00120 }
    00121 template<typename T>
    00122 void OBJ_Mesh::AddTextureData(T const* data, int n_data) {
    00123     AppendToVector(&m_texcoords, data, n_data);
    00124 }