00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00014 #include <map>
00015 #include "nvsg/nvsgapi.h"
00016 #include "nvmath/Mat44f.h"
00017
00018 namespace nvsg
00019 {
00020 class GeoNode;
00021 class Scene;
00022 class StateSet;
00023 class TextureAttributeItem;
00024 class Transform;
00025 }
00026
00027
00028
00029 #if ! defined( DOXYGEN_IGNORE )
00030
00031 class NVB2Animation
00032 {
00033 public:
00034 float frequency;
00035 std::vector<nvmath::Quatf> rotations;
00036 std::vector<nvmath::Vec3f> positions;
00037 std::vector<nvmath::Vec3f> scales;
00038 };
00039
00040 class NVB2Attribute
00041 {
00042 public:
00043 ~NVB2Attribute();
00044
00045 public:
00046 std::map<std::string,NVB2Attribute*> entries;
00047 unsigned int arraySize;
00048 unsigned int arrayType;
00049 std::vector<char> array;
00050 unsigned int udWord;
00051 };
00052
00053 class NVB2Material
00054 {
00055 public:
00056 std::string name;
00057 std::vector<unsigned int> textureIdxs;
00058 std::vector<unsigned int> textureChannels;
00059 nvmath::Vec4f diffuse;
00060 nvmath::Vec4f specular;
00061 float shininess;
00062 nvmath::Vec4f ambient;
00063 nvmath::Vec4f emission;
00064 float transparency;
00065 bool fog;
00066 nvmath::Vec4f fogColor;
00067 NVB2Attribute attribute;
00068
00069 const nvsg::StateSet * stateSet;
00070 };
00071
00072 class NVB2TexCoordSet
00073 {
00074 public:
00075 unsigned int texDim;
00076 std::vector<float> texCoords;
00077 std::vector<nvmath::Vec3f> binormals;
00078 std::vector<nvmath::Vec3f> tangents;
00079 };
00080
00081 class NVB2Mesh
00082 {
00083 public:
00084 unsigned int materialID;
00085 std::vector<nvmath::Vec3f> vertices;
00086 std::vector<nvmath::Vec3f> normals;
00087 std::vector<nvmath::Vec4f> colors;
00088 std::vector<nvmath::Vec4f> weights;
00089 std::vector<unsigned int> boneIdxs;
00090 std::vector<NVB2TexCoordSet> texCoordSets;
00091 std::vector<unsigned int> faceIdxs;
00092 NVB2Attribute attribute;
00093 nvmath::Vec3f aabbMin;
00094 nvmath::Vec3f aabbMax;
00095 };
00096
00097 class NVB2Texture
00098 {
00099 public:
00100 unsigned int texType;
00101 std::string fileName;
00102 nvmath::Mat44f xform;
00103 const nvsg::TextureAttributeItem * textureAttributeItem;
00104 };
00105
00106 class NVB2Node
00107 {
00108 public:
00109 NVB2Node();
00110 virtual ~NVB2Node();
00111
00112 public:
00113 std::string name;
00114 nvmath::Mat44f xform;
00115 std::vector<unsigned int> children;
00116 unsigned int parent;
00117 unsigned int target;
00118 NVB2Animation animation;
00119 NVB2Attribute attribute;
00120
00121 nvmath::Quatf orientation;
00122 nvmath::Vec3f position;
00123 const nvsg::Transform * transform;
00124 };
00125
00126 class NVB2Camera : public NVB2Node
00127 {
00128 public:
00129 float fieldOfView;
00130 float focalLength;
00131 };
00132
00133 class NVB2Light : public NVB2Node
00134 {
00135 public:
00136 nvmath::Vec4f color;
00137 nvmath::Vec4f specular;
00138 nvmath::Vec4f ambient;
00139 unsigned int lightType;
00140 float specularExp;
00141 nvmath::Vec3f direction;
00142 float range;
00143 float attConst;
00144 float attLinear;
00145 float attQuadratic;
00146 float falloff;
00147 float theta;
00148 float phi;
00149 };
00150
00151 class NVB2Model : public NVB2Node
00152 {
00153 public:
00154 std::vector<NVB2Mesh> meshes;
00155 nvmath::Vec3f aabbMin;
00156 nvmath::Vec3f aabbMax;
00157 };
00158
00159 class NVNVB2
00160 {
00161 public:
00162 NVNVB2();
00163
00164 public:
00165 const nvsg::Scene * load( const std::string& filename, const std::vector<std::string> &searchPaths );
00166
00167 private:
00168 void interpretAttribute( NVB2Attribute &attribute );
00169 void interpretCamera( NVB2Camera *camera );
00170 void interpretLight( NVB2Light *light );
00171 void interpretMaterials( void );
00172 void interpretMesh( NVB2Mesh &mesh, nvsg::GeoNode *geoNode );
00173 void interpretModel( NVB2Model *node );
00174 void interpretNode( NVB2Node *node );
00175 void interpretNodes( void );
00176 void interpretTextures( void );
00177 void interpretTransform( NVB2Node *node );
00178 void loadAnimation( NVB2Animation &animation );
00179 void loadAttribute( NVB2Attribute &attribute );
00180 void loadCamera( NVB2Camera *camera );
00181 void loadLight( NVB2Light *light );
00182 unsigned int loadMaterial( NVB2Material &material );
00183 void loadMesh( NVB2Mesh &mesh );
00184 void loadModel( NVB2Model *node );
00185 void loadNode( NVB2Node *node );
00186 void loadScene( void );
00187 void loadTexCoordSet( NVB2TexCoordSet &texCoordSet );
00188 void loadTexture( NVB2Texture &texture );
00189
00190 private:
00191 FILE * m_fh;
00192 std::vector<NVB2Node*> m_nodes;
00193 std::vector<NVB2Material> m_materials;
00194 const nvsg::Scene * m_scene;
00195 std::vector<std::string> m_searchPaths;
00196 std::vector<NVB2Texture> m_textures;
00197 };
00198
00199 typedef enum
00200 {
00201 LT_ANONYMOUS,
00202 LT_POINT,
00203 LT_DIRECTIONAL,
00204 LT_SPOT
00205 } NVB2LightType;
00206
00207 typedef enum
00208 {
00209 NT_ANONYMOUS = 0x00000000,
00210 NT_GEOMETRY = 0x00000001,
00211 NT_LIGHT = 0x00000002,
00212 NT_CAMERA = 0x00000003
00213 } NVB2NodeType;
00214
00215 typedef enum
00216 {
00217 NVB2TT_CUSTOM = 0x00000000,
00218 NVB2TT_AMBIENT = 0x00000001,
00219 NVB2TT_DIFFUSE = 0x00000002,
00220 NVB2TT_SPECULAR = 0x00000003,
00221 NVB2TT_SPECULAR_POWER = 0x00000004,
00222 NVB2TT_GLOSS = 0x00000005,
00223 NVB2TT_SELF_ILLUMATION = 0x00000006,
00224 NVB2TT_BUMP = 0x00000007,
00225 NVB2TT_NORMAL = 0x00000008,
00226 NVB2TT_OPACITY = 0x00000009,
00227 NVB2TT_REFLECTION = 0x0000000A,
00228 NVB2TT_REFRACTION = 0x0000000B,
00229 NVB2TT_CUBE_MAP = 0x0000000C
00230 } NVB2TexType;
00231
00232 enum
00233 {
00234 NV_FLOAT = 0x00000001,
00235 NV_CHAR = 0x00000002,
00236 NV_UNSIGNED_CHAR = 0x00000004,
00237 NV_UNSIGNED_INT = 0x00000008,
00238 NV_INT = 0x00000010,
00239 NV_SHORT = 0x00000040,
00240
00241 NV_ARRAY = 0x00010000,
00242 NV_FLOAT_ARRAY = 0x00010001,
00243 NV_CHAR_ARRAY = 0x00010002,
00244 NV_UNSIGNED_CHAR_ARRAY = 0x00010004,
00245 NV_UNSIGNED_INT_ARRAY = 0x00010008,
00246 NV_INT_ARRAY = 0x00010010,
00247 NV_ATTRIBUTE_ARRAY = 0x00010020,
00248 NV_SHORT_ARRAY = 0x00010040,
00249 NV_STRING = 0x00010002,
00250
00251 NV_UNASSIGNED = 0xFFFFFFFF
00252 };
00253
00254 #endif // DOXYGEN_IGNORE