2010-03-13 22:10:45 +01:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest Shared Library (www.glest.org)
|
|
|
|
//
|
2010-09-07 07:25:40 +02:00
|
|
|
// Copyright (C) 2001-2008 Martio Figueroa
|
2010-03-13 22:10:45 +01:00
|
|
|
//
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#ifndef _SHARED_GRAPHICS_MODEL_H_
|
|
|
|
#define _SHARED_GRAPHICS_MODEL_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include "types.h"
|
|
|
|
#include "pixmap.h"
|
|
|
|
#include "texture_manager.h"
|
|
|
|
#include "texture.h"
|
|
|
|
#include "model_header.h"
|
2010-09-07 07:25:40 +02:00
|
|
|
#include "leak_dumper.h"
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::map;
|
|
|
|
using std::pair;
|
|
|
|
|
2011-02-04 02:24:26 +01:00
|
|
|
namespace Shared { namespace Graphics {
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
class Model;
|
|
|
|
class Mesh;
|
|
|
|
class ShadowVolumeData;
|
|
|
|
class InterpolationData;
|
|
|
|
class TextureManager;
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Mesh
|
|
|
|
//
|
|
|
|
// Part of a 3D model
|
|
|
|
// =====================================================
|
|
|
|
|
2011-01-18 08:52:06 +01:00
|
|
|
class Mesh {
|
2010-03-13 22:10:45 +01:00
|
|
|
private:
|
|
|
|
//mesh data
|
|
|
|
Texture2D *textures[meshTextureCount];
|
2010-10-28 02:51:25 +02:00
|
|
|
bool texturesOwned[meshTextureCount];
|
2010-03-13 22:10:45 +01:00
|
|
|
string texturePaths[meshTextureCount];
|
|
|
|
|
2011-03-12 22:29:37 +01:00
|
|
|
string name;
|
2010-03-13 22:10:45 +01:00
|
|
|
//vertex data counts
|
|
|
|
uint32 frameCount;
|
|
|
|
uint32 vertexCount;
|
|
|
|
uint32 indexCount;
|
2011-01-18 08:52:06 +01:00
|
|
|
uint32 texCoordFrameCount;
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
//vertex data
|
|
|
|
Vec3f *vertices;
|
|
|
|
Vec3f *normals;
|
|
|
|
Vec2f *texCoords;
|
|
|
|
Vec3f *tangents;
|
|
|
|
uint32 *indices;
|
|
|
|
|
|
|
|
//material data
|
|
|
|
Vec3f diffuseColor;
|
|
|
|
Vec3f specularColor;
|
|
|
|
float specularPower;
|
|
|
|
float opacity;
|
|
|
|
|
|
|
|
//properties
|
|
|
|
bool twoSided;
|
|
|
|
bool customColor;
|
|
|
|
|
2011-03-12 22:29:37 +01:00
|
|
|
uint32 textureFlags;
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
InterpolationData *interpolationData;
|
2010-10-28 02:51:25 +02:00
|
|
|
TextureManager *textureManager;
|
2010-03-13 22:10:45 +01:00
|
|
|
|
2011-01-18 08:52:06 +01:00
|
|
|
// Vertex Buffer Object Names
|
2011-01-19 00:56:30 +01:00
|
|
|
bool hasBuiltVBOs;
|
|
|
|
uint32 m_nVBOVertices; // Vertex VBO Name
|
|
|
|
uint32 m_nVBOTexCoords; // Texture Coordinate VBO Name
|
|
|
|
uint32 m_nVBONormals; // Normal VBO Name
|
|
|
|
uint32 m_nVBOIndexes; // Indexes VBO Name
|
2011-01-18 08:52:06 +01:00
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
public:
|
|
|
|
//init & end
|
|
|
|
Mesh();
|
|
|
|
~Mesh();
|
|
|
|
void init();
|
|
|
|
void end();
|
|
|
|
|
|
|
|
//maps
|
|
|
|
const Texture2D *getTexture(int i) const {return textures[i];}
|
|
|
|
|
|
|
|
//counts
|
|
|
|
uint32 getFrameCount() const {return frameCount;}
|
|
|
|
uint32 getVertexCount() const {return vertexCount;}
|
|
|
|
uint32 getIndexCount() const {return indexCount;}
|
|
|
|
uint32 getTriangleCount() const;
|
|
|
|
|
2011-01-19 00:56:30 +01:00
|
|
|
uint32 getVBOVertices() const { return m_nVBOVertices;}
|
2011-01-18 08:52:06 +01:00
|
|
|
uint32 getVBOTexCoords() const { return m_nVBOTexCoords;}
|
2011-01-19 00:56:30 +01:00
|
|
|
uint32 getVBONormals() const { return m_nVBONormals;}
|
|
|
|
uint32 getVBOIndexes() const { return m_nVBOIndexes;}
|
|
|
|
bool hasBuiltVBOEntities() const { return hasBuiltVBOs;}
|
2011-01-18 08:52:06 +01:00
|
|
|
void BuildVBOs();
|
2011-01-19 00:56:30 +01:00
|
|
|
void ReleaseVBOs();
|
2011-01-18 08:52:06 +01:00
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
//data
|
|
|
|
const Vec3f *getVertices() const {return vertices;}
|
|
|
|
const Vec3f *getNormals() const {return normals;}
|
|
|
|
const Vec2f *getTexCoords() const {return texCoords;}
|
|
|
|
const Vec3f *getTangents() const {return tangents;}
|
|
|
|
const uint32 *getIndices() const {return indices;}
|
|
|
|
|
|
|
|
//material
|
|
|
|
const Vec3f &getDiffuseColor() const {return diffuseColor;}
|
|
|
|
const Vec3f &getSpecularColor() const {return specularColor;}
|
|
|
|
float getSpecularPower() const {return specularPower;}
|
|
|
|
float getOpacity() const {return opacity;}
|
|
|
|
|
|
|
|
//properties
|
|
|
|
bool getTwoSided() const {return twoSided;}
|
|
|
|
bool getCustomTexture() const {return customColor;}
|
|
|
|
|
|
|
|
//external data
|
|
|
|
const InterpolationData *getInterpolationData() const {return interpolationData;}
|
|
|
|
|
|
|
|
//interpolation
|
|
|
|
void buildInterpolationData();
|
2011-01-18 08:52:06 +01:00
|
|
|
void updateInterpolationData(float t, bool cycle);
|
|
|
|
void updateInterpolationVertices(float t, bool cycle);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
2011-03-13 09:23:43 +01:00
|
|
|
Texture2D *loadMeshTexture(int meshIndex, int textureIndex, TextureManager *textureManager, string textureFile,
|
2011-03-12 22:29:37 +01:00
|
|
|
int textureChannelCount, bool &textureOwned,
|
2011-05-06 09:47:31 +02:00
|
|
|
bool deletePixMapAfterLoad, std::map<string,vector<pair<string, string> > > *loadedFileList=NULL,
|
2011-05-05 21:21:50 +02:00
|
|
|
string sourceLoader="");
|
2011-03-12 22:29:37 +01:00
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
//load
|
2011-03-15 16:30:28 +01:00
|
|
|
void loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
|
2011-05-06 09:47:31 +02:00
|
|
|
bool deletePixMapAfterLoad,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL,string sourceLoader="");
|
2011-03-15 16:30:28 +01:00
|
|
|
void loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
|
2011-05-06 09:47:31 +02:00
|
|
|
bool deletePixMapAfterLoad,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL,string sourceLoader="");
|
|
|
|
void load(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL,string sourceLoader="");
|
2011-03-13 09:23:43 +01:00
|
|
|
void save(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
|
2011-03-13 10:57:04 +01:00
|
|
|
string convertTextureToFormat, std::map<string,int> &textureDeleteList,
|
|
|
|
bool keepsmallest);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
2010-10-28 02:51:25 +02:00
|
|
|
void deletePixels();
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
private:
|
2011-03-13 09:23:43 +01:00
|
|
|
string findAlternateTexture(vector<string> conversionList, string textureFile);
|
2010-03-13 22:10:45 +01:00
|
|
|
void computeTangents();
|
|
|
|
};
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Model
|
|
|
|
//
|
|
|
|
// 3D Model, than can be loaded from a g3d file
|
|
|
|
// =====================================================
|
|
|
|
|
2011-01-18 08:52:06 +01:00
|
|
|
class Model {
|
2010-03-13 22:10:45 +01:00
|
|
|
private:
|
|
|
|
TextureManager *textureManager;
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint8 fileVersion;
|
|
|
|
uint32 meshCount;
|
|
|
|
Mesh *meshes;
|
|
|
|
|
2011-01-18 08:52:06 +01:00
|
|
|
float lastTData;
|
|
|
|
bool lastCycleData;
|
|
|
|
float lastTVertex;
|
|
|
|
bool lastCycleVertex;
|
|
|
|
|
2011-01-19 00:56:30 +01:00
|
|
|
string fileName;
|
2011-05-05 21:21:50 +02:00
|
|
|
string sourceLoader;
|
2011-01-18 08:52:06 +01:00
|
|
|
|
2011-12-02 23:04:02 +01:00
|
|
|
//static bool masterserverMode;
|
2011-09-26 07:29:52 +02:00
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
public:
|
|
|
|
//constructor & destructor
|
|
|
|
Model();
|
|
|
|
virtual ~Model();
|
|
|
|
virtual void init()= 0;
|
|
|
|
virtual void end()= 0;
|
|
|
|
|
2011-12-02 23:04:02 +01:00
|
|
|
//static void setMasterserverMode(bool value) { masterserverMode=value; }
|
2011-09-26 07:29:52 +02:00
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
//data
|
2011-01-18 08:52:06 +01:00
|
|
|
void updateInterpolationData(float t, bool cycle);
|
|
|
|
void updateInterpolationVertices(float t, bool cycle);
|
2010-03-13 22:10:45 +01:00
|
|
|
void buildShadowVolumeData() const;
|
|
|
|
|
|
|
|
//get
|
|
|
|
uint8 getFileVersion() const {return fileVersion;}
|
|
|
|
uint32 getMeshCount() const {return meshCount;}
|
|
|
|
const Mesh *getMesh(int i) const {return &meshes[i];}
|
2011-01-19 00:56:30 +01:00
|
|
|
Mesh *getMeshPtr(int i) const {return &meshes[i];}
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
uint32 getTriangleCount() const;
|
|
|
|
uint32 getVertexCount() const;
|
|
|
|
|
|
|
|
//io
|
2011-05-06 09:47:31 +02:00
|
|
|
void load(const string &path,bool deletePixMapAfterLoad=false,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, string *sourceLoader=NULL);
|
2011-03-13 10:57:04 +01:00
|
|
|
void save(const string &path, string convertTextureToFormat,bool keepsmallest);
|
2011-05-06 09:47:31 +02:00
|
|
|
void loadG3d(const string &path,bool deletePixMapAfterLoad=false,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, string sourceLoader="");
|
2011-03-13 10:57:04 +01:00
|
|
|
void saveG3d(const string &path, string convertTextureToFormat,bool keepsmallest);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}
|
2010-10-28 02:51:25 +02:00
|
|
|
void deletePixels();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
2011-01-19 00:56:30 +01:00
|
|
|
string getFileName() const { return fileName; }
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
private:
|
|
|
|
void buildInterpolationData() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
#endif
|