{"id":52604,"date":"2024-12-03T12:05:36","date_gmt":"2024-12-03T04:05:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52604\/"},"modified":"2024-12-03T12:05:36","modified_gmt":"2024-12-03T04:05:36","slug":"%e4%bd%bf%e7%94%a8-unpkg-%e5%af%bc%e5%85%a5-three-js-%e6%97%b6%ef%bc%8c%e4%b8%ba%e4%bb%80%e4%b9%88%e5%9c%a8-main-js-%e4%b8%ad%e6%97%a0%e6%b3%95%e8%af%86%e5%88%ab-three%ef%bc%9f-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52604\/","title":{"rendered":"\u4f7f\u7528 unpkg \u5bfc\u5165 three.js \u65f6\uff0c\u4e3a\u4ec0\u4e48\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u4f7f\u7528 unpkg \u5bfc\u5165 three.js \u65f6\uff0c\u4e3a\u4ec0\u4e48\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE\uff1f <\/h1>\n<p>\u6587\u7ae0\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300a\u4f7f\u7528 unpkg \u5bfc\u5165 three.js \u65f6\uff0c\u4e3a\u4ec0\u4e48\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE\uff1f \u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241121\/1732200131673f46c3b58bb.jpg\" class=\"aligncenter\" title=\"\u4f7f\u7528 unpkg \u5bfc\u5165 three.js \u65f6\uff0c\u4e3a\u4ec0\u4e48\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE\uff1f\u63d2\u56fe\" alt=\"\u4f7f\u7528 unpkg \u5bfc\u5165 three.js \u65f6\uff0c\u4e3a\u4ec0\u4e48\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u901a\u8fc7 unpkg \u5f15\u5165 three.js<\/strong><\/p>\n<p>\u60a8\u5e0c\u671b\u901a\u8fc7 unpkg \u5728\u6ca1\u6709\u4efb\u4f55\u524d\u7aef\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\u5bfc\u5165 three.js\u3002\u7136\u800c\uff0c\u5728\u60a8\u7684\u4ee3\u7801\u4e2d\uff0c\u60a8\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE\u3002<\/p>\n<p>\u51fa\u73b0\u6b64\u9519\u8bef\u662f\u56e0\u4e3a\u60a8\u5c1a\u672a\u5728 index.html \u4e2d\u6b63\u786e\u5bfc\u5165 THREE \u6a21\u5757\u3002\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u8fdb\u884c\u4ee5\u4e0b\u66f4\u6539\uff1a<\/p>\n<p>\u4f7f\u7528 importmap \u5f15\u5165 three.js \u6a21\u5757\uff1a<\/p>\n<p><strong>index.html<\/strong><\/p>\n<pre>&lt;script type=\"importmap\"&gt;\n  {\n    \"imports\": {\n      \"three\": \"https:\/\/unpkg.com\/three@0.155.0\/build\/three.module.js\"\n    }\n  }\n&lt;\/script&gt;\n&lt;script type=\"module\"&gt;\n  import * as THREE from 'three';\n  console.log(THREE);\n&lt;\/script&gt;<\/pre>\n<p>\u6216\u8005\uff0c\u76f4\u63a5\u5728 &lt;script&gt; \u6807\u7b7e\u4e2d\u5bfc\u5165 three.js \u6a21\u5757\uff1a<\/p>\n<p><strong>index.html<\/strong><\/p>\n<pre>&lt;script type=\"module\"&gt;\n  import * as THREE from 'https:\/\/unpkg.com\/three@0.155.0\/build\/three.module.js';\n  console.log(THREE);\n&lt;\/script&gt;<\/pre>\n<p>\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u5728 main.js \u4e2d\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u8bbf\u95ee THREE\uff1a<\/p>\n<p><strong>main.js<\/strong><\/p>\n<pre>console.log(\"Hello Three.js\");\nconsole.log(\"js\" + THREE);\nconst scene = new THREE.Scene();<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u4f7f\u7528 unpkg \u5bfc\u5165 three.js \u65f6\uff0c\u4e3a\u4ec0\u4e48\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE\uff1f \u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u5185\u5d4c CSS \u7684\u7a7a\u6807\u7b7e\u4e4b\u8c1c\uff1a\u6837\u5f0f\u89c4\u5219\u662f\u5982\u4f55\u5e94\u7528\u7684\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 unpkg \u5bfc\u5165 three.js \u65f6\uff0c\u4e3a\u4ec0\u4e48\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE\uff1f \u6587\u7ae0\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300a\u4f7f\u7528 unpkg \u5bfc\u5165 three.js \u65f6\uff0c\u4e3a\u4ec0\u4e48\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE\uff1f \u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 \u901a\u8fc7 unpkg \u5f15\u5165 three.js \u60a8\u5e0c\u671b\u901a\u8fc7 unpkg \u5728\u6ca1\u6709\u4efb\u4f55\u524d\u7aef\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\u5bfc\u5165 three.js\u3002\u7136\u800c\uff0c\u5728\u60a8\u7684\u4ee3\u7801\u4e2d\uff0c\u60a8\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE\u3002 \u51fa\u73b0\u6b64\u9519\u8bef\u662f\u56e0\u4e3a\u60a8\u5c1a\u672a\u5728 index.html \u4e2d\u6b63\u786e\u5bfc\u5165 THREE \u6a21\u5757\u3002\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u8fdb\u884c\u4ee5\u4e0b\u66f4\u6539\uff1a \u4f7f\u7528 importmap \u5f15\u5165 three.js \u6a21\u5757\uff1a index.html &lt;script type=&#8221;importmap&#8221;&gt; { &#8220;imports&#8221;: { &#8220;three&#8221;: &#8220;https:\/\/unpkg.com\/three@0.155.0\/build\/three.module.js&#8221; } } &lt;\/script&gt; &lt;script type=&#8221;module&#8221;&gt; import * as THREE [&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-52604","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52604","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=52604"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52604\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}