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


C++ Geometry::SetMesh方法代码示例

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


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

示例1: LoadGeometry

Geometry* SceneLoader::LoadGeometry(QDomElement element)
{
  Geometry* geom = GeometryPool::Get()->GetGeometry(_geometryName, _geometryIdx);
  if (geom)
    {
      return geom;
    }

  if (element.nodeName() != QString ("geometry"))
    {
      printf ("ceXMLDataLoader::LoadGeometry: Illegal data format: '%s' != 'geometry'\n", element.nodeName().toStdString().c_str()); fflush (stdout);
      return 0;
    }

  geom = new Geometry ();

  QDomElement staticElement = element.firstChildElement("staticmesh");
  if (!staticElement.isNull())
    {
      ceMesh* mesh = LoadMesh (staticElement);
      if (!mesh)
        {
          geom->Release();
          return 0;
        }
      iStaticMesh* staticMesh = _engine->GetDevice()->CreateStaticMesh();
      staticMesh->SetMesh(mesh);
      geom->SetMesh(staticMesh);
      geom->SetMetaMesh(MT_Static,
      staticElement.firstChildElement("mesh").attribute("filename"));
    }

  MaterialManager* matMgr = Session::Get()->GetMaterialManager();

  QDomElement materialElement = element.firstChildElement("material");
  Material* mat = 0;
  if (!materialElement.isNull())
    {
      mat = matMgr->GetMaterial(materialElement.text());
    }

  if (!mat)
    {
      mat = matMgr->GetDefaultMaterial();
    }
  geom->SetMetaMaterial(mat);

  GeometryPool::Get()->Set(_geometryName, _geometryIdx, geom);
  return geom;

}
开发者ID:BtbN,项目名称:crimson-core,代码行数:51,代码来源:sceneloader.cpp

示例2: LoadObject

Geometry* ObjectMan::LoadObject(string id,
	string name,
	bool collidable,
	string parent_id)
{
	objLoader* loader = new objLoader();
	string filename = MODELSPATH + name + GEOEXT;
	
	cout << "\t" << filename << "...";
	
	char* file = (char*)(filename).c_str();
	loader->load(file);

	obj_vector** verts = loader->vertexList;
	int num_v = loader->vertexCount;
	vector<Vec4> vertices;

	obj_vector** norms = loader->normalList;
	int num_n = loader->normalCount;
	vector<Vec4> normals;

	obj_vector** uvs = loader->textureList;
	int num_u = loader->textureCount;
	vector<Vec4> uv_points;

	obj_face** face_list = loader->faceList;
	int num_f = loader->faceCount;
	vector<Face> faces;

	int* index_of_faces = new int[num_f * 3];

	btScalar* index_of_verts = new btScalar[num_v * 3];

	for (int i = 0; i < num_v; i++)
	{
		obj_vector* cur = verts[i];
		Vec4 point((float)cur->e[0], (float)cur->e[1], (float)cur->e[2]);
		vertices.push_back(point);
		index_of_verts[i * 3] = btScalar((float)cur->e[0]);
		index_of_verts[i * 3 + 1] = btScalar((float)cur->e[1]);
		index_of_verts[i * 3 + 2] = btScalar((float)cur->e[2]);
	}

	for (int j = 0; j < num_n; j++)
	{
		obj_vector* cur = norms[j];
		Vec4 norm((float)cur->e[0], (float)cur->e[1], (float)cur->e[2]);
		normals.push_back(norm);
	}

	for (int k = 0; k < num_u; k++)
	{
		obj_vector* cur = uvs[k];
		Vec4 uv_point((float)cur->e[0], (float)cur->e[1], 0);
		uv_points.push_back(uv_point);
		//if (id == "car") {
		//	printf("UV: %f\t%f\n", uv_point[0], uv_point[1]);
		//}
	}

	for (int m = 0; m < num_f; m++)
	{
		obj_face* cur = face_list[m];
		Face new_face;

		for (int n = 0; n < cur->vertex_count; n++)
		{
			index_of_faces[(m * 3) + n] = cur->vertex_index[n];
			new_face.vertices.push_back(vertices[cur->vertex_index[n]]);
			new_face.normals.push_back(normals[cur->normal_index[n]]);
			new_face.uvs.push_back(uv_points[cur->texture_index[n]]);
		}

		faces.push_back(new_face);
	}

	btTriangleIndexVertexArray* mesh = new btTriangleIndexVertexArray(num_f,
		index_of_faces,
		3 * sizeof(int),
		num_v,
		index_of_verts,
		3 * sizeof(btScalar));

	Geometry* p = NULL;
	map<string, Geometry*>::const_iterator parentFound = objectMap.find(parent_id);
	if (parentFound != objectMap.end()) {
		p = parentFound->second;
	}

	Geometry* geo = new Geometry(id, vertices, normals, uv_points, faces, p);
	geo->SetMesh(mesh);
	objectMap.insert(make_pair(id, geo));
	objects.push_back(geo);

	if (collidable)
	{
		collidables.push_back(geo);
	}

	// Is there a reason the loader isn't deleted? I tried uncommenting this, and nothing appeared to die a violent death.
//.........这里部分代码省略.........
开发者ID:spartacus125,项目名称:Racer_v3,代码行数:101,代码来源:ObjectMan.cpp


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