Browse Source

MeshTools: recognize & ignore morph targets in compile().

No builtin support for these at the moment.
pull/623/head
Vladimír Vondruš 3 years ago
parent
commit
9b4ee91239
  1. 14
      src/Magnum/MeshTools/Compile.cpp
  2. 8
      src/Magnum/MeshTools/Compile.h
  3. 28
      src/Magnum/MeshTools/Test/CompileGLTest.cpp

14
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

8
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}

28
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);

Loading…
Cancel
Save