• Runtimes
  • Get bone world scale

I'm trying to get the world scale of a bone (exactly what I can see by selecting relative to world axis in the editor), but the C++ runtime seems to only have a way to get the magnitude (positive value) of the scale through getWorldScaleX/Y. What should I do to get the actual, signed world scale?

Related Discussions
...
  • Modificato

To obtain the world scale of a bone in the Spine C++ runtime, you can use the getWorldScaleX and getWorldScaleY methods. These methods provide the scale of a bone in world space relative to the world space x-axis and y-axis, respectively. However, if you need the signed scale, you should ensure that the local scale and any transformations applied to the bone are considered. The world scale is computed based on the local scale and the transformations of parent bones, so you may need to manually calculate the sign by considering the local scale and any rotations that might affect the sign of the scale.

If the getWorldScaleX and getWorldScaleY methods are returning only positive values, you might need to check the local scale and the hierarchy of transformations to determine the correct sign. This involves understanding how the local transformations are applied and how they propagate through the bone hierarchy.

The best you can do is look at the sign of all the parent bones' scale, eg:

float worldScaleX = bone.getWorldScaleX();
while (bone != null) {
	sign *= bone.getScaleX() < 0 ? -1 : 1;
	bone = bone.getParent();
}