GSoC 2021: Continued Development on Adaptive Cloth Simulator for Blender: Weekly Reports

Week 01

  • Went through and updated notes related to the cloth simulator and
    the modifiers.
  • Had a discussion with @ZedDB on whether to make the remeshing step a
    separate modifier or to integrate it directly with the cloth
    modifier. Came to the conclusion that creating a new modifier and
    having it work well with the cloth modifier (or any future modifier
    that depends on this new modifier) might take up too much time and
    may not be possible to complete within the time limits of GSoC. Thus
    the remeshing step will be directly integrated with the cloth
    modifier.
  • Converted the cloth modifier from an only deform (deformVerts)
    modifier to a non constructive (modifyMesh) modifier (still need
    to add back support for Dynamic Meshes and Hair simulation).
  • Started work on a better test suite than that made in 2019.

Plan for following week

  • Work on the new Mesh structure needed for the remeshing step.
  • Continue work on the test suite.
8 Likes

Week 02

  • Created a new container (with respective tests), a generational
    arena. Each element has an associated “generation” so indexing is
    done via a special structure Index which contains the location of
    the element as well as the generation when the Index was generated
    aka when an element in inserted. Deleting an element involves
    marking the element in the array as empty, updating a list which
    stores the next free location and incrementing the generation. When
    inserting an element, it checks if any free locations exist and
    makes the necessary changes to the array and the list of free
    locations. With a generational arena, inserting and deleting
    elements is O(1), and elements are accessed via Index avoiding the
    “ABA problem” (in multi-threaded and single-threaded workloads).

    For the mesh structure, generational arena allows for adding
    references to other elements by storing Index instead of working
    with pointers. This leads to less error prone code, allows for
    faster debugging, all while maintaining run time speed similar to
    that of using raw pointers.

  • Created the basic classes needed for the mesh structure based on
    “Adjacency and incidence framework: a data structure for efficient
    and fast management of multiresolution meshes” by Frutuoso
    G. M. Silva and Abel J. P. Gomes (GRAPHITE '03) with some
    changes. Documentation for this is ongoing.

Plan for following week

  • Continue work on the mesh structure.
    • Add a conversion to and from Blender’s DNA Mesh.
    • Start work on mesh operations like- split edge, collapse edge,
      flip edge.
10 Likes

Week 03

  • Added iterator support to the generational arena.

  • The new mesh structure is now complete. The mesh operations can now
    be worked on.

  • Added a new method to interface with other mesh
    structures/files. This makes it easier for conversion between
    different mesh structures due to the simplicity of the MeshIO
    structure.

  • Added support for loading from and saving to Wavefront OBJ for
    easier debugging.

  • Test cases for each of the above.

  • Created notes about DNA Mesh.

Plan for following week

  • Continue work on the mesh structure.
    • Add a conversion to and from Blender’s DNA Mesh.
    • Start work on mesh operations like- split edge, collapse edge,
      flip edge.
11 Likes

Week 04

  • MeshIO now supports reading from and writing to DNA Mesh.

    • Adding tests for this was challenging.
      • Creating a DNA Mesh is not possible without initializing
        idtype using BKE_idtype_init() (there should actually be a
        check for this, at least in debug mode).
      • BM_mesh_bm_to_me() and BKE_mesh_from_bmesh_eval_nomain() can
        be used to convert BMesh to DNA Mesh. The CustomData
        blocks stored in the BMesh are copied over but for some
        reason, BMesh does not update the blocks corresponding to
        mvert, mloop, mpoly, etc. during the operations on BMesh
        (for which I had used BMO_op_callf()). This leads to the newly
        formed DNA Mesh to have incorrect values in mvert, mloop,
        mpoly, etc. One way to fix this is to create a copy of the
        BMesh, which internally initializes the blocks correctly, and
        using the copy to convert to DNA Mesh. This method is not
        ideal but since this is only in the test suite, it should be
        good enough.
  • Mesh and MeshIO now support loose edges.

  • The cloth modifier now creates and returns a new Mesh only if
    needed.

  • Started work on the mesh operations.

    • MeshDiff class will be returned for every operation
      • In the future, adaptive remesh is going to need to know which
        elements were updated (added or deleted) during the operation,
        thus each operation should return the updated elements via the
        MeshDiff class.

Plan for following week

  • Continue work on mesh operations like- split edge, collapse edge,
    flip edge.
  • Start work on the remeshing step.
8 Likes

Hi, @ish_bosamiya
I’m trying to know more about this project and I’m very surprised! This is very exciting, thank you for bringing this to blender.
I’m still trying to understand this project but is this quoted text related to the cloth tearing effect?

EDIT
I just saw in the proposal under benefits that you mention Adaptive Cloth Tearing for this year.
Thank you so much! This is very exciting!
Is the branch compileable and ready for test?

2 Likes

Week 05

  • Added support to add new elements (Node, Vert, Edge, Face) with
    interpolated values
  • Added support to delete elements
    • Deletes the element and updates the elements that refer to this
      element
    • First version worked but if the deletion of the elements was not
      thought through at each step, it could every easily lead to
      crashes.
    • A second, significantly better version ensures that deletion of
      the elements is allowed to be done in a safe manner to reduce
      potential crashes.
  • Fixed a critical bug in the generational arena
    • the begin() function of the arena, before the fix, could give an
      element that doesn’t exist leading to a crash.
  • In a new modifier, created some GUI options to help test the mesh
    operations more easily.
    • For those who are compiling this branch, checkout the
      Adaptive Remesh modifier.
    • Side note, this will not be a modifier available in master, this
      is only for my personal testing. (Check week 01 report for reasons
      why).
  • Split edge done
    • This mesh operation splits the given edge and ensures
      triangulation of the faces around the edge remains after the
      operation as well.
    • This is done by creating a new vert and node by interpolating the
      edge verts and nodes. Then new triangulated faces and edges are
      created and the correct references between the various elements
      affected by this operation are created.
    • Since Edge stores Vert and not Node, this operation will
      split the edge/face in UV space but not in the world space. For
      this, an option across_seams, if true, will consider edge nodes
      instead of edge verts only which is often the desired result.
  • De-duplication of elements
    • DNA Mesh stores UVs per loop which can lead to duplication of
      the UVs. If the UVs are not de-duplicated correctly, it can lead
      to extra elements in Mesh so mesh operations may not work as
      expected.
  • Handle gaps created in the Arena of nodes, verts during the mesh
    operations
    • Certain mesh operations can lead to gaps in the Arena, this
      leads to wrong indexing of the elements when converting Mesh to
      MeshIO. For this, a Map of the generational arena Index to
      positional index needs to be created during the conversion
      process.
  • Collapse edge
    • This mesh operation collapses the given edge and ensures
      triangulation of the faces around the edge remains after the
      operation as well.
    • Ran into trouble with the first version of the delete elements
      implementation thus the second version of the delete elements was
      born.
    • Currently there is a bug where collapsing the edge from v1 to v2
      leads to a crash because the faces that remain have only 1 vert
      but collapsing from v2 to v1 works perfectly.

Plan for following week

  • Continue work on mesh operations like- collapse edge, flip edge.
  • Start work on the remeshing step.
6 Likes

Hello @EvertonSchneider !

It is nice to see the community is excited about this project as I am :slight_smile:

The mesh operations will definitely help with the cloth tearing functionality but this is currently out of scope as I have mentioned in my project proposal. Currently, these mesh operations are for adding adaptive remeshing support which will help with getting higher quality simulations without the expense of simulating a very dense mesh and having to manually tweak the mesh topology to prevent that stair stepping effect and other artifacts.

Yes, the branch should be compile but as of now, it is purely in the development stage so no features to test. Hopefully within the next 2-3 weeks, you should have something fun to test.

Let further discussion on this topic happen on the feedback/discussion thread.

7 Likes

Week 06

  • Collapse edge
    • Rewrote from scratch to allow collapsing of edges across seams.
  • Flip edge
    • This mesh operation flips an edge to the other verts of the quad
      formed by the triangles. The operation is not allowed if the edge
      is on a seam or boundary.
    • The operation is done by deleting and adding new elements instead
      of just adjusting the references of the elements since the
      remeshing operations will need to know which elements were
      affected by the operation. This does not have any negative hit on
      performance since the Mesh utilizes generational arenas. So after
      deletion of an element, a new element is added at the same
      location but with a different generation not requiring any
      reallocation of memory.
  • Fix rare bug in split edge
    • An edge reference is broken rarely due to a reallocation of memory
      which can lead to access of memory which is no longer valid.
  • float2x2
    • Created this new class based on float4x4.
    • This is needed by the “Sizing” field of the verts.
  • Static remeshing
    • Started work on static remeshing which will then be extended to
      dynamic remeshing.
    • Created the necessary structures which will be used in the future.

Plan for following week

  • Continue work on static remeshing.
  • Hope to start work on dynamic remeshing.
5 Likes