kick
/Users/morten/Programmering/cpp/kick/src/kick/obj/obj_data.h
00001 //
00002 //  ObjData.h
00003 //  KickObjLoader
00004 //
00005 //  Created by morten on 8/31/13.
00006 //  Copyright (c) 2013 morten. All rights reserved.
00007 //
00008 
00009 
00010 #pragma once
00011 
00012 #include <memory>
00013 #include <iostream>
00014 #include <glm/glm.hpp>
00015 #include <vector>
00016 #include "kick/mesh/mesh_data.h"
00017 
00018 namespace kick {
00019     struct ObjVertex {
00020         int vertexPositionIdx;
00021         int textureIdx;
00022         int normalIdx;
00023     };
00024     
00025     enum class ObjIlluminationMode {
00026         Mode0 = 0, // Color on and Ambient off
00027         Mode1 = 1, // Color on and Ambient on
00028         Mode2 = 2, // Highlight on
00029         Mode3 = 3, // Reflection on and Ray trace on
00030         Mode4 = 4, // Transparency: Glass on, Reflection: Ray trace on
00031         Mode5 = 5, // Reflection: Fresnel on and Ray trace on
00032         Mode6 = 6, // Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
00033         Mode7 = 7, // Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
00034         Mode8 = 8, // Reflection on and Ray trace off
00035         Mode9 = 9, // Transparency: Glass on, Reflection: Ray trace off
00036         Mode10 = 10 // Casts shadows onto invisible surfaces
00037     };
00038     
00039     enum class ObjTextureMapType {
00040         Diffuse, // map_Kd
00041         Ambient, // map_Ka
00042         Specular, // map_Ks
00043         SpecularCoeficient, // map_Ns
00044         Transparancy, // map_d or map_Tr
00045         Bump, // map_bump or bump
00046         Displacement, // disp
00047         StencilDecal // decal
00048     };
00049     
00050     struct ObjTextureMap {
00051         std::string filename;
00052         ObjTextureMapType type;
00053     };
00054     
00055     struct ObjMaterial {
00056         std::string name;
00057         glm::vec3 ambientColor; // Ka
00058         glm::vec3 diffuseColor; // Kd
00059         glm::vec3 specularColor; // Ks
00060         float specularCoefficient; // Ns
00061         float transparent; // d or Tr
00062         std::vector<ObjIlluminationMode> illuminationModes;
00063         std::vector<ObjTextureMap> textureMaps;
00064     };
00065     
00066     struct ObjMaterialChange {
00067         int faceIndex;
00068         std::string name;
00069     };
00070     
00071     typedef std::vector<ObjVertex> ObjFace;
00072     
00073     struct ObjGroup {
00074         int faceIndex;
00075         std::string name;
00076     };
00077     
00078     struct SmoothGroup {
00079         int faceIndex;
00080         int smoothGroupIdx; // 0 means none
00081     };
00082     
00083     struct ObjData {
00084         std::string initialComment;
00085         std::vector<glm::vec4> vertexPositions;
00086         std::vector<glm::vec3> textureCoords;
00087         std::vector<glm::vec3> normals;
00088         std::vector<ObjFace> faces;
00089         std::vector<ObjGroup> namedObjects;
00090         std::vector<ObjGroup> polygonGroups;
00091         std::vector<SmoothGroup> smoothGroups;
00092         std::vector<ObjMaterialChange> materialChanges;
00093         std::vector<ObjMaterial> materials;
00094         
00096         bool verifyFaces();
00097         
00098         ObjMaterial*material(std::string name);
00099         
00100         std::vector<float> interleavedVertexData(bool includeTextureCoords = true, bool includeNormals = true, int vertexPositionSize = 3, int texCoordinateSize = 2);
00101 
00102         std::vector<unsigned int> indices();
00103 
00104         std::shared_ptr<MeshData> meshData();
00105     };
00106 
00107 }
 All Classes Functions Variables