Browse Source

Trade: ability to specify custom animation target names on conversion.

Added this API to the importer, forgot about the converter. Sigh.
pull/620/head
Vladimír Vondruš 3 years ago
parent
commit
2bba1834a0
  1. 13
      src/Magnum/Trade/AbstractSceneConverter.cpp
  2. 32
      src/Magnum/Trade/AbstractSceneConverter.h
  3. 80
      src/Magnum/Trade/Test/AbstractSceneConverterTest.cpp

13
src/Magnum/Trade/AbstractSceneConverter.cpp

@ -675,6 +675,19 @@ bool AbstractSceneConverter::doAdd(UnsignedInt, const AnimationData&, Containers
CORRADE_ASSERT_UNREACHABLE("Trade::AbstractSceneConverter::add(): animation conversion advertised but not implemented", {});
}
void AbstractSceneConverter::setAnimationTrackTargetName(const AnimationTrackTarget target, const Containers::StringView name) {
CORRADE_ASSERT(features() & SceneConverterFeature::AddAnimations,
"Trade::AbstractSceneConverter::setAnimationTrackTargetName(): feature not supported", );
CORRADE_ASSERT(_state,
"Trade::AbstractSceneConverter::setAnimationTrackTargetName(): no conversion in progress", );
CORRADE_ASSERT(isAnimationTrackTargetCustom(target),
"Trade::AbstractSceneConverter::setAnimationTrackTargetName():" << target << "is not custom", );
doSetAnimationTrackTargetName(target, name);
}
void AbstractSceneConverter::doSetAnimationTrackTargetName(AnimationTrackTarget, Containers::StringView) {}
UnsignedInt AbstractSceneConverter::lightCount() const {
CORRADE_ASSERT(_state, "Trade::AbstractSceneConverter::lightCount(): no conversion in progress", {});
return _state->lightCount;

32
src/Magnum/Trade/AbstractSceneConverter.h

@ -1184,7 +1184,7 @@ class MAGNUM_TRADE_EXPORT AbstractSceneConverter: public PluginManager::Abstract
* support custom scene fields or doesn't support naming them, the call
* is ignored.
* @see @ref isConverting(), @ref features(), @ref isSceneFieldCustom(),
* @ref setMeshAttributeName()
* @ref setAnimationTrackTargetName(), @ref setMeshAttributeName()
*/
void setSceneFieldName(SceneField field, Containers::StringView name);
@ -1241,7 +1241,8 @@ class MAGNUM_TRADE_EXPORT AbstractSceneConverter: public PluginManager::Abstract
*
* If the converter doesn't support animation naming, @p name is
* ignored.
* @see @ref isConverting(), @ref features()
* @see @ref isConverting(), @ref features(),
* @ref setAnimationTrackTargetName()
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
Containers::Optional<UnsignedInt> add(const AnimationData& animation, Containers::StringView name = {});
@ -1250,6 +1251,22 @@ class MAGNUM_TRADE_EXPORT AbstractSceneConverter: public PluginManager::Abstract
Containers::Optional<UnsignedInt> add(const AnimationData& animation);
#endif
/**
* @brief Set name of a custom animation track target
* @m_since_latest
*
* Expects that a conversion is currently in progress,
* @ref SceneConverterFeature::AddAnimations is supported and
* @p target is a custom target. The target name will get used only for
* animation data added after this function has been called. If the
* converter doesn't support custom animation track target or doesn't
* support naming them, the call is ignored.
* @see @ref isConverting(), @ref features(),
* @ref isAnimationTrackTargetCustom(), @ref setSceneFieldName(),
* @ref setMeshAttributeName()
*/
void setAnimationTrackTargetName(AnimationTrackTarget target, Containers::StringView name);
/**
* @brief Count of added lights
* @m_since_latest
@ -1490,7 +1507,8 @@ class MAGNUM_TRADE_EXPORT AbstractSceneConverter: public PluginManager::Abstract
* converter doesn't support custom mesh attributes or doesn't support
* naming them, the call is ignored.
* @see @ref isConverting(), @ref features(),
* @ref isMeshAttributeCustom(), @ref setSceneFieldName()
* @ref isMeshAttributeCustom(), @ref setSceneFieldName(),
* @ref setAnimationTrackTargetName()
*/
void setMeshAttributeName(MeshAttribute attribute, Containers::StringView name);
@ -2226,6 +2244,14 @@ class MAGNUM_TRADE_EXPORT AbstractSceneConverter: public PluginManager::Abstract
*/
virtual bool doAdd(UnsignedInt id, const AnimationData& animation, Containers::StringView name);
/**
* @brief Implementation for @ref setAnimationTrackTargetName()
* @m_since_latest
*
* The @p target is always custom. Default implementation does nothing.
*/
virtual void doSetAnimationTrackTargetName(AnimationTrackTarget target, Containers::StringView name);
/**
* @brief Implementation for @ref add(const LightData&, Containers::StringView)
* @m_since_latest

80
src/Magnum/Trade/Test/AbstractSceneConverterTest.cpp

@ -168,6 +168,10 @@ struct AbstractSceneConverterTest: TestSuite::Tester {
void addAnimationFailed();
void addAnimationNotImplemented();
void setAnimationTrackTargetName();
void setAnimationTrackTargetNameNotImplemented();
void setAnimationTrackTargetNameNotCustom();
void addLight();
void addLightFailed();
void addLightNotImplemented();
@ -717,6 +721,10 @@ AbstractSceneConverterTest::AbstractSceneConverterTest() {
&AbstractSceneConverterTest::addAnimationFailed,
&AbstractSceneConverterTest::addAnimationNotImplemented,
&AbstractSceneConverterTest::setAnimationTrackTargetName,
&AbstractSceneConverterTest::setAnimationTrackTargetNameNotImplemented,
&AbstractSceneConverterTest::setAnimationTrackTargetNameNotCustom,
&AbstractSceneConverterTest::addLight,
&AbstractSceneConverterTest::addLightFailed,
&AbstractSceneConverterTest::addLightNotImplemented,
@ -1080,6 +1088,8 @@ void AbstractSceneConverterTest::thingNotSupported() {
converter.setDefaultScene(0);
converter.add(AnimationData{nullptr, nullptr});
converter.setAnimationTrackTargetName({}, {});
converter.add(LightData{LightType::Point, {}, 0.0f});
converter.add(CameraData{CameraType::Orthographic3D, {}, 0.0f, 1.0f});
converter.add(SkinData2D{nullptr, nullptr});
@ -1107,7 +1117,7 @@ void AbstractSceneConverterTest::thingNotSupported() {
converter.add({image3D, image3D});
converter.add({compressedImage3D, compressedImage3D});
CORRADE_COMPARE(out.str(),
CORRADE_COMPARE_AS(out.str(),
"Trade::AbstractSceneConverter::convert(): mesh conversion not supported\n"
"Trade::AbstractSceneConverter::convertInPlace(): mesh conversion not supported\n"
"Trade::AbstractSceneConverter::convertToData(): mesh conversion not supported\n"
@ -1123,6 +1133,8 @@ void AbstractSceneConverterTest::thingNotSupported() {
"Trade::AbstractSceneConverter::setDefaultScene(): feature not supported\n"
"Trade::AbstractSceneConverter::add(): animation conversion not supported\n"
"Trade::AbstractSceneConverter::setAnimationTrackTargetName(): feature not supported\n"
"Trade::AbstractSceneConverter::add(): light conversion not supported\n"
"Trade::AbstractSceneConverter::add(): camera conversion not supported\n"
"Trade::AbstractSceneConverter::add(): 2D skin conversion not supported\n"
@ -1148,7 +1160,8 @@ void AbstractSceneConverterTest::thingNotSupported() {
"Trade::AbstractSceneConverter::add(): 3D image conversion not supported\n"
"Trade::AbstractSceneConverter::add(): compressed 3D image conversion not supported\n"
"Trade::AbstractSceneConverter::add(): multi-level 3D image conversion not supported\n"
"Trade::AbstractSceneConverter::add(): multi-level compressed 3D image conversion not supported\n");
"Trade::AbstractSceneConverter::add(): multi-level compressed 3D image conversion not supported\n",
TestSuite::Compare::String);
}
void AbstractSceneConverterTest::thingLevelsNotSupported() {
@ -2582,6 +2595,7 @@ void AbstractSceneConverterTest::thingNoBegin() {
converter.animationCount();
converter.add(AnimationData{nullptr, nullptr});
converter.setAnimationTrackTargetName({}, {});
converter.lightCount();
converter.add(LightData{LightType::Point, {}, 0.0f});
@ -2637,6 +2651,7 @@ void AbstractSceneConverterTest::thingNoBegin() {
"Trade::AbstractSceneConverter::animationCount(): no conversion in progress\n"
"Trade::AbstractSceneConverter::add(): no conversion in progress\n"
"Trade::AbstractSceneConverter::setAnimationTrackTargetName(): no conversion in progress\n"
"Trade::AbstractSceneConverter::lightCount(): no conversion in progress\n"
"Trade::AbstractSceneConverter::add(): no conversion in progress\n"
@ -3080,6 +3095,67 @@ void AbstractSceneConverterTest::addAnimationNotImplemented() {
CORRADE_COMPARE(out.str(), "Trade::AbstractSceneConverter::add(): animation conversion advertised but not implemented\n");
}
void AbstractSceneConverterTest::setAnimationTrackTargetName() {
struct: AbstractSceneConverter {
SceneConverterFeatures doFeatures() const override {
return SceneConverterFeature::ConvertMultiple|
SceneConverterFeature::AddAnimations;
}
bool doBegin() override { return true; }
void doSetAnimationTrackTargetName(AnimationTrackTarget target, Containers::StringView name) override {
CORRADE_COMPARE(target, animationTrackTargetCustom(1337));
CORRADE_COMPARE(name, "hello!");
setAnimationTrackTargetNameCalled = true;
}
bool setAnimationTrackTargetNameCalled = false;
} converter;
CORRADE_VERIFY(true); /* capture correct function name */
CORRADE_VERIFY(converter.begin());
converter.setAnimationTrackTargetName(animationTrackTargetCustom(1337), "hello!");
CORRADE_VERIFY(converter.setAnimationTrackTargetNameCalled);
}
void AbstractSceneConverterTest::setAnimationTrackTargetNameNotImplemented() {
struct: AbstractSceneConverter {
SceneConverterFeatures doFeatures() const override {
return SceneConverterFeature::ConvertMultiple|
SceneConverterFeature::AddAnimations;
}
bool doBegin() override { return true; }
} converter;
/* This should work, there's no need for a plugin to implement this */
CORRADE_VERIFY(converter.begin());
converter.setAnimationTrackTargetName(animationTrackTargetCustom(1337), "hello!");
CORRADE_VERIFY(true);
}
void AbstractSceneConverterTest::setAnimationTrackTargetNameNotCustom() {
CORRADE_SKIP_IF_NO_ASSERT();
struct: AbstractSceneConverter {
SceneConverterFeatures doFeatures() const override {
return SceneConverterFeature::ConvertMultiple|
SceneConverterFeature::AddAnimations;
}
bool doBegin() override { return true; }
} converter;
CORRADE_VERIFY(converter.begin());
std::ostringstream out;
Error redirectError{&out};
converter.setAnimationTrackTargetName(AnimationTrackTarget::Scaling2D, "hello!");
CORRADE_COMPARE(out.str(), "Trade::AbstractSceneConverter::setAnimationTrackTargetName(): Trade::AnimationTrackTarget::Scaling2D is not custom\n");
}
void AbstractSceneConverterTest::addLight() {
struct: AbstractSceneConverter {
SceneConverterFeatures doFeatures() const override {

Loading…
Cancel
Save