1 #include "bones/weight.hpp"
2 #include "container_component.hpp"
3 #include "shapes/path_vertex.hpp"
7 StatusCode Weight::onAddedDirty(CoreContext* context)
9 StatusCode code = Super::onAddedDirty(context);
10 if (code != StatusCode::Ok)
14 if (!parent()->is<PathVertex>())
16 return StatusCode::MissingObject;
19 parent()->as<PathVertex>()->weight(this);
21 return StatusCode::Ok;
24 static int encodedWeightValue(unsigned int index, unsigned int data)
26 return (data >> (index * 8)) & 0xFF;
29 void Weight::deform(float x,
34 const float* boneTransforms,
37 float xx = 0, xy = 0, yx = 0, yy = 0, tx = 0, ty = 0;
38 float rx = world[0] * x + world[2] * y + world[4];
39 float ry = world[1] * x + world[3] * y + world[5];
40 for (int i = 0; i < 4; i++)
42 int weight = encodedWeightValue(i, weights);
48 float normalizedWeight = weight / 255.0f;
49 int index = encodedWeightValue(i, indices);
50 int startBoneTransformIndex = index * 6;
51 xx += boneTransforms[startBoneTransformIndex++] * normalizedWeight;
52 xy += boneTransforms[startBoneTransformIndex++] * normalizedWeight;
53 yx += boneTransforms[startBoneTransformIndex++] * normalizedWeight;
54 yy += boneTransforms[startBoneTransformIndex++] * normalizedWeight;
55 tx += boneTransforms[startBoneTransformIndex++] * normalizedWeight;
56 ty += boneTransforms[startBoneTransformIndex++] * normalizedWeight;
58 result[0] = xx * rx + yx * ry + tx;
59 result[1] = xy * rx + yy * ry + ty;