• Runtimes
  • VertexAttachment property : vertices

Related Discussions
...

I am working on a brand new Spine+Physics engine (irrelevant). Anyhow, I am trying to figure out what exactly vertices property contains in the case where there are bone influences.

The API reference says:

vertices: float[] from VertexAttachment
The vertex positions in the bone's coordinate system. For a non-weighted attachment, the values are x,y entries for each vertex. For a weighted attachment, the values are x,y,weight entries for each bone affecting each vertex.

Unfortunately I haven't found any character (from the Unity examples) that has vertex attachment (bounding or mesh) with bone influences. So, from the API text I imagine this e.g.:

VertexAttachment with 3 bone influences and 4 vertices. In this case, vertices contains:
x1,y1,w11,w12,w13, x2,y2,w21,w22,w23, x3,y3,w31,w32,w33, x4,y4,w41,w42,w43
Is this correct?
And what is the worldVerticesLength? 6?

If anyone can share an example with vertex-bone-influences I will be happy to figure out myself. Thank you!

EDIT:

The above is obviously wrong. I have checked the relevant code in SkeletonJson.c but I can't figure it out:

attachment->verticesCount = 0;
attachment->bonesCount = 0;
for (i = 0; i < entrySize;) {
   int bonesCount = (int)vertices[i];
   attachment->bonesCount += 1 + bonesCount;
   attachment->verticesCount += 3 * bonesCount;
   i += 1 + bonesCount * 4;
}

???

Check out the Raptor example, e.g. the mesh "raptor_arm_back" is a weighted, deformed mesh (many more in raptor) spine-runtimes/examples/raptor at master. Alternatively I'd suggest to setup a simple Spine project with one unweighted mesh and a weighted mesh, each with one or two triangles, then export to JSON. That will make writting your Spine+Physics engine much easier.

I did just that, one mesh attachment consisting of 2 triangles without weights, and another mesh attachment consisting of 2 triangles weighted to a single bone. Here's the resulting JSON:

"skins": {
   "default": {
      "Screen Shot 2017-03-23 at 10.37.37 AM2": {
         "Screen Shot 2017-03-23 at 10.37.37 AM": {
            "type": "mesh",
            "uvs": [ 1, 1, 0, 1, 0, 0, 1, 0 ],
            "triangles": [ 1, 2, 3, 1, 3, 0 ],
            "vertices": [ -108.05, -161.57, -110.32, 160.04, 108.05, 161.57, 110.32, -160.04 ],
            "hull": 4,
            "edges": [ 0, 2, 2, 4, 4, 6, 0, 6 ],
            "width": 595,
            "height": 404
         }
      },
      "Screen Shot 2017-03-23 at 10.37.37 AM3": {
         "Screen Shot 2017-03-23 at 10.37.37 AM": {
            "type": "mesh",
            "uvs": [ 1, 1, 0, 1, 0, 0, 1, 0 ],
            "triangles": [ 1, 2, 3, 1, 3, 0 ],
            "vertices": [ 1, 2, 177.1, -120.25, 1, 1, 2, -177.1, -120.25, 1, 1, 2, -177.1, 120.25, 1, 1, 2, 177.1, 120.25, 1 ],
            "hull": 4,
            "edges": [ 0, 2, 2, 4, 4, 6, 0, 6 ],
            "width": 595,
            "height": 404
         }
      }
   }
},

For the unweighted mesh, the vertices property is pretty trivial. It's simple a list of vertices, each vertex encoded as an x/y coordinate.

For the weighted mesh, the vertices property works like this:

"vertices": [ 1, <- number of bones influencing this vertex
2, <- index of first bone influencing that vertex
177.1, -120.25,  <- x/Y coordinate of this vertex
1, <- weight of first bone influencing

1, 2, -177.1, -120.25, 1, 

1, 2, -177.1, 120.25, 1, 1, 2, 177.1, 120.25, 1 ],

So the format per vertex in a weighted mesh is:

  1. Number of bones influencing this vertex (let's call this number #bones)

  2. List of #bones bone indices influencing this vertex

  3. Vertex x/y coordinate

  4. List of #bones bone weights

badlogic wrote

Check out the Raptor example, e.g. the mesh "raptor_arm_back" is a weighted, deformed mesh (many more in raptor) spine-runtimes/examples/raptor at master. Alternatively I'd suggest to setup a simple Spine project with one unweighted mesh and a weighted mesh, each with one or two triangles, then export to JSON. That will make writting your Spine+Physics engine much easier.

Thanks! BTW I didn't mention this ๐Ÿ™ I can't export cause I am using the trial version, or else I would have already done an example myself. I expect to get a full time job any time now so I'll be able to afford the pro version.


badlogic wrote
  1. Number of bones influencing this vertex (let's call this number #bones)

  2. List of #bones bone indices influencing this vertex

  3. Vertex x/y coordinate

  4. List of #bones bone weights

Hmm, that mustn't be right actually, here's an output I found:

"asdf": {
   "type": "boundingbox",
   "vertexCount": 3,
   "vertices": [ 2, 1, 1.67, 51.33, 0.664, 0, 71.67, 130.33, 0.336, 1, 1, 64.67, -11.67, 1, 1, 1, -66.33, -9.67, 1 ]
},

So it's:

  1. Number of bones influencing this vertex (let's call this number #bones)

  2. First bone index influencing this vertex

  3. Vertex x/y coordinate relative to this bone

  4. Weight of this vertex

  5. Second bone index influencing this vertex

  6. Vertex x/y coordinate relative to this bone

  7. Weight of this vertex
    ...

  8. #bones bone index influencing this vertex

  9. Vertex x/y coordinate relative to this bone

  10. Weight of this vertex

Whoa! That's complex.

Oh my, should have had my coffee... Yes, you are correct, the vertex is "duplicated" per bone its influenced by.

6 days later

Just a quick appetizer cause I am happy with the results so far - that Spine+Full Physics I mentioned. Of course there's still a lot of work to be done, but the basics are already there. ๐Ÿ™‚

i mapped this out a long time ago, on this forum somewhere. but the search sucks ๐Ÿ˜ This stuff should be in the docs ๐Ÿ™‚

BinaryCats wrote

i mapped this out a long time ago, on this forum somewhere. but the search sucks ๐Ÿ˜ This stuff should be in the docs ๐Ÿ™‚

Are you talking about the Unity physics? Mine is C++ Cocos2d based. Boy you have lots of posts, it will be hard to find the exact reference you mention.

I have also played a lot with the Unity implementation but I have something more "physics-based" in mind. :-)

I made a tool which merged two skeleton jsons into one, which you could then import into spine again (as one skeleton). Parsing the vertex data in the json (I.e what you did above) was a pain :s