vrml 读取和写入
来源:互联网 发布:知行论坛pt 编辑:程序博客网 时间:2024/04/27 17:22
本学期计算机图形学作业的一部分。
还是采用vrml读取为obj, 和obj写入为vrml。
只能读取最简单的点和面, 其他纹理没写。
#ifndef VRML_H_#define VRML_H_#include <stdlib.h>#include <stdio.h>#include <string.h>int vrml_point(FILE *fp, float (*point)[3]){char tmp[256];int point_count = 0;while(!feof(fp)){fscanf(fp, "%s", tmp);if (!strcmp(tmp, "[")){fscanf(fp, "%s", tmp);while(strcmp(tmp, "]")){point[point_count][0] = atof(tmp);fscanf(fp, "%s", tmp);point[point_count][1] = atof(tmp);fscanf(fp, "%s", tmp);point[point_count][2] = atof(tmp);point_count++;fscanf(fp, "%s", tmp);}return point_count;}}}int vrml_face(FILE *fp, int (*face)[3]){char tmp[256];int face_count = 0;while(!feof(fp)){fscanf(fp, "%s", tmp);if (!strcmp(tmp, "[")){fscanf(fp, "%s", tmp);while(strcmp(tmp, "]")){face[face_count][0] = atoi(tmp);fscanf(fp, "%s", tmp);face[face_count][1] = atoi(tmp);fscanf(fp, "%s", tmp);face[face_count][2] = atoi(tmp);fscanf(fp, "%s", tmp);face_count++;fscanf(fp, "%s", tmp);}return face_count;}}}// 默认三角面片// 只读取point和coordIndex// 点的索引从0开始// 逆时针void vrml2obj(char *filename, float (*point)[3], int (*face)[3], int &point_count, int &face_count){FILE *fp = fopen(filename, "r");char tmp[256];while(!feof(fp)){fscanf(fp, "%s", tmp);if (!strcmp(tmp, "point")){point_count = vrml_point(fp, point);}else if (!strcmp(tmp, "coordIndex")){face_count = vrml_face(fp, face);}elsefgets(tmp, 256, fp);}}void obj2vrml(char *filename, float (*point)[3], int (*face)[3], int point_count, int face_count){FILE *fp = fopen(filename, "w");fprintf(fp, "%s\n", "#VRML V2.0");fprintf(fp, "#points: %d\tfaces: %d\n\n", point_count, face_count);fprintf(fp, "Shape {\n");fprintf(fp, "\tgeometry IndexedFaceSet {\n");fprintf(fp, "\t\tcoord Coordinate {\n");fprintf(fp, "\t\t\tpoint [\n");for (int i = 0; i< point_count; i++){fprintf(fp, "\t\t\t%f %f %f\n", point[i][0], point[i][1], point[i][2]);}fprintf(fp, "\t\t\t]\n");fprintf(fp, "\t\t}\n");fprintf(fp, "\t\tcoordIndex [\n");for (int i = 0; i< face_count; i++){fprintf(fp, "\t\t\t%d %d %d -1\n", face[i][0], face[i][1], face[i][2]);}fprintf(fp, "\t\t]\n");fprintf(fp, "\t}\n");fprintf(fp, "}\n");fclose(fp);}#endif
over。
0 0
- vrml 读取和写入
- xml读取和写入
- 文本文件读取和写入
- ListView 读取和写入
- plist写入和读取
- CSV读取和写入
- 文件读取和写入
- 文件读取和写入
- 文件读取和写入
- Json写入和读取
- 读取和写入配置文件
- 什么是 VRML 和 X3D
- 文件的读取和写入
- javascript写入和读取cookies
- properties 读取和写入配置文件
- 读取和写入plist文件
- 写入和读取cookie数组?
- 写入和读取cookie数组
- nagios+cacti部署安装
- VisualStudio2012轻松把JSON数据转换到POCO的代码
- POJ 2186 Popular Cows(强连通)
- 项目管理软件 Redmine 安装
- 使用向量实现敌人向英雄走动
- vrml 读取和写入
- KVM问题锦集及解决方法
- matlab 一副图片中添加多个矩形
- C++ Builder 开发DLL项目
- Visual Studio 2013 官方免费社区版/简体中文旗舰版下载 (VS2013 MSDN原版ISO镜像)
- centos 6.5安装zebra-0.95
- 算法导论--学习笔记010
- hdoj进制转换
- 133A - HQ9+