Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
93acbe9
AssimpImporter: import animations
pezcode Jun 18, 2021
2b2f7d7
AssimpImporter: animation import docs
pezcode Jun 20, 2021
88ffee3
AssimpImporter: warn about having to patch glTF animation speed
pezcode Jun 20, 2021
65ba86e
AssimpImporter: fix whitespaces
pezcode Jun 20, 2021
e1ed0a2
AssimpImporter: detect and warn about possibly broken spline-interpol…
pezcode Jun 20, 2021
ccb0689
AssimpImporter: fix warnings
pezcode Jun 20, 2021
f23782e
AssimpImporter: review feedback
pezcode Jun 23, 2021
08e1867
AssimpImporter: only assert on unknown target node name
pezcode Jun 23, 2021
e5e7823
AssimpImporter: ignore dummy tracks inserted by Assimp
pezcode Jun 23, 2021
15647cc
AssimpImporter: add animation tests
pezcode Jun 23, 2021
07ea683
AssimpImporter: add test files
pezcode Jun 23, 2021
29e71ea
AssimpImporter: oops
pezcode Jun 24, 2021
e9f8508
AssimpImporter: update list of test files for corrade_add_test
pezcode Jun 24, 2021
fd58c6b
AssimpImporter: lowercase checkAssimpVersion.cpp
pezcode Jun 24, 2021
95c0385
AssimpImporter: add config value for dummy animation track removal
pezcode Jun 25, 2021
4784218
AssimpImporter: mention (missing) test coverage for aiAnimBehaviour
pezcode Jun 25, 2021
fecf7c1
AssimpImporter: make missing animation target node an internal assert
pezcode Jun 25, 2021
b2cedc3
AssimpImporter: uses stridedArrayView directly
pezcode Jun 25, 2021
5cee73d
AssimpImporter: don't test all possible glTF file types
pezcode Jun 25, 2021
5c26211
AssimpImporter: use EXPECT_FAIL to document known bugs
pezcode Jun 25, 2021
9afb329
AssimpImporter: test removeDummyAnimationTracks
pezcode Jun 25, 2021
4203a8f
AssimpImporter: begone, std::tuple!
pezcode Jun 25, 2021
91166ce
AssimpImporter: use StringView for extension comparison
pezcode Jun 25, 2021
498d653
AssimpImporter: forgot to check for glTF support in some tests
pezcode Jun 26, 2021
bd1eff9
AssimpImporter: don't assume fixed animation channel order
pezcode Jun 27, 2021
0a64f20
AssimpImporter: test dummy track removal a bit more rigorously
pezcode Jun 27, 2021
9c3e7c5
AssimpImporter: test player output in animation()
pezcode Jun 27, 2021
c56079b
AssimpImporter: oops
pezcode Jun 27, 2021
ae5b7be
AssimpImporter: test Collada rotation
pezcode Jun 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/MagnumPlugins/AssimpImporter/AssimpImporter.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ provides=XglImporter
# Controls the workaround for an Assimp 4.1 "white ambient" bug
forceWhiteAmbientToBlack=true

# Optimize imported linearly-interpolated quaternion animation tracks to
# ensure shortest path is always chosen. This can be controlled separately for
# each animation import.
optimizeQuaternionShortestPath=true

# Normalize quaternion animation tracks, if they are not already.
# This can be controlled separately for each animation import.
normalizeQuaternions=true

# Merge all animations into a single clip. Useful for preserving cinematic
# animations when using the Blender glTF exporter, as it exports animation of
# every object as a separate clip. See https://blender.stackexchange.com/q/5689
# and https://github.com/KhronosGroup/glTF-Blender-Exporter/pull/166 for more
# information.
mergeAnimationClips=false

# Remove dummy animation tracks inserted by Assimp that contain only a single
# key/value pair with the default node transformation
removeDummyAnimationTracks=true

# AI_CONFIG_* values, can be changed only before the first file is opened
ImportColladaIgnoreUpDirection=false

Expand Down
372 changes: 364 additions & 8 deletions src/MagnumPlugins/AssimpImporter/AssimpImporter.cpp

Large diffs are not rendered by default.

56 changes: 53 additions & 3 deletions src/MagnumPlugins/AssimpImporter/AssimpImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ See @ref building-plugins, @ref cmake-plugins, @ref plugins and

@section Trade-AssimpImporter-behavior Behavior and limitations

The plugin supports @ref ImporterFeature::OpenData and
@ref ImporterFeature::FileCallback features. The Assimp library loads
The plugin supports @ref ImporterFeature::OpenData, @ref ImporterFeature::OpenState
and @ref ImporterFeature::FileCallback features. The Assimp library loads
everything during initial import, meaning all external file loading callbacks
are called with @ref InputFileCallbackPolicy::LoadTemporary and the resources
can be safely freed right after the @ref openData() / @ref openFile() function
Expand All @@ -197,13 +197,57 @@ with @ref InputFileCallbackPolicy::LoadTemporary and
@ref InputFileCallbackPolicy::Close is emitted right after the file is fully
read.

Import of animation data is not supported at the moment.
Import of skeleton, skin and morph data is not supported at the moment.

The importer recognizes @ref ImporterFlag::Verbose, enabling verbose logging
in Assimp when the flag is enabled. However please note that since Assimp
handles logging through a global singleton, it's not possible to have different
verbosity levels in each instance.

@subsection Trade-AssimpImporter-behavior-animation Animation import

- Assimp sometimes adds dummy animation tracks with a single key-value pair
and the default node transformation. If found, the importer removes these dummy
tracks and prints a message if verbose logging is enabled. Can be disabled
per-animation with the @cb{.ini} removeDummyAnimationTracks @ce option, see
@ref Trade-AssimpImporter-configuration "below".
- Channel order within animations is not always preserved
by Assimp, depending on file type and compiler. You may have to manually
order tracks by type and target after importing.
- Quaternion rotation tracks are postprocessed in order to make it
possible to use the faster
@ref Math::lerp(const Quaternion<T>&, const Quaternion<T>&, T) "Math::lerp()" /
@ref Math::slerp(const Quaternion<T>&, const Quaternion<T>&, T) "Math::slerp()"
functions instead of
@ref Math::lerpShortestPath(const Quaternion<T>&, const Quaternion<T>&, T) "Math::lerpShortestPath()" /
@ref Math::slerpShortestPath(const Quaternion<T>&, const Quaternion<T>&, T) "Math::slerpShortestPath()". Can be disabled per-animation with the
@cb{.ini} optimizeQuaternionShortestPath @ce option, see
@ref Trade-AssimpImporter-configuration "below".
- If quaternion rotation tracks are not normalized, the importer
prints a warning and normalizes them. Can be disabled per-animation with
the @cb{.ini} normalizeQuaternions @ce option, see
@ref Trade-AssimpImporter-configuration "below".
- Skeletons and skins are not supported
- Morph targets are not supported
- Animation tracks are always imported with
@ref Animation::Interpolation::Linear, because Assimp doesn't expose
any interpolation modes
- Animation tracks using `aiAnimBehaviour_DEFAULT` or `aiAnimBehaviour_REPEAT`
fall back to using @ref Animation::Extrapolation::Constant
- It's possible to request all animation clips to be merged into one using
the @cb{.ini} mergeAnimationClips @ce option in order to for example
preserve cinematic animations when using the Blender glTF exporter (as it
otherwise outputs a separate clip for each object). When this option is
enabled, @ref animationCount() always report either @cpp 0 @ce or
@cpp 1 @ce and the merged animation has no name. With this option enabled,
however, it can happen that multiple conflicting tracks affecting the same
node are merged in the same clip, causing the animation to misbehave.
- Assimp versions before commit [e3083c21f0a7beae6c37a2265b7919a02cbf83c4](https://github.com/assimp/assimp/commit/e3083c21f0a7beae6c37a2265b7919a02cbf83c4)
read spline-interpolated glTF animation tracks incorrectly and produce broken
animations. A warning is printed when importing glTF animations on these versions.
Because it's impossible to detect the actual brokenness, the warning is
printed even if the imported data may be correct.

@subsection Trade-AssimpImporter-behavior-materials Material import

- Only materials with shading mode `aiShadingMode_Phong` are supported
Expand Down Expand Up @@ -326,6 +370,7 @@ importer state methods:
- @ref LightData::importerState() returns `aiLight`
- @ref ImageData2D::importerState() may return `aiTexture`, if texture was embedded
into the loaded file.
- @ref AnimationData::importerState() returns `aiAnimation`
- @ref openState() expects a pointer to an Assimp scene (i.e., `const aiScene*`)
and optionally a path (in order to be able to load textures, if needed)

Expand Down Expand Up @@ -401,6 +446,11 @@ class MAGNUM_ASSIMPIMPORTER_EXPORT AssimpImporter: public AbstractImporter {
MAGNUM_ASSIMPIMPORTER_LOCAL UnsignedInt doImage2DLevelCount(UnsignedInt id) override;
MAGNUM_ASSIMPIMPORTER_LOCAL Containers::Optional<ImageData2D> doImage2D(UnsignedInt id, UnsignedInt level) override;

MAGNUM_ASSIMPIMPORTER_LOCAL UnsignedInt doAnimationCount() const override;
MAGNUM_ASSIMPIMPORTER_LOCAL std::string doAnimationName(UnsignedInt id) override;
MAGNUM_ASSIMPIMPORTER_LOCAL Int doAnimationForName(const std::string& name) override;
MAGNUM_ASSIMPIMPORTER_LOCAL Containers::Optional<AnimationData> doAnimation(UnsignedInt id) override;

MAGNUM_ASSIMPIMPORTER_LOCAL const void* doImporterState() const override;

Containers::Pointer<Assimp::Importer> _importer;
Expand Down
25 changes: 25 additions & 0 deletions src/MagnumPlugins/AssimpImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,38 @@ endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/configure.h)

# Go through all versions of interest and pick the highest one that compiles
foreach(_version 20201123 20190915 20151031)
try_compile(_works ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/checkAssimpVersion.cpp
LINK_LIBRARIES Assimp::Assimp
COMPILE_DEFINITIONS
-DCHECK_VERSION=${_version}
# I thought I could make this use C++11 by linking to
# Corrade::Utility, but for some reason the effect of the
# CORRADE_CXX_STANDARD property doesn't get passed through. So I
# have to use an internal variable for that instead.
${CORRADE_CXX11_STANDARD_FLAG}
OUTPUT_VARIABLE _version_output)
if(_works)
set(ASSIMP_VERSION ${_version})
break()
endif()
endforeach()
if(NOT ASSIMP_VERSION)
message(SEND_ERROR "Could not detect Assimp version. Maybe even older than 3.2? ${_version_output}")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configureInternal.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/configureInternal.h)

# AssimpImporter plugin
add_plugin(AssimpImporter
"${MAGNUM_PLUGINS_IMPORTER_DEBUG_BINARY_INSTALL_DIR};${MAGNUM_PLUGINS_IMPORTER_DEBUG_LIBRARY_INSTALL_DIR}"
"${MAGNUM_PLUGINS_IMPORTER_RELEASE_BINARY_INSTALL_DIR};${MAGNUM_PLUGINS_IMPORTER_RELEASE_LIBRARY_INSTALL_DIR}"
AssimpImporter.conf
AssimpImporter.cpp
AssimpImporter.h)
target_include_directories(AssimpImporter PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
if(MAGNUM_ASSIMPIMPORTER_BUILD_STATIC AND BUILD_STATIC_PIC)
set_target_properties(AssimpImporter PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
Expand Down
Loading