读取 obj 信息

该程序专注于读取 OBJ 文件,从中提取点、面及纹理信息。适用于处理由 meshlab 转换的 OBJ 文件。
摘要由CSDN通过智能技术生成

本程序可以读取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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值