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

📄 ms3dloader.h

📁 3D游戏展示程序
💻 H
字号:
//--------------------------------------------------
//  Desc: MS3D model Loader
//  Date: 2007.3.6 /update
//  Author: artsylee
//
//  Copyright (C) 2007 artsylee
//
//  Info: only support one texture & one material(2007_3_6)
//        Support Mulit-Texture, Mulit-Material, Mulit-Mesh(2007_3_8)
//		  改变纹理坐标转换以支持WOW模型导出(2007_3_8)
//		  只解释静态模型, 动画暂时不解释.
//  问题: 全屏切换时纹理消失.(估计是设备丢失时灯光问题)
//
//--------------------------------------------------

#ifndef _MS3DLOADER_
#define _MS3DLOADER_

#include <d3d9.h>
#include <d3dx9.h>
#include "StdHeader.h"
#include "BaseLoader.h"

#pragma pack(1)
// MS3D header
struct MS3DHeader
{
	char m_ID[10];
	int  m_version;
};

// Vertex information
struct MS3DVertex
{
	unsigned char m_flags;
	float m_vertex[3];
	char m_boneID;
	unsigned char m_refCount;
};

// Triangle information
struct MS3DTriangle
{
	unsigned short m_flags;
	unsigned short m_vertexIndices[3];
	float m_vertexNormals[3][3];
	float m_u[3];
	float m_v[3];
	unsigned char m_smoothingGroup;
	unsigned char m_groupIndex;
};

// Mesh information
struct MS3DMesh
{
	unsigned char m_flags;
	char m_name[32];
	unsigned short  m_numTriangles;
	unsigned short *m_TriangleIndices;
	char m_MaterialIndex;
};

// Material information
struct MS3DMaterial
{
	char m_name[32];
	float m_ambient[4];
	float m_diffuse[4];
	float m_specular[4];
	float m_emissive[4];
	float m_shininess;		// 0.0f - 128.0f
	float m_transparency;	// 0.0f - 1.0f
	char m_mode;			// 0, 1, 2 is unused now
	char m_texture[128];
	char m_alphamap[128];
};
#pragma pack()

//---------------------------------------------------
// Vertex
struct Vertex
{
	float m_location[3];
};
// Triangle
struct Triangle
{
	float m_normal[3];
	float m_u[3], m_v[3];
	unsigned short   m_vertexIndices[3];
};
// Mesh
struct Mesh
{
	unsigned int   m_textureIndex;
	unsigned short m_numTriangles;
	unsigned short *m_pTriangleIndices;
};
// Material
struct Material
{
	float m_ambient[4], m_diffuse[4], m_specular[4], m_emissive[4];
	float m_shininess;
	unsigned m_texture;
	char *m_pTextureFilename;
};
//---------------------------------------------------

struct MS3DRenderVertex
{
	MS3DRenderVertex()	{}
	MS3DRenderVertex(float fx, float fy, float fz, 	
		float fnx, float fny, float fnz, float fu, float fv)
	{
		x = fx; 
		y = fy; 
		z = fz;
		
		nx = fnx;
		ny = fny;
		nz = fnz;
		
		u = fu;
		v = fv;
	}
	float x, y, z;
	float nx, ny, nz;
	float u, v;

	static const DWORD MS3DFVF;
};

struct CollisionBox
{
	CollisionBox()	{}
	CollisionBox(float fx, float fy, float fz, DWORD dwColor = 0xffffffff)
	{
		x = fx;
		y = fy;
		z = fz;
		color = dwColor;
	}
	float x, y, z;
	DWORD color;
	static const DWORD COLLISIONFVF;
};

class CMS3DLoader : public CBaseLoader
{
public:
	CMS3DLoader();
	~CMS3DLoader();

	virtual bool Load(const char *pFileName);
	virtual void Render(void);
	virtual void Destroy(void);

	void DrawBoundary();
	D3DXVECTOR3 GetVertex(int number);

private:
	void CreateBoundary();

private:
	// Meshes
	unsigned short m_numMeshes;
	Mesh *m_pMeshes;
	// Triangles
	unsigned short m_numTriangles;	
	Triangle *m_pTriangles;
	// Vertices
	unsigned short m_numVertices;
	Vertex *m_pVertices;
	// Materials
	int m_numMaterials;
	Material *m_pMaterials;
	// Render
	MS3DRenderVertex **m_ppRenderVertex;
	D3DMATERIAL9 m_material;
	CollisionBox m_CollisionVertex[24];
	bool m_bLoad;
	// Collision
	Boundary_3D m_boundary;
};

#endif // _MS3DLOADER_

⌨️ 快捷键说明

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