Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssimpImporter: import skin data #99

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f6c6443
AssimpImporter: expose mesh names
pezcode Jul 2, 2021
91bb9d2
AssimpImporter: fix internal animation state pointer
pezcode Jul 2, 2021
ac8b6d8
AssimpImporter: tell Assimp not to create skeleton visualizer meshes
pezcode Jul 3, 2021
ed1f38f
AssimpImporter: import skin data
pezcode Jul 3, 2021
3ac6e4a
AssimpImporter: import joint weight mesh attributes
pezcode Jul 3, 2021
0c4d3d8
AssimpImporter: some extra tests
pezcode Jul 3, 2021
9868b63
AssimpImporter: enable aiProcess_LimitBoneWeights implicitly
pezcode Jul 4, 2021
8d8a7f9
AssimpImporter: use the same custom attribute id for all layers
pezcode Jul 4, 2021
53abe78
AssimpImporter: de-duplicate joints for mergeSkins
pezcode Jul 4, 2021
5880d34
AssimpImporter: set MeshObjectData3D::skin
pezcode Jul 6, 2021
3bf82b0
AssimpImporter: test skin inverse bind matrices
pezcode Jul 6, 2021
f13b516
AssimpImporter: ignore dummy joint weights
pezcode Jul 6, 2021
cf89adb
AssimpImporter: set correct skin in MeshObjectData3D if mergeSkins is…
pezcode Jul 6, 2021
bd76ce1
AssimpImporter: test joint weight attribute
pezcode Jul 6, 2021
ee731d5
AssimpImporter: test mergeSkins
pezcode Jul 7, 2021
79adfe3
AssimpImporter: test joint weight mesh attributes
pezcode Jul 7, 2021
4a1aa40
AssimpImporter: update test files
pezcode Jul 7, 2021
dbe741f
AssimpImporter: really?
pezcode Jul 7, 2021
306b36b
AssimpImporter: fix typo
pezcode Jul 7, 2021
a6199d9
AssimpImporter: test dummy weight removal
pezcode Jul 7, 2021
733e14d
AssimpImporter: no need to check for these
pezcode Jul 7, 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
11 changes: 11 additions & 0 deletions src/MagnumPlugins/AssimpImporter/AssimpImporter.conf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ mergeAnimationClips=false
# key/value pair with the default node transformation
removeDummyAnimationTracks=true

# Maximum amount of joint weights per vertex to import as vertex attributes.
# A value of 0 disables any limit, any other value implicitly enables
# aiProcess_LimitBoneWeights. This can be changed only before the first file
# is opened.
maxJointWeights=4
pezcode marked this conversation as resolved.
Show resolved Hide resolved

# Merge all skins into a single skin. Since Assimp exposes one skin for each
# mesh with joint weights, this is useful for getting a single skin covering
# all meshes in the file. This can only be controlled on a per-file basis.
mergeSkins=false

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

Expand Down
288 changes: 271 additions & 17 deletions src/MagnumPlugins/AssimpImporter/AssimpImporter.cpp

Large diffs are not rendered by default.

40 changes: 34 additions & 6 deletions src/MagnumPlugins/AssimpImporter/AssimpImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ with @ref InputFileCallbackPolicy::LoadTemporary and
@ref InputFileCallbackPolicy::Close is emitted right after the file is fully
read.

Import of skeleton, skin and morph data is not supported at the moment.
Import of 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
Expand Down Expand Up @@ -228,7 +228,6 @@ verbosity levels in each instance.
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
Expand All @@ -250,6 +249,18 @@ verbosity levels in each instance.
these versions.
Because it's impossible to detect the actual brokenness, the warning is
printed even if the imported data may be correct.
- Original skins are not exposed by Assimp, instead each mesh with joint
weights produces its own skin. Skin names will be equal to their
corresponding mesh names. A consequence of this is that Assimp only
imports joint weight attributes for one skin and ignores all other
skins targetting the same mesh.
- You can request to merge all mesh skins into one using the
@cb{.ini} mergeSkins @ce option. Duplicate joints (same object index and
inverse bind matrix) will be merged and joint ids in vertex attributes
adjusted accordingly. When this option is enabled,
@ref skinCount() always report either @cpp 0 @ce or @cpp 1 @ce and
the merged skin has no name. This option needs to be set before opening
a file because it affects skin as well as mesh loading.

@subsection Trade-AssimpImporter-behavior-materials Material import

Expand Down Expand Up @@ -287,9 +298,6 @@ verbosity levels in each instance.
- Custom mesh attributes (such as `object_id` in Stanford PLY files) are
not imported.
- Texture coordinate layers with other than two components are skipped
- For some file formats (such as COLLADA), Assimp may create a dummy
"skeleton visualizer" mesh if the file has no mesh data. For others (such
as glTF) not.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed by setting AI_CONFIG_IMPORT_NO_SKELETON_MESHES, but there's another comment down below in the Scene import section ("[...] there's sometimes just a single root node") which I'm not sure about. The node collapsing doesn't happen anymore with this setting (the test got adapted accordingly), but I wonder if this is the only circumstance where this happens.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- Per-face attributes in Stanford PLY files are not imported.
- Stanford PLY files that contain a comment before the format line fail to
import.
Expand All @@ -302,6 +310,14 @@ verbosity levels in each instance.
- The imported model always has either both @ref MeshAttribute::Tangent
@ref MeshAttribute::Bitangent or neither of them, tangents are always
three-component with binormals separate.
- Joint Ids and weights for skinning are imported as custom vertex attributes
named "JOINTS" and "WEIGHTS" with formats @ref VertexFormat::Vector4ui and
@ref VertexFormat::Vector4, respectively. Imported meshes always have
either both or neither of them. Their mapping to/from a string can be
queried using @ref meshAttributeName() and @ref meshAttributeForName().
By default, the number of weights per vertex is limited to 4, but you can
change this limit by setting the @cb{.ini} maxJointWeights @ce option,
see @ref Trade-AssimpImporter-configuration "below".
- Multi-mesh nodes and multi-primitive meshes are loaded as follows,
consistently with the behavior of @link TinyGltfImporter @endlink:
- Multi-primitive meshes are split by Assimp into individual meshes
Expand Down Expand Up @@ -373,7 +389,10 @@ 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 AnimationData::importerState() returns `aiAnimation`, or `nullptr` if the
@cb{.ini} mergeAnimationClips @ce option is enabled
- @ref SkinData::importerState() returns `aiMesh`, or `nullptr` if the
@cb{.ini} mergeSkins @ce option is enabled
- @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 @@ -433,7 +452,11 @@ class MAGNUM_ASSIMPIMPORTER_EXPORT AssimpImporter: public AbstractImporter {
MAGNUM_ASSIMPIMPORTER_LOCAL Containers::Optional<LightData> doLight(UnsignedInt id) override;

MAGNUM_ASSIMPIMPORTER_LOCAL UnsignedInt doMeshCount() const override;
MAGNUM_ASSIMPIMPORTER_LOCAL Int doMeshForName(const std::string& name) override;
MAGNUM_ASSIMPIMPORTER_LOCAL std::string doMeshName(UnsignedInt id) override;
MAGNUM_ASSIMPIMPORTER_LOCAL Containers::Optional<MeshData> doMesh(UnsignedInt id, UnsignedInt level) override;
MAGNUM_ASSIMPIMPORTER_LOCAL MeshAttribute doMeshAttributeForName(const std::string& name) override;
MAGNUM_ASSIMPIMPORTER_LOCAL std::string doMeshAttributeName(UnsignedShort name) override;

MAGNUM_ASSIMPIMPORTER_LOCAL UnsignedInt doMaterialCount() const override;
MAGNUM_ASSIMPIMPORTER_LOCAL Int doMaterialForName(const std::string& name) override;
Expand All @@ -454,6 +477,11 @@ class MAGNUM_ASSIMPIMPORTER_EXPORT AssimpImporter: public AbstractImporter {
MAGNUM_ASSIMPIMPORTER_LOCAL Int doAnimationForName(const std::string& name) override;
MAGNUM_ASSIMPIMPORTER_LOCAL Containers::Optional<AnimationData> doAnimation(UnsignedInt id) override;

MAGNUM_ASSIMPIMPORTER_LOCAL UnsignedInt doSkin3DCount() const override;
MAGNUM_ASSIMPIMPORTER_LOCAL Int doSkin3DForName(const std::string& name) override;
MAGNUM_ASSIMPIMPORTER_LOCAL std::string doSkin3DName(UnsignedInt id) override;
MAGNUM_ASSIMPIMPORTER_LOCAL Containers::Optional<SkinData3D> doSkin3D(UnsignedInt id) override;

MAGNUM_ASSIMPIMPORTER_LOCAL const void* doImporterState() const override;

Containers::Pointer<Assimp::Importer> _importer;
Expand Down
Loading