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

📄 model.h

📁 wowmodelview魔兽世界的模型查看工具。下了看看吧
💻 H
字号:
#ifndef MODEL_H
#define MODEL_H

// C++ files#include <vector>//#include <stdlib.h>
//#include <crtdbg.h>

// Our files
#include "video.h"
#include "displayable.h"

#include "vec3d.h"

class Model;
class Bone;
Vec3D fixCoordSystem(Vec3D v);
#include "manager.h"
#include "mpq.h"

#include "modelheaders.h"#include "quaternion.h"#include "matrix.h"
#include "animated.h"
#include "particle.h"

// This will be our animation manager
// instead of using a STL vector or list or table, etc.  
// Decided to just limit it upto 4 animations to loop through - for experimental testing.
// The second id and loop count will later be used for being able to have a primary and secondary animation.

// Currently, this is more of a "Wrapper" over the existing code
// but hopefully over time I can remove and re-write it so this is the core.
struct AnimInfo {
	short AnimID;
	short Loops;
};

class AnimManager {
	ModelAnimation *anims;

	bool Paused;
	bool AnimateParticles;

	unsigned int Frame;		// Frame number we're upto in the current animation
	unsigned int TotalFrames;

	AnimInfo animList[4];
	
	short Count;			// Total index of animations
	short PlayIndex;		// Current animation index we're upto
	short CurLoop;			// Current loop that we're upto.

	int TimeDiff;			// Difference in time between each frame

public:
	AnimManager(ModelAnimation *anim);
	~AnimManager();
	
	void AddAnim(short id, short loop); // Adds an animation to our array.
	void Set(short index, short id, short loop); // sets one of the 4 existing animations and changes it (not really used currently)
	
	void Play(); // Players the animation, and reconfigures if nothing currently inputed
	void Stop(); // Stops and resets the animation
	void Pause(bool force = false); // Toggles 'Pause' of the animation, use force to pause the animation no matter what.
	
	void Next(); // Plays the 'next' animation or loop
	void Prev(); // Plays the 'previous' animation or loop

	int Tick(int time);

	unsigned int GetFrameCount();
	unsigned int GetFrame() {return Frame;}
	void SetFrame(unsigned int f);
	
	void PrevFrame();
	void NextFrame();

	void Clear();
	void Reset() { Count = 0; }

	bool IsPaused() { return Paused; }
	bool IsParticlePaused() { return !AnimateParticles; }
	//void AnimateParticles() { AnimParticles = true; }

	unsigned int GetAnim() { return (unsigned int)animList[PlayIndex].AnimID; }
	int GetTimeDiff();
	void SetTimeDiff(int i);
};

class Bone {
	Animated<Vec3D> trans;
	Animated<Quaternion> rot;
	Animated<Vec3D> scale;
public:
	Vec3D pivot, transPivot;
	int parent;

	bool billboard;
	Matrix mat;
	Matrix mrot;

	bool calc;
	void calcMatrix(Bone* allbones, int anim, int time);
	void init(MPQFile &f, ModelBoneDef &b, int *global);
};

class TextureAnim {
	Animated<Vec3D> trans, rot, scale;

public:
	Vec3D tval, rval, sval;

	void calc(int anim, int time);
	void init(MPQFile &f, ModelTexAnimDef &mta, int *global);
	void setup();
};

struct ModelColor {
	Animated<Vec3D> color;
	AnimatedShort opacity;

	void init(MPQFile &f, ModelColorDef &mcd, int *global);
};

struct ModelTransparency {
	AnimatedShort trans;

	void init(MPQFile &f, ModelTransDef &mtd, int *global);
};

// copied from the .mdl docs? this might be completely wrong
enum BlendModes {
	BM_OPAQUE,
	BM_TRANSPARENT,
	BM_ALPHA_BLEND,
	BM_ADDITIVE,
	BM_ADDITIVE_ALPHA,
	BM_MODULATE
};

struct ModelRenderPass {
	uint16 indexStart, indexCount, vertexStart, vertexEnd;
	//TextureID texture, texture2;
	int tex;
	bool usetex2, useenvmap, cull, trans, unlit, nozwrite;
	float p;
	
	int16 texanim, color, opacity, blendmode;
	int16 order;

	int geoset;

	bool swrap, twrap;

	bool init(Model *m);
	void deinit();

	bool operator< (const ModelRenderPass &m) const
	{
		//return !trans;
		if (order<m.order) return true;
		else if (order>m.order) return false;
		else return blendmode == m.blendmode ? (p<m.p) : blendmode < m.blendmode;
	}
};

struct ModelCamera {
	bool ok;

	Vec3D pos, target;
	float nearclip, farclip, fov;
	Animated<Vec3D> tPos, tTarget;
	Animated<float> rot;

	void init(MPQFile &f, ModelCameraDef &mcd, int *global);
	void setup(int time=0);

	ModelCamera():ok(false) {}
};

struct ModelLight {
	int type, parent;
	Vec3D pos, tpos, dir, tdir;
	Animated<Vec3D> diffColor, ambColor;
	Animated<float> diffIntensity, ambIntensity;

	void init(MPQFile &f, ModelLightDef &mld, int *global);
	void setup(int time, GLuint l);
};


struct ModelAttachment {
	int id;
	Vec3D pos;
	int bone;
	Model *model;

	void init(MPQFile &f, ModelAttachmentDef &mad, int *global);
	void setup();
	void setupParticle();
};

class Model: public ManagedItem, public Displayable {

	// Raw Data
	ModelVertex *origVertices;

	// VBO Data
	GLuint vbuf, nbuf, tbuf;
	size_t vbufsize;

	// Non VBO Data
	GLuint dlist;
	Vec3D *vertices, *normals;
	Vec2D *texcoords;
	uint16 *indices;
	size_t nIndices;

	bool animGeometry,animTextures,animBones;
	bool forceAnim;

	void init(MPQFile &f);

	TextureAnim *texanims;
	int *globalSequences;
	ModelColor *colors;
	ModelTransparency *transparency;
	ModelLight *lights;
	ParticleSystem *particleSystems;
	RibbonEmitter *ribbons;

	void drawModel();
	void initCommon(MPQFile &f);	bool isAnimated(MPQFile &f);
	void initAnimated(MPQFile &f);
	void initStatic(MPQFile &f);

	void animate(int anim);
	void calcBones(int anim, int time);

	void lightsOn(GLuint lbase);
	void lightsOff(GLuint lbase);

	Vec3D *bounds;
	uint16 *boundTris;


public:
	ModelHeader header;
	ModelAnimation *anims;
	AnimManager *animManager;
	ModelCamera cam;
	Bone *bones;
	TextureID *textures;

	std::vector<ModelRenderPass> passes;
	std::vector<ModelGeoset> geosets;
	bool *showGeosets;

	int specialTextures[32];
	GLuint replaceTextures[32];
	bool useReplaceTextures[32];

	int currentAnim;

	bool ok;
	bool ind;
	bool hasCamera;
	bool hasParticles;
	bool isWMO;
	bool isMounted;
	bool animated;

	float rad;
	float trans;
	bool animcalc;
	int anim, animtime;

	Model(std::string name, bool forceAnim=false);
	~Model();
	void draw();
	void updateEmitters(float dt);

	void setupAtt(int id);
	void reset() { 
		animcalc = false; 
	}

	// (float dt)
	void update(int dt) { 
		animManager->Tick(dt);
		updateEmitters((dt/1000.0f)); 
	};

	void drawBones();
	void drawBoundingVolume();
	void drawParticles();

	std::vector<ModelAttachment> atts;
	int attLookup[40];

	friend struct ModelRenderPass;
};

class ModelManager: public SimpleManager {
public:
	int add(std::string name);

	ModelManager() : v(0) {}

	int v;

	void resetAnim();
	void updateEmitters(float dt);
	void clear();

};

#endif

⌨️ 快捷键说明

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