{"id":100799,"date":"2026-09-05T11:01:02","date_gmt":"2026-09-05T03:01:02","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/100799.html"},"modified":"2026-09-05T11:01:02","modified_gmt":"2026-09-05T03:01:02","slug":"three-js-%e9%9b%b6%e5%9f%ba%e7%a1%80%e7%b3%bb%e7%bb%9f%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/100799.html","title":{"rendered":"Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b"},"content":{"rendered":"<h2>Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b<\/h2>\n<h2>\u524d\u8a00<\/h2>\n<p>\u4ece\u96f6\u5230\u4f01\u4e1a\u7ea7\u7684 Three.js \u5b8c\u6574\u7cfb\u7edf\u6559\u7a0b&#xff0c;\u4e13\u4e3a\u524d\u7aef\u5f00\u53d1\u8005\u6574\u7406&#xff0c;\u7ed3\u6784\u6e05\u6670\u3001\u7531\u6d45\u5165\u6df1\u3001\u65e0\u5e9f\u8bdd\u3001\u53ef\u76f4\u63a5\u5f53\u505a\u535a\u5ba2\u7b14\u8bb0\u3001\u5b66\u4e60\u624b\u518c\u3001\u9762\u8bd5\u590d\u4e60\u6587\u6863\u3002<br \/>\n\u8986\u76d6&#xff1a;\u57fa\u7840\u67b6\u6784 \u2192 \u76f8\u673a\/\u63a7\u4ef6\/\u5149\u7167\/\u9634\u5f71 \u2192 \u51e0\u4f55\u4f53\/\u6750\u8d28\/\u7eb9\u7406 \u2192 \u52a8\u753b\/\u4ea4\u4e92\/\u6a21\u578b\u52a0\u8f7d \u2192 \u7279\u6548\/\u540e\u5904\u7406 \u2192 \u5b9e\u6218\u9879\u76ee \u2192 \u6027\u80fd\u4f18\u5316\u3002<\/p>\n<h2>\u7b2c\u4e00\u7ae0 Three.js \u7b80\u4ecb\u4e0e\u73af\u5883\u642d\u5efa<\/h2>\n<h3>1.1 \u4ec0\u4e48\u662f Three.js<\/h3>\n<p>Three.js \u662f\u57fa\u4e8e\u539f\u751f WebGL \/ WebGPU \u7684\u524d\u7aef 3D \u56fe\u5f62\u6e32\u67d3\u5f15\u64ce\u3002<\/p>\n<p>\u539f\u751f WebGL \u6781\u5176\u5e95\u5c42\u3001\u4ee3\u7801\u7e41\u7410\u3001\u9700\u8981\u624b\u52a8\u7ba1\u7406\u7f13\u51b2\u533a\u3001\u7740\u8272\u5668\u3001\u77e9\u9635\u3001\u5e27\u7f13\u5b58\u3002Three.js \u5bf9\u5e95\u5c42\u8fdb\u884c\u4e86\u9ad8\u5ea6\u5c01\u88c5&#xff0c;\u8ba9\u524d\u7aef\u53ef\u4ee5\u7528\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u5f0f\u5feb\u901f\u5f00\u53d1 3D \u573a\u666f\u3002<\/p>\n<p>\u4e00\u53e5\u8bdd\u672c\u8d28&#xff1a;Three.js &#061; \u524d\u7aef\u7684 3D \u6846\u67b6<\/p>\n<h4>\u9002\u7528\u573a\u666f<\/h4>\n<ul>\n<li>\n<p>\u6570\u636e\u53ef\u89c6\u5316&#xff1a;3D \u5730\u56fe\u3001\u6570\u5b57\u5b6a\u751f\u3001\u5927\u5c4f\u6c99\u76d8<\/p>\n<\/li>\n<li>\n<p>Web 3D \u5c55\u793a&#xff1a;\u5546\u54c1\u3001\u6237\u578b\u3001\u6c7d\u8f66\u3001\u6a21\u578b\u9884\u89c8<\/p>\n<\/li>\n<li>\n<p>Web \u5c0f\u6e38\u620f\u30013D \u827a\u672f\u7279\u6548\u3001\u7c92\u5b50\u52a8\u753b<\/p>\n<\/li>\n<li>\n<p>WebXR \/ VR \/ AR \u865a\u62df\u73b0\u5b9e\u573a\u666f<\/p>\n<\/li>\n<\/ul>\n<h3>1.2 Three.js \u6838\u5fc3\u4e09\u5927\u4ef6&#xff08;\u5fc5\u80cc&#xff09;<\/h3>\n<p>\u6240\u6709 Three.js \u753b\u9762&#xff0c;\u53ea\u7531\u4e09\u4e2a\u6838\u5fc3\u7ec4\u4ef6\u6784\u6210&#xff1a;<\/p>\n<li>\n<p>Scene \u573a\u666f&#xff1a;3D \u4e16\u754c\u7684\u5bb9\u5668&#xff08;\u821e\u53f0&#xff09;<\/p>\n<\/li>\n<li>\n<p>Camera \u76f8\u673a&#xff1a;\u89c2\u5bdf\u8005&#xff08;\u4f60\u80fd\u770b\u5230\u4ec0\u4e48&#xff09;<\/p>\n<\/li>\n<li>\n<p>Renderer \u6e32\u67d3\u5668&#xff1a;\u7ed8\u5236\u753b\u9762&#xff08;\u628a 3D \u753b\u5230\u753b\u5e03&#xff09;<\/p>\n<\/li>\n<p>\u4e07\u80fd\u516c\u5f0f&#xff1a;3D\u753b\u9762 &#061; \u573a\u666f &#043; \u76f8\u673a &#043; \u9010\u5e27\u6e32\u67d3<\/p>\n<h3>1.3 \u73af\u5883\u5b89\u88c5<\/h3>\n<h4>\u65b9\u5f0f\u4e00&#xff1a;Vite \u5de5\u7a0b\u5316&#xff08;\u63a8\u8350\u4f01\u4e1a\u5f00\u53d1&#xff09;<\/h4>\n<p>npm create vite&#064;latest three-demo &#8212; &#8211;template vanilla<br \/>\ncd three-demo<br \/>\nnpm install three<br \/>\nnpm run dev<\/p>\n<h4>\u65b9\u5f0f\u4e8c&#xff1a;CDN \u5feb\u901f\u4f53\u9a8c<\/h4>\n<p>&lt;script type&#061;&#034;importmap&#034;&gt;<br \/>\n{<br \/>\n  &#034;imports&#034;: {<br \/>\n    &#034;three&#034;: &#034;https:\/\/unpkg.com\/three&#064;0.160.0\/build\/three.module.js&#034;,<br \/>\n    &#034;three\/addons\/&#034;: &#034;https:\/\/unpkg.com\/three&#064;0.160.0\/examples\/jsm\/&#034;<br \/>\n  }<br \/>\n}<br \/>\n&lt;\/script&gt;<br \/>\n&lt;script type&#061;&#034;module&#034;&gt;<br \/>\nimport * as THREE from &#039;three&#039;<br \/>\n&lt;\/script&gt;<\/p>\n<h3>1.4 \u6700\u7b80\u901a\u7528\u521d\u59cb\u5316\u6a21\u677f&#xff08;\u9879\u76ee\u4e07\u80fd\u9aa8\u67b6&#xff09;<\/h3>\n<p>\u5305\u542b&#xff1a;\u573a\u666f\u3001\u76f8\u673a\u3001\u6e32\u67d3\u5668\u3001\u6297\u952f\u9f7f\u3001\u9002\u914d\u3001\u52a8\u753b\u5faa\u73af\u3001\u8f68\u9053\u63a7\u5236\u5668<\/p>\n<p>import * as THREE from &#039;three&#039;<br \/>\nimport { OrbitControls } from &#039;three\/addons\/controls\/OrbitControls.js&#039;<\/p>\n<p>\/\/ 1. \u573a\u666f<br \/>\nconst scene &#061; new THREE.Scene()<\/p>\n<p>\/\/ 2. \u76f8\u673a<br \/>\nconst camera &#061; new THREE.PerspectiveCamera(75, window.innerWidth \/ window.innerHeight, 0.1, 1000)<br \/>\ncamera.position.z &#061; 5<\/p>\n<p>\/\/ 3. \u6e32\u67d3\u5668<br \/>\nconst renderer &#061; new THREE.WebGLRenderer({ antialias: true })<br \/>\nrenderer.setSize(window.innerWidth, window.innerHeight)<br \/>\nrenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))<br \/>\ndocument.body.appendChild(renderer.domElement)<\/p>\n<p>\/\/ 4. \u63a7\u5236\u5668<br \/>\nconst controls &#061; new OrbitControls(camera, renderer.domElement)<br \/>\ncontrols.enableDamping &#061; true<\/p>\n<p>\/\/ 5. \u6d4b\u8bd5\u7269\u4f53<br \/>\nconst cube &#061; new THREE.Mesh(<br \/>\n  new THREE.BoxGeometry(1, 1, 1),<br \/>\n  new THREE.MeshNormalMaterial()<br \/>\n)<br \/>\nscene.add(cube)<\/p>\n<p>\/\/ \u52a8\u753b\u5faa\u73af<br \/>\nfunction animate() {<br \/>\n  requestAnimationFrame(animate)<br \/>\n  controls.update()<br \/>\n  cube.rotation.y &#043;&#061; 0.01<br \/>\n  renderer.render(scene, camera)<br \/>\n}<br \/>\nanimate()<\/p>\n<p>\/\/ \u7a97\u53e3\u9002\u914d<br \/>\nwindow.addEventListener(&#039;resize&#039;, () &#061;&gt; {<br \/>\n  camera.aspect &#061; window.innerWidth \/ window.innerHeight<br \/>\n  camera.updateProjectionMatrix()<br \/>\n  renderer.setSize(window.innerWidth, window.innerHeight)<br \/>\n})<\/p>\n<h2>\u7b2c\u4e8c\u7ae0 \u76f8\u673a\u4e0e\u63a7\u5236\u5668\u7cfb\u7edf<\/h2>\n<h3>2.1 \u4e24\u79cd\u76f8\u673a\u539f\u7406\u4e0e\u533a\u522b<\/h3>\n<h4>\u900f\u89c6\u76f8\u673a PerspectiveCamera&#xff08;99% \u573a\u666f&#xff09;<\/h4>\n<p>\u6a21\u62df\u4eba\u773c&#xff0c;\u8fd1\u5927\u8fdc\u5c0f\u3001\u900f\u89c6\u7578\u53d8\u3002<\/p>\n<p>new THREE.PerspectiveCamera(FOV, \u5bbd\u9ad8\u6bd4, \u8fd1\u88c1\u526a\u9762, \u8fdc\u88c1\u526a\u9762)<\/p>\n<ul>\n<li>\n<p>FOV&#xff1a;\u89c6\u573a\u89d2&#xff0c;\u8d8a\u5927\u8d8a\u5e7f\u89d2\u3001\u53d8\u5f62\u8d8a\u5f3a&#xff08;45~75 \u6700\u4f73&#xff09;<\/p>\n<\/li>\n<li>\n<p>near&#xff1a;\u8fd1\u88c1\u526a\u9762&#xff0c;\u4e0d\u80fd\u8bbe 0<\/p>\n<\/li>\n<li>\n<p>far&#xff1a;\u8fdc\u88c1\u526a\u9762&#xff0c;\u8fc7\u5927\u4f1a\u51fa\u73b0\u6df1\u5ea6\u6296\u52a8<\/p>\n<\/li>\n<\/ul>\n<h4>\u6b63\u4ea4\u76f8\u673a OrthographicCamera&#xff08;\u65e0\u900f\u89c6&#xff09;<\/h4>\n<p>\u7269\u4f53\u8fdc\u8fd1\u5927\u5c0f\u4e00\u81f4&#xff0c;\u9002\u5408 CAD\u30012.5D\u3001UI\u3001\u6c99\u76d8\u3002<\/p>\n<h3>2.2 OrbitControls \u8f68\u9053\u63a7\u5236\u5668\u5168\u89e3<\/h3>\n<p>\u652f\u6301\u62d6\u62fd\u65cb\u8f6c\u3001\u6eda\u8f6e\u7f29\u653e\u3001\u53f3\u952e\u5e73\u79fb&#xff0c;\u662f\u6240\u6709 3D \u9879\u76ee\u6807\u914d\u3002<\/p>\n<p>const controls &#061; new OrbitControls(camera, renderer.domElement)<br \/>\ncontrols.enableDamping &#061; true \/\/ \u60ef\u6027\u987a\u6ed1<br \/>\ncontrols.dampingFactor &#061; 0.04<\/p>\n<p>\/\/ \u7f29\u653e\u9650\u5236<br \/>\ncontrols.minDistance &#061; 2<br \/>\ncontrols.maxDistance &#061; 20<\/p>\n<p>\/\/ \u89d2\u5ea6\u9650\u5236&#xff08;\u9632\u7a7f\u5e2e&#xff09;<br \/>\ncontrols.maxPolarAngle &#061; Math.PI \/ 2.1<\/p>\n<p>\/\/ \u81ea\u52a8\u65cb\u8f6c<br \/>\ncontrols.autoRotate &#061; false<br \/>\ncontrols.autoRotateSpeed &#061; 2<\/p>\n<p>\u26a0\ufe0f \u5fc5\u987b\u5728\u52a8\u753b\u5faa\u73af\u6267\u884c controls.update()<\/p>\n<h2>\u7b2c\u4e09\u7ae0 \u5149\u7167\u4e0e\u9634\u5f71\u7cfb\u7edf<\/h2>\n<h3>3.1 \u4e94\u5927\u5149\u6e90\u8be6\u89e3<\/h3>\n<h4>AmbientLight \u73af\u5883\u5149<\/h4>\n<p>\u5168\u5c40\u5747\u5300\u8865\u5149&#xff0c;\u65e0\u65b9\u5411\u3001\u65e0\u9634\u5f71&#xff0c;\u53ea\u63d0\u4eae\u573a\u666f\u3002<\/p>\n<h4>DirectionalLight \u5e73\u884c\u5149&#xff08;\u4e3b\u5149\u6e90\/\u592a\u9633\u5149&#xff09;<\/h4>\n<p>\u65b9\u5411\u56fa\u5b9a\u3001\u53ef\u4ea7\u751f\u9ad8\u8d28\u91cf\u9634\u5f71&#xff0c;\u9879\u76ee\u4e3b\u5149\u9996\u9009\u3002<\/p>\n<h4>PointLight \u70b9\u5149\u6e90<\/h4>\n<p>\u706f\u6ce1\u6548\u679c&#xff0c;\u5411\u56db\u5468\u53d1\u6563&#xff0c;\u6709\u8870\u51cf\u3001\u6709\u9634\u5f71\u3002<\/p>\n<h4>SpotLight \u805a\u5149\u706f<\/h4>\n<p>\u624b\u7535\u7b52\/\u821e\u53f0\u706f&#xff0c;\u9525\u5f62\u7167\u5c04\u3001\u8fb9\u7f18\u7fbd\u5316\u3002<\/p>\n<h4>HemisphereLight \u534a\u7403\u5149<\/h4>\n<p>\u5929\u7a7a&#043;\u5730\u9762\u6e10\u53d8&#xff0c;\u6a21\u62df\u81ea\u7136\u5ba4\u5916\u5929\u5149\u3002<\/p>\n<h3>3.2 \u9634\u5f71\u5b8c\u6574\u5f00\u542f\u6d41\u7a0b&#xff08;\u9762\u8bd5\u9ad8\u9891&#xff09;<\/h3>\n<p>\u9634\u5f71\u5fc5\u987b\u56db\u6b65\u5168\u5f00&#xff0c;\u7f3a\u4e00\u4e0d\u663e\u793a&#xff1a;<\/p>\n<p>\/\/ 1. \u6e32\u67d3\u5668\u5f00\u542f\u9634\u5f71<br \/>\nrenderer.shadowMap.enabled &#061; true<br \/>\nrenderer.shadowMap.type &#061; THREE.PCFSoftShadowMap<\/p>\n<p>\/\/ 2. \u5149\u6e90\u5f00\u542f\u9634\u5f71<br \/>\nlight.castShadow &#061; true<br \/>\nlight.shadow.mapSize.set(2048, 2048)<\/p>\n<p>\/\/ 3. \u7269\u4f53\u6295\u5c04\u9634\u5f71<br \/>\nmesh.castShadow &#061; true<\/p>\n<p>\/\/ 4. \u5730\u9762\u63a5\u6536\u9634\u5f71<br \/>\nfloor.receiveShadow &#061; true<\/p>\n<h3>3.3 \u9634\u5f71\u5e38\u89c1\u95ee\u9898\u89e3\u51b3<\/h3>\n<ul>\n<li>\n<p>\u9634\u5f71\u952f\u9f7f&#xff1a;\u63d0\u5347 mapSize<\/p>\n<\/li>\n<li>\n<p>\u9634\u5f71\u6761\u7eb9\u95ea\u70c1&#xff1a;light.shadow.bias &#061; -0.001<\/p>\n<\/li>\n<li>\n<p>\u9634\u5f71\u8303\u56f4\u592a\u5c0f&#xff1a;\u8c03\u6574 shadow.camera \u89c6\u53e3<\/p>\n<\/li>\n<\/ul>\n<h2>\u7b2c\u56db\u7ae0 \u51e0\u4f55\u4f53\u7cfb\u7edf<\/h2>\n<h3>4.1 \u5e38\u7528\u5185\u7f6e\u51e0\u4f55\u4f53<\/h3>\n<p>\u6240\u6709\u51e0\u4f55\u4f53\u5e95\u5c42\u90fd\u662f BufferGeometry \u9876\u70b9\u7f13\u51b2\u6570\u636e\u3002<\/p>\n<ul>\n<li>\n<p>BoxGeometry \u7acb\u65b9\u4f53<\/p>\n<\/li>\n<li>\n<p>SphereGeometry \u7403\u4f53<\/p>\n<\/li>\n<li>\n<p>CylinderGeometry \u5706\u67f1<\/p>\n<\/li>\n<li>\n<p>ConeGeometry \u5706\u9525<\/p>\n<\/li>\n<li>\n<p>PlaneGeometry \u5e73\u9762<\/p>\n<\/li>\n<li>\n<p>TorusGeometry \u5706\u73af<\/p>\n<\/li>\n<li>\n<p>CapsuleGeometry \u80f6\u56ca\u4f53<\/p>\n<\/li>\n<\/ul>\n<h3>4.2 \u81ea\u5b9a\u4e49\u9876\u70b9\u51e0\u4f55\u4f53<\/h3>\n<p>\u624b\u52a8\u7ed8\u5236\u4e09\u89d2\u9762&#xff0c;\u81ea\u7531\u6784\u5efa\u4efb\u610f\u5f62\u72b6\u3002<\/p>\n<p>const geometry &#061; new THREE.BufferGeometry()<br \/>\nconst points &#061; new Float32Array([<br \/>\n  -1, -1, 0,<br \/>\n  1, -1, 0,<br \/>\n  0, 1, 0<br \/>\n])<br \/>\ngeometry.setAttribute(&#039;position&#039;, new THREE.BufferAttribute(points, 3))<br \/>\ngeometry.computeVertexNormals()<\/p>\n<h3>4.3 \u62c9\u4f38\u51e0\u4f55\u4f53 ExtrudeGeometry<\/h3>\n<p>\u5c06 2D \u56fe\u5f62\u62c9\u4f38\u4e3a 3D \u7acb\u4f53&#xff0c;3D\u5730\u56fe\u3001\u697c\u5b87\u5efa\u6a21\u6838\u5fc3\u3002<\/p>\n<h2>\u7b2c\u4e94\u7ae0 \u6750\u8d28\u7cfb\u7edf&#xff08;PBR\u6838\u5fc3&#xff09;<\/h2>\n<h3>5.1 \u6750\u8d28\u5206\u7c7b<\/h3>\n<h4>\u4e0d\u53d7\u5149\u6750\u8d28<\/h4>\n<ul>\n<li>\n<p>MeshBasicMaterial&#xff1a;\u7eaf\u8272\u65e0\u5149\u5f71<\/p>\n<\/li>\n<li>\n<p>MeshNormalMaterial&#xff1a;\u6cd5\u7ebf\u8c03\u8bd5\u6750\u8d28<\/p>\n<\/li>\n<\/ul>\n<h4>\u4f20\u7edf\u5149\u7167\u6750\u8d28<\/h4>\n<ul>\n<li>\n<p>MeshLambertMaterial&#xff1a;\u6f2b\u53cd\u5c04\u3001\u65e0\u9ad8\u5149<\/p>\n<\/li>\n<li>\n<p>MeshPhongMaterial&#xff1a;\u9ad8\u5149\u3001\u5851\u6599\u8d28\u611f<\/p>\n<\/li>\n<\/ul>\n<h4>PBR \u7269\u7406\u6750\u8d28&#xff08;\u4f01\u4e1a\u9996\u9009&#xff09;<\/h4>\n<p>MeshStandardMaterial \u771f\u5b9e\u7269\u7406\u6e32\u67d3<\/p>\n<ul>\n<li>\n<p>metalness \u91d1\u5c5e\u5ea6&#xff1a;0\u7edd\u7f18 \/ 1\u91d1\u5c5e<\/p>\n<\/li>\n<li>\n<p>roughness \u7c97\u7cd9\u5ea6&#xff1a;0\u955c\u9762 \/ 1\u7c97\u7cd9<\/p>\n<\/li>\n<\/ul>\n<p>MeshPhysicalMaterial&#xff1a;\u652f\u6301\u6298\u5c04\u3001\u900f\u5149\u3001\u73bb\u7483\u3001\u8f66\u6f06<\/p>\n<h2>\u7b2c\u516d\u7ae0 \u7eb9\u7406\u8d34\u56fe\u7cfb\u7edf<\/h2>\n<h3>6.1 \u4e5d\u5927\u6838\u5fc3\u8d34\u56fe<\/h3>\n<ul>\n<li>\n<p>map \u989c\u8272\u8d34\u56fe<\/p>\n<\/li>\n<li>\n<p>normalMap \u6cd5\u7ebf\u51f9\u51f8\u8d34\u56fe<\/p>\n<\/li>\n<li>\n<p>roughnessMap \u7c97\u7cd9\u5ea6\u8d34\u56fe<\/p>\n<\/li>\n<li>\n<p>metalnessMap \u91d1\u5c5e\u5ea6\u8d34\u56fe<\/p>\n<\/li>\n<li>\n<p>aoMap \u73af\u5883\u5149\u906e\u853d<\/p>\n<\/li>\n<li>\n<p>displacementMap \u4f4d\u79fb\u8d34\u56fe<\/p>\n<\/li>\n<li>\n<p>alphaMap \u900f\u660e\u8d34\u56fe<\/p>\n<\/li>\n<li>\n<p>emissiveMap \u81ea\u53d1\u5149\u8d34\u56fe<\/p>\n<\/li>\n<li>\n<p>envMap \u73af\u5883\u53cd\u5c04\u8d34\u56fe<\/p>\n<\/li>\n<\/ul>\n<h3>6.2 \u7eb9\u7406\u57fa\u7840\u914d\u7f6e<\/h3>\n<p>const texture &#061; new THREE.TextureLoader().load(&#039;xxx.jpg&#039;)<br \/>\ntexture.wrapS &#061; THREE.RepeatWrapping<br \/>\ntexture.wrapT &#061; THREE.RepeatWrapping<br \/>\ntexture.repeat.set(2,2)<\/p>\n<h2>\u7b2c\u4e03\u7ae0 \u52a8\u753b\u7cfb\u7edf<\/h2>\n<h3>7.1 \u65f6\u95f4\u9a71\u52a8\u52a8\u753b&#xff08;\u65e0\u5e27\u7387\u6296\u52a8&#xff09;<\/h3>\n<p>const clock &#061; new THREE.Clock()<br \/>\nfunction animate(){<br \/>\n  requestAnimationFrame(animate)<br \/>\n  const t &#061; clock.getElapsedTime()<br \/>\n  cube.position.y &#061; Math.sin(t) * 0.5<br \/>\n  cube.rotation.y &#061; t * 2<br \/>\n  renderer.render(scene,camera)<br \/>\n}<\/p>\n<h3>7.2 GSAP \u4e13\u4e1a\u52a8\u753b<\/h3>\n<p>import gsap from &#039;gsap&#039;<br \/>\ngsap.to(cube.position,{<br \/>\n  x:2,<br \/>\n  duration:1,<br \/>\n  repeat:-1,<br \/>\n  yoyo:true<br \/>\n})<\/p>\n<h2>\u7b2c\u516b\u7ae0 \u9f20\u6807\u4ea4\u4e92\u4e0e\u5c04\u7ebf\u62fe\u53d6<\/h2>\n<h3>8.1 Raycaster \u5c04\u7ebf\u68c0\u6d4b\u539f\u7406<\/h3>\n<p>\u4ece\u76f8\u673a\u53d1\u5c04\u4e00\u6761\u5c04\u7ebf&#xff0c;\u7a7f\u900f\u573a\u666f\u7269\u4f53&#xff0c;\u5b9e\u73b0 hover\u3001\u70b9\u51fb\u62fe\u53d6\u3002<\/p>\n<h3>8.2 \u901a\u7528\u62fe\u53d6\u4ee3\u7801\u6a21\u677f<\/h3>\n<p>const raycaster &#061; new THREE.Raycaster()<br \/>\nconst mouse &#061; new THREE.Vector2()<\/p>\n<p>window.addEventListener(&#039;mousemove&#039;,e&#061;&gt;{<br \/>\n  mouse.x &#061; (e.clientX \/ innerWidth) * 2 &#8211; 1<br \/>\n  mouse.y &#061; -(e.clientY \/ innerHeight) * 2 &#043; 1<br \/>\n})<\/p>\n<p>function checkHover(){<br \/>\n  raycaster.setFromCamera(mouse,camera)<br \/>\n  const res &#061; raycaster.intersectObjects(scene.children)<br \/>\n  if(res.length){<br \/>\n    console.log(&#039;\u9009\u4e2d\u7269\u4f53&#039;,res[0].object)<br \/>\n  }<br \/>\n}<\/p>\n<h2>\u7b2c\u4e5d\u7ae0 3D\u6a21\u578b\u52a0\u8f7d\u7cfb\u7edf<\/h2>\n<h3>9.1 \u4e3b\u6d41\u6a21\u578b\u683c\u5f0f\u5bf9\u6bd4<\/h3>\n<ul>\n<li>\n<p>GLB \/ GLTF&#xff1a;\u884c\u4e1a\u6807\u51c6\u3001\u4f53\u79ef\u5c0f\u3001\u8d34\u56fe\u52a8\u753b\u9f50\u5168\u3001\u9996\u9009<\/p>\n<\/li>\n<li>\n<p>FBX&#xff1a;\u6a21\u578b\u5927\u3001\u517c\u5bb9\u8001\u9879\u76ee<\/p>\n<\/li>\n<li>\n<p>OBJ&#xff1a;\u65e0\u52a8\u753b\u3001\u8001\u5f0f\u683c\u5f0f<\/p>\n<\/li>\n<\/ul>\n<h3>9.2 GLB \u6a21\u578b\u52a0\u8f7d\u6a21\u677f<\/h3>\n<p>import { GLTFLoader } from &#039;three\/addons\/loaders\/GLTFLoader.js&#039;<br \/>\nconst loader &#061; new GLTFLoader()<\/p>\n<p>loader.load(&#039;\/model.glb&#039;,gltf&#061;&gt;{<br \/>\n  const model &#061; gltf.scene<br \/>\n  model.traverse(child&#061;&gt;{<br \/>\n    if(child.isMesh){<br \/>\n      child.castShadow &#061; true<br \/>\n      child.receiveShadow &#061; true<br \/>\n    }<br \/>\n  })<br \/>\n  scene.add(model)<br \/>\n})<\/p>\n<h2>\u7b2c\u5341\u7ae0 \u9ad8\u7ea7\u7279\u6548\u4e0e\u5de5\u7a0b\u4f18\u5316<\/h2>\n<h3>10.1 \u540e\u5904\u7406\u7279\u6548<\/h3>\n<p>\u8f89\u5149\u3001\u666f\u6df1\u3001\u63cf\u8fb9\u3001AO\u3001\u8c03\u8272&#xff0c;\u5927\u5e45\u63d0\u5347\u753b\u9762\u8d28\u611f\u3002<\/p>\n<h3>10.2 \u6027\u80fd\u4f18\u5316\u6838\u5fc3\u65b9\u6848<\/h3>\n<ul>\n<li>\n<p>InstancedMesh \u5b9e\u4f8b\u5316\u6e32\u67d3&#xff08;\u6d77\u91cf\u7269\u4f53&#xff09;<\/p>\n<\/li>\n<li>\n<p>DRACO \u6a21\u578b\u538b\u7f29<\/p>\n<\/li>\n<li>\n<p>\u8d34\u56fe\u5c3a\u5bf8\u9650\u5236 1024\/2048<\/p>\n<\/li>\n<li>\n<p>\u89c6\u9525\u4f53\u5254\u9664\u3001LOD \u591a\u7ea7\u7ec6\u8282<\/p>\n<\/li>\n<li>\n<p>\u5c04\u7ebf\u68c0\u6d4b\u8282\u6d41\u3001\u9650\u5b9a\u68c0\u6d4b\u5bf9\u8c61<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b<br \/>\n\u524d\u8a00<br \/>\n\u4ece\u96f6\u5230\u4f01\u4e1a\u7ea7\u7684 Three.js \u5b8c\u6574\u7cfb\u7edf\u6559\u7a0b&#xff0c;\u4e13\u4e3a\u524d\u7aef\u5f00\u53d1\u8005\u6574\u7406&#xff0c;\u7ed3\u6784\u6e05\u6670\u3001\u7531\u6d45\u5165\u6df1\u3001\u65e0\u5e9f\u8bdd\u3001\u53ef\u76f4\u63a5\u5f53\u505a\u535a\u5ba2\u7b14\u8bb0\u3001\u5b66\u4e60\u624b\u518c\u3001\u9762\u8bd5\u590d\u4e60\u6587\u6863\u3002<br \/>\n\u8986\u76d6&#xff1a;\u57fa\u7840\u67b6\u6784 \u2192 \u76f8\u673a\/\u63a7\u4ef6\/\u5149\u7167\/\u9634\u5f71 \u2192 \u51e0\u4f55\u4f53\/\u6750\u8d28\/\u7eb9\u7406 \u2192 \u52a8\u753b\/\u4ea4\u4e92\/\u6a21\u578b\u52a0\u8f7d \u2192 \u7279\u6548\/\u540e\u5904\u7406 \u2192 \u5b9e\u6218\u9879\u76ee \u2192 \u6027\u80fd\u4f18\u5316\u3002<br \/>\n\u7b2c\u4e00\u7ae0 Three.js \u7b80\u4ecb\u4e0e\u73af\u5883\u642d\u5efa<br \/>\n1.1 \u4ec0\u4e48\u662f Three.js<br \/>\nThree.js \u662f\u57fa\u4e8e\u539f\u751f WebG<\/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":[722,187,5299,190],"topic":[],"class_list":["post-100799","post","type-post","status-publish","format-standard","hentry","category-server","tag-ecmascript","tag-javascript","tag-threejs","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b - \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\/100799.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b \u524d\u8a00 \u4ece\u96f6\u5230\u4f01\u4e1a\u7ea7\u7684 Three.js \u5b8c\u6574\u7cfb\u7edf\u6559\u7a0b&#xff0c;\u4e13\u4e3a\u524d\u7aef\u5f00\u53d1\u8005\u6574\u7406&#xff0c;\u7ed3\u6784\u6e05\u6670\u3001\u7531\u6d45\u5165\u6df1\u3001\u65e0\u5e9f\u8bdd\u3001\u53ef\u76f4\u63a5\u5f53\u505a\u535a\u5ba2\u7b14\u8bb0\u3001\u5b66\u4e60\u624b\u518c\u3001\u9762\u8bd5\u590d\u4e60\u6587\u6863\u3002 \u8986\u76d6&#xff1a;\u57fa\u7840\u67b6\u6784 \u2192 \u76f8\u673a\/\u63a7\u4ef6\/\u5149\u7167\/\u9634\u5f71 \u2192 \u51e0\u4f55\u4f53\/\u6750\u8d28\/\u7eb9\u7406 \u2192 \u52a8\u753b\/\u4ea4\u4e92\/\u6a21\u578b\u52a0\u8f7d \u2192 \u7279\u6548\/\u540e\u5904\u7406 \u2192 \u5b9e\u6218\u9879\u76ee \u2192 \u6027\u80fd\u4f18\u5316\u3002 \u7b2c\u4e00\u7ae0 Three.js \u7b80\u4ecb\u4e0e\u73af\u5883\u642d\u5efa 1.1 \u4ec0\u4e48\u662f Three.js Three.js \u662f\u57fa\u4e8e\u539f\u751f WebG\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/100799.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-05T03:01:02+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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/100799.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/100799.html\",\"name\":\"Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-05T03:01:02+00:00\",\"dateModified\":\"2026-09-05T03:01:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/100799.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/100799.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/100799.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b\"}]},{\"@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":"Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b - \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\/100799.html","og_locale":"zh_CN","og_type":"article","og_title":"Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b \u524d\u8a00 \u4ece\u96f6\u5230\u4f01\u4e1a\u7ea7\u7684 Three.js \u5b8c\u6574\u7cfb\u7edf\u6559\u7a0b&#xff0c;\u4e13\u4e3a\u524d\u7aef\u5f00\u53d1\u8005\u6574\u7406&#xff0c;\u7ed3\u6784\u6e05\u6670\u3001\u7531\u6d45\u5165\u6df1\u3001\u65e0\u5e9f\u8bdd\u3001\u53ef\u76f4\u63a5\u5f53\u505a\u535a\u5ba2\u7b14\u8bb0\u3001\u5b66\u4e60\u624b\u518c\u3001\u9762\u8bd5\u590d\u4e60\u6587\u6863\u3002 \u8986\u76d6&#xff1a;\u57fa\u7840\u67b6\u6784 \u2192 \u76f8\u673a\/\u63a7\u4ef6\/\u5149\u7167\/\u9634\u5f71 \u2192 \u51e0\u4f55\u4f53\/\u6750\u8d28\/\u7eb9\u7406 \u2192 \u52a8\u753b\/\u4ea4\u4e92\/\u6a21\u578b\u52a0\u8f7d \u2192 \u7279\u6548\/\u540e\u5904\u7406 \u2192 \u5b9e\u6218\u9879\u76ee \u2192 \u6027\u80fd\u4f18\u5316\u3002 \u7b2c\u4e00\u7ae0 Three.js \u7b80\u4ecb\u4e0e\u73af\u5883\u642d\u5efa 1.1 \u4ec0\u4e48\u662f Three.js Three.js \u662f\u57fa\u4e8e\u539f\u751f WebG","og_url":"https:\/\/www.wsisp.com\/helps\/100799.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-05T03:01:02+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/100799.html","url":"https:\/\/www.wsisp.com\/helps\/100799.html","name":"Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-05T03:01:02+00:00","dateModified":"2026-09-05T03:01:02+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/100799.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/100799.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/100799.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Three.js \u96f6\u57fa\u7840\u7cfb\u7edf\u6559\u7a0b"}]},{"@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\/100799","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=100799"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/100799\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=100799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=100799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=100799"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=100799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}