{"id":2469,"date":"2024-12-02T15:59:07","date_gmt":"2024-12-02T07:59:07","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=2469"},"modified":"2024-12-02T15:59:07","modified_gmt":"2024-12-02T07:59:07","slug":"threejs%e5%ae%9e%e7%8e%b0%e5%a4%96%e9%83%a8%e6%a8%a1%e5%9e%8b%e5%af%bc%e5%85%a5%e4%b8%8e%e5%9f%ba%e6%9c%ac%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2024\/12\/02\/threejs%e5%ae%9e%e7%8e%b0%e5%a4%96%e9%83%a8%e6%a8%a1%e5%9e%8b%e5%af%bc%e5%85%a5%e4%b8%8e%e5%9f%ba%e6%9c%ac%e8%ae%be%e7%bd%ae\/","title":{"rendered":"Web3D\u5b66\u4e60-ThreeJS\u5b9e\u73b0\u5916\u90e8\u6a21\u578b\u5bfc\u5165\u4e0e\u57fa\u672c\u8bbe\u7f6e"},"content":{"rendered":"\n<p>\u4f7f\u7528 Three.js \u5bfc\u5165\u5916\u90e8\u6a21\u578b\u548c\u8bbe\u7f6e\u573a\u666f\u9700\u8981\u51e0\u4e2a\u6b65\u9aa4\uff0c\u5305\u62ec\u52a0\u8f7d\u5668\u7684\u4f7f\u7528\u3001\u573a\u666f\u7684\u8bbe\u7f6e\u4ee5\u53ca\u6a21\u578b\u7684\u57fa\u672c\u6e32\u67d3\u903b\u8f91\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/sanroimg.oss-cn-shanghai.aliyuncs.com\/img\/202412021558236.png\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u521d\u59cb\u5316 Three.js \u573a\u666f<\/strong><\/h3>\n\n\n\n<p>\u5148\u642d\u5efa\u57fa\u672c\u7684 Three.js \u573a\u666f\uff0c\u5305\u62ec\u76f8\u673a\u3001\u6e32\u67d3\u5668\u548c\u5149\u7167\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import * as THREE from 'three';\n\nconst scene = new THREE.Scene();\n\n\/\/ \u8bbe\u7f6e\u76f8\u673a\nconst camera = new THREE.PerspectiveCamera(\n    75, window.innerWidth \/ window.innerHeight, 0.1, 1000\n);\ncamera.position.set(0, 2, 5);\n\n\/\/ \u8bbe\u7f6e\u6e32\u67d3\u5668\nconst renderer = new THREE.WebGLRenderer({ antialias: true });\nrenderer.setSize(window.innerWidth, window.innerHeight);\nrenderer.setPixelRatio(window.devicePixelRatio);\ndocument.body.appendChild(renderer.domElement);\n\n\/\/ \u6dfb\u52a0\u5149\u6e90\nconst light = new THREE.DirectionalLight(0xffffff, 1);\nlight.position.set(5, 10, 7.5);\nscene.add(light);\n\n\/\/ \u73af\u5883\u5149\nconst ambientLight = new THREE.AmbientLight(0x404040, 0.5);\nscene.add(ambientLight);\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u52a0\u8f7d\u5916\u90e8\u6a21\u578b<\/strong><\/h3>\n\n\n\n<p>Three.js \u652f\u6301\u591a\u79cd 3D \u6a21\u578b\u683c\u5f0f\uff0c\u5e38\u89c1\u7684\u6709 GLTF\/GLB\u3001OBJ\u3001FBX \u7b49\u3002\u8fd9\u91cc\u4ee5 GLTF \u6a21\u578b\u4e3a\u4f8b\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5b89\u88c5\u52a0\u8f7d\u5668<\/h4>\n\n\n\n<p>\u786e\u4fdd\u5728\u9879\u76ee\u4e2d\u5b89\u88c5 <code>three<\/code> \u548c <code>three\/examples<\/code> \u6a21\u5757\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install three\n<\/code><\/pre>\n\n\n\n<p>\u5f15\u5165 <code>GLTFLoader<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { GLTFLoader } from 'three\/examples\/jsm\/loaders\/GLTFLoader.js';\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u52a0\u8f7d\u6a21\u578b<\/h4>\n\n\n\n<p>\u4f7f\u7528 <code>GLTFLoader<\/code> \u52a0\u8f7d\u5916\u90e8\u6a21\u578b\u6587\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const loader = new GLTFLoader();\nloader.load(\n    '\/path\/to\/model.gltf',  \/\/ \u6a21\u578b\u8def\u5f84\n    (gltf) =&gt; {\n        const model = gltf.scene;\n        model.scale.set(1, 1, 1); \/\/ \u8bbe\u7f6e\u7f29\u653e\u6bd4\u4f8b\n        model.position.set(0, 0, 0); \/\/ \u8bbe\u7f6e\u4f4d\u7f6e\n        scene.add(model); \/\/ \u6dfb\u52a0\u6a21\u578b\u5230\u573a\u666f\u4e2d\n    },\n    (xhr) =&gt; {\n        console.log(`\u6a21\u578b\u52a0\u8f7d\u8fdb\u5ea6: ${(xhr.loaded \/ xhr.total * 100).toFixed(2)}%`);\n    },\n    (error) =&gt; {\n        console.error('\u6a21\u578b\u52a0\u8f7d\u5931\u8d25', error);\n    }\n);\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u8bbe\u7f6e\u573a\u666f\u80cc\u666f<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u5355\u8272\u80cc\u666f<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>scene.background = new THREE.Color(0x87ceeb); \/\/ \u5929\u7a7a\u84dd\u8272\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u73af\u5883\u8d34\u56fe\uff08\u5168\u666f\u80cc\u666f\uff09<\/h4>\n\n\n\n<p>\u4f7f\u7528 <code>CubeTextureLoader<\/code> \u52a0\u8f7d\u516d\u9762\u4f53\u8d34\u56fe\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const loader = new THREE.CubeTextureLoader();\nconst texture = loader.load(&#91;\n    '\/path\/to\/px.jpg', \/\/ \u6b63X\n    '\/path\/to\/nx.jpg', \/\/ \u8d1fX\n    '\/path\/to\/py.jpg', \/\/ \u6b63Y\n    '\/path\/to\/ny.jpg', \/\/ \u8d1fY\n    '\/path\/to\/pz.jpg', \/\/ \u6b63Z\n    '\/path\/to\/nz.jpg', \/\/ \u8d1fZ\n]);\nscene.background = texture;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u6dfb\u52a0\u5730\u9762<\/strong><\/h3>\n\n\n\n<p>\u4e3a\u573a\u666f\u6dfb\u52a0\u4e00\u4e2a\u7b80\u5355\u7684\u5730\u9762\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const planeGeometry = new THREE.PlaneGeometry(10, 10);\nconst planeMaterial = new THREE.MeshStandardMaterial({ color: 0xaaaaaa });\nconst plane = new THREE.Mesh(planeGeometry, planeMaterial);\nplane.rotation.x = -Math.PI \/ 2; \/\/ \u8ba9\u5e73\u9762\u6c34\u5e73\nplane.receiveShadow = true; \/\/ \u63a5\u53d7\u9634\u5f71\nscene.add(plane);\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u6e32\u67d3\u5faa\u73af<\/strong><\/h3>\n\n\n\n<p>\u5728\u52a8\u753b\u5faa\u73af\u4e2d\u66f4\u65b0\u6e32\u67d3\u5668\u548c\u76f8\u673a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function animate() {\n    requestAnimationFrame(animate);\n    renderer.render(scene, camera);\n}\n\nanimate();\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>\u8c03\u6574\u7a97\u53e3\u5927\u5c0f<\/strong><\/h3>\n\n\n\n<p>\u786e\u4fdd\u5728\u7a97\u53e3\u5927\u5c0f\u53d8\u5316\u65f6\u8c03\u6574\u6e32\u67d3\u5668\u548c\u76f8\u673a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>window.addEventListener('resize', () =&gt; {\n    camera.aspect = window.innerWidth \/ window.innerHeight;\n    camera.updateProjectionMatrix();\n    renderer.setSize(window.innerWidth, window.innerHeight);\n});\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>\u5bfc\u5165\u5916\u90e8\u6a21\u578b\u6ce8\u610f\u4e8b\u9879<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>\u8def\u5f84\u95ee\u9898<\/strong>\uff1a\u786e\u4fdd\u6a21\u578b\u548c\u6750\u8d28\u7684\u76f8\u5bf9\u8def\u5f84\u6b63\u786e\uff0c\u4f7f\u7528\u672c\u5730\u670d\u52a1\u5668\u6216 CDN \u63d0\u4f9b\u8d44\u6e90\u3002<\/li><li><strong>\u683c\u5f0f\u517c\u5bb9<\/strong>\uff1a\u5982\u679c\u4f7f\u7528\u975e GLTF \u683c\u5f0f\u6a21\u578b\uff08\u5982 OBJ\u3001FBX\uff09\uff0c\u9700\u8981\u5bf9\u5e94\u7684\u52a0\u8f7d\u5668\u3002<\/li><li><strong>\u6027\u80fd\u4f18\u5316<\/strong>\uff1a\u5bf9\u590d\u6742\u6a21\u578b\u53ef\u4ee5\u542f\u7528\u6750\u8d28\u538b\u7f29\u6216 LOD\uff08\u5c42\u7ea7\u7ec6\u8282\uff09\u3002<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>\u6211\u7684\u5c1d\u8bd5<\/p>\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 3D Model Import Demo&lt;\/title>\n    &lt;style>\n        body {\n            margin: 0;\n            display: flex; \/* Flex \u5e03\u5c40 *\/\n            align-items: center; \/* \u5782\u76f4\u5c45\u4e2d *\/\n            justify-content: center; \/* \u6c34\u5e73\u5c45\u4e2d *\/\n            height: 100vh; \/* \u89c6\u7a97\u9ad8\u5ea6 *\/\n            background-color: #eaeaea; \/* \u80cc\u666f\u989c\u8272 *\/\n        }\n        #model-container {\n            width: 80%; \/* \u5bbd\u5ea6\u5360\u7236\u5bb9\u5668 50% *\/\n            height: 80%; \/* \u9ad8\u5ea6\u5360\u7236\u5bb9\u5668 50% *\/\n            position: relative; \/* \u4e3a\u5b50\u5143\u7d20\u5b9a\u4f4d *\/\n            background-color: #ffffff; \/* \u53ef\u9009\uff1a\u8bbe\u7f6e\u80cc\u666f\u8272\u4ee5\u6e05\u6670\u663e\u793a\u5bb9\u5668\u8fb9\u754c *\/\n            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); \/* \u6dfb\u52a0\u9634\u5f71 *\/\n        }\n        canvas {\n            display: block; \/* \u9632\u6b62 canvas \u9ed8\u8ba4\u5185\u8fb9\u8ddd *\/\n            width: 100%; \/* \u5360\u6ee1\u5bb9\u5668\u5bbd\u5ea6 *\/\n            height: 100%; \/* \u5360\u6ee1\u5bb9\u5668\u9ad8\u5ea6 *\/\n        }\n    &lt;\/style>\n&lt;\/head>\n&lt;body>\n&lt;div id=\"model-container\">&lt;\/div>\n\n\n&lt;script type=\"module\">\n    import * as THREE from \"..\/libs\/three.module.js\";\n    import { GLTFLoader } from \"..\/three.js-dev\/examples\/jsm\/loaders\/GLTFLoader.js\";\n    import { OrbitControls } from \"..\/three.js-dev\/examples\/jsm\/controls\/OrbitControls.js\";\n\n    \/\/ \u521b\u5efa\u573a\u666f\n    const scene = new THREE.Scene();\n    scene.background = new THREE.Color(0xf5eaf7); \/\/ \u8bbe\u7f6e\u573a\u666f\u80cc\u666f\u989c\u8272\n\n    \/\/ \u6dfb\u52a0\u5750\u6807\u8f74\u8f85\u52a9\n    const axesHelper = new THREE.AxesHelper(50); \/\/ \u53c2\u6570\u4e3a\u5750\u6807\u8f74\u7684\u957f\u5ea6\n    scene.add(axesHelper);\n\n    \/\/ \u521b\u5efa\u76f8\u673a\n    const camera = new THREE.PerspectiveCamera(\n        75,\n        window.innerWidth \/ window.innerHeight,\n        0.1,\n        1000\n    );\n    camera.position.set(400, 400, 150);\n    camera.lookAt(0, 0, 0);\n\n    \/\/ \u521b\u5efa\u6e32\u67d3\u5668\n    \/\/ \u627e\u5230\u6a21\u578b\u5bb9\u5668\u7684 DOM \u5143\u7d20\n    const container = document.getElementById(\"model-container\");\n\n    \/\/ \u521b\u5efa\u6e32\u67d3\u5668\n    const renderer = new THREE.WebGLRenderer({ antialias: true });\n    renderer.setSize(container.clientWidth, container.clientHeight); \/\/ \u8bbe\u7f6e\u6e32\u67d3\u5668\u5927\u5c0f\u4e0e\u5bb9\u5668\u4e00\u81f4\n    renderer.shadowMap.enabled = true; \/\/ \u542f\u7528\u9634\u5f71\n    container.appendChild(renderer.domElement); \/\/ \u5c06\u6e32\u67d3\u5668\u6302\u8f7d\u5230\u5bb9\u5668\n\n    \/\/ \u6dfb\u52a0\u5149\u6e90\n    const ambientLight = new THREE.AmbientLight(0x404040, 5); \/\/ \u73af\u5883\u5149\uff0c\u5f3a\u5ea6\u4e3a 1\n    scene.add(ambientLight);\n\n    \/\/ \u6dfb\u52a0\u591a\u4e2a\u5b9a\u5411\u5149\uff08\u6765\u81ea\u4e0d\u540c\u89d2\u5ea6\uff09\n    const directionalLight1 = new THREE.DirectionalLight(0xffffff, 1); \/\/ \u7b2c\u4e00\u4e2a\u5b9a\u5411\u5149\n    directionalLight1.position.set(5, 10, 5); \/\/ \u5b9a\u5411\u5149\u7684\u4f4d\u7f6e\n    scene.add(directionalLight1);\n\n    \/\/ \u7b2c\u4e8c\u4e2a\u5b9a\u5411\u5149\n    const directionalLight2 = new THREE.DirectionalLight(0xffffff, 1); \/\/ \u7b2c\u4e8c\u4e2a\u5b9a\u5411\u5149\n    directionalLight2.position.set(-5, 10, -5); \/\/ \u8bbe\u7f6e\u4e00\u4e2a\u4ece\u53e6\u4e00\u65b9\u5411\u7684\u5149\n    scene.add(directionalLight2);\n\n    \/\/ \u7b2c\u4e09\u4e2a\u5b9a\u5411\u5149\n    const directionalLight3 = new THREE.DirectionalLight(0xffffff, 1); \/\/ \u7b2c\u4e09\u4e2a\u5b9a\u5411\u5149\n    directionalLight3.position.set(0, 10, -5); \/\/ \u5149\u6e90\u65b9\u5411\n    scene.add(directionalLight3);\n\n    \/\/ \u6dfb\u52a0\u70b9\u5149\u6e90\u6a21\u62df\u5c40\u90e8\u5149\u7167\n    const pointLight1 = new THREE.PointLight(0xffffff, 2, 500); \/\/ \u7ea2\u8272\u70b9\u5149\u6e90\uff0c\u5f3a\u5ea6\u4e3a 2\uff0c\u8303\u56f4\u4e3a 50\n    pointLight1.position.set(100, 50, 0); \/\/ \u70b9\u5149\u6e90\u7684\u4f4d\u7f6e\n    scene.add(pointLight1);\n\n    \/\/ \u7b2c\u4e8c\u4e2a\u70b9\u5149\u6e90\n    const pointLight2 = new THREE.PointLight(0xffffff, 2, 500); \/\/ \u7eff\u8272\u70b9\u5149\u6e90\n    pointLight2.position.set(-200, -50, -300); \/\/ \u8bbe\u7f6e\u4e0d\u540c\u7684\u5149\u6e90\u4f4d\u7f6e\n    scene.add(pointLight2);\n\n\n    \/\/ \u5149\u6e90\u8f85\u52a9\u89c2\u5bdf\n    const pointLightHelper0= new THREE.PointLightHelper(directionalLight3, 10);\n    \/\/scene.add(pointLightHelper0);\n\n    const pointLightHelper1= new THREE.PointLightHelper(pointLight1, 10);\n    \/\/scene.add(pointLightHelper1);\n\n    const pointLightHelper2 = new THREE.PointLightHelper(pointLight2, 10);\n    \/\/scene.add(pointLightHelper2);\n\n    \/\/ \u53ef\u9009\uff1a\u8c03\u6574\u9634\u5f71\n    directionalLight1.castShadow = true; \/\/ \u542f\u7528\u9634\u5f71\n    directionalLight2.castShadow = true;\n    directionalLight3.castShadow = true;\n\n    \/\/ \u521b\u5efa\u5730\u9762\u63a5\u6536\u9634\u5f71\n    const planeGeometry = new THREE.PlaneGeometry(1000, 1000);\n    const planeMaterial = new THREE.ShadowMaterial({ opacity: 0.5 }); \/\/ \u534a\u900f\u660e\u9634\u5f71\u6750\u8d28\n    const plane = new THREE.Mesh(planeGeometry, planeMaterial);\n    plane.rotation.x = -Math.PI \/ 2;\n    \/\/plane.position.y = -1;\n    plane.receiveShadow = true; \/\/ \u63a5\u6536\u9634\u5f71\n    scene.add(plane);\n\n    \/\/ \u52a0\u8f7d 3D \u6a21\u578b\n    const loader = new GLTFLoader();\n\n    loader.load(\n        '..\/models\/t1.glb', \/\/ \u6a21\u578b\u8def\u5f84\n        (gltf) => {\n            const model = gltf.scene;\n            scene.add(model); \/\/ \u6dfb\u52a0\u5230\u573a\u666f\n            model.scale.set(3, 3, 3); \/\/ \u8c03\u6574\u5927\u5c0f\n            \/\/model.position.y = -1;   \/\/ \u5c06\u6a21\u578b\u653e\u5728\u89c6\u91ce\u4e2d\u592e\n            model.position.set(-200,0,0);  \/\/ \u5c06\u6a21\u578b\u653e\u5728\u539f\u70b9\n            \/\/ \u4fdd\u5b58\u6a21\u578b\u4ee5\u4fbf\u540e\u7eed\u65cb\u8f6c\n            model.rotationSpeed = 0.01; \/\/ \u65cb\u8f6c\u901f\u5ea6\n            \/\/ \u904d\u5386\u6a21\u578b\u5b50\u5bf9\u8c61\uff0c\u68c0\u67e5\u6750\u8d28\u4fe1\u606f\n            model.traverse((child) => {\n                if (child.isMesh) {\n                    console.log(`Mesh Name: ${child.name}`); \/\/ \u8f93\u51fa\u7f51\u683c\u540d\u79f0\n\n                    \/\/ \u68c0\u67e5\u6750\u8d28\u4fe1\u606f\n                    \/\/const material = child.material;\n                    const material = new THREE.MeshBasicMaterial({\n                        color: 0x0000ff, \/\/\u8bbe\u7f6e\u6750\u8d28\u989c\u8272\n                        transparent:true,\/\/\u5f00\u542f\u900f\u660e\n                        opacity:0.5,\/\/\u8bbe\u7f6e\u900f\u660e\u5ea6\n                    });\n\n                    if (Array.isArray(material)) {\n                        \/\/ \u5982\u679c\u662f\u591a\u6750\u8d28\u7f51\u683c\n                        material.forEach((mat, index) => {\n                            console.log(`Material ${index}:`, mat);\n                            if (mat.map) console.log(`- Diffuse Map:`, mat.map);\n                            if (mat.normalMap) console.log(`- Normal Map:`, mat.normalMap);\n                            if (mat.roughnessMap) console.log(`- Roughness Map:`, mat.roughnessMap);\n                            if (mat.metalnessMap) console.log(`- Metalness Map:`, mat.metalnessMap);\n                        });\n                    } else {\n                        console.log(`Material:`, material);\n                        if (material.map) console.log(`- Diffuse Map:`, material.map);\n                        if (material.normalMap) console.log(`- Normal Map:`, material.normalMap);\n                        if (material.roughnessMap) console.log(`- Roughness Map:`, material.roughnessMap);\n                        if (material.metalnessMap) console.log(`- Metalness Map:`, material.metalnessMap);\n                    }\n                }\n            });\n        },\n        (xhr) => {\n            console.log((xhr.loaded \/ xhr.total * 100) + '% loaded'); \/\/ \u52a0\u8f7d\u8fdb\u5ea6\n        },\n        (error) => {\n            console.error('An error occurred while loading the model', error);\n        }\n    );\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        \/\/ \u6e32\u67d3\u573a\u666f\u548c\u76f8\u673a\n        renderer.render(scene, camera);\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","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 Three.js \u5bfc\u5165\u5916\u90e8&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2473,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2469","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2469","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=2469"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2469\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=2469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=2469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=2469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}