Merge branch 'master' into UpdateUtf8cpp

pull/5148/head
Kim Kulling 2023-06-27 22:09:20 +02:00 committed by GitHub
commit f55eebad06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 2 deletions

View File

@ -481,6 +481,8 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
pcNew->achFormatHint[2] = 's';
pcNew->achFormatHint[3] = '\0';
SizeCheck(szCurrent + pcNew->mWidth);
pcNew->pcData = (aiTexel *)new unsigned char[pcNew->mWidth];
memcpy(pcNew->pcData, szCurrent, pcNew->mWidth);
szCurrent += iWidth;

View File

@ -239,8 +239,6 @@ struct Mesh {
unsigned int m_uiMaterialIndex;
/// True, if normals are stored.
bool m_hasNormals;
/// True, if vertex colors are stored.
bool m_hasVertexColors;
/// Constructor
explicit Mesh(const std::string &name) :

View File

@ -156,9 +156,17 @@ void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
// read in vertex definition (homogeneous coords)
getHomogeneousVector3(m_pModel->mVertices);
} else if (numComponents == 6) {
// fill previous omitted vertex-colors by default
if (m_pModel->mVertexColors.size() < m_pModel->mVertices.size()) {
m_pModel->mVertexColors.resize(m_pModel->mVertices.size(), aiVector3D(0, 0, 0));
}
// read vertex and vertex-color
getTwoVectors3(m_pModel->mVertices, m_pModel->mVertexColors);
}
// append omitted vertex-colors as default for the end if any vertex-color exists
if (!m_pModel->mVertexColors.empty() && m_pModel->mVertexColors.size() < m_pModel->mVertices.size()) {
m_pModel->mVertexColors.resize(m_pModel->mVertices.size(), aiVector3D(0, 0, 0));
}
} else if (*m_DataIt == 't') {
// read in texture coordinate ( 2D or 3D )
++m_DataIt;

View File

@ -0,0 +1,11 @@
g cube
v 0.0 0.0 0.0
v 0.0 0.0 1.0 0.0 0.0 1.0
v 0.0 1.0 0.0
v 1.0 0.0 0.0 1.0 0.6 0.3
v 1.0 1.0 0.0
f 1 2 3
f 1 4 3
f 2 5 4

View File

@ -286,6 +286,54 @@ TEST_F(utObjImportExport, issue1923_vertex_color_Test) {
delete scene;
}
TEST_F(utObjImportExport, only_a_part_of_vertex_colors_Test) {
::Assimp::Importer importer;
const aiScene *const scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OBJ/only_a_part_of_vertexcolors.obj", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mNumMeshes, 1U);
const aiMesh *const mesh = scene->mMeshes[0];
EXPECT_EQ(mesh->mNumVertices, 9U);
EXPECT_EQ(mesh->mNumFaces, 3U);
EXPECT_TRUE(mesh->HasVertexColors(0));
const aiVector3D *const vertices = mesh->mVertices;
const aiColor4D *const colors = mesh->mColors[0];
EXPECT_EQ(aiVector3D(0.0f, 0.0f, 0.0f), vertices[0]);
EXPECT_EQ(aiColor4D(0.0f, 0.0f, 0.0f, 1.0f), colors[0]);
EXPECT_EQ(aiVector3D(0.0f, 0.0f, 1.0f), vertices[1]);
EXPECT_EQ(aiColor4D(0.0f, 0.0f, 1.0f, 1.0f), colors[1]);
EXPECT_EQ(aiVector3D(0.0f, 1.0f, 0.0f), vertices[2]);
EXPECT_EQ(aiColor4D(0.0f, 0.0f, 0.0f, 1.0f), colors[2]);
EXPECT_EQ(aiVector3D(0.0f, 0.0f, 0.0f), vertices[3]);
EXPECT_EQ(aiColor4D(0.0f, 0.0f, 0.0f, 1.0f), colors[3]);
EXPECT_EQ(aiVector3D(1.0f, 0.0f, 0.0f), vertices[4]);
EXPECT_EQ(aiColor4D(1.0f, 0.6f, 0.3f, 1.0f), colors[4]);
EXPECT_EQ(aiVector3D(0.0f, 1.0f, 0.0f), vertices[5]);
EXPECT_EQ(aiColor4D(0.0f, 0.0f, 0.0f, 1.0f), colors[5]);
EXPECT_EQ(aiVector3D(0.0f, 0.0f, 1.0f), vertices[6]);
EXPECT_EQ(aiColor4D(0.0f, 0.0f, 1.0f, 1.0f), colors[6]);
EXPECT_EQ(aiVector3D(1.0f, 1.0f, 0.0f), vertices[7]);
EXPECT_EQ(aiColor4D(0.0f, 0.0f, 0.0f, 1.0f), colors[7]);
EXPECT_EQ(aiVector3D(1.0f, 0.0f, 0.0f), vertices[8]);
EXPECT_EQ(aiColor4D(1.0f, 0.6f, 0.3f, 1.0f), colors[8]);
#ifndef ASSIMP_BUILD_NO_EXPORT
::Assimp::Exporter exporter;
EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "obj", ASSIMP_TEST_MODELS_DIR "/OBJ/test_out.obj"));
#endif // ASSIMP_BUILD_NO_EXPORT
}
TEST_F(utObjImportExport, no_vertex_colors_Test) {
::Assimp::Importer importer;
const aiScene *const scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OBJ/box.obj", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mNumMeshes, 1U);
const aiMesh *const mesh = scene->mMeshes[0];
EXPECT_FALSE(mesh->HasVertexColors(0));
}
TEST_F(utObjImportExport, issue1453_segfault) {
static const char *curObjModel =
"v 0.0 0.0 0.0\n"