{"id":2458,"date":"2024-11-27T17:12:25","date_gmt":"2024-11-27T09:12:25","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=2458"},"modified":"2024-11-27T17:12:25","modified_gmt":"2024-11-27T09:12:25","slug":"web3d%e5%ad%a6%e4%b9%a0-%e4%bd%bf%e7%94%a8vue3%e5%88%9b%e5%bb%ba%e7%ae%80%e5%8d%95%e5%8f%af%e4%bb%a5%e4%ba%a4%e4%ba%92%e7%9a%84%e5%9f%ba%e7%a1%80%e7%ab%8b%e4%bd%93%e6%a8%a1%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2024\/11\/27\/web3d%e5%ad%a6%e4%b9%a0-%e4%bd%bf%e7%94%a8vue3%e5%88%9b%e5%bb%ba%e7%ae%80%e5%8d%95%e5%8f%af%e4%bb%a5%e4%ba%a4%e4%ba%92%e7%9a%84%e5%9f%ba%e7%a1%80%e7%ab%8b%e4%bd%93%e6%a8%a1%e5%9e%8b\/","title":{"rendered":"Web3D\u5b66\u4e60-\u4f7f\u7528Vue3\u521b\u5efa\u7b80\u5355\u53ef\u4ee5\u4ea4\u4e92\u7684\u57fa\u7840\u7acb\u4f53\u6a21\u578b"},"content":{"rendered":"\n<p><strong>Three.js<\/strong> \u662f\u4e00\u4e2a\u6d41\u884c\u7684\u5f00\u6e90 JavaScript \u5e93\uff0c\u65e8\u5728\u901a\u8fc7 WebGL \u5728\u7f51\u9875\u4e0a\u521b\u5efa\u548c\u6e32\u67d3 3D \u56fe\u5f62\u3002\u5b83\u62bd\u8c61\u4e86 WebGL \u7684\u590d\u6742\u6027\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7b80\u5355\u7684 API\uff0c\u4f7f\u5f00\u53d1\u8005\u80fd\u591f\u66f4\u5bb9\u6613\u5730\u521b\u5efa\u4e92\u52a8\u5f0f 3D \u5185\u5bb9\u3002\u4ee5\u4e0b\u662f Three.js \u7684\u4e00\u4e9b\u5173\u952e\u7279\u70b9\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/sanroimg.oss-cn-shanghai.aliyuncs.com\/img\/202411271714888.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n&lt;head>\n    &lt;meta charset=\"UTF-8\">\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    &lt;title>Three.js Demo with Mouse Interaction&lt;\/title>\n    &lt;style>\n        body {\n            margin: 0;\n            overflow: hidden;\n            background: #2c3e50;\n        }\n        canvas {\n            display: block;\n        }\n    &lt;\/style>\n&lt;\/head>\n&lt;body>\n&lt;script type=\"module\">\n    import * as THREE from \"..\/libs\/three.module.js\";\n\n    import { OrbitControls } from \"..\/libs\/OrbitControls.js\"; \/\/ \u5f15\u5165 OrbitControls\n\n    \/\/ \u521b\u5efa\u573a\u666f\n    const scene = new THREE.Scene();\n\n    \/\/ \u521b\u5efa\u76f8\u673a\n    const camera = new THREE.PerspectiveCamera(\n        75, \/\/ \u89c6\u89d2\n        window.innerWidth \/ window.innerHeight, \/\/ \u5bbd\u9ad8\u6bd4\n        0.1, \/\/ \u8fd1\u7aef\u88c1\u526a\n        1000 \/\/ \u8fdc\u7aef\u88c1\u526a\n    );\n    camera.position.z = 5; \/\/ \u786e\u4fdd\u76f8\u673a\u79bb\u7acb\u65b9\u4f53\u8fdc\u4e00\u4e9b\n\n    \/\/ \u521b\u5efa\u6e32\u67d3\u5668\n    const renderer = new THREE.WebGLRenderer();\n    renderer.setSize(window.innerWidth, window.innerHeight);\n    document.body.appendChild(renderer.domElement);\n\n    \/\/ \u521b\u5efa\u7acb\u65b9\u4f53\n    const geometry = new THREE.BoxGeometry();\n    const material = new THREE.MeshBasicMaterial({ color: 0x56585d });\n    const cube = new THREE.Mesh(geometry, material);\n    scene.add(cube);\n\n    \/\/ \u6dfb\u52a0\u5149\u6e90\n    const ambientLight = new THREE.AmbientLight(0x404040, 1); \/\/ \u73af\u5883\u5149\n    scene.add(ambientLight);\n\n    \/\/ \u6dfb\u52a0 OrbitControls\uff08\u9f20\u6807\u4ea4\u4e92\u63a7\u5236\uff09\n    const controls = new OrbitControls(camera, renderer.domElement);\n    controls.enableDamping = true; \/\/ \u542f\u7528\u60ef\u6027\n    controls.dampingFactor = 0.25; \/\/ \u963b\u5c3c\u56e0\u5b50\n    controls.screenSpacePanning = false; \/\/ \u7981\u6b62\u5c4f\u5e55\u5e73\u79fb\n\n    \/\/ \u52a8\u753b\u5faa\u73af\n    function animate() {\n        requestAnimationFrame(animate);\n\n        \/\/ \u6e32\u67d3\u573a\u666f\u548c\u76f8\u673a\n        renderer.render(scene, camera);\n\n        \/\/ \u66f4\u65b0\u63a7\u5236\u5668\n        controls.update();\n    }\n\n    animate();\n\n    \/\/ \u76d1\u542c\u7a97\u53e3\u5927\u5c0f\u53d8\u5316\uff0c\u8c03\u6574\u6e32\u67d3\u5668\u548c\u76f8\u673a\n    window.addEventListener(\"resize\", () => {\n        camera.aspect = window.innerWidth \/ window.innerHeight;\n        camera.updateProjectionMatrix();\n        renderer.setSize(window.innerWidth, window.innerHeight);\n    });\n&lt;\/script>\n&lt;\/body>\n&lt;\/html>\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u7b80\u5316\u7684 3D \u56fe\u5f62\u6e32\u67d3<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Three.js \u901a\u8fc7\u7b80\u5316 WebGL \u63d0\u4f9b\u7684 API\uff0c\u8ba9\u5f00\u53d1\u8005\u80fd\u591f\u8f7b\u677e\u5730\u5728\u7f51\u9875\u4e2d\u521b\u5efa 3D \u573a\u666f\u3002\u4f60\u4e0d\u9700\u8981\u6df1\u5165\u4e86\u89e3 WebGL \u7684\u5e95\u5c42\u5b9e\u73b0\uff0c\u53ea\u9700\u8981\u4f7f\u7528 Three.js \u63d0\u4f9b\u7684\u9ad8\u7ea7\u62bd\u8c61\u6765\u521b\u5efa\u7269\u4f53\u3001\u5149\u7167\u548c\u76f8\u673a\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u5f3a\u5927\u7684\u529f\u80fd<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>\u51e0\u4f55\u4f53<\/strong>\uff1aThree.js \u652f\u6301\u591a\u79cd 3D \u51e0\u4f55\u4f53\uff0c\u5305\u62ec\u7acb\u65b9\u4f53\u3001\u7403\u4f53\u3001\u5706\u73af\u3001\u5e73\u9762\u7b49\u3002<\/li><li><strong>\u6750\u8d28<\/strong>\uff1a\u4f60\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u6750\u8d28\u6765\u4e3a\u7269\u4f53\u8d4b\u4e88\u4e0d\u540c\u7684\u5916\u89c2\uff0c\u5982\u57fa\u7840\u6750\u8d28\u3001Phong \u6750\u8d28\u3001Lambert \u6750\u8d28\u3001\u6807\u51c6\u6750\u8d28\u7b49\uff0c\u652f\u6301\u7eb9\u7406\u6620\u5c04\u548c\u900f\u660e\u5ea6\u63a7\u5236\u3002<\/li><li><strong>\u5149\u6e90\u548c\u9634\u5f71<\/strong>\uff1a\u652f\u6301\u5404\u79cd\u5149\u6e90\u7c7b\u578b\uff08\u5982\u70b9\u5149\u6e90\u3001\u65b9\u5411\u5149\u3001\u73af\u5883\u5149\u7b49\uff09\uff0c\u5e76\u4e14\u80fd\u591f\u5b9e\u73b0\u590d\u6742\u7684\u9634\u5f71\u6548\u679c\u3002<\/li><li><strong>\u76f8\u673a<\/strong>\uff1aThree.js \u63d0\u4f9b\u4e86\u591a\u79cd\u7c7b\u578b\u7684\u76f8\u673a\uff08\u5982\u900f\u89c6\u76f8\u673a\u548c\u6b63\u4ea4\u76f8\u673a\uff09\uff0c\u4ee5\u53ca\u4e30\u5bcc\u7684\u76f8\u673a\u63a7\u5236\u529f\u80fd\uff0c\u53ef\u4ee5\u8f7b\u677e\u8bbe\u7f6e\u89c6\u89d2\u3002<\/li><li><strong>\u52a8\u753b<\/strong>\uff1a\u5185\u7f6e\u7684\u52a8\u753b\u7cfb\u7edf\u53ef\u4ee5\u7528\u6765\u63a7\u5236\u7269\u4f53\u7684\u8fd0\u52a8\u3001\u65cb\u8f6c\u3001\u7f29\u653e\u7b49\u5c5e\u6027\u3002<\/li><li><strong>\u540e\u671f\u5904\u7406\u6548\u679c<\/strong>\uff1a\u652f\u6301\u540e\u671f\u6548\u679c\uff0c\u5982\u6a21\u7cca\u3001\u5149\u6655\u3001\u7c92\u5b50\u6548\u679c\u7b49\uff0c\u53ef\u4ee5\u7528\u6765\u589e\u5f3a\u6e32\u67d3\u6548\u679c\u3002<\/li><li><strong>\u52a0\u8f7d\u6a21\u578b<\/strong>\uff1a\u901a\u8fc7\u52a0\u8f7d\u5916\u90e8\u6a21\u578b\uff08\u5982 <code>.obj<\/code>\u3001<code>.glb<\/code> \u7b49\u683c\u5f0f\uff09\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u590d\u6742\u7684 3D \u573a\u666f\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u8de8\u5e73\u53f0\u652f\u6301<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Three.js \u4f7f\u7528 WebGL\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u8fd0\u884c\u5728\u73b0\u4ee3\u6d4f\u89c8\u5668\u4e2d\uff0c\u65e0\u9700\u989d\u5916\u5b89\u88c5\u63d2\u4ef6\uff0c\u652f\u6301\u684c\u9762\u548c\u79fb\u52a8\u8bbe\u5907\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u4e30\u5bcc\u7684\u793e\u533a\u548c\u6587\u6863<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Three.js \u62e5\u6709\u5e9e\u5927\u7684\u5f00\u53d1\u8005\u793e\u533a\uff0c\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u793a\u4f8b\u548c\u6559\u7a0b\u3002\u5b98\u65b9\u6587\u6863\u8be6\u5c3d\uff0c\u6db5\u76d6\u4e86\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u7684\u5404\u7c7b\u4f7f\u7528\u573a\u666f\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u5b9e\u65f6\u6e32\u67d3<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Three.js \u652f\u6301\u5b9e\u65f6\u6e32\u67d3\uff0c\u9002\u7528\u4e8e\u6e38\u620f\u3001\u6570\u636e\u53ef\u89c6\u5316\u3001\u865a\u62df\u73b0\u5b9e\uff08VR\uff09\u3001\u589e\u5f3a\u73b0\u5b9e\uff08AR\uff09\u3001\u79d1\u5b66\u53ef\u89c6\u5316\u7b49\u5e94\u7528\u573a\u666f\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>\u4e0e\u5176\u4ed6\u5e93\u7684\u517c\u5bb9\u6027<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Three.js \u53ef\u4ee5\u4e0e\u5176\u4ed6 JavaScript \u5e93\u548c\u6846\u67b6\uff08\u5982 React\u3001Vue \u7b49\uff09\u65e0\u7f1d\u96c6\u6210\uff0c\u8fd8\u53ef\u4ee5\u4e0e WebXR API \u914d\u5408\u4f7f\u7528\uff0c\u652f\u6301 VR \u548c AR \u5e94\u7528\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>\u9002\u7528\u573a\u666f<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>\u6e38\u620f\u5f00\u53d1<\/strong>\uff1a\u521b\u5efa\u6d4f\u89c8\u5668\u4e2d\u8fd0\u884c\u7684 3D \u6e38\u620f\u3002<\/li><li><strong>\u865a\u62df\u73b0\u5b9e\uff08VR\uff09<\/strong>\uff1a\u6784\u5efa VR \u573a\u666f\uff0c\u8ba9\u7528\u6237\u5728\u865a\u62df\u7a7a\u95f4\u4e2d\u8fdb\u884c\u4e92\u52a8\u3002<\/li><li><strong>\u589e\u5f3a\u73b0\u5b9e\uff08AR\uff09<\/strong>\uff1a\u7ed3\u5408\u73b0\u5b9e\u4e16\u754c\u6570\u636e\u8fdb\u884c\u589e\u5f3a\u73b0\u5b9e\u663e\u793a\u3002<\/li><li><strong>\u6570\u636e\u53ef\u89c6\u5316<\/strong>\uff1a\u901a\u8fc7 3D \u56fe\u5f62\u5c55\u793a\u590d\u6742\u6570\u636e\uff0c\u63d0\u4f9b\u66f4\u76f4\u89c2\u7684\u5206\u6790\u3002<\/li><li><strong>\u827a\u672f\u521b\u4f5c<\/strong>\uff1a\u521b\u4f5c\u548c\u5c55\u793a\u6570\u5b57\u827a\u672f\u4f5c\u54c1\u3002<\/li><\/ul>\n\n\n\n<p>\u603b\u4e4b\uff0cThree.js \u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u4e14\u6613\u4e8e\u4e0a\u624b\u7684\u5e93\uff0c\u9002\u7528\u4e8e\u4efb\u4f55\u60f3\u8981\u5728 Web \u4e0a\u8fdb\u884c 3D \u521b\u4f5c\u7684\u5f00\u53d1\u8005\u3002\u5982\u679c\u4f60\u6709\u66f4\u6df1\u5165\u7684\u9700\u6c42\u6216\u60f3\u4e86\u89e3\u66f4\u591a\u9ad8\u7ea7\u529f\u80fd\uff0c\u968f\u65f6\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63a2\u7d22 Three.js \u7684\u5b98\u65b9\u6587\u6863\u548c\u793e\u533a\u8d44\u6e90\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Three.js \u662f\u4e00\u4e2a\u6d41\u884c\u7684\u5f00&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2458","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=2458"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2458\/revisions"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=2458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=2458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=2458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}