⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mesh.h

📁 liu7788414
💻 H
字号:
#ifndef CMESH_H
#define CMESH_H

#include "Matrix.h"
#include "graphics3d.h"

//class CEngine;

//Bounding box structure. 
struct BBox
{
	Vertex vtmax;  //the maximum vertex of box
	Vertex vtmin;
};

//Submesh is aggregation of faces. It is the sub part of a mesh, which only have one material attached. 
struct Submesh 
{
	int m_facenum;                   //face count in this submesh
	Face *m_pfaceIndics;	           //faces array pointer.
	Point3d * m_pNormals;            //normal of every face
	Material m_material;             //material used for this submesh
	BBox *m_bbox;                    //bounding boxes of this submesh, if the mesh is static one, it
																	 //only have one bbox, else it will hold a array of bboxes 
																	 //for every frame.
};


//0x80;// if have the texture
//0x20;// we have the normal	
//0x10;// we have the animation	
//0x01;// we USE the VERTEX animation
//0x02;// we have the Maximam TWO BONES for one vertex to do animation.
//0x04;// the model use 1/16 cm as unit.
const int FLAG_HAVETEXTURE = 0x80;
const int FLAG_HAVEVERTEXNORMAL = 0x20;
const int FLAG_VERTEXANIMATION = 0x10;
const int FLAG_MAXTWOBONES = 0x02;
const int FLAG_UNITDIV16 = 0x04;


//The structure used to store the bones transformations every frame. It also has the vertexes' info
//attched to it. But that info only valid for maximum one bone per vertex condition.
//If you use "One bone" option in gmod file export dialog, it would be used.
struct Bone
{
	int vertexCount;               //vertex count
	short *vertexIndics;           //vertics array
	CMatrix44 *transforms;         //transformation array for per frame
};

//When max bone count per vertex changed to 2, 
//we use two structures to instore bones information, which may save some calculation
//time for applications. 

//Structure1: used to instore the vertexes only attached to one bone
struct OneBoneVertex
{
	short vertexIndex;            //index of the vertex in mesh vertics array
	char  boneIndex;              //index of the bone in mesh bones array
};

//Structure1: used to instore the vertexes only attached to two bones
struct TwoBoneVertex
{	
	short vertexIndex;         //index of the vertex in mesh vertics array
	char boneIndex1;           //index of the first bone in mesh bones array
	unsigned char boneWeight1; //weigth of bone1, 255 reprasent 100% 
	char boneIndex2;           //index of the second bone in mesh bones array
	unsigned char boneWeight2; //weigth of bone2, 255 reprasent 100%
};


//mesh class: It implement static and animated mesh's loading, drawing and animation. 
class CMesh
{

	//---------Animation data-------------
	OneBoneVertex *m_oneBoneVertex;
	TwoBoneVertex *m_twoBoneVertex;
	int m_oneBVCount;	
	int m_twoBVCount;

	Bone *m_pBones;               //bones data
	int m_boneNum;                //bone count used in this mesh
	int m_frameCount;             //frame count of this animation mesh. when mesh is static one, it should be 0.
	int m_iCurFrame;              //current frame. indicate the vertex info in m_pVertexRenderBuf is.

	//-------geometry data----------------

	Vertex *m_pvertexlist;	//array to instore all the vertics data of this mesh, 

  Texcoord * m_ptexcoordlist; //array to instore the texture coordination data
	int m_texcoordnum;          //count of texture coordination

	Vertex *m_pVertexRenderBuf;  //Buffer use to instore vertex render data. It need for animation mesh.

	int m_submeshCount;          //Submeshs' count

public:
	//Get the first submesh's bonding box center of the frame, only valid for animation mesh with one submesh
	void GetBBCenter(int frame, Vertex &center/*out*/);
	//Generate face normal. Should be called when the mesh's vertics data updated				 
	void GenerateFaceNormal();
	//Set Animation mesh's current frame. It recalculated the vertics data and face normal data as need.
	void SetCurrentFrame(int frameid);
	
	~CMesh();
	CMesh();

	//return animation mesh's frame count
	int getFrameCount(){ return m_frameCount;}
	
	//Load mesh data and related textures to heap from descripted file in the zipped resource file res.pak
	//pG3d:     pointer of CGraphics3D Object.
	//filename: the file name of mesh. The string may have ".GMOD" extension.
	//return:   if true then load successful.
	bool LoadMesh(CGraphics3D *pG3d, const char* filename);

	//reset the mesh data and pointers which hold the block of memory is used in self memory.
	//So it DOES NOT really release memory. Also, the textures used by this mesh are not release 
	//here. 
	void Release();

	//Render the whole mesh under the current condition descripted in pG3d. 
	void DrawMesh(CGraphics3D *pG3d); //call drawSubmesh() for every submesh
	void DrawTexturedMesh(CGraphics3D *pG3d, int texid);

	int m_vertexnum;				//count of vertics
	Submesh *m_pSubMeshs;        //Submeshs' array
	
	
private:
	CGraphics3D *m_pG3d;

	//mesh file flag
	//FILE FLAG's values
	//0x80;// if have the texture
	//0x20;// we have the normal	
	//0x10;// we have the animation	
	//0x01;// we USE the VERTEX animation
	//0x02;// we have the Maximam TWO BONES for one vertex to do animation.
	int m_fileflag;	

	//Render the specified submesh 
	void DrawSubMesh(int submeshIndex);

};


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -