-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.h
executable file
·91 lines (79 loc) · 2.24 KB
/
Model.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Model.hpp
// ogl4
//
// Created by Philipp Lensing on 21.09.16.
// Copyright © 2016 Philipp Lensing. All rights reserved.
//
#ifndef Model_hpp
#define Model_hpp
#include <stdio.h>
#include "basemodel.h"
#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include "vertexbuffer.h"
#include "indexbuffer.h"
#include "texture.h"
#include "aabb.h"
#include <string>
class Model : public BaseModel
{
public:
Model();
Model(const char* ModelFile, bool FitSize);
virtual ~Model();
bool load(const char* ModelFile, bool FitSize);
virtual void draw(const BaseCamera& Cam);
const AABB& boundingBox() const { return BoundingBox; }
protected: // protected types
struct Mesh
{
Mesh() {}
VertexBuffer VB;
IndexBuffer IB;
int MaterialIdx;
};
struct Material
{
Material() : DiffTex(NULL), DiffColor(1,1,1),SpecColor(0.3f,0.3f,0.3f), AmbColor(0,0,0), SpecExp(10) {}
Color DiffColor;
Color SpecColor;
Color AmbColor;
float SpecExp;
const Texture* DiffTex;
};
struct Node
{
Node() : Parent(NULL), Children(NULL), ChildCount(0), MeshCount(0), Meshes(NULL) {}
Matrix Trans;
Matrix GlobalTrans;
int* Meshes;
unsigned int MeshCount;
Node* Parent;
Node* Children;
unsigned int ChildCount;
std::string Name;
};
protected: // protected methods
void loadMeshes(const aiScene* pScene, bool FitSize);
void loadMaterials(const aiScene* pScene);
void calcBoundingBox( const aiScene* pScene, AABB& Box);
void loadNodes(const aiScene* pScene);
void copyNodesRecursive(const aiNode* paiNode, Node* pNode);
Matrix convert(const aiMatrix4x4& m);
void applyMaterial( unsigned int index);
void deleteNodes(Node* pNode);
protected: // protected member variables
Mesh* pMeshes;
unsigned int MeshCount;
Material* pMaterials;
unsigned int MaterialCount;
AABB BoundingBox;
std::string Filepath; // stores pathname and filename
std::string Path; // stores path without filename
Node RootNode;
private:
void defineExtremes(float point, float &max, float &min);
};
#endif /* Model_hpp */