{"id":826,"date":"2023-05-20T04:15:16","date_gmt":"2023-05-19T20:15:16","guid":{"rendered":"https:\/\/www.cgdev.net\/blog\/?p=826"},"modified":"2024-06-08T21:29:53","modified_gmt":"2024-06-08T13:29:53","slug":"test","status":"publish","type":"post","link":"https:\/\/www.cgdev.net\/blog\/826.html","title":{"rendered":"Skin for glTF,  X and JD File Format"},"content":{"rendered":"<p>In X format this template within a mesh defines the vertices and weights influence of a particular bone.<\/p>\n<pre lang='a_c'>\r\ntemplate SkinWeights \r\n{\r\n    STRING transformNodeName;            \/\/ Bone name\r\n    DWORD nWeights;                      \/\/ The number of vertices affected by this bone\r\n    array DWORD vertexIndices[nWeights]; \/\/ The vertices indices influenced by this bone\r\n    array FLOAT weights[nWeights];       \/\/ The weights for each of the vertices influenced by this bone\r\n    Matrix4x4 matrixOffset;              \/\/ The matrix transforms the mesh vertices to the space of the bone\r\n}\r\n<\/pre>\n<p>The corresponding structure in glTF \/ glb is:<\/p>\n<pre lang='a_c'>\r\n  \"skins\": [\r\n    {\r\n      \"inverseBindMatrices\": 0,\r\n      \"joints\": [0, 1, 2, 3]\r\n    }\r\n  ],\r\n<\/pre>\n<p>Assuming we have a mesh with 4 bones and use row matrix style, the bone skinning transformation process of the vertices is as follows:<\/p>\n<pre lang='a_c'>\r\nMatrix4x4 mBone[4];        \/\/ 4 bones world matrices\r\nMatrix4x4 matrixOffset[4]; \/\/ inverse bind matrix from SkinWeights\r\nfloat weight[4];           \/\/ bones weights array from SkinWeights\r\n\r\nvoid skin_compute()        \/\/ gltf and X file formats have the same idea\r\n{\r\n    Matrix4x4 mSkin = matrixOffset[0] * mBone[0] * weight[0] +\r\n                      matrixOffset[1] * mBone[1] * weight[1] +\r\n                      matrixOffset[2] * mBone[2] * weight[2] +\r\n                      matrixOffset[3] * mBone[3] * weight[3];\r\n\r\n    vec4 pos_world = pos * mSkin;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In X format this template within a mesh defines the vertices and weights influence of a particular bone. template SkinWeights { STRING transformNodeName; \/\/ Bone name DWORD nWeights; \/\/ The number of vertices affected by this bone array DWORD vertexIndices[nWeights]; \/\/ The vertices indices influenced by this bone array FLOAT weights[nWeights]; \/\/ The weights for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39,5,3,34],"tags":[],"class_list":["post-826","post","type-post","status-publish","format-standard","hentry","category-algorithm","category-cpp","category-dxtools","category-gltf"],"_links":{"self":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/posts\/826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/comments?post=826"}],"version-history":[{"count":0,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/posts\/826\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/media?parent=826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/categories?post=826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/tags?post=826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}