{"id":461,"date":"2022-08-26T18:00:10","date_gmt":"2022-08-26T10:00:10","guid":{"rendered":"http:\/\/gjweb.top\/?p=461"},"modified":"2022-08-26T18:00:11","modified_gmt":"2022-08-26T10:00:11","slug":"08-%e6%9b%b2%e7%ba%bf%e7%a7%bb%e5%8a%a8","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=461","title":{"rendered":"08.\u66f2\u7ebf\u79fb\u52a8"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/\/ \u521b\u5efa\u7269\u4f53<br>const boxGeometry = new THREE.BoxGeometry(2, 2, 2);<br>const cubeMaterial = new THREE.MeshBasicMaterial({ color: \"#ff0000\" });<br>cube = new THREE.Mesh(boxGeometry, cubeMaterial);<br>scene.add(cube);<br>\/\/ \u521d\u59cb\u5316\u8f68\u9053\u5668,\u4e3aCSS2D\u53ef\u4ee5\u548c\u6a21\u578b\u540c\u6b65\u79fb\u52a8\uff0c\u9700\u8981\u8bbe\u7f6e\u4e3alabelRenderer\u6e32\u67d3\u5668<br>controls = new OrbitControls(camera, renderer.domElement);<br>\/\/ \u521b\u5efa\u66f2\u7ebf<br>curve = new THREE.CatmullRomCurve3(&#91;<br> &nbsp; &nbsp;new THREE.Vector3(-10, 0, 10),<br> &nbsp; &nbsp;new THREE.Vector3(-5, 5, 5),<br> &nbsp; &nbsp;new THREE.Vector3(0, 0, 0),<br> &nbsp; &nbsp;new THREE.Vector3(5, -5, 5),<br> &nbsp; &nbsp;new THREE.Vector3(10, 0, 10),<br>]);<br>\/\/ \u662f\u5426\u95ed\u5408<br>curve.closed = true;<br>\/\/ \u5728\u66f2\u7ebf\u91cc\u9762 \u901a\u8fc7getPoints\u83b7\u53d651\u4e2a\u70b9<br>const points = curve.getPoints(50);<br>console.log(points);<br>const geometry = new THREE.BufferGeometry().setFromPoints(points);<br>const material = new THREE.LineBasicMaterial({ color: 0xff0000 });<br>const curveObject = new THREE.Line(geometry, material);<br>scene.add(curveObject);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"> render() {<br> &nbsp; &nbsp; &nbsp;controls.update();<br> &nbsp; &nbsp; &nbsp;renderer.render(scene, camera);<br> &nbsp; &nbsp; &nbsp;\/\/ \u6cbf\u7740\u66f2\u7ebf\u79fb\u52a8<br> &nbsp; &nbsp; &nbsp;const elapsed = clock.getElapsedTime();<br> &nbsp; &nbsp; &nbsp;const time = (elapsed \/ 10) % 1;<br> &nbsp; &nbsp; &nbsp;console.log(time);<br> &nbsp; &nbsp; &nbsp;const point = curve.getPoint(time);<br> &nbsp; &nbsp; &nbsp;console.log(point);<br> &nbsp; &nbsp; &nbsp;cube.position.copy(point);<br>\u200b<br> &nbsp; &nbsp; &nbsp;requestAnimationFrame(this.render);<br> },<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>render() { &nbsp; &nbsp; &nbsp;controls.update(); &#038;nbsp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[],"class_list":["post-461","post","type-post","status-publish","format-standard","hentry","category-three"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=461"}],"version-history":[{"count":1,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/461\/revisions"}],"predecessor-version":[{"id":462,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/461\/revisions\/462"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}