Bläddra i källkod

Fix: Weights don't match targets in Arm. Constrt.

the problem was caused by forgetting to sort the links
this is really bad, I should refactor things Mantis could have a set of
SortArrayInputs and automatically do this for me
Joseph Brandenburg 1 vecka sedan
förälder
incheckning
32e4e465a8
3 ändrade filer med 18 tillägg och 9 borttagningar
  1. 13 9
      link_nodes.py
  2. 4 0
      misc_nodes.py
  3. 1 0
      versioning.py

+ 13 - 9
link_nodes.py

@@ -781,29 +781,33 @@ class LinkArmature(MantisLinkNode):
             #       are all in the same armature
             # Mantis should intelligently provide a working armature constraint
             # even if the user supplies targets that would not work in vanilla Blender
-            # TODO find out this is reading the arrays in reverse order? is that bad?
             targets_weights = {}
+            # NOTE: Mantis does not generally sort links because it is slow
+            #       so it is the responsibility of array types to do this.
+            from .base_definitions import links_sort_key
+            for inp in {'Targets', 'Weights'}:
+                self.inputs[inp].links.sort(key=links_sort_key)
             for i in range(num_targets):
                 target = c.targets.new()
                 self.get_target_and_subtarget(target, 'Targets', i)
                 weight_value=self.evaluate_input("Weights", i)
-                if not isinstance(weight_value, float):
-                    weight_value=0
-                targets_weights[i]=weight_value
-                from .mantis_dataclasses import MantisSocketFiller
                 default_value = 1.0
                 if self.inputs['Weights'].links:
                     default_value = 1/len(self.inputs['Weights'].links)
+                if not isinstance(weight_value, float):
+                    weight_value=default_value
+                targets_weights[i]=weight_value
+                from .mantis_dataclasses import MantisSocketFiller
+                property_group=f"target.{str(i).zfill(4)}"
                 prop_name = 'weight'
-                # prop_name = f"targets[{i}].weight"
                 filler = MantisSocketFiller(
-                    property_group = f"target.{str(i).zfill(4)}",
+                    property_group = property_group,
                     property_name = prop_name,
                     socket_name = "Weights",
                     array_index=i,
-                    default_value=default_value,
+                    default_value=weight_value,
                 )
-                b_objects[f"target.{str(i).zfill(4)}"] = target
+                b_objects[property_group] = target
                 props_sockets[prop_name+str(i)] = filler
             evaluate_sockets(self, b_objects, props_sockets)
             for target, value in targets_weights.items():

+ 4 - 0
misc_nodes.py

@@ -922,6 +922,10 @@ class UtilityFCurve(MantisMiscNode):
             keys.append( self.evaluate_input('Keyframes', i) )
         if len(keys) <1:
             prOrange(f"WARN: no keys in fCurve {self}.")
+        # IT IS VERY IMPORTANT to sort the links
+        from .base_definitions import links_sort_key
+        for inp in {'Keyframes'}:
+            self.inputs[inp].links.sort(key=links_sort_key)
         keys.append(extrap_mode)
         self.parameters["fCurve"] = keys
         self.prepared = True

+ 1 - 0
versioning.py

@@ -22,6 +22,7 @@ from .utilities.utilities import (prRed, prGreen, prPurple, prWhite,
 # (add more whenever a weird or difficult to debug problem occurs)
 # Did you check the update script on a tree that doesn't need it?
 # Did you use a >= when you should have used a > (or similar)?
+# Did you make sure that nodes with array inputs are sorting them properly?
 
 def version_upgrade_very_old(*args, **kwargs):
     node = kwargs['node']