GPv3: Delete duplicated frames #114182

Open
opened 2023-10-26 22:29:52 +02:00 by Pratik Borhade · 5 comments
Member

Delete next keyframe if its duplicate of current keyframe

  • Define GREASE_PENCIL_OT_frame_clean_duplicate in grease_pencil_frames.cc
  • Add boolean operator property selected to remove selected/all frames
  • Loop all the layers, in every layer run a loop for every single frame: for (frame : layer.frames().items()) (might need values() or index based for loop (i = 0; i < frame_size; i++)
  • With the current keyframe, also retrieve next keyframe
  • If selected is true, run following code when frame.is_selected()
  • Get geometry:
    • Get drawing_index from frame number: layer->drawing_index_at(frame_number);
    • Use drawing_index to get active drawing: grease_pencil.drawing(drawing_index)
    • Get geometry: bke::CurvesGeometry &geometry = drawing.strokes_for_write();
  • Verify whether content of both keyframes are same
  • Check for curve, point count (points_num(), curves_num())
  • Check whether attributes are same: attributes.for_all()
Delete next keyframe if its duplicate of current keyframe - Define `GREASE_PENCIL_OT_frame_clean_duplicate` in `grease_pencil_frames.cc` - Add boolean operator property `selected` to remove selected/all frames - Loop all the layers, in every layer run a loop for every single frame: `for (frame : layer.frames().items())` (might need `values()` or index based for loop `(i = 0; i < frame_size; i++)` - With the current keyframe, also retrieve next keyframe - If `selected` is true, run following code when `frame.is_selected()` - Get geometry: - Get drawing_index from frame number: `layer->drawing_index_at(frame_number);` - Use drawing_index to get active drawing: `grease_pencil.drawing(drawing_index)` - Get geometry: `bke::CurvesGeometry &geometry = drawing.strokes_for_write();` - Verify whether content of both keyframes are same - Check for curve, point count (`points_num(), curves_num()`) - Check whether attributes are same: `attributes.for_all()`
Pratik Borhade added the
Priority
Normal
Module
Grease Pencil
Type
To Do
labels 2023-10-26 22:30:39 +02:00
Pratik Borhade added this to the Grease Pencil project 2023-10-26 22:30:54 +02:00

I would love to help with this task, but I wanted to check with you first if you would consider it a good task for someone who is contributing to Blender for the first time. From the description it seems simple enough and, given that I have C/C++ experience and have already built Blender from source a couple of times before, I believe I will be able to do it, but I just want to confirm this with you before I start working on it.

I would love to help with this task, but I wanted to check with you first if you would consider it a good task for someone who is contributing to Blender for the first time. From the description it seems simple enough and, given that I have C/C++ experience and have already built Blender from source a couple of times before, I believe I will be able to do it, but I just want to confirm this with you before I start working on it.
Author
Member

@amsaid1989 hi, this task seems good for someone contributing for the first time.

@amsaid1989 hi, this task seems good for someone contributing for the first time.

@PratikPB2123 Great.. thank you very much.. I will give it a go and ask on the chat if I need any help

@PratikPB2123 Great.. thank you very much.. I will give it a go and ask on the chat if I need any help
Member

I'm going to add some more details to this part: "Verify whether content of both keyframes are same"

I suggest to write a static function like this:

static bool curves_geometry_is_equal(const CurvesGeometry &curves_a, const CurvesGeometry &curves_b)

First we do the easy checks (number of points and number of curves):

if (curves_a.curves_num() != curves_b.curves_num() || curves_a.points_num() != curves_b.points_num()) {
   return false;
}

Second, we check if the curve offsets are all the same:

if (curves_a.offsets() != curves_b.offsets()) {
   return false;
}

Third, we check if the set of attributes are the same (this does not check the values in the attributes, just if the number of attributes are the same and the ids match):

const bke::AttributeAccessor attributes_a = curves_a.attributes();
const bke::AttributeAccessor attributes_b = curves_b.attributes();
const Set<AttributeIDRef> ids_a = attributes_a.all_ids();
const Set<AttributeIDRef> ids_b = attributes_b.all_ids();
if (ids_a != ids_b) {
  return false;
}

Finally, we check if all the attributes have the same values:

  • We know attributes_a == attributes_b at this point so we can just iterate over one of them like
for (const AttributeIDRef &id : attributes_a)
  • We get the GVArray from both geometies
const GVArray &values_a = *attributes_a.lookup(id);
  • First, check the sizes (.size()) and return false if they aren't the same
  • Then, get the types const CPPType &type_a = values_a.type() and make sure they are the same, otherwise return false.
  • Loop over arrays using IndexRange(values_a.size())
  • Use type.is_equal_or_false(values_a[i], values_b[i]) to compare the individual values. And again, when this is false, return

In the end we can return true.

I'm going to add some more details to this part: "Verify whether content of both keyframes are same" I suggest to write a `static` function like this: ``` static bool curves_geometry_is_equal(const CurvesGeometry &curves_a, const CurvesGeometry &curves_b) ``` First we do the easy checks (number of points and number of curves): ``` if (curves_a.curves_num() != curves_b.curves_num() || curves_a.points_num() != curves_b.points_num()) { return false; } ``` Second, we check if the curve offsets are all the same: ``` if (curves_a.offsets() != curves_b.offsets()) { return false; } ``` Third, we check if the set of attributes are the same (this does not check the values in the attributes, just if the number of attributes are the same and the ids match): ``` const bke::AttributeAccessor attributes_a = curves_a.attributes(); const bke::AttributeAccessor attributes_b = curves_b.attributes(); const Set<AttributeIDRef> ids_a = attributes_a.all_ids(); const Set<AttributeIDRef> ids_b = attributes_b.all_ids(); if (ids_a != ids_b) { return false; } ``` Finally, we check if all the attributes have the same values: * We know `attributes_a == attributes_b` at this point so we can just iterate over one of them like ``` for (const AttributeIDRef &id : attributes_a) ``` * We get the `GVArray` from both geometies ``` const GVArray &values_a = *attributes_a.lookup(id); ``` * First, check the sizes (`.size()`) and return `false` if they aren't the same * Then, get the types `const CPPType &type_a = values_a.type()` and make sure they are the same, otherwise return `false`. * Loop over arrays using `IndexRange(values_a.size())` * Use `type.is_equal_or_false(values_a[i], values_b[i])` to compare the individual values. And again, when this is false, return In the end we can `return true`.

Hey @filedescriptor. I've implemented most of what you included in your description, however, there is one thing that I haven't figured out yet.

GVArray doesn't implement operator[]. There are 2 overloads of the get() method, but I haven't figured out how to use either of them. This means that I am currently stuck implementing the last point in your description:

  • Use type.is_equal_or_false(values_a[i], values_b[i]) to compare the individual values. And again, when this is false, return

I would appreciate your help here.

Hey @filedescriptor. I've [implemented](https://projects.blender.org/amsaid1989/blender/src/commit/7d24286c0465ad489f1c5e588866f451dba059e3/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc#L369-L488) most of what you included in your description, however, there is one thing that I haven't figured out yet. `GVArray` doesn't implement `operator[]`. There are 2 overloads of the `get()` method, but I haven't figured out how to use either of them. This means that I am currently stuck implementing the last point in your description: >- Use `type.is_equal_or_false(values_a[i], values_b[i])` to compare the individual values. And again, when this is false, return I would appreciate your help here.
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#114182
No description provided.