{"id":3525,"date":"2024-11-10T11:59:17","date_gmt":"2024-11-10T03:59:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3525\/"},"modified":"2024-11-10T11:59:17","modified_gmt":"2024-11-10T03:59:17","slug":"%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8-three-js-%e7%bb%98%e5%88%b6%e7%94%b1%e4%b8%89%e7%bb%b4%e5%9d%90%e6%a0%87%e6%95%b0%e7%bb%84%e5%ae%9a%e4%b9%89%e7%9a%84%e4%bb%bb%e6%84%8f%e5%bd%a2%e7%8a%b6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3525\/","title":{"rendered":"\u5982\u4f55\u5229\u7528 Three.js \u7ed8\u5236\u7531\u4e09\u7ef4\u5750\u6807\u6570\u7ec4\u5b9a\u4e49\u7684\u4efb\u610f\u5f62\u72b6\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173105183898045.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5229\u7528 Three.js \u7ed8\u5236\u7531\u4e09\u7ef4\u5750\u6807\u6570\u7ec4\u5b9a\u4e49\u7684\u4efb\u610f\u5f62\u72b6\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5229\u7528 Three.js \u7ed8\u5236\u7531\u4e09\u7ef4\u5750\u6807\u6570\u7ec4\u5b9a\u4e49\u7684\u4efb\u610f\u5f62\u72b6\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7528\u4e09\u7ef4\u5750\u6807\u7ed8\u5236\u4efb\u610f\u5f62\u72b6<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong>\u5df2\u6709\u4e09\u7ef4\u5750\u6807\u6570\u7ec4\uff0c\u5982 [[162,81,10],[162,704,10],[773,704,20],[773,145,20]]\u3002\u5982\u4f55\u5229\u7528 three.js \u7ed8\u5236\u5bf9\u5e94\u7684 3d \u5f62\u72b6\uff1f<\/p>\n<p><strong>\u7b54\u6848\uff1a<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u5f15\u7528 three.js \u5e93\uff1a<\/strong><\/p>\n<pre>&lt;script src=\"three.min.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  <\/li>\n<li>\n<p><strong>\u521b\u5efa\u573a\u666f\u548c\u6444\u50cf\u673a\uff1a<\/strong><\/p>\n<pre>const scene = new three.scene();\nconst camera = new three.perspectivecamera(75, window.innerwidth \/ window.innerheight, 0.1, 1000);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  <\/li>\n<li>\n<p><strong>\u4ece\u5750\u6807\u6570\u7ec4\u521b\u5efa\u51e0\u4f55\u4f53\uff1a<\/strong><\/p>\n<pre>const points = [[162,81,10],[162,704,10],[773,704,20],[773,145,20]];\nconst geometry = new three.geometry();\nfor (let i = 0; i &lt; points.length; i++) {\n  geometry.vertices.push(new three.vector3(...points[i]));\n}\ngeometry.faces.push(new three.face3(0, 1, 2), new three.face3(0, 2, 3));<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  <\/li>\n<li>\n<p><strong>\u521b\u5efa\u6750\u8d28\u5e76\u5c06\u5176\u5e94\u7528\u4e8e\u51e0\u4f55\u4f53\uff1a<\/strong><\/p>\n<pre>const material = new three.meshbasicmaterial({color: 0x00ff00, wireframe: true});\nconst mesh = new three.mesh(geometry, material);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  <\/li>\n<li>\n<p><strong>\u5c06\u7f51\u683c\u6dfb\u52a0\u5230\u573a\u666f\u4e2d\uff1a<\/strong><\/p>\n<pre>scene.add(mesh);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  <\/li>\n<li>\n<p><strong>\u6e32\u67d3\u573a\u666f\uff1a<\/strong><\/p>\n<pre>const renderer = new THREE.WebGLRenderer();\nrenderer.setSize(window.innerWidth, window.innerHeight);\ndocument.body.appendChild(renderer.domElement);\nrenderer.render(scene, camera);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  <\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5229\u7528 Three.js \u7ed8\u5236\u7531\u4e09\u7ef4\u5750\u6807\u6570\u7ec4\u5b9a\u4e49\u7684\u4efb\u610f\u5f62\u72b6\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528\u4e09\u7ef4\u5750\u6807\u7ed8\u5236\u4efb\u610f\u5f62\u72b6 \u95ee\u9898\uff1a\u5df2\u6709\u4e09\u7ef4\u5750\u6807\u6570\u7ec4\uff0c\u5982 [[162,81,10],[162,704,10],[773,704,20],[773,145,20]]\u3002\u5982\u4f55\u5229\u7528 three.js \u7ed8\u5236\u5bf9\u5e94\u7684 3d \u5f62\u72b6\uff1f \u7b54\u6848\uff1a \u5f15\u7528 three.js \u5e93\uff1a &lt;script src=&#8221;three.min.js&#8221;&gt;&lt;\/script&gt; \u767b\u5f55\u540e\u590d\u5236 \u521b\u5efa\u573a\u666f\u548c\u6444\u50cf\u673a\uff1a const scene = new three.scene(); const camera = new three.perspectivecamera(75, window.innerwidth \/ window.innerheight, 0.1, 1000); \u767b\u5f55\u540e\u590d\u5236 \u4ece\u5750\u6807\u6570\u7ec4\u521b\u5efa\u51e0\u4f55\u4f53\uff1a const points = [[162,81,10],[162,704,10],[773,704,20],[773,145,20]]; const geometry = new three.geometry(); for (let i = 0; i &lt; points.length; i++) { geometry.vertices.push(new three.vector3(&#8230;points[i])); } geometry.faces.push(new [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3525","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3525"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3525\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}