浏览代码

Fix: Bone parenting works

before there was no attempt to trace backward through the tree to find the parent. the parent was requested in Edit mode for some reason. and because the armature was posed, the inverse matrix was all wrong. All of that is fixed, and as a bonus, it should fix automatic weight painting, too.
also fix object parenting, which was checking if the mantis node was a Blender Obejct and trying to set the parent to the node.
Joseph Brandenburg 9 月之前
父节点
当前提交
acb0fb6ac6
共有 2 个文件被更改,包括 27 次插入16 次删除
  1. 3 2
      readtree.py
  2. 24 14
      xForm_containers.py

+ 3 - 2
readtree.py

@@ -625,13 +625,12 @@ def execute_tree(nodes, base_tree, context):
     if (active):
         with context.temp_override(**{'active_object':active, 'selected_objects':switch_me}):
             bpy.ops.object.mode_set(mode='POSE')
-    
 
     for n in executed:
         n.bPrepare(context)
         if not n.executed:
             n.bExecute(context)
-    
+
     for n in executed:
         n.bFinalize(context)
 
@@ -644,6 +643,8 @@ def execute_tree(nodes, base_tree, context):
     if (active):
         with context.temp_override(**{'active_object':active, 'selected_objects':switch_me}):
             bpy.ops.object.mode_set(mode='OBJECT')
+    for ob in switch_me:
+        ob.data.pose_position = 'POSE'
     tot_time = (time() - start_execution_time)
     prGreen(f"Executed tree of {len(executed)} nodes in {tot_time} seconds")
     if (original_active):

+ 24 - 14
xForm_containers.py

@@ -145,6 +145,7 @@ class xFormArmature:
             
         self.bObject = ob.name
         ob.matrix_world = matrix.copy()
+        ob.data.pose_position = 'REST'
         
         # # first, get the parent object
         # parent_node = get_parent(self)
@@ -886,20 +887,29 @@ class xFormGeometryObject:
         from bpy.types import Object, Bone
         parent_nc = get_parent(self, type='LINK')
         if (parent_nc):
-            #TODO: this is a lazy HACK that will lead to many a BUG. FIXME.
-            parent = parent_nc.inputs['Parent'].links[0].from_node # <===
-            parent_bOb = parent.bGetObject(mode = 'EDIT')
-            if isinstance(parent_bOb, Bone):
-                armOb= parent.bGetParentArmature()
-                ob.parent = armOb
-                ob.parent_type = 'BONE'
-                ob.parent_bone = parent_bOb.name
-            elif isinstance(parent, Object):
-                ob.parent = parent
-            # blender will do the matrix math for me IF I set the world
-            #   matrix after setting the parent.
-            #
-            # deal with parenting settings here, if necesary
+            parent = None
+            if self.inputs["Relationship"].is_linked:
+                trace = trace_single_line(self, "Relationship")
+                for node in trace[0]:
+                    if node is self: continue # lol
+                    if (node.node_type == 'XFORM'):
+                        parent = node; break
+                if parent is None:
+                    raise GraphError(f"Could not set parent for {self}")
+
+                parent_bOb = parent.bGetObject(mode = 'OBJECT')
+                if parent_bOb is None:
+                    raise GraphError(f"Could not get parent object  for {self}")
+                
+                print (parent_bOb.__class__.__name__)
+
+                if isinstance(parent_bOb, Bone):
+                    armOb= parent.bGetParentArmature()
+                    ob.parent = armOb
+                    ob.parent_type = 'BONE'
+                    ob.parent_bone = parent_bOb.name
+                elif isinstance(parent_bOb, Object):
+                    ob.parent = parent_bOb
 
     def bPrepare(self, bContext = None,):
         import bpy