Subversion Repositories gelsvn

Rev

Rev 398 | Rev 492 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 398 Rev 442
Line 40... Line 40...
40
#include "GLGraphics/gel_glut.h"
40
#include "GLGraphics/gel_glut.h"
41
#include "GLGraphics/QuatTrackBall.h"
41
#include "GLGraphics/QuatTrackBall.h"
42
#include "GLGraphics/draw.h"
42
#include "GLGraphics/draw.h"
43
#include "GLGraphics/SOIL.h"
43
#include "GLGraphics/SOIL.h"
44
#include "Geometry/TriMesh.h"
44
#include "Geometry/TriMesh.h"
45
#include "Geometry/obj_load.h"
-
 
46
#include "Geometry/ply_load.h"
45
#include "Geometry/load.h"
47
#include "HMesh/x3d_load.h"
46
#include "HMesh/x3d_load.h"
48
#include "HMesh/FaceCirculator.h"
47
#include "HMesh/FaceCirculator.h"
49
 
48
 
50
using namespace std;
49
using namespace std;
51
using namespace CGLA;
50
using namespace CGLA;
Line 63... Line 62...
63
int spin_timer = 20;
62
int spin_timer = 20;
64
void spin(int x);
63
void spin(int x);
65
int main_window;
64
int main_window;
66
TriMesh mesh;
65
TriMesh mesh;
67
bool do_textures = true;
66
bool do_textures = true;
68
vector<bool> has_texture;
-
 
69
 
67
 
70
void enable_textures(TriMesh& tm)
-
 
71
{
-
 
72
	for(unsigned int i=0;i<has_texture.size(); ++i)
-
 
73
		tm.materials[i].has_texture = has_texture[i];
-
 
74
}
-
 
75
 
-
 
76
void disable_textures(TriMesh& tm)
-
 
77
{
-
 
78
	for(unsigned int i=0;i<has_texture.size(); ++i)
-
 
79
		tm.materials[i].has_texture = false;
-
 
80
}
-
 
81
 
-
 
82
void load_textures(TriMesh& tm)
-
 
83
{
-
 
84
  has_texture.resize(tm.materials.size());
-
 
85
	for(unsigned int i=0;i<tm.materials.size(); ++i)
-
 
86
	{
-
 
87
		Material& mat = tm.materials[i];
-
 
88
		if(mat.tex_name != "")
-
 
89
		{
-
 
90
			string name = mat.tex_path + mat.tex_name;
-
 
91
			mat.tex_id = SOIL_load_OGL_texture(name.data(), 0, 0, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_POWER_OF_TWO);
-
 
92
      if(mat.tex_id)
-
 
93
        has_texture[i] = true;
-
 
94
		}
-
 
95
	}
-
 
96
}
-
 
97
 
-
 
98
void load_mesh(const string& fn)
-
 
99
{
-
 
100
	if(fn.substr(fn.length()-4,fn.length())==".obj")
-
 
101
	{
-
 
102
		obj_load(fn, mesh);
-
 
103
	}
-
 
104
	else if(fn.substr(fn.length()-4,fn.length())==".ply")
-
 
105
	{
-
 
106
		ply_load(fn, mesh);
-
 
107
	}	
-
 
108
	else if(fn.substr(fn.length()-4,fn.length())==".x3d")
-
 
109
	{
-
 
110
		Manifold m;
-
 
111
		x3d_load(fn, m);
-
 
112
		
-
 
113
		for(VertexIter v=m.vertices_begin(); v != m.vertices_end();++v)
-
 
114
			v->touched = mesh.geometry.add_vertex(v->pos);
-
 
115
		
-
 
116
		for(FaceIter f = m.faces_begin(); f!= m.faces_end(); ++f)
-
 
117
		{
-
 
118
			Vec3i face;
-
 
119
			int i=0;
-
 
120
			for(FaceCirculator fc(f); !fc.end(); ++fc,++i)
-
 
121
			{
-
 
122
				if(i<2)
-
 
123
					face[i] = fc.get_vertex()->touched;
-
 
124
				else
-
 
125
				{
-
 
126
					face[2] = fc.get_vertex()->touched;
-
 
127
					mesh.geometry.add_face(face);
-
 
128
					face[1] = face[2];
-
 
129
				}
-
 
130
			}	
-
 
131
		}
-
 
132
	}
-
 
133
	else
-
 
134
	{
-
 
135
		cout << "Either the format was unrecognized or the file did not have the appropriate extension" << endl;
-
 
136
		exit(0);
-
 
137
	}
-
 
138
  load_textures(mesh);	
-
 
139
  if(!do_textures)
-
 
140
    disable_textures(mesh);		
-
 
141
}
-
 
142
 
68
 
143
bool depth_pick(int x, int y,Vec3f& wp)
69
bool depth_pick(int x, int y,Vec3f& wp)
144
{
70
{
145
	// Enquire about the viewport dimensions
71
	// Enquire about the viewport dimensions
146
	GLint viewport[4];
72
	GLint viewport[4];
Line 247... Line 173...
247
    switch(key)
173
    switch(key)
248
    {
174
    {
249
		case '\033': exit(0); break;
175
		case '\033': exit(0); break;
250
		case 'w': do_wireframe = !do_wireframe; break;
176
		case 'w': do_wireframe = !do_wireframe; break;
251
		case 'f': per_vertex_normals = !per_vertex_normals; redo_display_list = true; break;
177
		case 'f': per_vertex_normals = !per_vertex_normals; redo_display_list = true; break;
252
    case 't': 
-
 
253
        do_textures = !do_textures; 
-
 
254
        if(do_textures) 
-
 
255
          enable_textures(mesh); 
-
 
256
        else 
-
 
257
          disable_textures(mesh); 
-
 
258
        redo_display_list = true; 
-
 
259
        break;
178
        break;
260
    }
179
    }
-
 
180
	redo_display_list=true;
261
}
181
}
262
 
182
 
263
int main(int argc, char** argv)
183
int main(int argc, char** argv)
264
{
184
{
265
	Util::ArgExtracter ae(argc, argv);
185
	Util::ArgExtracter ae(argc, argv);
Line 292... Line 212...
292
    if(ae.no_remaining_args())
212
    if(ae.no_remaining_args())
293
        fn = ae.get_last_arg();
213
        fn = ae.get_last_arg();
294
    else
214
    else
295
        fn = "../../data/head.obj";
215
        fn = "../../data/head.obj";
296
	
216
	
297
	load_mesh(fn);	
217
	load(fn, mesh);
-
 
218
	load_textures(mesh);
298
	
219
	
299
	if(!mesh.has_normals() || redo_normals)
220
	if(!mesh.has_normals() || redo_normals)
300
	{
221
	{
301
		cout << "Computing normals" << endl;
222
		cout << "Computing normals" << endl;
302
		mesh.compute_normals();
223
		mesh.compute_normals();
303
	}
224
	}
304
	cout<< __FILE__ << __LINE__ << " "  << mesh.geometry.no_faces() << " " << mesh.geometry.no_vertices() << endl;
-
 
305
	
225
	
306
	// Initialize Trackball
226
	// Initialize Trackball
307
	Vec3f c;
227
	Vec3f c;
308
	float r;
228
	float r;
309
	mesh.get_bsphere(c,r);
229
	mesh.get_bsphere(c,r);