Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: ab89dae0e283f4481a0bdaf42fb714fd4329a812 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
   render/model.cc
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#include "sys/sys.h"
#include "model/model.h"
#include "model/asefile.h"
#include "model/mapfile.h"
#include "model/vertexarray.h"

namespace model
{

// static model registry
Model::Registry Model::model_registry;

Model::Model(const std::string & name) :
		model_enginecolor(1.0f, 0.0f, 0.0f),
		model_name(name)

{
	model_radius = 0.5f;
	model_enginesound = 0;
	model_impulsesound = 0;

	model_tris_detail_count = 0;
	model_tris_count = 0;
	model_quad_detail_count = 0;
	model_quad_count = 0;
	
	model_collisionmodel = 0;
}

Model::~Model()
{
	// delete all fragment groups
	for (Groups::iterator git = model_groups.begin(); git != model_groups.end(); git++) {
		delete(*git);
	}
	model_groups.clear();

	// delete all docks
	for (Docks::iterator dit = model_docks.begin(); dit != model_docks.end(); dit++) {
		delete(*dit);
	}
	model_docks.clear();

	// delete all particle systems
	for (Model::ParticleSystems::iterator pit = model_particles.begin(); pit != model_particles.end(); pit++) {
		delete(*pit);
	}
	model_particles.clear();

	// delete all lights
	for (Lights::iterator lit = model_lights.begin(); lit != model_lights.end(); lit++) {
		delete(*lit);
	}
	model_lights.clear();

	// delete all flares
	for (Flares::iterator flit = model_flares.begin(); flit != model_flares.end(); flit++) {
		delete(*flit);
	}
	model_flares.clear();

	// delete all sound tags
	for (Sounds::iterator sit = model_sounds.begin(); sit != model_sounds.end(); sit++) {
		delete (*sit);
	}
	model_sounds.clear();
}

void Model::set_collisionmodel(CollisionModel *collisionmodel)
{	model_collisionmodel = collisionmodel;
	
}

void Model::set_origin(const math::Vector3f &origin)
{
	model_origin.assign(origin);
}

void Model::set_radius(const float radius)
{
	model_radius = radius;
}

void Model::add_particles(Particles *particles)
{
	model_particles.push_back(particles);
}

void Model::add_group(FragmentGroup *group)
{
	model_groups.push_back(group);
}

void Model::add_light(Light *light)
{
	model_lights.push_back(light);
}

void Model::add_flare(Flare *flare)
{
	model_flares.push_back(flare);
}

void Model::add_sound(Sound *sound)
{
	model_sounds.push_back(sound);
}

void Model::add_dock(Dock *dock)
{
	model_docks.push_back(dock);
}

Model *Model::find(const std::string & name)
{
	Registry::iterator it = model_registry.find(name);
	if (it == model_registry.end())
		return 0;
	else
		return (*it).second;
}

Model *Model::load(const std::string & name)
{
	Model *model = find(name);
	if (!model) {
		// try loading the .map model
		model = MapFile::load(name);
	}

	if (!model) {
		// if it can't be found, try the ase model
		model = ASEFile::load(name);
	}

	if (!model) {
		con_warn << "Could not open model " << name << std::endl;
	} else {
		model_registry[model->name()] = model;
	}

	return model;
}

void Model::clear()
{
	// delete all models in the registry
	for (Registry::iterator mit = model_registry.begin(); mit != model_registry.end(); mit++) {
		delete(*mit).second;
	}
	model_registry.clear();

	// clear the vertex array
	if (VertexArray::instance())
		VertexArray::instance()->clear();
}

void Model::list_model(Model *model)
{
	size_t frags = 0;
	for (Groups::iterator git = model->groups().begin(); git != model->groups().end(); git++) {
		frags += (*git)->size();
	}

	con_print << "  " << model->name() << " "  <<  frags << " frags " <<
	model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris " <<
	model->model_quad_detail_count << "/" << model->model_quad_count << " detail/quads" << std::endl;
}

void Model::list()
{
	for (Registry::iterator mit = model_registry.begin(); mit != model_registry.end(); mit++) {
		list_model((*mit).second);

	}

	if (VertexArray::instance()) {
		VertexArray::instance()->info();
	}
	
	con_print << "^B  " << model_registry.size() << " registered models" << std::endl;
}

}