WIP: Replace copy weights to selected op with data transfer #107695

Draft
Daniel Salazar wants to merge 2 commits from zanqdo/blender:transfer-vertex-groups into main

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

In the past Blender used to store vgroups in objects, not in meshes. The object.vertex_group_copy_to_selected() operator was meant to sync between linked duplicates by replacing all the selected objects vgroups with the active object ones (deleting all existing vgroups in the process).

Nowadays this functionality is not so useful since vgroups are stored in meshes (and hence shared between duplicates) and is quite dangerous to have it such readily available in the vertex group menu.

image

Not only that but the name is misleading since it implies it copies only the active vertex group. In reality it copies all vertex groups.

I've replaced the operator with 2 properly configured object_data_transfer() operators. The first one copies only the active vertex group to the selected objects, the second one copies all vertex groups to the selected objects.

image

The main difference is that this operation does not delete existing vgroups in the selected objects.

Same as before the transfer can only happen with matching vertex ids. For more complex transfers there's always the Object Transfer menu.

image

In the past Blender used to store vgroups in objects, not in meshes. The object.vertex_group_copy_to_selected() operator was meant to sync between linked duplicates by replacing all the selected objects vgroups with the active object ones (deleting all existing vgroups in the process). Nowadays this functionality is not so useful since vgroups are stored in meshes (and hence shared between duplicates) and is quite dangerous to have it such readily available in the vertex group menu. ![image](/attachments/182cc636-95f4-4cca-90c8-2aaa9a9b5191) Not only that but the name is misleading since it implies it copies only the active vertex group. In reality it copies all vertex groups. I've replaced the operator with 2 properly configured object_data_transfer() operators. The first one copies only the active vertex group to the selected objects, the second one copies all vertex groups to the selected objects. ![image](/attachments/e7699860-77e0-40d2-af9a-42d64e28fae4) The main difference is that this operation does not delete existing vgroups in the selected objects. Same as before the transfer can only happen with matching vertex ids. For more complex transfers there's always the Object Transfer menu. ![image](/attachments/3873c1db-f3e1-4e17-9c26-ab4461154346)
Daniel Salazar added 1 commit 2023-05-07 02:00:40 +02:00
Daniel Salazar added this to the Animation & Rigging project 2023-05-07 02:06:33 +02:00
Member

Hi, change looks correct to me.
Not sure why this tagged with Animation & Rigging module.
@HooglyBoogly , can you check?

Hi, change looks correct to me. Not sure why this tagged with `Animation & Rigging` module. @HooglyBoogly , can you check?
Member

Does it makes sense to remove the vertex_group_copy_to_selected operator in 4.0 then? If it's redundant or dangerous anyway.

The existing operator could also be modified to skip changing the name lists if the object data is the same, just like it does already for the weight data. In that sense this PR is a combination of a new feature and a fix that makes it sort of hard to review.

Does it makes sense to remove the `vertex_group_copy_to_selected` operator in 4.0 then? If it's redundant or dangerous anyway. The existing operator could also be modified to skip changing the name lists if the object data is the same, just like it does already for the weight data. In that sense this PR is a combination of a new feature and a fix that makes it sort of hard to review.
Author
Member

One thing that I don't like of the current patch is the tooltip of the operator is too generic since it's the tooltip of the massive Data Transfer operator. Not sure how to solve that.

One thing that I don't like of the current patch is the tooltip of the operator is too generic since it's the tooltip of the massive Data Transfer operator. Not sure how to solve that.
Daniel Salazar added 1 commit 2023-05-12 23:40:56 +02:00
Daniel Salazar changed title from Replace copy to selected op with data transfer to WIP: Replace copy to selected op with data transfer 2023-05-15 23:26:59 +02:00
Daniel Salazar requested review from Sybren A. Stüvel 2023-05-15 23:34:26 +02:00
Author
Member

It was commented in #blender-coders that:

If you're still looking for a way to dynamically set an operator's tooltip in python, you can define a description classmethod in your operator to return a different tooltip based on some criteria:
https://docs.blender.org/api/3.6/bpy.types.Operator.html#bpy.types.Operator.description

I believe this is what I need to set a proper tooltip for the operator in this context. But I might need some help @dr.sybren !

It was commented in #blender-coders that: > If you're still looking for a way to dynamically set an operator's tooltip in python, you can define a description classmethod in your operator to return a different tooltip based on some criteria: > https://docs.blender.org/api/3.6/bpy.types.Operator.html#bpy.types.Operator.description I believe this is what I need to set a proper tooltip for the operator in this context. But I might need some help @dr.sybren !
Sybren A. Stüvel added the
Module
Animation & Rigging
label 2023-06-22 11:09:01 +02:00

It was commented in #blender-coders that:

If you're still looking for a way to dynamically set an operator's tooltip in python, you can define a description classmethod in your operator to return a different tooltip based on some criteria:
https://docs.blender.org/api/3.6/bpy.types.Operator.html#bpy.types.Operator.description

I believe this is what I need to set a proper tooltip for the operator in this context. But I might need some help @dr.sybren !

Yeah, that's not really going to help here because this operator is not made in Python ;-)

You'd have to change data_transfer_get_description() in source/blender/editors/object/object_data_transfer.c for that.
I can help with that, if you give me the texts needed, and some logic of when to use which text. Then I can turn that into C code.

> It was commented in #blender-coders that: > > > If you're still looking for a way to dynamically set an operator's tooltip in python, you can define a description classmethod in your operator to return a different tooltip based on some criteria: > > https://docs.blender.org/api/3.6/bpy.types.Operator.html#bpy.types.Operator.description > > I believe this is what I need to set a proper tooltip for the operator in this context. But I might need some help @dr.sybren ! Yeah, that's not really going to help here because this operator is not made in Python ;-) You'd have to change `data_transfer_get_description()` in `source/blender/editors/object/object_data_transfer.c` for that. I can help with that, if you give me the texts needed, and some logic of when to use which text. Then I can turn that into C code.
Author
Member

You'd have to change data_transfer_get_description() in source/blender/editors/object/object_data_transfer.c for that.
I can help with that, if you give me the texts needed, and some logic of when to use which text. Then I can turn that into C code.

Thank you. In the case it is used within the Vertex Group menu, the text should be:

Transfer the vertex groups of the active object to the selected objects based on topology

> You'd have to change `data_transfer_get_description()` in `source/blender/editors/object/object_data_transfer.c` for that. > I can help with that, if you give me the texts needed, and some logic of when to use which text. Then I can turn that into C code. Thank you. In the case it is used within the Vertex Group menu, the text should be: _Transfer the vertex groups of the active object to the selected objects based on topology_
Daniel Salazar changed title from WIP: Replace copy to selected op with data transfer to WIP: Replace copy weights to selected op with data transfer 2023-08-04 20:18:53 +02:00

Thank you. In the case it is used within the Vertex Group menu, the text should be:

Is that in all cases where .data_type = "VGROUP_WEIGHTS"?

The operator has no knowledge of where it is actually being used, it can only respond to the property values.

Just in case the answer is "yeah, that's it", this change should do the trick:

diff --git a/source/blender/editors/object/object_data_transfer.cc b/source/blender/editors/object/object_data_transfer.cc
index 034a52983cd..abdba127875 100644
--- a/source/blender/editors/object/object_data_transfer.cc
+++ b/source/blender/editors/object/object_data_transfer.cc
@@ -651,6 +651,13 @@ static std::string data_transfer_get_description(bContext * /*C*/,
         "Transfer data layer(s) (weights, edge sharp, etc.) from selected meshes to active one");
   }
 
+  const int data_type = RNA_enum_get(ptr, "data_type");
+  if (data_type == DT_TYPE_MDEFORMVERT) {
+    return TIP_(
+        "Transfer the vertex groups of the active object to the selected objects based on "
+        "topology");
+  }
+
   return "";
 }
 
> Thank you. In the case it is used within the Vertex Group menu, the text should be: Is that in all cases where `.data_type = "VGROUP_WEIGHTS"`? The operator has no knowledge of where it is actually being used, it can only respond to the property values. Just in case the answer is "yeah, that's it", this change should do the trick: ```diff diff --git a/source/blender/editors/object/object_data_transfer.cc b/source/blender/editors/object/object_data_transfer.cc index 034a52983cd..abdba127875 100644 --- a/source/blender/editors/object/object_data_transfer.cc +++ b/source/blender/editors/object/object_data_transfer.cc @@ -651,6 +651,13 @@ static std::string data_transfer_get_description(bContext * /*C*/, "Transfer data layer(s) (weights, edge sharp, etc.) from selected meshes to active one"); } + const int data_type = RNA_enum_get(ptr, "data_type"); + if (data_type == DT_TYPE_MDEFORMVERT) { + return TIP_( + "Transfer the vertex groups of the active object to the selected objects based on " + "topology"); + } + return ""; } ```

@zanqdo poke that there's still an unanswered question in my comment above ;-)

@zanqdo poke that there's still an unanswered question in my comment above ;-)
Author
Member

@zanqdo poke that there's still an unanswered question in my comment above ;-)

I think that implementation makes sense so yes from me!

Does it makes sense to remove the vertex_group_copy_to_selected operator in 4.0 then? If it's redundant or dangerous anyway.

Probably a decision for later. Wouldn't like to break addons based on this.

> @zanqdo poke that there's still an unanswered question in my comment above ;-) I think that implementation makes sense so yes from me! > Does it makes sense to remove the `vertex_group_copy_to_selected` operator in 4.0 then? If it's redundant or dangerous anyway. Probably a decision for later. Wouldn't like to break addons based on this.
Daniel Salazar closed this pull request 2024-03-26 18:07:13 +01:00
Daniel Salazar reopened this pull request 2024-03-26 18:07:28 +01:00
This pull request is marked as a work in progress.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u transfer-vertex-groups:zanqdo-transfer-vertex-groups
git checkout zanqdo-transfer-vertex-groups
Sign in to join this conversation.
No reviewers
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 Assignees
4 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#107695
No description provided.