{"id":456,"date":"2022-08-26T17:55:05","date_gmt":"2022-08-26T09:55:05","guid":{"rendered":"http:\/\/gjweb.top\/?p=456"},"modified":"2022-08-26T17:55:06","modified_gmt":"2022-08-26T09:55:06","slug":"06-%e5%85%89%e5%bd%b1%e6%8a%95%e5%b0%84","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=456","title":{"rendered":"06.\u5149\u5f71\u6295\u5c04"},"content":{"rendered":"\n<p>\u7528\u4e8e\u7269\u4f53\u7684\u62fe\u53d6\u548c\u9875\u9762\u4e8b\u4ef6\u7684\u4ea4\u4e92<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u521b\u5efa\u591a\u4e2a\u7acb\u65b9\u4f53<br>const cubeGeometry = new THREE.BoxBufferGeometry(1,1,1);<br>const material = new THREE.MeshBasicMaterial({<br> &nbsp; &nbsp;wireframe:true<br>});<br>const redmaterial = new THREE.MeshBasicMaterial({<br> &nbsp; &nbsp;color:\"#ff0000\"<br>})<br>const cubeArr = &#91;];<br>for(let i=0;i&lt;10;i++){<br> &nbsp; &nbsp;const cube = new THREE.Mesh(cubeGeometry,material);<br> &nbsp; &nbsp;cube.position.set(i,i,0)<br> &nbsp; &nbsp;scene.add(cube)<br> &nbsp; &nbsp;cubeArr.push(cube)<br>}<br>\/\/ \u521b\u5efa\u6295\u5c04\u5149\u7ebf\u5bf9\u8c61<br>const raycaster = new THREE.Raycaster();<br>\/\/ \u9f20\u6807\u7684\u4f4d\u7f6e\u5bf9\u8c61<br>const mouse = new THREE.Vector2();<br>\/\/ \u76d1\u542c\u9f20\u6807\u7684\u4f4d\u7f6e<br>window.addEventListener(\"click\",(event)=&gt;{<br> &nbsp; &nbsp;mouse.x = (event.clientX \/ window.innerWidth) * 2 - 1;<br> &nbsp; &nbsp;mouse.y = -((event.clientY \/ window.innerHeight) * 2 - 1);<br> &nbsp; &nbsp;raycaster.setFromCamera(mouse,camera);<br> &nbsp; &nbsp;\/\/ intersectObjects  \u68c0\u6d4b\u591a\u4e2a\u7269\u4f53<br> &nbsp; &nbsp;let result = raycaster.intersectObjects(cubeArr)<br> &nbsp; &nbsp;console.log(result)<br> &nbsp; &nbsp;result&#91;0].object.material = redmaterial<br>})<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7528\u4e8e\u7269\u4f53\u7684\u62fe\u53d6\u548c\u9875\u9762\u4e8b\u4ef6\u7684\u4ea4\u4e92<\/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-456","post","type-post","status-publish","format-standard","hentry","category-three"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/456","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=456"}],"version-history":[{"count":1,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/456\/revisions"}],"predecessor-version":[{"id":457,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/456\/revisions\/457"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}