forked from larspensjo/ephenation-client
/
BlenderModel.h
70 lines (56 loc) · 2.42 KB
/
BlenderModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2012 The Ephenation Authors
//
// This file is part of Ephenation.
//
// Ephenation is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// Ephenation is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Ephenation. If not, see <http://www.gnu.org/licenses/>.
//
#pragma once
#include <string>
#include <vector>
#include <map>
#include <memory>
#include "glm/glm.hpp"
class AnimationShader;
class aiNode;
class BlenderModel {
public:
struct Animation;
struct Mesh;
BlenderModel();
virtual ~BlenderModel();
// Initialize a model from a file.
// xRotateCorrection: Compensate for model being rotated wrong around x axis.
// normalize: Normalize the size to 1.0. Doesn't work for animations.
void Init(const char *filename, float xRotateCorrection, bool normalize);
void Draw(AnimationShader *shader, const glm::mat4 &modelMatrix, double animationStart = 0.0, bool dead = false);
// Use the model, but don't animate it using bones. Use default shader.
void DrawStatic(void);
static void InitModels(void);
// Modify a transformation matrix that will align the model, as needed.
void Align(glm::mat4 &mat) const;
private:
GLuint fBufferId;
GLuint fIndexBufferId;
GLuint fVao; // A list of Vertex Attribute Object
float fRotateXCorrection; // How much to rotate around the X axis to normalize direction
// Traverse the node tree. Compute the absolute matrices (the matrices are relative to the parent). Also update meshes.
void FindMeshTransformations(int level, glm::mat4 *meshmatrix, const glm::mat4 &base, const aiNode *node);
bool fUsingBones; // True if bones are used to define mesh positions.
std::unique_ptr<Animation[]> fAnimations; // for each animation.
unsigned fNumMeshes;
std::unique_ptr<Mesh[]> fMeshData; // Data for each mesh.
// All joints are ordered. Map from bone name to joint number. Only bones actually used in a mesh are saved here.
typedef std::map<std::string, unsigned int>::iterator boneindexIT_t;
std::map<std::string, unsigned int> fBoneIndex;
};
extern BlenderModel gSwordModel1, gTuftOfGrass, gFrog, gMorran;