mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-05 21:40:31 +00:00
update assimp lib
This commit is contained in:
parent
03a348deb7
commit
d3f8fee74e
1725 changed files with 196314 additions and 62009 deletions
|
|
@ -188,12 +188,57 @@ mg_m_err:
|
|||
pFaces.clear();
|
||||
}
|
||||
|
||||
void X3DGeoHelper::coordIdx_str2lines_arr(const std::vector<int32_t> &pCoordIdx, std::vector<aiFace> &pFaces) {
|
||||
std::vector<int32_t> f_data(pCoordIdx);
|
||||
|
||||
if (f_data.back() != (-1)) {
|
||||
f_data.push_back(-1);
|
||||
}
|
||||
|
||||
// reserve average size.
|
||||
pFaces.reserve(f_data.size() / 2);
|
||||
for (std::vector<int32_t>::const_iterator startIt = f_data.cbegin(), endIt = f_data.cbegin(); endIt != f_data.cend(); ++endIt) {
|
||||
// check for end of current polyline
|
||||
if (*endIt != -1)
|
||||
continue;
|
||||
|
||||
// found end of polyline, check if this is a valid polyline
|
||||
std::size_t numIndices = std::distance(startIt, endIt);
|
||||
if (numIndices <= 1)
|
||||
goto mg_m_err;
|
||||
|
||||
// create line faces out of polyline indices
|
||||
for (int32_t idx0 = *startIt++; startIt != endIt; ++startIt) {
|
||||
int32_t idx1 = *startIt;
|
||||
|
||||
aiFace tface;
|
||||
tface.mNumIndices = 2;
|
||||
tface.mIndices = new unsigned int[2];
|
||||
tface.mIndices[0] = idx0;
|
||||
tface.mIndices[1] = idx1;
|
||||
pFaces.push_back(tface);
|
||||
|
||||
idx0 = idx1;
|
||||
}
|
||||
|
||||
++startIt;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
mg_m_err:
|
||||
for (size_t i = 0, i_e = pFaces.size(); i < i_e; i++)
|
||||
delete[] pFaces[i].mIndices;
|
||||
|
||||
pFaces.clear();
|
||||
}
|
||||
|
||||
void X3DGeoHelper::add_color(aiMesh &pMesh, const std::list<aiColor3D> &pColors, const bool pColorPerVertex) {
|
||||
std::list<aiColor4D> tcol;
|
||||
|
||||
// create RGBA array from RGB.
|
||||
for (std::list<aiColor3D>::const_iterator it = pColors.begin(); it != pColors.end(); ++it)
|
||||
tcol.emplace_back((*it).r, (*it).g, (*it).b, 1);
|
||||
tcol.emplace_back((*it).r, (*it).g, (*it).b, static_cast<ai_real>(1));
|
||||
|
||||
// call existing function for adding RGBA colors
|
||||
add_color(pMesh, tcol, pColorPerVertex);
|
||||
|
|
@ -238,7 +283,7 @@ void X3DGeoHelper::add_color(aiMesh &pMesh, const std::vector<int32_t> &pCoordId
|
|||
|
||||
// create RGBA array from RGB.
|
||||
for (std::list<aiColor3D>::const_iterator it = pColors.begin(); it != pColors.end(); ++it) {
|
||||
tcol.emplace_back((*it).r, (*it).g, (*it).b, 1);
|
||||
tcol.emplace_back((*it).r, (*it).g, (*it).b, static_cast<ai_real>(1));
|
||||
}
|
||||
|
||||
// call existing function for adding RGBA colors
|
||||
|
|
@ -440,7 +485,7 @@ void X3DGeoHelper::add_tex_coord(aiMesh &pMesh, const std::vector<int32_t> &pCoo
|
|||
// copy list to array because we are need indexed access to normals.
|
||||
texcoord_arr_copy.reserve(pTexCoords.size());
|
||||
for (std::list<aiVector2D>::const_iterator it = pTexCoords.begin(); it != pTexCoords.end(); ++it) {
|
||||
texcoord_arr_copy.emplace_back((*it).x, (*it).y, 0);
|
||||
texcoord_arr_copy.emplace_back((*it).x, (*it).y, static_cast<ai_real>(0));
|
||||
}
|
||||
|
||||
if (pTexCoordIdx.size() > 0) {
|
||||
|
|
@ -480,7 +525,7 @@ void X3DGeoHelper::add_tex_coord(aiMesh &pMesh, const std::list<aiVector2D> &pTe
|
|||
// copy list to array because we are need convert aiVector2D to aiVector3D and also get indexed access as a bonus.
|
||||
tc_arr_copy.reserve(pTexCoords.size());
|
||||
for (std::list<aiVector2D>::const_iterator it = pTexCoords.begin(); it != pTexCoords.end(); ++it) {
|
||||
tc_arr_copy.emplace_back((*it).x, (*it).y, 0);
|
||||
tc_arr_copy.emplace_back((*it).x, (*it).y, static_cast<ai_real>(0));
|
||||
}
|
||||
|
||||
// copy texture coordinates to mesh
|
||||
|
|
@ -528,4 +573,40 @@ aiMesh *X3DGeoHelper::make_mesh(const std::vector<int32_t> &pCoordIdx, const std
|
|||
return tmesh;
|
||||
}
|
||||
|
||||
aiMesh *X3DGeoHelper::make_line_mesh(const std::vector<int32_t> &pCoordIdx, const std::list<aiVector3D> &pVertices) {
|
||||
std::vector<aiFace> faces;
|
||||
|
||||
// create faces array from input string with vertices indices.
|
||||
X3DGeoHelper::coordIdx_str2lines_arr(pCoordIdx, faces);
|
||||
if (!faces.size()) {
|
||||
throw DeadlyImportError("Failed to create mesh, faces list is empty.");
|
||||
}
|
||||
|
||||
//
|
||||
// Create new mesh and copy geometry data.
|
||||
//
|
||||
aiMesh *tmesh = new aiMesh;
|
||||
size_t ts = faces.size();
|
||||
// faces
|
||||
tmesh->mFaces = new aiFace[ts];
|
||||
tmesh->mNumFaces = static_cast<unsigned int>(ts);
|
||||
for (size_t i = 0; i < ts; i++)
|
||||
tmesh->mFaces[i] = faces[i];
|
||||
|
||||
// vertices
|
||||
std::list<aiVector3D>::const_iterator vit = pVertices.begin();
|
||||
|
||||
ts = pVertices.size();
|
||||
tmesh->mVertices = new aiVector3D[ts];
|
||||
tmesh->mNumVertices = static_cast<unsigned int>(ts);
|
||||
for (size_t i = 0; i < ts; i++) {
|
||||
tmesh->mVertices[i] = *vit++;
|
||||
}
|
||||
|
||||
// set primitive type and return result.
|
||||
tmesh->mPrimitiveTypes = aiPrimitiveType_LINE;
|
||||
|
||||
return tmesh;
|
||||
}
|
||||
|
||||
} // namespace Assimp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue