{"id":295,"date":"2013-12-18T19:35:21","date_gmt":"2013-12-18T11:35:21","guid":{"rendered":"http:\/\/www.cgdev.net\/blog\/?p=295"},"modified":"2024-10-09T00:35:27","modified_gmt":"2024-10-08T16:35:27","slug":"parsing-decldata","status":"publish","type":"post","link":"https:\/\/www.cgdev.net\/blog\/295.html","title":{"rendered":"DeclData"},"content":{"rendered":"<p>A simple <a href=\"\/axe\/x-file.html\" target=\"_blank\" rel=\"noopener\">x-file<\/a> example: a plane has 4 vertices ( You can save it as a .x file or download the example file: <a href=\"\/axe\/download.php#examples\" target=\"_blank\" rel=\"noopener\">DeclData_Plane1_2011.zip<\/a> );<br \/>\neach vertex has these elements: position, normal, texcoord, then the layout is:<\/p>\n<pre>xof 0303txt 0032\r\n\r\nFrame Plane1 \r\n{\r\n\u00a0\r\n\u00a0FrameTransformMatrix \r\n\u00a0{\r\n    1.0,    0,      0,      0,\r\n    0,      0,   -1.0,      0,\r\n    0,    1.0,      0,      0,\r\n    0,      0,      0,    1.0;;\r\n\u00a0}\r\n\r\n\u00a0Mesh Plane1 \r\n\u00a0{\r\n\u00a0 4;\r\n\u00a0 -100.0;  0;  100.0;,\r\n\u00a0  100.0;\u00a0 0;  100.0;,\r\n\u00a0 -100.0;  0; -100.0;,\r\n\u00a0  100.0;\u00a0 0; -100.0;;\r\n\u00a0 2;\r\n\u00a0 3;0,1,2;,\r\n\u00a0 3;3,2,1;;\r\n\r\n\u00a0 MeshMaterialList \r\n\u00a0 {\r\n\u00a0\u00a0 1;\r\n\u00a0\u00a0 2;\r\n\u00a0\u00a0 0,\r\n\u00a0\u00a0 0;\r\n\u00a0 \u00a0\r\n\u00a0\u00a0 Material \u00a0\r\n\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0 0.1; 0.2; 0.5; 1.0;;\r\n\u00a0\u00a0\u00a0 0.0;\r\n\u00a0\u00a0\u00a0 0.0; 0.0; 0.0;;\r\n\u00a0\u00a0\u00a0 0.0; 0.0; 0.0;;\r\n\u00a0\u00a0 }\r\n\u00a0 }\r\n\r\n\u00a0 DeclData \r\n\u00a0 {\r\n     2;           \/\/ nElements == 2 \r\n     2;0;3;0;,    \/\/ type == 2 (Float3);  usage == 3 (Normal) \r\n     1;0;5;0;;    \/\/ type == 1 (Float2);  usage == 5 (Texcoord) \r\n     20;          \/\/ nDWords == 20;  Normal and Texcoord use 5 DWORDs, so 4 * 5 = 20\r\n     0,           \/\/ normal0.x == 0\r\n     1065353216,  \/\/ normal0.y == 1.0   \r\n     0,           \/\/ normal0.z == 0\r\n     0,           \/\/ tex0.x == 0\r\n     0,           \/\/ tex0.y == 0\r\n     0,           \/\/ normal1.x == 0\r\n     1065353216,  \/\/ normal1.y == 1.0\r\n     0,           \/\/ normal1.y == 0\r\n     1065353216,  \/\/ tex1.x == 1.0\r\n     0,           \/\/ tex1.y == 0\r\n     0,           \/\/ normal2.x == 0\r\n     1065353216,  \/\/ normal2.y == 1.0 \r\n     0,           \/\/ normal2.z == 0\r\n     0,           \/\/ tex2.x == 0\r\n     1065353216,  \/\/ tex2.y == 1\r\n     0,           \/\/ normal3.x == 0\r\n     1065353216,  \/\/ normal3.y == 1.0 \r\n     0,           \/\/ normal3.z == 0\r\n     1065353216,  \/\/ tex3.x == 1.0\r\n     1065353216;  \/\/ tex3.y == 1.0\r\n\u00a0 }\r\n\u00a0}\r\n}\r\n<\/pre>\n<p>The reason of using DWORD (unsigned int) in X file is because it has no precision problem with floats.<br \/>\nYou can use the following code to convert DWORD to float:<\/p>\n<pre>DWORD d = 1065353216;   \/\/ suppose you have load a DWORD from DeclData in x-file\r\nfloat f = *(float*)&amp;d;  \/\/ convert it back to float\r\nprintf(\"%f\", f);        \/\/ should be 1.0\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A simple x-file example: a plane has 4 vertices ( You can save it as a .x file or download the example file: DeclData_Plane1_2011.zip ); each vertex has these elements: position, normal, texcoord, then the layout is: xof 0303txt 0032 Frame Plane1 { \u00a0 \u00a0FrameTransformMatrix \u00a0{ 1.0, 0, 0, 0, 0, 0, -1.0, 0, 0, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-295","post","type-post","status-publish","format-standard","hentry","category-dxtools"],"_links":{"self":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/posts\/295","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=295"}],"version-history":[{"count":0,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/posts\/295\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/media?parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/categories?post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/tags?post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}