scan ALL objects for constraints targeting orig

This commit is contained in:
Nathan
2026-03-13 15:45:07 -06:00
parent 991fd07f9e
commit 038537186c
2 changed files with 167 additions and 3 deletions
@@ -199,3 +199,164 @@ The code was inserted after the armature modifiers section and before the next f
---
_**User**_
summarize this change in 72 characters or less.
---
_**Agent (model kimi-k2.5, mode Agent)**_
<think><details><summary>Thought Process</summary>
The user wants a summary of the change I just made in 72 characters or less. This is the change I made to the migrator.py file where I added camera DOF focus_object retargeting.
Let me think about a concise summary:
- Added camera DOF focus_object retargeting to migrator
- Camera DOF focus_object now retargets during migration
- Fix: camera DOF focus_object retargeted from orig to rep
I need to keep it under 72 characters. Let me check:
"Added camera DOF focus_object retargeting to migrator." = 50 characters - good!
"Camera DOF focus_object now retargets during migration." = 55 characters - good!
"Fix: camera DOF focus_object retargeted from orig to rep." = 58 characters - good!
I'll go with something clear and concise.</details></think>
---
Added camera DOF focus_object retargeting to migrator run_retarg_relatives.
---
_**User**_
I had another character whose eyes were constrained via `Copy Location` to the origchar, but retargrelatives didn't retarget this constraint. Let's make it do so.
---
_**Agent (model kimi-k2.5, mode Agent)**_
<think><details><summary>Thought Process</summary>
The user is saying that a character's eyes have a "Copy Location" constraint that targets the origchar, but the retargetrelatives function didn't retarget this constraint. Let me look at the `run_retarg_relatives` function to understand how it handles constraints and see what might be missing.
Let me read the relevant parts of the migrator.py file to understand the current constraint handling logic.</details></think>
---
Let me examine the current constraint retargeting logic in `run_retarg_relatives`.
---
<tool-use data-tool-type="read" data-tool-name="read_file_v2">
<details><summary>Tool use: **read_file_v2** • Read file: T:/Dynamic-Link-Manager/ops/migrator.py</summary>
</details>
</tool-use>
---
<think><details><summary>Thought Process</summary>
The current code looks for objects that either:
1. Have a parent that is the original armature
2. Have constraints where `c.target == orig`
It then adds those objects to the `candidates` set and retargets their constraints.
The issue is that the eyes are likely objects in the original character's hierarchy (children of the armature), so they get excluded by `candidates -= orig_hierarchy` on line 481.
Looking at the candidates building logic:
- It starts with `rep_descendants` (objects under the replacement character)
- It adds objects that are parented to orig or have constraints targeting orig
- Then it removes `orig_hierarchy` (the original character and all its descendants)
The eye objects are probably in the original character's hierarchy (children/descendants of the armature), so they get filtered out.
The solution is to also scan ALL objects in the scene for constraints targeting orig, not just the candidates. The current logic only retargets constraints on the candidates set, which excludes objects in orig's hierarchy.
Let me modify the function to retarget constraints on ALL objects, not just the candidates.</details></think>
---
I see the issue. The current code builds a `candidates` set and then filters out `orig_hierarchy` (line 481). The eyes are likely objects in the original character's hierarchy (children of the armature), so they get excluded and their constraints aren't retargeted.
The fix is to scan ALL objects for constraints targeting orig, not just the candidates set.
---
<tool-use data-tool-type="write" data-tool-name="edit_file_v2">
<details><summary>Tool use: **edit_file_v2** • Edit file: T:/Dynamic-Link-Manager/ops/migrator.py</summary>
</details>
</tool-use>
---
<think><details><summary>Thought Process</summary>
Good, I separated the constraint retargeting to scan all objects instead of just the candidates. This means that even objects in the original character's hierarchy (like eyes with Copy Location constraints) will have their constraints retargeted.
Let me verify the change and check for any linter errors.</details></think>
---
<tool-use data-tool-type="unknown" data-tool-name="read_lints">
<details>
<summary>Tool use: **read_lints**</summary>
Parameters:
```json
{
"paths": [
"T:/Dynamic-Link-Manager/ops/migrator.py"
]
}
```
Result:
```json
{
"linterErrorsByFile": [
{
"relativeWorkspacePath": "T:/Dynamic-Link-Manager/ops/migrator.py"
}
]
}
```
Status: **completed**
</details>
</tool-use>
---
<think><details><summary>Thought Process</summary>
No linter errors. Let me verify the change looks correct.</details></think>
---
<tool-use data-tool-type="read" data-tool-name="read_file_v2">
<details><summary>Tool use: **read_file_v2** • Read file: T:/Dynamic-Link-Manager/ops/migrator.py</summary>
</details>
</tool-use>
---
<think><details><summary>Thought Process</summary>
The fix looks good. The constraint retargeting is now separate from the candidates loop and scans all objects in the scene. This means that even objects in the original character's hierarchy (like eyes with Copy Location constraints) will have their constraints retargeted properly.</details></think>
---
Fixed. The issue was that constraint retargeting was only applied to `candidates - orig_hierarchy`, which excluded objects in the original character's hierarchy (like eyes).
Now the constraint retargeting (lines 490-494) scans ALL objects in the scene, so Copy Location constraints on eyes or any other object targeting the original armature will be properly retargeted to the replacement.
---
+6 -3
View File
@@ -482,14 +482,17 @@ def run_retarg_relatives(orig, rep, rep_descendants, orig_to_rep):
for ob in candidates:
if ob.parent == orig:
ob.parent = rep
for c in getattr(ob, "constraints", []):
if getattr(c, "target", None) == orig:
c.target = rep
if ob.type == "MESH" and ob.modifiers:
for m in ob.modifiers:
if getattr(m, "object", None) == orig:
m.object = rep
# Retarget constraints on ALL objects (including orig hierarchy like eyes)
for ob in bpy.data.objects:
for c in getattr(ob, "constraints", []):
if getattr(c, "target", None) == orig:
c.target = rep
# Camera DOF: retarget focus_object from orig to rep
for ob in bpy.data.objects:
if ob.type != 'CAMERA':