From 9b4ee91239a71c117a04b9b7a2e365a0a986eb84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 21 Jun 2023 11:15:33 +0200 Subject: [PATCH] MeshTools: recognize & ignore morph targets in compile(). No builtin support for these at the moment. --- src/Magnum/MeshTools/Compile.cpp | 14 +++++++++++ src/Magnum/MeshTools/Compile.h | 8 +++--- src/Magnum/MeshTools/Test/CompileGLTest.cpp | 28 ++++++++++++++++++++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/Magnum/MeshTools/Compile.cpp b/src/Magnum/MeshTools/Compile.cpp index 87c8aae2c..78fa0cf10 100644 --- a/src/Magnum/MeshTools/Compile.cpp +++ b/src/Magnum/MeshTools/Compile.cpp @@ -83,6 +83,10 @@ GL::Mesh compileInternal(const Trade::MeshData& meshData, GL::Buffer&& indices, UnsignedInt weightAttributeCount = 0; #endif + /* All morph target attributes are ignored now, count them and print just a + single warning for all */ + UnsignedInt morphTargetAttributeCount = 0; + for(UnsignedInt i = 0; i != meshData.attributeCount(); ++i) { auto addAttribute = [&](GL::DynamicAttribute attribute, std::size_t offset) { /* Ensure each attribute gets bound only once -- so for example @@ -125,6 +129,13 @@ GL::Mesh compileInternal(const Trade::MeshData& meshData, GL::Buffer&& indices, continue; } + /* No builtin support for morph targets yet, count them and print a + single warning at the end */ + if(meshData.attributeMorphTargetId(i) != -1) { + ++morphTargetAttributeCount; + continue; + } + switch(meshData.attributeName(i)) { case Trade::MeshAttribute::Position: /* Pick 3D position always, the format will properly reduce it @@ -220,6 +231,9 @@ GL::Mesh compileInternal(const Trade::MeshData& meshData, GL::Buffer&& indices, Warning{} << "MeshTools::compile(): ignoring unknown/unsupported attribute" << meshData.attributeName(i); } + if(morphTargetAttributeCount && !(flags & CompileFlag::NoWarnOnCustomAttributes)) + Warning{} << "MeshTools::compile(): ignoring" << morphTargetAttributeCount << "morph target attributes"; + #ifndef MAGNUM_TARGET_GLES2 CORRADE_INTERNAL_ASSERT(jointIdAttributeCount == weightAttributeCount); #endif diff --git a/src/Magnum/MeshTools/Compile.h b/src/Magnum/MeshTools/Compile.h index 8c5c0c11f..a921d4c75 100644 --- a/src/Magnum/MeshTools/Compile.h +++ b/src/Magnum/MeshTools/Compile.h @@ -73,10 +73,10 @@ enum class CompileFlag: UnsignedByte { GenerateSmoothNormals = 1 << 1, /** - * By default, @ref compile() warns when it encounters custom attributes - * and attributes with implementation-specific format, as those get ignored - * by it. If you're binding those manually with - * @ref compile(const Trade::MeshData&, GL::Buffer&, GL::Buffer&) or + * By default, @ref compile() warns when it encounters custom attributes, + * morph target attributes and attributes with an implementation-specific + * format, as those get ignored by it. If you're binding those manually + * with @ref compile(const Trade::MeshData&, GL::Buffer&, GL::Buffer&) or * handling them in some other way on the application side already, use * this flag to suppress the warning messages. * @m_since{2020,06} diff --git a/src/Magnum/MeshTools/Test/CompileGLTest.cpp b/src/Magnum/MeshTools/Test/CompileGLTest.cpp index 5e94dade7..fc1224025 100644 --- a/src/Magnum/MeshTools/Test/CompileGLTest.cpp +++ b/src/Magnum/MeshTools/Test/CompileGLTest.cpp @@ -118,6 +118,7 @@ struct CompileGLTest: GL::OpenGLTester { void conflictingAttributes(); void unsupportedIndexStride(); + void morphTargetAttributes(); void customAttribute(); void unsupportedAttribute(); void unsupportedAttributeStride(); @@ -473,7 +474,8 @@ CompileGLTest::CompileGLTest() { addTests({&CompileGLTest::unsupportedIndexStride}); - addInstancedTests({&CompileGLTest::customAttribute, + addInstancedTests({&CompileGLTest::morphTargetAttributes, + &CompileGLTest::customAttribute, &CompileGLTest::unsupportedAttribute}, Containers::arraySize(CustomAttributeWarningData)); @@ -1562,6 +1564,30 @@ void CompileGLTest::unsupportedIndexStride() { "MeshTools::compile(): MeshIndexType::UnsignedShort with stride of 4 bytes isn't supported by OpenGL\n"); } +void CompileGLTest::morphTargetAttributes() { + auto&& instanceData = CustomAttributeWarningData[testCaseInstanceId()]; + setTestCaseDescription(instanceData.name); + + Vector3 vertexData[2]{}; + Trade::MeshData data{MeshPrimitive::Triangles, {}, vertexData, { + Trade::MeshAttributeData{Trade::MeshAttribute::Position, + Containers::arrayView(vertexData)}, + Trade::MeshAttributeData{Trade::MeshAttribute::Color, + Containers::arrayView(vertexData), 37}, + Trade::MeshAttributeData{Trade::MeshAttribute::Position, + Containers::arrayView(vertexData), 26}, + }}; + + std::ostringstream out; + Warning redirectError{&out}; + if(instanceData.flags) + MeshTools::compile(data, instanceData.flags); + else + MeshTools::compile(data); + CORRADE_COMPARE(out.str(), instanceData.flags ? "" : + "MeshTools::compile(): ignoring 2 morph target attributes\n"); +} + void CompileGLTest::customAttribute() { auto&& instanceData = CustomAttributeWarningData[testCaseInstanceId()]; setTestCaseDescription(instanceData.name);