Fix #2077 : GLTF segfault using triangle strip
parent
468549b752
commit
ae0f82d5b7
|
@ -550,9 +550,18 @@ void glTF2Importer::ImportMeshes(glTF2::Asset& r)
|
||||||
case PrimitiveMode_TRIANGLE_STRIP: {
|
case PrimitiveMode_TRIANGLE_STRIP: {
|
||||||
nFaces = count - 2;
|
nFaces = count - 2;
|
||||||
faces = new aiFace[nFaces];
|
faces = new aiFace[nFaces];
|
||||||
SetFace(faces[0], data.GetUInt(0), data.GetUInt(1), data.GetUInt(2));
|
for (unsigned int i = 0; i < nFaces; ++i) {
|
||||||
for (unsigned int i = 3; i < count; ++i) {
|
//The ordering is to ensure that the triangles are all drawn with the same orientation
|
||||||
SetFace(faces[i - 2], faces[i - 1].mIndices[1], faces[i - 1].mIndices[2], data.GetUInt(i));
|
if ((i + 1) % 2 == 0)
|
||||||
|
{
|
||||||
|
//For even n, vertices n + 1, n, and n + 2 define triangle n
|
||||||
|
SetFace(faces[i], data.GetUInt(i + 1), data.GetUInt(i), data.GetUInt(i + 2));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//For odd n, vertices n, n+1, and n+2 define triangle n
|
||||||
|
SetFace(faces[i], data.GetUInt(i), data.GetUInt(i + 1), data.GetUInt(i + 2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -560,8 +569,8 @@ void glTF2Importer::ImportMeshes(glTF2::Asset& r)
|
||||||
nFaces = count - 2;
|
nFaces = count - 2;
|
||||||
faces = new aiFace[nFaces];
|
faces = new aiFace[nFaces];
|
||||||
SetFace(faces[0], data.GetUInt(0), data.GetUInt(1), data.GetUInt(2));
|
SetFace(faces[0], data.GetUInt(0), data.GetUInt(1), data.GetUInt(2));
|
||||||
for (unsigned int i = 3; i < count; ++i) {
|
for (unsigned int i = 1; i < nFaces; ++i) {
|
||||||
SetFace(faces[i - 2], faces[0].mIndices[0], faces[i - 1].mIndices[2], data.GetUInt(i));
|
SetFace(faces[i], faces[0].mIndices[0], faces[i - 1].mIndices[2], data.GetUInt(i + 2));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -615,9 +624,18 @@ void glTF2Importer::ImportMeshes(glTF2::Asset& r)
|
||||||
case PrimitiveMode_TRIANGLE_STRIP: {
|
case PrimitiveMode_TRIANGLE_STRIP: {
|
||||||
nFaces = count - 2;
|
nFaces = count - 2;
|
||||||
faces = new aiFace[nFaces];
|
faces = new aiFace[nFaces];
|
||||||
SetFace(faces[0], 0, 1, 2);
|
for (unsigned int i = 0; i < nFaces; ++i) {
|
||||||
for (unsigned int i = 3; i < count; ++i) {
|
//The ordering is to ensure that the triangles are all drawn with the same orientation
|
||||||
SetFace(faces[i - 2], faces[i - 1].mIndices[1], faces[i - 1].mIndices[2], i);
|
if ((i+1) % 2 == 0)
|
||||||
|
{
|
||||||
|
//For even n, vertices n + 1, n, and n + 2 define triangle n
|
||||||
|
SetFace(faces[i], i+1, i, i+2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//For odd n, vertices n, n+1, and n+2 define triangle n
|
||||||
|
SetFace(faces[i], i, i+1, i+2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -625,8 +643,8 @@ void glTF2Importer::ImportMeshes(glTF2::Asset& r)
|
||||||
nFaces = count - 2;
|
nFaces = count - 2;
|
||||||
faces = new aiFace[nFaces];
|
faces = new aiFace[nFaces];
|
||||||
SetFace(faces[0], 0, 1, 2);
|
SetFace(faces[0], 0, 1, 2);
|
||||||
for (unsigned int i = 3; i < count; ++i) {
|
for (unsigned int i = 1; i < nFaces; ++i) {
|
||||||
SetFace(faces[i - 2], faces[0].mIndices[0], faces[i - 1].mIndices[2], i);
|
SetFace(faces[i], faces[0].mIndices[0], faces[i - 1].mIndices[2], i + 2);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -848,12 +866,6 @@ void glTF2Importer::InternReadFile(const std::string& pFile, aiScene* pScene, IO
|
||||||
|
|
||||||
ImportNodes(asset);
|
ImportNodes(asset);
|
||||||
|
|
||||||
// TODO: it does not split the loaded vertices, should it?
|
|
||||||
//pScene->mFlags |= AI_SCENE_FLAGS_NON_VERBOSE_FORMAT;
|
|
||||||
MakeVerboseFormatProcess process;
|
|
||||||
process.Execute(pScene);
|
|
||||||
|
|
||||||
|
|
||||||
if (pScene->mNumMeshes == 0) {
|
if (pScene->mNumMeshes == 0) {
|
||||||
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
|
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -740,11 +740,6 @@ void glTFImporter::InternReadFile(const std::string& pFile, aiScene* pScene, IOS
|
||||||
|
|
||||||
ImportNodes(asset);
|
ImportNodes(asset);
|
||||||
|
|
||||||
// TODO: it does not split the loaded vertices, should it?
|
|
||||||
//pScene->mFlags |= AI_SCENE_FLAGS_NON_VERBOSE_FORMAT;
|
|
||||||
MakeVerboseFormatProcess process;
|
|
||||||
process.Execute(pScene);
|
|
||||||
|
|
||||||
|
|
||||||
if (pScene->mNumMeshes == 0) {
|
if (pScene->mNumMeshes == 0) {
|
||||||
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
|
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
|
||||||
|
|
Loading…
Reference in New Issue