当前位置: 首页>>代码示例>>C++>>正文


C++ TriMesh::find_material方法代码示例

本文整理汇总了C++中TriMesh::find_material方法的典型用法代码示例。如果您正苦于以下问题:C++ TriMesh::find_material方法的具体用法?C++ TriMesh::find_material怎么用?C++ TriMesh::find_material使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TriMesh的用法示例。


在下文中一共展示了TriMesh::find_material方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: load

void TriMeshObjLoader::load(const std::string& filename) 
{
	pathname = get_path(filename);
	FILE *fp = fopen(filename.data(), "r");
	if (fp==0) {
		cerr << "File " << filename << " does not exist" << endl;
    exit(0);
	}
	mesh->materials.resize(1);
	
	char buf[256];
	float3 v_geo;
	float3 v_normals;
	float3 v_texcoords;

	uint3 f_geo;
	uint3 f_normals;
	uint3 f_texcoords;
	int current_material=0;
	int v, n, t;
	while(fscanf(fp, "%s", buf) != EOF) 
		{
			switch(buf[0]) 
				{
				case '#': // A comment
					fgets(buf, sizeof(buf), fp);
					break;
				case 'm':
					fgets(buf, sizeof(buf), fp);
					sscanf(buf, "%s %s", buf, buf);
					read_material_library(buf, mesh->materials);
					break;
				case 'u':
					fgets(buf, sizeof(buf), fp);
					sscanf(buf, "%s %s", buf, buf);
					current_material = mesh->find_material(buf);
					break;
				case 'v': // v, vn, vt
					switch(buf[1]) 
						{
						case '\0': // vertex
							fscanf(fp, "%f %f %f", &v_geo.x, &v_geo.y, &v_geo.z);
							mesh->geometry.add_vertex(v_geo);
							break;
						case 'n': // normal
							fscanf(fp, "%f %f %f", &v_normals.x, &v_normals.y, &v_normals.z);
							mesh->normals.add_vertex(v_normals);
							break;
						case 't': // texcoord
							fscanf(fp, "%f %f", &v_texcoords.x, &v_texcoords.y);
							v_texcoords.z=1;
							mesh->texcoords.add_vertex(v_texcoords);
							break;
						}
					break;
				case 'f':
					v = n = t = 0;
					fscanf(fp, "%s", buf);
					// can be one of %d, %d//%d, %d/%d, %d/%d/%d 
					if(sscanf(buf, "%d/%d/%d", &v, &t, &n) == 3)
						{ // v/t/n
							
							f_geo.x = get_vert(v); 
							f_texcoords.x = get_texcoord(t);
							f_normals.x = get_normal(n);

							fscanf(fp, "%d/%d/%d", &v, &t, &n); 
							f_geo.y = get_vert(v); 
							f_texcoords.y = get_texcoord(t);
							f_normals.y = get_normal(n);

							fscanf(fp, "%d/%d/%d", &v, &t, &n); 
							f_geo.z = get_vert(v); 
							f_texcoords.z = get_texcoord(t);
							f_normals.z = get_normal(n);

							int idx = mesh->geometry.add_face(f_geo);
							mesh->normals.add_face(f_normals, idx);
							mesh->texcoords.add_face(f_texcoords, idx);
							mesh->mat_idx.push_back(current_material);

							// Load a general polygon and convert to triangles
							while(fscanf(fp, "%d/%d/%d", &v, &t, &n) == 3) 
								{
									f_geo.y = f_geo.z;
									f_normals.y = f_normals.z;
									f_texcoords.y = f_texcoords.z;

									f_geo.z = get_vert(v);
									f_normals.z = get_normal(n);
									f_texcoords.z = get_texcoord(t);

									int idx = mesh->geometry.add_face(f_geo);
									mesh->normals.add_face(f_normals, idx);
									mesh->texcoords.add_face(f_texcoords, idx);
									mesh->mat_idx.push_back(current_material);
								}
						} 
					else if (sscanf(buf, "%d//%d", &v, &n) == 2)
						{// v//n 
//.........这里部分代码省略.........
开发者ID:parahunter,项目名称:RaytracingFrameworkFinalProject,代码行数:101,代码来源:obj_load.cpp


注:本文中的TriMesh::find_material方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。