MCPcopy Create free account
hub / github.com/axmolengine/axmol / exportFaceGroupToShape

Function exportFaceGroupToShape

core/3d/ObjLoader.cpp:395–448  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393}
394
395static bool exportFaceGroupToShape(shape_t& shape,
396 std::map<vertex_index, unsigned int> vertexCache,
397 const std::vector<float>& in_positions,
398 const std::vector<float>& in_normals,
399 const std::vector<float>& in_texcoords,
400 const std::vector<std::vector<vertex_index>>& faceGroup,
401 const int material_id,
402 std::string_view name,
403 bool clearCache)
404{
405 if (faceGroup.empty())
406 {
407 return false;
408 }
409
410 // Flatten vertices and indices
411 for (size_t i = 0, size = faceGroup.size(); i < size; ++i)
412 {
413 const std::vector<vertex_index>& face = faceGroup[i];
414
415 vertex_index i0 = face[0];
416 vertex_index i1(-1);
417 vertex_index i2 = face[1];
418
419 size_t npolys = face.size();
420
421 // Polygon -> triangle fan conversion
422 for (size_t k = 2; k < npolys; k++)
423 {
424 i1 = i2;
425 i2 = face[k];
426
427 unsigned int v0 = updateVertex(vertexCache, shape.mesh.positions, shape.mesh.normals, shape.mesh.texcoords,
428 in_positions, in_normals, in_texcoords, i0);
429 unsigned int v1 = updateVertex(vertexCache, shape.mesh.positions, shape.mesh.normals, shape.mesh.texcoords,
430 in_positions, in_normals, in_texcoords, i1);
431 unsigned int v2 = updateVertex(vertexCache, shape.mesh.positions, shape.mesh.normals, shape.mesh.texcoords,
432 in_positions, in_normals, in_texcoords, i2);
433
434 shape.mesh.indices.emplace_back(v0);
435 shape.mesh.indices.emplace_back(v1);
436 shape.mesh.indices.emplace_back(v2);
437
438 shape.mesh.material_ids.emplace_back(material_id);
439 }
440 }
441
442 shape.name = name;
443
444 if (clearCache)
445 vertexCache.clear();
446
447 return true;
448}
449
450static std::string& replacePathSeperator(std::string& path)
451{

Callers 1

LoadObjFunction · 0.85

Calls 5

updateVertexFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
emplace_backMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected