{"id":74597,"date":"2026-02-10T08:25:07","date_gmt":"2026-02-10T00:25:07","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/74597.html"},"modified":"2026-02-10T08:25:07","modified_gmt":"2026-02-10T00:25:07","slug":"building-a-simple-engine-loading-models-model-system","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/74597.html","title":{"rendered":"Building a Simple Engine -- Loading Models -- Model system"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"-toc\" style=\"margin-left:0px\">\n<p id=\"1.1%20%E5%9F%BA%E4%BA%8E%E5%B7%B2%E6%9C%89%20glTF%20%E7%9F%A5%E8%AF%86%E6%8B%93%E5%B1%95-toc\" style=\"margin-left:0px\">1.1 \u57fa\u4e8e\u5df2\u6709 glTF \u77e5\u8bc6\u62d3\u5c55<\/p>\n<p id=\"1.2%20%E6%90%AD%E5%BB%BA%E5%BC%95%E6%93%8E%E7%9A%84%E6%A8%A1%E5%9E%8B%E7%B3%BB%E7%BB%9F-toc\" style=\"margin-left:0px\">1.2 \u642d\u5efa\u5f15\u64ce\u7684\u6a21\u578b\u7cfb\u7edf<\/p>\n<p id=\"1.3%20%E5%AE%9A%E4%B9%89%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84-toc\" style=\"margin-left:0px\">1.3 \u5b9a\u4e49\u6570\u636e\u7ed3\u6784<\/p>\n<p id=\"1.4%20%E4%B8%BA%E4%BD%95%E9%9C%80%E8%A6%81%E5%9C%BA%E6%99%AF%E5%9B%BE-toc\" style=\"margin-left:0px\">1.4 \u4e3a\u4f55\u9700\u8981\u573a\u666f\u56fe<\/p>\n<p id=\"1.4.1%20%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF%E5%9B%BE%E7%9A%84%E4%BC%98%E5%8A%BF-toc\" style=\"margin-left:40px\">1.4.1 \u4f7f\u7528\u573a\u666f\u56fe\u7684\u4f18\u52bf<\/p>\n<p id=\"1.4.2%20%E5%9C%BA%E6%99%AF%E5%9B%BE%20vs%20%E7%AE%80%E5%8D%95%E9%9B%86%E5%90%88-toc\" style=\"margin-left:40px\">1.4.2 \u573a\u666f\u56fe vs \u7b80\u5355\u96c6\u5408<\/p>\n<p id=\"1.4.3%20%E5%9C%BA%E6%99%AF%E5%9B%BE%20vs%20%E7%A9%BA%E9%97%B4%E5%88%86%E5%8C%BA%E7%B3%BB%E7%BB%9F%EF%BC%88%E6%B8%B8%E6%88%8F%E5%9C%B0%E5%9B%BE%EF%BC%89-toc\" style=\"margin-left:40px\">1.4.3 \u573a\u666f\u56fe vs \u7a7a\u95f4\u5206\u533a\u7cfb\u7edf&#xff08;\u6e38\u620f\u5730\u56fe&#xff09;<\/p>\n<p id=\"1.4.3.1%20%E5%B8%B8%E8%A7%81%E7%9A%84%E7%A9%BA%E9%97%B4%E5%88%86%E5%8C%BA%E7%B3%BB%E7%BB%9F-toc\" style=\"margin-left:80px\">1.4.3.1 \u5e38\u89c1\u7684\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf<\/p>\n<p id=\"1.4.3.2%20%E4%B8%BB%E6%B5%81%E5%BC%95%E6%93%8E%E4%B8%AD%E7%9A%84%E7%A9%BA%E9%97%B4%E5%88%86%E5%8C%BA%E7%B3%BB%E7%BB%9F-toc\" style=\"margin-left:80px\">1.4.3.2 \u4e3b\u6d41\u5f15\u64ce\u4e2d\u7684\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf<\/p>\n<p id=\"1.5%20%E6%9E%B6%E6%9E%84%E5%86%B3%E7%AD%96-toc\" style=\"margin-left:0px\">1.5 \u67b6\u6784\u51b3\u7b56<\/p>\n<p id=\"1.6%20%E5%BC%80%E5%8F%91%E8%80%85%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E6%A8%A1%E5%9E%8B%E7%B3%BB%E7%BB%9F-toc\" style=\"margin-left:0px\">1.6 \u5f00\u53d1\u8005\u5982\u4f55\u4f7f\u7528\u6a21\u578b\u7cfb\u7edf<\/p>\n<p id=\"1.6.1%20%E5%8A%A0%E8%BD%BD%E5%B9%B6%E5%88%9D%E5%A7%8B%E5%8C%96%E6%A8%A1%E5%9E%8B-toc\" style=\"margin-left:40px\">1.6.1 \u52a0\u8f7d\u5e76\u521d\u59cb\u5316\u6a21\u578b<\/p>\n<p id=\"1.6.2%20%E6%9B%B4%E6%96%B0%E5%B9%B6%E5%8A%A8%E7%94%BB%E5%8C%96%E6%A8%A1%E5%9E%8B-toc\" style=\"margin-left:40px\">1.6.2 \u66f4\u65b0\u5e76\u52a8\u753b\u5316\u6a21\u578b<\/p>\n<p id=\"1.6.3%20%E6%B8%B2%E6%9F%93%E6%A8%A1%E5%9E%8B-toc\" style=\"margin-left:40px\">1.6.3 \u6e32\u67d3\u6a21\u578b<\/p>\n<p id=\"1.7%20%E5%9B%9E%E5%88%B0%E6%95%99%E7%A8%8B%E4%B8%BB%E7%BA%BF-toc\" style=\"margin-left:0px\">1.7 \u56de\u5230\u6559\u7a0b\u4e3b\u7ebf<\/p>\n<p id=\"1.8%20%E5%AE%9E%E7%8E%B0%E5%9C%BA%E6%99%AF%E5%9B%BE-toc\" style=\"margin-left:0px\">1.8 \u5b9e\u73b0\u573a\u666f\u56fe<\/p>\n<p id=\"1.9%20%E5%8A%A8%E7%94%BB%E7%9B%B8%E5%85%B3%E7%BB%93%E6%9E%84-toc\" style=\"margin-left:0px\">1.9 \u52a8\u753b\u76f8\u5173\u7ed3\u6784<\/p>\n<p id=\"1.10%20Model%20%E7%B1%BB-toc\" style=\"margin-left:0px\">1.10 Model \u7c7b<\/p>\n<p id=\"1.11%20%E4%B8%8B%E4%B8%80%E6%AD%A5%EF%BC%9A%E5%8A%A0%E8%BD%BD%20glTF%20%E6%96%87%E4%BB%B6-toc\" style=\"margin-left:0px\">1.11 \u4e0b\u4e00\u6b65&#xff1a;\u52a0\u8f7d glTF \u6587\u4ef6<\/p>\n<p id=\"%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:80px\">\u603b\u7ed3<\/p>\n<hr id=\"hr-toc\" \/>\n<h2 id=\"1.1%20%E5%9F%BA%E4%BA%8E%E5%B7%B2%E6%9C%89%20glTF%20%E7%9F%A5%E8%AF%86%E6%8B%93%E5%B1%95\">1.1 \u57fa\u4e8e\u5df2\u6709 glTF \u77e5\u8bc6\u62d3\u5c55<\/h2>\n<p>\u6b63\u5982\u6211\u4eec\u5728\u300aglTF \u4e0e KTX2 \u8fc1\u79fb\u300b\u7ae0\u8282\u6240\u5b66&#xff0c;glTF \u662f\u4e00\u79cd\u73b0\u4ee3 3D \u683c\u5f0f&#xff0c;\u652f\u6301 PBR \u6750\u8d28\u3001\u52a8\u753b\u3001\u573a\u666f\u5c42\u7ea7\u7b49\u4e30\u5bcc\u7279\u6027\u3002\u672c\u7ae0\u4e2d&#xff0c;\u6211\u4eec\u5c06\u5229\u7528\u8fd9\u4e9b\u7279\u6027\u6784\u5efa\u4e00\u5957\u66f4\u5065\u58ee\u7684\u5f15\u64ce\u3002<\/p>\n<p>\u4e0a\u4e00\u7ae0\u4ec5\u8bb2\u89e3\u4e86\u52a0\u8f7d glTF \u6a21\u578b\u7684\u57fa\u7840\u65b9\u6cd5&#xff0c;\u800c\u672c\u7ae0\u4f1a\u91cd\u70b9\u5173\u6ce8\u5c06\u52a0\u8f7d\u7684\u6570\u636e\u7ec4\u7ec7\u4e3a\u89c4\u8303\u7684\u573a\u666f\u56fe&#xff08;scene graph&#xff09;&#xff0c;\u5e76\u5b9e\u73b0\u52a8\u753b\u652f\u6301\u3002\u8fd9\u79cd\u8bbe\u8ba1\u80fd\u8ba9\u6211\u4eec\u521b\u5efa\u66f4\u590d\u6742\u3001\u66f4\u5177\u52a8\u6001\u6027\u7684\u573a\u666f\u3002<\/p>\n<p>\u672c\u7ae0\u4e0d\u4ec5\u4f1a\u5b9e\u73b0\u6a21\u578b\u52a0\u8f7d\u7684\u6280\u672f\u7ec6\u8282&#xff0c;\u8fd8\u4f1a\u63a2\u8ba8\u8bbe\u8ba1\u80cc\u540e\u7684\u67b6\u6784\u51b3\u7b56&#xff0c;\u4ee5\u53ca\u5f00\u53d1\u8005\u5982\u4f55\u5728\u5e94\u7528\u4e2d\u9ad8\u6548\u4f7f\u7528\u8fd9\u5957\u7cfb\u7edf\u3002\u7406\u89e3\u8fd9\u4e9b\u6982\u5ff5&#xff0c;\u662f\u6784\u5efa\u53ef\u7ef4\u62a4\u3001\u53ef\u6269\u5c55\u5f15\u64ce\u7684\u5173\u952e\u3002<\/p>\n<h2 id=\"1.2%20%E6%90%AD%E5%BB%BA%E5%BC%95%E6%93%8E%E7%9A%84%E6%A8%A1%E5%9E%8B%E7%B3%BB%E7%BB%9F\">1.2 \u642d\u5efa\u5f15\u64ce\u7684\u6a21\u578b\u7cfb\u7edf<\/h2>\n<p>\u6211\u4eec\u5c06\u6cbf\u7528\u4e0e\u4e0a\u4e00\u7ae0\u76f8\u540c\u7684 tinygltf \u5e93\u914d\u7f6e&#xff1a;<\/p>\n<p>\/\/ \u5f15\u5165 tinygltf \u7528\u4e8e\u6a21\u578b\u52a0\u8f7d<br \/>\n#include &lt;tiny_gltf.h&gt;<\/p>\n<p>\u4f46\u4e0e\u76f4\u63a5\u5c06\u6a21\u578b\u6570\u636e\u52a0\u8f7d\u5230\u9876\u70b9 \/ \u7d22\u5f15\u7f13\u51b2\u533a\u7684\u65b9\u5f0f\u4e0d\u540c&#xff0c;\u6211\u4eec\u4f1a\u91c7\u7528\u66f4\u7ed3\u6784\u5316\u7684\u8bbe\u8ba1&#xff0c;\u901a\u8fc7\u89c4\u8303\u7684\u6570\u636e\u7c7b\u6765\u8868\u793a\u573a\u666f\u3002<\/p>\n<h2 id=\"1.3%20%E5%AE%9A%E4%B9%89%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84\">1.3 \u5b9a\u4e49\u6570\u636e\u7ed3\u6784<\/h2>\n<p>\u4e3a\u4e86\u5904\u7406 glTF \u63d0\u4f9b\u7684\u4e30\u5bcc\u6570\u636e&#xff0c;\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4ee5\u4e0b\u6570\u636e\u7ed3\u6784&#xff1a;<\/p>\n<p>\/\/ \u5305\u542b\u4f4d\u7f6e\u3001\u6cd5\u7ebf\u3001\u989c\u8272\u548c\u7eb9\u7406\u5750\u6807\u7684\u9876\u70b9\u7ed3\u6784<br \/>\nstruct Vertex {<br \/>\n    glm::vec3 pos;<br \/>\n    glm::vec3 normal;<br \/>\n    glm::vec3 color;<br \/>\n    glm::vec2 texCoord;<\/p>\n<p>    \/\/ Vulkan \u9876\u70b9\u8f93\u5165\u7ed1\u5b9a\u63cf\u8ff0<br \/>\n    static vk::VertexInputBindingDescription getBindingDescription() {<br \/>\n        return { 0, sizeof(Vertex), vk::VertexInputRate::eVertex };<br \/>\n    }<\/p>\n<p>    \/\/ Vulkan \u9876\u70b9\u8f93\u5165\u5c5e\u6027\u63cf\u8ff0<br \/>\n    static std::array&lt;vk::VertexInputAttributeDescription, 4&gt; getAttributeDescriptions() {<br \/>\n        return {<br \/>\n            vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, pos) ),<br \/>\n            vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, normal) ),<br \/>\n            vk::VertexInputAttributeDescription( 2, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, color) ),<br \/>\n            vk::VertexInputAttributeDescription( 3, 0, vk::Format::eR32G32Sfloat, offsetof(Vertex, texCoord) )<br \/>\n        };<br \/>\n    }<\/p>\n<p>    \/\/ \u7528\u4e8e\u9876\u70b9\u53bb\u91cd\u7684\u76f8\u7b49\u8fd0\u7b97\u7b26\u548c\u54c8\u5e0c\u51fd\u6570<br \/>\n    bool operator&#061;&#061;(const Vertex&amp; other) const {<br \/>\n        return pos &#061;&#061; other.pos &amp;&amp; normal &#061;&#061; other.normal &amp;&amp; color &#061;&#061; other.color &amp;&amp; texCoord &#061;&#061; other.texCoord;<br \/>\n    }<br \/>\n};<\/p>\n<p>\/\/ PBR \u6750\u8d28\u5c5e\u6027\u7ed3\u6784<br \/>\nstruct Material {<br \/>\n    glm::vec4 baseColorFactor &#061; glm::vec4(1.0f);<br \/>\n    float metallicFactor &#061; 1.0f;<br \/>\n    float roughnessFactor &#061; 1.0f;<br \/>\n    glm::vec3 emissiveFactor &#061; glm::vec3(0.0f);<\/p>\n<p>    int baseColorTextureIndex &#061; -1;<br \/>\n    int metallicRoughnessTextureIndex &#061; -1;<br \/>\n    int normalTextureIndex &#061; -1;<br \/>\n    int occlusionTextureIndex &#061; -1;<br \/>\n    int emissiveTextureIndex &#061; -1;<br \/>\n};<\/p>\n<p>\/\/ \u5305\u542b\u9876\u70b9\u3001\u7d22\u5f15\u548c\u6750\u8d28\u7684\u7f51\u683c\u7ed3\u6784<br \/>\nstruct Mesh {<br \/>\n    std::vector&lt;Vertex&gt; vertices;<br \/>\n    std::vector&lt;uint32_t&gt; indices;<br \/>\n    int materialIndex &#061; -1;<br \/>\n};<\/p>\n<h2 id=\"1.4%20%E4%B8%BA%E4%BD%95%E9%9C%80%E8%A6%81%E5%9C%BA%E6%99%AF%E5%9B%BE\">1.4 \u4e3a\u4f55\u9700\u8981\u573a\u666f\u56fe<\/h2>\n<p>\u573a\u666f\u56fe\u662f\u4e00\u79cd\u6811\u5f62\u6570\u636e\u7ed3\u6784&#xff0c;\u7528\u4e8e\u7ec4\u7ec7\u56fe\u5f62\u5316\u573a\u666f\u7684\u7a7a\u95f4\u8868\u793a\u3002\u5c3d\u7ba1\u4f7f\u7528\u7b80\u5355\u7684\u96c6\u5408\u6216\u6620\u5c04\u5b58\u50a8 3D \u5bf9\u8c61\u770b\u4f3c\u4fbf\u6377&#xff0c;\u4f46\u573a\u666f\u56fe\u5177\u5907\u591a\u9879\u5173\u952e\u4f18\u52bf&#xff1a;<\/p>\n<h3 id=\"1.4.1%20%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF%E5%9B%BE%E7%9A%84%E4%BC%98%E5%8A%BF\">1.4.1 \u4f7f\u7528\u573a\u666f\u56fe\u7684\u4f18\u52bf<\/h3>\n<ul>\n<li>\u5c42\u7ea7\u53d8\u6362&#xff08;Hierarchical Transformations&#xff09;&#xff1a;\u573a\u666f\u56fe\u5141\u8bb8\u5b50\u5bf9\u8c61\u7ee7\u627f\u7236\u5bf9\u8c61\u7684\u53d8\u6362\u5c5e\u6027\u3002\u5f53\u4f60\u79fb\u52a8\u3001\u65cb\u8f6c\u6216\u7f29\u653e\u7236\u8282\u70b9\u65f6&#xff0c;\u5176\u6240\u6709\u5b50\u8282\u70b9\u4f1a\u81ea\u52a8\u76f8\u5bf9\u4e8e\u7236\u8282\u70b9\u5b8c\u6210\u53d8\u6362\u3002\u8fd9\u5bf9\u4e8e\u89d2\u8272\u7b49\u590d\u6742\u6a21\u578b\u81f3\u5173\u91cd\u8981 \u2014\u2014 \u79fb\u52a8\u8eaf\u5e72\u65f6&#xff0c;\u9644\u5c5e\u7684\u80a2\u4f53\u4e5f\u5e94\u968f\u4e4b\u79fb\u52a8\u3002<\/li>\n<li>\u7a7a\u95f4\u7ec4\u7ec7&#xff08;Spatial Organization&#xff09;&#xff1a;\u573a\u666f\u56fe\u57fa\u4e8e\u7a7a\u95f4\u5173\u7cfb\u7ec4\u7ec7\u5bf9\u8c61&#xff0c;\u4fbf\u4e8e\u6267\u884c\u5254\u9664&#xff08;culling&#xff09;\u3001\u78b0\u649e\u68c0\u6d4b\u3001\u7ec6\u8282\u5c42\u7ea7&#xff08;LOD&#xff09;\u7ba1\u7406\u7b49\u64cd\u4f5c\u3002<\/li>\n<li>\u52a8\u753b\u652f\u6301&#xff08;Animation Support&#xff09;&#xff1a;\u5c42\u7ea7\u7ed3\u6784\u662f\u9aa8\u9abc\u52a8\u753b\u7684\u6838\u5fc3\u57fa\u7840&#xff0c;\u52a8\u753b\u52a8\u4f5c\u4f1a\u6cbf\u7740\u9aa8\u9abc\u94fe\u9010\u5c42\u4f20\u9012\u3002<\/li>\n<li>\u573a\u666f\u7ba1\u7406&#xff08;Scene Management&#xff09;&#xff1a;\u573a\u666f\u56fe\u7b80\u5316\u4e86\u573a\u666f\u7684\u4fdd\u5b58 \/ \u52a0\u8f7d\u3001\u5b9e\u4f8b\u5316&#xff08;\u5728\u4e0d\u540c\u4f4d\u7f6e\u590d\u7528\u540c\u4e00\u6a21\u578b&#xff09;\u3001\u52a8\u6001\u4fee\u6539\u7b49\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<h3 id=\"1.4.2%20%E5%9C%BA%E6%99%AF%E5%9B%BE%20vs%20%E7%AE%80%E5%8D%95%E9%9B%86%E5%90%88\">1.4.2 \u573a\u666f\u56fe vs \u7b80\u5355\u96c6\u5408<\/h3>\n<p>\u4e0e\u7b80\u5355\u7684\u5bf9\u8c61\u6620\u5c04 \/ \u6570\u7ec4\u4e0d\u540c&#xff0c;\u573a\u666f\u56fe&#xff1a;<\/p>\n<ul>\n<li>\u7ef4\u62a4\u5bf9\u8c61\u95f4\u7684\u7236\u5b50\u5173\u7cfb<\/li>\n<li>\u81ea\u52a8\u5c06\u53d8\u6362\u5c5e\u6027\u6cbf\u5c42\u7ea7\u5411\u4e0b\u4f20\u9012<\/li>\n<li>\u4e3a\u904d\u5386\u7b97\u6cd5&#xff08;\u6e32\u67d3\u3001\u62fe\u53d6\u3001\u78b0\u649e\u68c0\u6d4b&#xff09;\u63d0\u4f9b\u81ea\u7136\u7684\u7ed3\u6784<\/li>\n<li>\u652f\u6301\u5c40\u90e8\u5750\u6807\u7cfb\u5230\u5168\u5c40\u5750\u6807\u7cfb\u7684\u53d8\u6362<\/li>\n<\/ul>\n<p>\u4f8b\u5982&#xff0c;\u82e5\u4f7f\u7528\u6241\u5e73\u7684\u5bf9\u8c61\u96c6\u5408&#xff0c;\u79fb\u52a8\u89d2\u8272\u53ca\u5176\u6240\u6709\u88c5\u5907\u65f6&#xff0c;\u9700\u8981\u9010\u4e2a\u66f4\u65b0\u6bcf\u4e2a\u90e8\u4ef6&#xff1b;\u800c\u4f7f\u7528\u573a\u666f\u56fe\u65f6&#xff0c;\u53ea\u9700\u79fb\u52a8\u89d2\u8272\u8282\u70b9&#xff0c;\u6240\u6709\u9644\u5c5e\u88c5\u5907\u4f1a\u81ea\u52a8\u968f\u4e4b\u79fb\u52a8\u3002<\/p>\n<h3 id=\"1.4.3%20%E5%9C%BA%E6%99%AF%E5%9B%BE%20vs%20%E7%A9%BA%E9%97%B4%E5%88%86%E5%8C%BA%E7%B3%BB%E7%BB%9F%EF%BC%88%E6%B8%B8%E6%88%8F%E5%9C%B0%E5%9B%BE%EF%BC%89\">1.4.3 \u573a\u666f\u56fe vs \u7a7a\u95f4\u5206\u533a\u7cfb\u7edf&#xff08;\u6e38\u620f\u5730\u56fe&#xff09;<\/h3>\n<p>\u9700\u6ce8\u610f\u533a\u5206\u573a\u666f\u56fe\u4e0e\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf&#xff08;\u5f15\u64ce\u5f00\u53d1\u4e2d\u5e38\u79f0 \u201c\u6e38\u620f\u5730\u56fe\u201d&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u573a\u666f\u56fe&#xff1a;\u805a\u7126\u4e8e\u5bf9\u8c61\u95f4\u7684\u5c42\u7ea7\u5173\u7cfb\u548c\u53d8\u6362\u903b\u8f91<\/li>\n<li>\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf&#xff1a;\u805a\u7126\u4e8e\u5728\u7a7a\u95f4\u4e2d\u9ad8\u6548\u7ec4\u7ec7\u5bf9\u8c61&#xff0c;\u4ee5\u4f18\u5316\u78b0\u649e\u68c0\u6d4b\u3001\u53ef\u89c1\u6027\u5224\u65ad\u3001\u7269\u7406\u8ba1\u7b97\u7b49\u64cd\u4f5c<\/li>\n<\/ul>\n<p>\u573a\u666f\u56fe\u57fa\u4e8e\u903b\u8f91\u5173\u7cfb\u7ec4\u7ec7\u5bf9\u8c61&#xff08;\u5982\u89d2\u8272\u4e0e\u88c5\u5907&#xff09;&#xff0c;\u800c\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf\u57fa\u4e8e\u5bf9\u8c61\u5728\u6e38\u620f\u4e16\u754c\u4e2d\u7684\u7269\u7406\u4f4d\u7f6e\u8fdb\u884c\u7ec4\u7ec7\u3002<\/p>\n<h4 id=\"1.4.3.1%20%E5%B8%B8%E8%A7%81%E7%9A%84%E7%A9%BA%E9%97%B4%E5%88%86%E5%8C%BA%E7%B3%BB%E7%BB%9F\">1.4.3.1 \u5e38\u89c1\u7684\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf<\/h4>\n<p>\u6e38\u620f\u5f00\u53d1\u4e2d\u5e38\u7528\u7684\u7a7a\u95f4\u5206\u533a\u6280\u672f\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\u516b\u53c9\u6811&#xff08;Octrees&#xff09;&#xff1a;\u5c06 3D \u7a7a\u95f4\u9012\u5f52\u5212\u5206\u4e3a 8 \u4e2a\u76f8\u7b49\u7684\u516b\u5206\u4f53&#xff0c;\u9002\u7528\u4e8e\u5bf9\u8c61\u5206\u5e03\u4e0d\u5747\u7684\u5927\u578b\u5f00\u653e\u4e16\u754c\u3002\u516b\u53c9\u6811\u4f1a\u6839\u636e\u5bf9\u8c61\u5bc6\u5ea6\u81ea\u9002\u5e94\u7ec6\u5206&#xff0c;\u5728\u5bf9\u8c61\u5bc6\u96c6\u533a\u57df\u5212\u5206\u66f4\u7ec6\u3002<\/li>\n<li>\u4e8c\u53c9\u7a7a\u95f4\u5206\u5272&#xff08;Binary Space Partitioning, BSP&#xff09;&#xff1a;\u901a\u8fc7\u5e73\u9762\u9012\u5f52\u5206\u5272\u7a7a\u95f4&#xff0c;\u5bf9\u5ba4\u5185\u573a\u666f\u5c24\u5176\u9ad8\u6548&#xff0c;\u56e0\u300a\u6bc1\u706d\u6218\u58eb\u300b&#xff08;Doom&#xff09;\u3001\u300a\u96f7\u795e\u4e4b\u9524\u300b&#xff08;Quake&#xff09;\u7b49\u65e9\u671f\u7b2c\u4e00\u4eba\u79f0\u5c04\u51fb\u6e38\u620f\u800c\u666e\u53ca\u3002<\/li>\n<li>\u56db\u53c9\u6811&#xff08;Quadtrees&#xff09;&#xff1a;\u516b\u53c9\u6811\u7684 2D \u7248\u672c&#xff0c;\u5c06\u7a7a\u95f4\u9012\u5f52\u5212\u5206\u4e3a 4 \u4e2a\u8c61\u9650&#xff0c;\u5e38\u7528\u4e8e 2D \u6e38\u620f\u6216 3D \u6e38\u620f\u7684\u5730\u5f62\u7ba1\u7406\u3002<\/li>\n<li>\u8f74\u5bf9\u9f50\u5305\u56f4\u76d2\u6811&#xff08;Axis-Aligned Bounding Boxes, AABB Trees&#xff09;&#xff1a;\u57fa\u4e8e\u5305\u56f4\u76d2\u7ec4\u7ec7\u5bf9\u8c61&#xff0c;\u6784\u5efa\u5c42\u7ea7\u7ed3\u6784\u4ee5\u5b9e\u73b0\u9ad8\u6548\u7684\u78b0\u649e\u68c0\u6d4b\u3002<\/li>\n<li>\u95e8\u6237\u7cfb\u7edf&#xff08;Portal Systems&#xff09;&#xff1a;\u5c06\u4e16\u754c\u5212\u5206\u4e3a\u7531 \u201c\u95e8\u6237\u201d \u8fde\u63a5\u7684 \u201c\u623f\u95f4\u201d&#xff0c;\u5bf9\u6709\u660e\u786e\u533a\u57df\u5212\u5206\u7684\u5ba4\u5185\u573a\u666f\u6548\u679c\u6781\u4f73\u3002<\/li>\n<li>\u7a7a\u95f4\u54c8\u5e0c&#xff08;Spatial Hashing&#xff09;&#xff1a;\u5c06 3D \u4f4d\u7f6e\u6620\u5c04\u5230\u54c8\u5e0c\u8868&#xff0c;\u53ef\u5728\u5e38\u6570\u65f6\u95f4\u5185\u67e5\u627e\u9644\u8fd1\u5bf9\u8c61&#xff0c;\u9002\u7528\u4e8e\u7c92\u5b50\u7cfb\u7edf\u7b49\u5305\u542b\u5927\u91cf\u540c\u5c3a\u5bf8\u5bf9\u8c61\u7684\u573a\u666f\u3002<\/li>\n<li>\u5305\u56f4\u4f53\u5c42\u7ea7&#xff08;Bounding Volume Hierarchies, BVH&#xff09;&#xff1a;\u6784\u5efa\u5d4c\u5957\u5305\u56f4\u4f53\u7684\u6811\u5f62\u7ed3\u6784&#xff0c;\u652f\u6301\u9ad8\u6548\u7684\u5c04\u7ebf\u6295\u5c04\u548c\u78b0\u649e\u68c0\u6d4b\u3002<\/li>\n<\/ul>\n<h4 id=\"1.4.3.2%20%E4%B8%BB%E6%B5%81%E5%BC%95%E6%93%8E%E4%B8%AD%E7%9A%84%E7%A9%BA%E9%97%B4%E5%88%86%E5%8C%BA%E7%B3%BB%E7%BB%9F\">1.4.3.2 \u4e3b\u6d41\u5f15\u64ce\u4e2d\u7684\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf<\/h4>\n<p>\u4e0d\u540c\u6e38\u620f\u5f15\u64ce\u91c7\u7528\u7684\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf\u5404\u5f02&#xff0c;\u4e14\u5e38\u7ec4\u5408\u591a\u79cd\u65b9\u6848&#xff1a;<\/p>\n<ul>\n<li>Unreal Engine&#xff1a;\u7ed3\u5408\u516b\u53c9\u6811&#xff08;\u5168\u5c40\u4e16\u754c&#xff09;\u548c BSP&#xff08;\u7cbe\u7ec6\u5ba4\u5185\u573a\u666f&#xff09;&#xff0c;\u8fd8\u4f7f\u7528\u540d\u4e3a \u201cUnreal Visibility Determination\u201d \u7684\u81ea\u5b9a\u4e49\u7cfb\u7edf&#xff0c;\u6574\u5408\u95e8\u6237\u548c\u6f5c\u5728\u53ef\u89c1\u96c6&#xff08;PVS&#xff09;\u3002<\/li>\n<li>Unity&#xff1a;\u4e3a\u7269\u7406\u548c\u6e32\u67d3\u5b9e\u73b0\u4e86\u56db\u53c9\u6811 \/ \u516b\u53c9\u6811\u6df7\u5408\u7cfb\u7edf&#xff1b;\u5bfc\u822a\u7cfb\u7edf\u5219\u4f7f\u7528\u5bfc\u822a\u7f51\u683c&#xff08;navigation mesh&#xff09;\u3002<\/li>\n<li>CryEngine\/CRYENGINE&#xff1a;\u5ba4\u5916\u573a\u666f\u7528\u516b\u53c9\u6811&#xff0c;\u5ba4\u5185\u533a\u57df\u7528\u95e8\u6237\u7cfb\u7edf\u3002<\/li>\n<li>Godot&#xff1a;\u7269\u7406\u5f15\u64ce\u91c7\u7528 BVH \u6811&#xff0c;\u6e32\u67d3\u7cfb\u7edf\u4f7f\u7528\u516b\u53c9\u6811\u3002<\/li>\n<li>Source Engine&#xff08;Valve&#xff09;&#xff1a;\u56e0\u7ed3\u5408 BSP \u548c\u540d\u4e3a \u201cPotentially Visible Set&#xff08;PVS&#xff09;\u201d \u7684\u95e8\u6237\u7cfb\u7edf\u800c\u95fb\u540d\u3002<\/li>\n<li>id Tech&#xff08;id Software&#xff09;&#xff1a;\u65e9\u671f\u7248\u672c&#xff08;Doom\u3001Quake&#xff09;\u5f00\u521b\u4e86 BSP \u7684\u5e94\u7528&#xff1b;\u540e\u7eed\u7248\u672c\u7ed3\u5408\u4e86 BSP\u3001\u516b\u53c9\u6811\u548c\u95e8\u6237\u7cfb\u7edf\u3002<\/li>\n<li>Frostbite&#xff08;EA&#xff09;&#xff1a;\u7ed3\u5408\u5c42\u7ea7\u7f51\u683c\u7cfb\u7edf\u548c\u516b\u53c9\u6811&#xff0c;\u9002\u914d\u5927\u89c4\u6a21\u53ef\u7834\u574f\u573a\u666f\u3002<\/li>\n<\/ul>\n<p>\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u73b0\u4ee3\u5f15\u64ce\u591a\u91c7\u7528\u6df7\u5408\u65b9\u6848&#xff0c;\u6839\u636e\u6e38\u620f\u4e16\u754c\u4e0d\u540c\u533a\u57df\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5206\u533a\u7cfb\u7edf\u3002<\/p>\n<h2 id=\"1.5%20%E6%9E%B6%E6%9E%84%E5%86%B3%E7%AD%96\">1.5 \u67b6\u6784\u51b3\u7b56<\/h2>\n<p>\u8bbe\u8ba1\u6a21\u578b\u7cfb\u7edf\u65f6&#xff0c;\u6211\u4eec\u505a\u51fa\u4e86\u4ee5\u4e0b\u6838\u5fc3\u67b6\u6784\u51b3\u7b56&#xff1a;<\/p>\n<ul>\n<li>\u57fa\u4e8e\u8282\u70b9\u7684\u7ed3\u6784&#xff08;Node-Based Structure&#xff09;&#xff1a;\u91c7\u7528\u8282\u70b9\u5316\u8bbe\u8ba1&#xff0c;\u6bcf\u4e2a\u8282\u70b9\u53ef\u5305\u542b\u7f51\u683c\u3001\u53d8\u6362\u5c5e\u6027\u548c\u5b50\u8282\u70b9&#xff0c;\u4e3a\u590d\u6742\u573a\u666f\u5c42\u7ea7\u63d0\u4f9b\u7075\u6d3b\u6027\u3002<\/li>\n<li>\u5173\u6ce8\u70b9\u5206\u79bb&#xff08;Separation of Concerns&#xff09;&#xff1a;\u5c06\u51e0\u4f55\u6570\u636e&#xff08;\u9876\u70b9\u3001\u7d22\u5f15&#xff09;\u4e0e\u6750\u8d28\u5c5e\u6027\u3001\u53d8\u6362\u903b\u8f91\u5206\u79bb&#xff0c;\u63d0\u5347\u5185\u5b58\u4f7f\u7528\u6548\u7387&#xff0c;\u7b80\u5316\u66f4\u65b0\u64cd\u4f5c\u3002<\/li>\n<li>\u52a8\u753b\u9002\u914d&#xff08;Animation-Ready&#xff09;&#xff1a;\u8bbe\u8ba1\u4e13\u7528\u4e8e\u52a8\u753b\u7684\u7ed3\u6784&#xff0c;\u652f\u6301\u5173\u952e\u5e27\u63d2\u503c\u548c\u4e0d\u540c\u52a8\u753b\u901a\u9053&#xff08;\u5e73\u79fb\u3001\u65cb\u8f6c\u3001\u7f29\u653e&#xff09;\u3002<\/li>\n<li>\u5185\u5b58\u7ba1\u7406&#xff08;Memory Management&#xff09;&#xff1a;\u91c7\u7528\u96c6\u4e2d\u5f0f\u6240\u6709\u6743\u6a21\u578b&#xff0c;\u7531 Model \u7c7b\u7ba1\u7406\u6240\u6709\u8282\u70b9&#xff0c;\u7b80\u5316\u8d44\u6e90\u6e05\u7406\u6d41\u7a0b&#xff0c;\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u3002<\/li>\n<li>\u9ad8\u6548\u904d\u5386&#xff08;Efficient Traversal&#xff09;&#xff1a;\u540c\u65f6\u7ef4\u62a4\u5c42\u7ea7\u7ed3\u6784&#xff08;nodes&#xff09;\u548c\u6241\u5e73\u5217\u8868&#xff08;linearNodes&#xff09;&#xff0c;\u9ad8\u6548\u652f\u6301\u4e0d\u540c\u7684\u904d\u5386\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n<h2 id=\"1.6%20%E5%BC%80%E5%8F%91%E8%80%85%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E6%A8%A1%E5%9E%8B%E7%B3%BB%E7%BB%9F\">1.6 \u5f00\u53d1\u8005\u5982\u4f55\u4f7f\u7528\u6a21\u578b\u7cfb\u7edf<\/h2>\n<p>\u4ee5\u4e0b\u662f\u5f00\u53d1\u8005\u5728\u5e94\u7528\u4e2d\u4f7f\u7528\u8be5\u6a21\u578b\u7cfb\u7edf\u7684\u5178\u578b\u65b9\u5f0f&#xff1a;<\/p>\n<h3 id=\"1.6.1%20%E5%8A%A0%E8%BD%BD%E5%B9%B6%E5%88%9D%E5%A7%8B%E5%8C%96%E6%A8%A1%E5%9E%8B\">1.6.1 \u52a0\u8f7d\u5e76\u521d\u59cb\u5316\u6a21\u578b<\/h3>\n<p>\/\/ \u521b\u5efa\u5e76\u52a0\u8f7d\u6a21\u578b<br \/>\nModel* characterModel &#061; new Model();<br \/>\nloadFromFile(characterModel, &#034;character.gltf&#034;);<\/p>\n<p>\/\/ \u5728\u6a21\u578b\u4e2d\u67e5\u627e\u7279\u5b9a\u8282\u70b9<br \/>\nNode* headNode &#061; characterModel-&gt;findNode(&#034;Head&#034;);<br \/>\nNode* weaponAttachPoint &#061; characterModel-&gt;findNode(&#034;RightHand&#034;);<\/p>\n<p>\/\/ \u4e3a\u6a21\u578b\u9644\u52a0\u989d\u5916\u5bf9\u8c61<br \/>\nModel* weaponModel &#061; new Model();<br \/>\nloadFromFile(weaponModel, &#034;weapon.gltf&#034;);<br \/>\nweaponAttachPoint-&gt;children.push_back(weaponModel-&gt;nodes[0]);<\/p>\n<h3 id=\"1.6.2%20%E6%9B%B4%E6%96%B0%E5%B9%B6%E5%8A%A8%E7%94%BB%E5%8C%96%E6%A8%A1%E5%9E%8B\">1.6.2 \u66f4\u65b0\u5e76\u52a8\u753b\u5316\u6a21\u578b<\/h3>\n<p>\/\/ \u64ad\u653e\u52a8\u753b<br \/>\nfloat deltaTime &#061; 0.016f; \/\/ 16\u6beb\u79d2&#xff0c;\u7ea660 FPS<br \/>\n\/\/ \u6ce8\u610f&#xff1a;\u5b9e\u9645\u4ee3\u7801\u4e2d\u9700\u57fa\u4e8e\u5e27\u65f6\u95f4\u52a8\u6001\u8ba1\u7b97&#xff0c;\u800c\u975e\u4f7f\u7528\u5e38\u91cf<br \/>\n\/\/ \u5426\u5219\u5728\u6027\u80fd\u4e0d\u540c\u7684\u7cfb\u7edf\u4e0a&#xff0c;\u52a8\u753b\u901f\u5ea6\u4f1a\u4e0d\u4e00\u81f4<br \/>\ncharacterModel-&gt;updateAnimation(0, deltaTime); \/\/ \u64ad\u653e\u7b2c\u4e00\u4e2a\u52a8\u753b<\/p>\n<p>\/\/ \u624b\u52a8\u53d8\u6362\u8282\u70b9<br \/>\nheadNode-&gt;rotation &#061; glm::rotate(headNode-&gt;rotation, glm::radians(15.0f), glm::vec3(0, 1, 0)); \/\/ \u5934\u90e8\u8f6c\u5411\u4fa7\u9762<\/p>\n<h3 id=\"1.6.3%20%E6%B8%B2%E6%9F%93%E6%A8%A1%E5%9E%8B\">1.6.3 \u6e32\u67d3\u6a21\u578b<\/h3>\n<p>void renderModel(Model* model, VkCommandBuffer commandBuffer) {<br \/>\n    \/\/ \u904d\u5386\u6a21\u578b\u7684\u6240\u6709\u8282\u70b9<br \/>\n    for (auto&amp; node : model-&gt;linearNodes) {<br \/>\n        if (node-&gt;mesh.indices.size() &gt; 0) {<br \/>\n            \/\/ \u83b7\u53d6\u5168\u5c40\u53d8\u6362\u77e9\u9635<br \/>\n            glm::mat4 nodeMatrix &#061; node-&gt;getGlobalMatrix();<\/p>\n<p>            \/\/ \u66f4\u65b0\u7edf\u4e00\u7f13\u51b2\u533a&#xff08;uniform buffer&#xff09;\u7684\u8282\u70b9\u53d8\u6362\u6570\u636e<br \/>\n            updateUniformBuffer(nodeMatrix);<\/p>\n<p>            \/\/ \u7ed1\u5b9a\u5bf9\u5e94\u7684\u6750\u8d28<br \/>\n            if (node-&gt;mesh.materialIndex &gt;&#061; 0) {<br \/>\n                bindMaterial(model-&gt;materials[node-&gt;mesh.materialIndex]);<br \/>\n            }<\/p>\n<p>            \/\/ \u7ed8\u5236\u7f51\u683c<br \/>\n            vkCmdDrawIndexed(commandBuffer,<br \/>\n                static_cast&lt;uint32_t&gt;(node-&gt;mesh.indices.size()),<br \/>\n                1, 0, 0, 0);<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h2 id=\"1.7%20%E5%9B%9E%E5%88%B0%E6%95%99%E7%A8%8B%E4%B8%BB%E7%BA%BF\">1.7 \u56de\u5230\u6559\u7a0b\u4e3b\u7ebf<\/h2>\n<p>\u4e86\u89e3\u4e86\u5f00\u53d1\u8005\u89c6\u89d2\u4e0b\u6a21\u578b\u7cfb\u7edf API \u7684\u4f7f\u7528\u65b9\u5f0f\u540e&#xff0c;\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\u3002\u540e\u7eed\u7ae0\u8282\u4e2d&#xff0c;\u6211\u4eec\u4f1a\u9010\u6b65\u6307\u5bfc\u4f60\u5b9e\u73b0\u652f\u6491\u5f15\u64ce\u7684\u573a\u666f\u56fe\u3001\u52a8\u753b\u7cfb\u7edf\u548c Model \u7c7b\u3002<\/p>\n<h2 id=\"1.8%20%E5%AE%9E%E7%8E%B0%E5%9C%BA%E6%99%AF%E5%9B%BE\">1.8 \u5b9e\u73b0\u573a\u666f\u56fe<\/h2>\n<p>\u4ee5\u4e0b\u662f\u573a\u666f\u56fe\u7ed3\u6784\u7684\u5177\u4f53\u5b9e\u73b0&#xff1a;<\/p>\n<p>\/\/ \u573a\u666f\u56fe\u4e2d\u7684\u8282\u70b9\u7ed3\u6784<br \/>\nstruct Node {<br \/>\n    Node* parent &#061; nullptr;<br \/>\n    std::vector&lt;Node*&gt; children;<br \/>\n    Mesh mesh;<br \/>\n    glm::mat4 matrix &#061; glm::mat4(1.0f);<\/p>\n<p>    \/\/ \u52a8\u753b\u76f8\u5173\u5c5e\u6027<br \/>\n    glm::vec3 translation &#061; glm::vec3(0.0f);<br \/>\n    glm::quat rotation &#061; glm::quat(1.0f, 0.0f, 0.0f, 0.0f);<br \/>\n    glm::vec3 scale &#061; glm::vec3(1.0f);<\/p>\n<p>    \/\/ \u83b7\u53d6\u5c40\u90e8\u53d8\u6362\u77e9\u9635<br \/>\n    glm::mat4 getLocalMatrix() {<br \/>\n        return glm::translate(glm::mat4(1.0f), translation) *<br \/>\n               glm::toMat4(rotation) *<br \/>\n               glm::scale(glm::mat4(1.0f), scale) *<br \/>\n               matrix;<br \/>\n    }<\/p>\n<p>    \/\/ \u83b7\u53d6\u5168\u5c40\u53d8\u6362\u77e9\u9635<br \/>\n    glm::mat4 getGlobalMatrix() {<br \/>\n        glm::mat4 m &#061; getLocalMatrix();<br \/>\n        Node* p &#061; parent;<br \/>\n        while (p) {<br \/>\n            m &#061; p-&gt;getLocalMatrix() * m;<br \/>\n            p &#061; p-&gt;parent;<br \/>\n        }<br \/>\n        return m;<br \/>\n    }<br \/>\n};<\/p>\n<h2 id=\"1.9%20%E5%8A%A8%E7%94%BB%E7%9B%B8%E5%85%B3%E7%BB%93%E6%9E%84\">1.9 \u52a8\u753b\u76f8\u5173\u7ed3\u6784<\/h2>\n<p>\u4e3a\u652f\u6301\u52a8\u753b\u529f\u80fd&#xff0c;\u6211\u4eec\u9700\u8981\u65b0\u589e\u4ee5\u4e0b\u7ed3\u6784&#xff1a;<\/p>\n<p>\/\/ \u52a8\u753b\u5173\u952e\u5e27\u7ed3\u6784<br \/>\nstruct AnimationChannel {<br \/>\n    enum PathType { TRANSLATION, ROTATION, SCALE };<br \/>\n    PathType path;<br \/>\n    Node* node &#061; nullptr;<br \/>\n    uint32_t samplerIndex;<br \/>\n};<\/p>\n<p>\/\/ \u52a8\u753b\u63d2\u503c\u7ed3\u6784<br \/>\nstruct AnimationSampler {<br \/>\n    enum InterpolationType { LINEAR, STEP, CUBICSPLINE };<br \/>\n    InterpolationType interpolation;<br \/>\n    std::vector&lt;float&gt; inputs;  \/\/ \u5173\u952e\u5e27\u65f6\u95f4\u6233<br \/>\n    std::vector&lt;glm::vec4&gt; outputsVec4;  \/\/ \u5173\u952e\u5e27\u503c&#xff08;\u7528\u4e8e\u65cb\u8f6c&#xff09;<br \/>\n    std::vector&lt;glm::vec3&gt; outputsVec3;  \/\/ \u5173\u952e\u5e27\u503c&#xff08;\u7528\u4e8e\u5e73\u79fb\u548c\u7f29\u653e&#xff09;<br \/>\n};<\/p>\n<p>\/\/ \u52a8\u753b\u7ed3\u6784<br \/>\nstruct Animation {<br \/>\n    std::string name;<br \/>\n    std::vector&lt;AnimationSampler&gt; samplers;<br \/>\n    std::vector&lt;AnimationChannel&gt; channels;<br \/>\n    float start &#061; std::numeric_limits&lt;float&gt;::max();<br \/>\n    float end &#061; std::numeric_limits&lt;float&gt;::min();<br \/>\n    float currentTime &#061; 0.0f;<br \/>\n};<\/p>\n<h2 id=\"1.10%20Model%20%E7%B1%BB\">1.10 Model \u7c7b<\/h2>\n<p>\u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u6574\u5408\u6240\u6709\u529f\u80fd\u7684 Model \u7c7b&#xff1a;<\/p>\n<p>\/\/ \u5305\u542b\u8282\u70b9\u3001\u7f51\u683c\u3001\u6750\u8d28\u3001\u7eb9\u7406\u548c\u52a8\u753b\u7684\u6a21\u578b\u7ed3\u6784<br \/>\nstruct Model {<br \/>\n    std::vector&lt;Node*&gt; nodes;<br \/>\n    std::vector&lt;Node*&gt; linearNodes;<br \/>\n    std::vector&lt;Material&gt; materials;<br \/>\n    std::vector&lt;Animation&gt; animations;<\/p>\n<p>    \/\/ \u6790\u6784\u51fd\u6570&#xff1a;\u91ca\u653e\u6240\u6709\u8282\u70b9\u5185\u5b58<br \/>\n    ~Model() {<br \/>\n        for (auto node : linearNodes) {<br \/>\n            delete node;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u6839\u636e\u540d\u79f0\u67e5\u627e\u8282\u70b9<br \/>\n    Node* findNode(const std::string&amp; name) {<br \/>\n        auto nodeIt &#061; std::ranges::find_if(linearNodes, [&amp;name](auto const&amp; node) {<br \/>\n            return node-&gt;name &#061;&#061; name;<br \/>\n        });<br \/>\n        return (nodeIt !&#061; linearNodes.end()) ? *nodeIt : nullptr;<br \/>\n    }<\/p>\n<p>    \/\/ \u66f4\u65b0\u52a8\u753b<br \/>\n    void updateAnimation(uint32_t index, float deltaTime) {<br \/>\n        assert(!animations.empty() &amp;&amp; index &lt; animations.size());<\/p>\n<p>        Animation&amp; animation &#061; animations[index];<br \/>\n        animation.currentTime &#043;&#061; deltaTime;<br \/>\n        if (animation.currentTime &gt; animation.end) {<br \/>\n            animation.currentTime &#061; animation.start;<br \/>\n        }<\/p>\n<p>        for (auto&amp; channel : animation.channels) {<br \/>\n            AnimationSampler&amp; sampler &#061; animation.samplers[channel.samplerIndex];<\/p>\n<p>            \/\/ \u4e8c\u5206\u67e5\u627e\u5f53\u524d\u5173\u952e\u5e27<br \/>\n            auto keyFrameIt &#061; std::ranges::lower_bound(sampler.inputs, animation.currentTime);<br \/>\n            if (keyFrameIt !&#061; sampler.inputs.end() &amp;&amp; keyFrameIt !&#061; sampler.inputs.begin()) {<br \/>\n                size_t i &#061; std::distance(sampler.inputs.begin(), keyFrameIt) &#8211; 1;<br \/>\n                float t &#061; (animation.currentTime &#8211; sampler.inputs[i]) \/ (sampler.inputs[i &#043; 1] &#8211; sampler.inputs[i]);<\/p>\n<p>                switch (channel.path) {<br \/>\n                    case AnimationChannel::TRANSLATION: {<br \/>\n                        glm::vec3 start &#061; sampler.outputsVec3[i];<br \/>\n                        glm::vec3 end &#061; sampler.outputsVec3[i &#043; 1];<br \/>\n                        channel.node-&gt;translation &#061; glm::mix(start, end, t);<br \/>\n                        break;<br \/>\n                    }<br \/>\n                    case AnimationChannel::ROTATION: {<br \/>\n                        glm::quat start &#061; glm::quat(sampler.outputsVec4[i].w, sampler.outputsVec4[i].x, sampler.outputsVec4[i].y, sampler.outputsVec4[i].z);<br \/>\n                        glm::quat end &#061; glm::quat(sampler.outputsVec4[i &#043; 1].w, sampler.outputsVec4[i &#043; 1].x, sampler.outputsVec4[i &#043; 1].y, sampler.outputsVec4[i &#043; 1].z);<br \/>\n                        channel.node-&gt;rotation &#061; glm::slerp(start, end, t);<br \/>\n                        break;<br \/>\n                    }<br \/>\n                    case AnimationChannel::SCALE: {<br \/>\n                        glm::vec3 start &#061; sampler.outputsVec3[i];<br \/>\n                        glm::vec3 end &#061; sampler.outputsVec3[i &#043; 1];<br \/>\n                        channel.node-&gt;scale &#061; glm::mix(start, end, t);<br \/>\n                        break;<br \/>\n                    }<br \/>\n                }<br \/>\n                break;<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n};<\/p>\n<h2 id=\"1.11%20%E4%B8%8B%E4%B8%80%E6%AD%A5%EF%BC%9A%E5%8A%A0%E8%BD%BD%20glTF%20%E6%96%87%E4%BB%B6\">1.11 \u4e0b\u4e00\u6b65&#xff1a;\u52a0\u8f7d glTF \u6587\u4ef6<\/h2>\n<p>\u5b8c\u6210\u6a21\u578b\u7cfb\u7edf\u7684\u67b6\u6784\u8bbe\u8ba1\u548c\u6838\u5fc3\u6570\u636e\u7ed3\u6784\u5b9e\u73b0\u540e&#xff0c;\u4e0b\u4e00\u6b65\u662f\u4ece glTF \u6587\u4ef6\u4e2d\u5b9e\u9645\u52a0\u8f7d 3D \u6a21\u578b\u3002\u4e0b\u4e00\u7ae0\u4e2d&#xff0c;\u6211\u4eec\u5c06\u8bb2\u89e3\u5982\u4f55\u4f7f\u7528 tinygltf \u5e93\u89e3\u6790 glTF \u6587\u4ef6&#xff0c;\u5e76\u5c06\u52a0\u8f7d\u7684\u6570\u636e\u586b\u5145\u5230\u573a\u666f\u56fe\u4e2d\u3002\u6211\u4eec\u4f1a\u5b66\u4e60\u4ece glTF \u6587\u4ef6\u4e2d\u63d0\u53d6\u7f51\u683c\u3001\u6750\u8d28\u3001\u7eb9\u7406\u548c\u52a8\u753b&#xff0c;\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u5f15\u64ce\u7684\u5185\u90e8\u8868\u793a\u5f62\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 1.1 \u57fa\u4e8e\u5df2\u6709 glTF \u77e5\u8bc6\u62d3\u5c55<br \/>\n1.2 \u642d\u5efa\u5f15\u64ce\u7684\u6a21\u578b\u7cfb\u7edf<br \/>\n1.3 \u5b9a\u4e49\u6570\u636e\u7ed3\u6784<br \/>\n1.4 \u4e3a\u4f55\u9700\u8981\u573a\u666f\u56fe<br \/>\n1.4.1 \u4f7f\u7528\u573a\u666f\u56fe\u7684\u4f18\u52bf<br \/>\n1.4.2 \u573a\u666f\u56fe vs \u7b80\u5355\u96c6\u5408<br \/>\n1.4.3 \u573a\u666f\u56fe vs \u7a7a\u95f4\u5206\u533a\u7cfb\u7edf&#xff08;\u6e38\u620f\u5730\u56fe&#xff09;<br \/>\n1.4.3.1 \u5e38\u89c1\u7684\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf<br \/>\n1.4.3.2 \u4e3b\u6d41\u5f15\u64ce\u4e2d\u7684\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf<br \/>\n1.5 \u67b6\u6784\u51b3\u7b56<br \/>\n1.6 \u5f00\u53d1\u8005\u5982\u4f55\u4f7f\u7528\u6a21\u578b\u7cfb\u7edf<br \/>\n1.6.1 \u52a0\u8f7d\u5e76\u521d\u59cb\u5316\u6a21\u578b<br \/>\n1.6.2 \u66f4\u65b0\u5e76\u52a8\u753b\u5316\u6a21\u578b<br \/>\n1<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7898,7897,7896,188],"topic":[],"class_list":["post-74597","post","type-post","status-publish","format-standard","hentry","category-server","tag-gltf","tag-pipeline","tag-vulkan","tag-188"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Building a Simple Engine - Loading Models - Model system - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/74597.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building a Simple Engine - Loading Models - Model system - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 1.1 \u57fa\u4e8e\u5df2\u6709 glTF \u77e5\u8bc6\u62d3\u5c55 1.2 \u642d\u5efa\u5f15\u64ce\u7684\u6a21\u578b\u7cfb\u7edf 1.3 \u5b9a\u4e49\u6570\u636e\u7ed3\u6784 1.4 \u4e3a\u4f55\u9700\u8981\u573a\u666f\u56fe 1.4.1 \u4f7f\u7528\u573a\u666f\u56fe\u7684\u4f18\u52bf 1.4.2 \u573a\u666f\u56fe vs \u7b80\u5355\u96c6\u5408 1.4.3 \u573a\u666f\u56fe vs \u7a7a\u95f4\u5206\u533a\u7cfb\u7edf&#xff08;\u6e38\u620f\u5730\u56fe&#xff09; 1.4.3.1 \u5e38\u89c1\u7684\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf 1.4.3.2 \u4e3b\u6d41\u5f15\u64ce\u4e2d\u7684\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf 1.5 \u67b6\u6784\u51b3\u7b56 1.6 \u5f00\u53d1\u8005\u5982\u4f55\u4f7f\u7528\u6a21\u578b\u7cfb\u7edf 1.6.1 \u52a0\u8f7d\u5e76\u521d\u59cb\u5316\u6a21\u578b 1.6.2 \u66f4\u65b0\u5e76\u52a8\u753b\u5316\u6a21\u578b 1\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/74597.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-10T00:25:07+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/74597.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/74597.html\",\"name\":\"Building a Simple Engine - Loading Models - Model system - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-10T00:25:07+00:00\",\"dateModified\":\"2026-02-10T00:25:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/74597.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/74597.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/74597.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building a Simple Engine -- Loading Models -- Model system\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Building a Simple Engine - Loading Models - Model system - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/74597.html","og_locale":"zh_CN","og_type":"article","og_title":"Building a Simple Engine - Loading Models - Model system - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 1.1 \u57fa\u4e8e\u5df2\u6709 glTF \u77e5\u8bc6\u62d3\u5c55 1.2 \u642d\u5efa\u5f15\u64ce\u7684\u6a21\u578b\u7cfb\u7edf 1.3 \u5b9a\u4e49\u6570\u636e\u7ed3\u6784 1.4 \u4e3a\u4f55\u9700\u8981\u573a\u666f\u56fe 1.4.1 \u4f7f\u7528\u573a\u666f\u56fe\u7684\u4f18\u52bf 1.4.2 \u573a\u666f\u56fe vs \u7b80\u5355\u96c6\u5408 1.4.3 \u573a\u666f\u56fe vs \u7a7a\u95f4\u5206\u533a\u7cfb\u7edf&#xff08;\u6e38\u620f\u5730\u56fe&#xff09; 1.4.3.1 \u5e38\u89c1\u7684\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf 1.4.3.2 \u4e3b\u6d41\u5f15\u64ce\u4e2d\u7684\u7a7a\u95f4\u5206\u533a\u7cfb\u7edf 1.5 \u67b6\u6784\u51b3\u7b56 1.6 \u5f00\u53d1\u8005\u5982\u4f55\u4f7f\u7528\u6a21\u578b\u7cfb\u7edf 1.6.1 \u52a0\u8f7d\u5e76\u521d\u59cb\u5316\u6a21\u578b 1.6.2 \u66f4\u65b0\u5e76\u52a8\u753b\u5316\u6a21\u578b 1","og_url":"https:\/\/www.wsisp.com\/helps\/74597.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-10T00:25:07+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/74597.html","url":"https:\/\/www.wsisp.com\/helps\/74597.html","name":"Building a Simple Engine - Loading Models - Model system - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-10T00:25:07+00:00","dateModified":"2026-02-10T00:25:07+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/74597.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/74597.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/74597.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Building a Simple Engine -- Loading Models -- Model system"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/74597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=74597"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/74597\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=74597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=74597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=74597"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=74597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}