本程序可以读取obj文件,得到点面纹理信息。
说明:我读取的是meshlab转换的obj,所以格式按照这个写的。
base.h
#ifndef BASE_H_
#define BASE_H_
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;
#include <string>
//x y z
typedef struct
{
float ptr[3];
float &operator[](int index)
{
return ptr[index];
}
} vertex;
//s t
typedef struct
{
float ptr[2];
float &operator[](int index)
{
return ptr[index];
}
} vertex_texture;
//x y z
typedef struct
{
float ptr[3];
float &operator[](int index)
{
return ptr[index];
}
} vertex_normal;
//v1 t1 n1 v2 t2 n2 v3 t3 n3
typedef struct
{
int ptr[10];
int &operator[](int index)
{
return ptr[index];
}
} face;
typedef struct
{
float Ka[3];
float Kd[3];
float Ks[3];
float Tr;
int illum;
float Ns;
string map_Kd;
} material;
typedef struct
{
float position[3];
float orientation[4];
float fieldOfView;
} viewpoint;
#endif
readobj.h
#ifndef READOBJ_H_
#define READOBJ_H_
#include "base.h"
#include <vector>
#include <map>
char prename[50] = "obj/";
//f是从1开始计数的
//所以v, vn, vt预先填0
void init
(
vector<vertex_normal> &vn_list,
vector<vertex> &v_list,
vector<vertex_texture> &vt_list
)
{
vertex_normal tmp_vn = {-1, -1, -1};
v