Fix #105409: vertex interpolation corrupts Alembic mesh #105867

Closed
Kévin Dietrich wants to merge 4 commits from kevindietrich:abc_topology_fix_3.5 into blender-v3.6-release

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

The Alembic data streaming can optionally interpolate between vertex of
two adjacent frames in order to smooth out the transition between
frames.

However, the decision to interpolate is only based on the vertex count.
This is not too robust as topology/connectivity can still differ even if
the number of vertices is the same (for example physics simulations and
videogrammetry can be set to output the same vertex count, but optimize
the triangle placement). This lead to vertices of unrelated polygons
being interpolated across frames.

To fix this, we now also check if the connectivity across frames is the
same, instead of just checking the topology counters. Although the bug
is revealed by the vertex interpolation routine, a similar fix is applied
to the check on topology change used to decide if the modifier has to be
evaluated.

The Alembic data streaming can optionally interpolate between vertex of two adjacent frames in order to smooth out the transition between frames. However, the decision to interpolate is only based on the vertex count. This is not too robust as topology/connectivity can still differ even if the number of vertices is the same (for example physics simulations and videogrammetry can be set to output the same vertex count, but optimize the triangle placement). This lead to vertices of unrelated polygons being interpolated across frames. To fix this, we now also check if the connectivity across frames is the same, instead of just checking the topology counters. Although the bug is revealed by the vertex interpolation routine, a similar fix is applied to the check on topology change used to decide if the modifier has to be evaluated.
Kévin Dietrich added the
Interest
Alembic
label 2023-03-17 23:25:54 +01:00
Kévin Dietrich requested review from Sybren A. Stüvel 2023-03-17 23:26:18 +01:00

I would guess Alembic does not store multiples samples of face counts and indices if the topology is the same for the entire animation? If so, this could avoid the overhead of comparison when .getNumSamples() == 1. Or maybe it could check if the array data pointers are equal.

I would guess Alembic does not store multiples samples of face counts and indices if the topology is the same for the entire animation? If so, this could avoid the overhead of comparison when `.getNumSamples() == 1`. Or maybe it could check if the array data pointers are equal.
Brecht Van Lommel reviewed 2023-03-18 00:28:10 +01:00
@ -469,0 +486,4 @@
}
/* Otherwise, we need to check the connectivity as files from e.g. videogrammetry may have the
* same face count, but different connexions between faces. */

connexions -> connections

connexions -> connections
brecht marked this conversation as resolved
@ -469,0 +502,4 @@
return false;
}
}
}

memcmp of the arrays would be a bit faster?

`memcmp` of the arrays would be a bit faster?
brecht marked this conversation as resolved
Brecht Van Lommel requested changes 2023-03-20 12:15:05 +01:00
@ -469,0 +488,4 @@
/* Otherwise, we need to check the connectivity as files from e.g. videogrammetry may have the
* same face count, but different connections between faces. */
if (memcmp(face_counts->get(), ceil_face_counts->get(), face_counts->size() * sizeof(int))) {

Could the pointers be compared here as well to speed things up in case they are the same?

if (face_counts->get() != ceil_face_counts->get() &&
    memcmp(face_counts->get(), ceil_face_counts->get(), face_counts->size() * sizeof(int))) {
    return false;
}
Could the pointers be compared here as well to speed things up in case they are the same? ``` if (face_counts->get() != ceil_face_counts->get() && memcmp(face_counts->get(), ceil_face_counts->get(), face_counts->size() * sizeof(int))) { return false; } ```
brecht marked this conversation as resolved
@ -675,0 +714,4 @@
}
/* Check first if we indeed have multiple samples. */
if (m_schema.getFaceIndicesProperty().getNumSamples() == 1 &&

I guess this does not work for a sequence of Alembic files, only for a single file that contains the full animation? Or is that a different code path?

I guess this does not work for a sequence of Alembic files, only for a single file that contains the full animation? Or is that a different code path?
brecht marked this conversation as resolved
Kévin Dietrich reviewed 2023-03-20 14:47:02 +01:00
@ -469,0 +488,4 @@
/* Otherwise, we need to check the connectivity as files from e.g. videogrammetry may have the
* same face count, but different connections between faces. */
if (memcmp(face_counts->get(), ceil_face_counts->get(), face_counts->size() * sizeof(int))) {
Author
Member

I did try that originally but did not notice any difference with or without. Although, we could argue that not having an explicit check on our side is betting on the implementation of memcmp. I would venture that any serious implementation of memcmp would return 0 if the pointers are the same.

I did try that originally but did not notice any difference with or without. Although, we could argue that not having an explicit check on our side is betting on the implementation of memcmp. I would venture that any serious implementation of memcmp would return 0 if the pointers are the same.
brecht marked this conversation as resolved
@ -469,3 +501,4 @@
static void read_mesh_sample(const std::string &iobject_full_name,
ImportSettings *settings,
const IPolyMeshSchema &schema,
Author
Member

Just to note, memcmp gives about 1-2 fps speedup in the file from the bug report (~150k faces).

Just to note, `memcmp` gives about 1-2 fps speedup in the file from the bug report (~150k faces).
brecht marked this conversation as resolved
@ -675,0 +714,4 @@
}
/* Check first if we indeed have multiple samples. */
if (m_schema.getFaceIndicesProperty().getNumSamples() == 1 &&
Author
Member

You're right, and there is no different code path for files sequences, so this may break; I did not think of that case. I do have some Alembic file sequences, so I can use those to correct the logic.

You're right, and there is no different code path for files sequences, so this may break; I did not think of that case. I do have some Alembic file sequences, so I can use those to correct the logic.
brecht marked this conversation as resolved
Brecht Van Lommel reviewed 2023-03-20 14:49:50 +01:00
@ -469,0 +488,4 @@
/* Otherwise, we need to check the connectivity as files from e.g. videogrammetry may have the
* same face count, but different connections between faces. */
if (memcmp(face_counts->get(), ceil_face_counts->get(), face_counts->size() * sizeof(int))) {

From this, it doesn't seem like something we should rely on:
https://stackoverflow.com/a/58305477

From this, it doesn't seem like something we should rely on: https://stackoverflow.com/a/58305477
brecht marked this conversation as resolved
Sybren A. Stüvel approved these changes 2023-04-17 16:52:18 +02:00
Sybren A. Stüvel left a comment
Member

Apart from what @brecht already said, the PR looks good to me.
Accepting so that the patch can be landed once Brecht also approves.

Apart from what @brecht already said, the PR looks good to me. Accepting so that the patch can be landed once Brecht also approves.
Kévin Dietrich force-pushed abc_topology_fix_3.5 from 1357054eeb to e8ea03e793 2023-06-14 13:13:19 +02:00 Compare
Kévin Dietrich changed title from Fix #105409: vertex interpolation corrupts Alembic mesh to Fix #105409: vertex interpolation corrupts Alembic mesh 2023-06-14 13:13:32 +02:00
kevindietrich changed target branch from blender-v3.5-release to blender-v3.6-release 2023-06-14 13:13:43 +02:00
Kévin Dietrich changed title from Fix #105409: vertex interpolation corrupts Alembic mesh to Fix #105409: vertex interpolation corrupts Alembic mesh 2023-06-14 13:13:55 +02:00
Author
Member

Sorry for the delayed update.

If a file sequence is being read, then we do a full topology comparison.

In order to detect if a file sequence is read, a new member is added to the base AbcObjectReader class, which is initialized when constructing a new reader. Technically, this information is alredy stored in ImportSettings which is already stored in the class, however, it is a pointer to some stack memory (either the stack from the import job, or the stack from CacheReader_open_alembic_object). This will need to be solved at some point (some of my other patches will remove the need for this object). CacheReader_open_alembic_object also had to be modified to take an extra parameter to tell if the CacheFile is a sequence.

Sorry for the delayed update. If a file sequence is being read, then we do a full topology comparison. In order to detect if a file sequence is read, a new member is added to the base AbcObjectReader class, which is initialized when constructing a new reader. Technically, this information is alredy stored in ImportSettings which is already stored in the class, however, it is a pointer to some stack memory (either the stack from the import job, or the stack from CacheReader_open_alembic_object). This will need to be solved at some point (some of my other patches will remove the need for this object). CacheReader_open_alembic_object also had to be modified to take an extra parameter to tell if the CacheFile is a sequence.
Brecht Van Lommel approved these changes 2023-06-14 13:18:46 +02:00
Brecht Van Lommel left a comment
Owner

Thanks, looks good now.

Thanks, looks good now.
Kévin Dietrich closed this pull request 2023-06-15 03:41:54 +02:00

Pull request closed

Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#105867
No description provided.