{"id":444,"date":"2022-08-26T17:46:49","date_gmt":"2022-08-26T09:46:49","guid":{"rendered":"http:\/\/gjweb.top\/?p=444"},"modified":"2022-08-26T17:47:43","modified_gmt":"2022-08-26T09:47:43","slug":"%e5%88%9b%e5%bb%ba%e5%9c%ba%e6%99%af","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=444","title":{"rendered":"01.\u521b\u5efa\u573a\u666f"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"1-\u521b\u5efa\u573a\u666f\">1. \u521b\u5efa\u573a\u666f<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code> &nbsp; &nbsp; &nbsp;import * as THREE from 'three';<br>     &nbsp;\/\/  \u573a\u666f<br> &nbsp; &nbsp; &nbsp;const scene= new THREE.Scene();<br> &nbsp; &nbsp; &nbsp;\/\/ \u76f8\u673a<br> &nbsp; &nbsp; &nbsp;const camera = new THREE.PerspectiveCamera(<br> &nbsp; &nbsp; &nbsp; &nbsp;75,<br> &nbsp; &nbsp; &nbsp; &nbsp;window.innerWidth\/window.innerHeight,<br> &nbsp; &nbsp; &nbsp; &nbsp;0.1,<br> &nbsp; &nbsp; &nbsp; &nbsp;1000<br> &nbsp; &nbsp;  );<br> &nbsp; &nbsp; &nbsp;\/\/ \u76f8\u673a\u4f4d\u7f6e<br> &nbsp; &nbsp; &nbsp;camera.position.set(0,0,10);<br> &nbsp; &nbsp; &nbsp;scene.add(camera)<br>\u200b<br> &nbsp; &nbsp; &nbsp;\/\/ \u6dfb\u52a0\u7269\u4f53<br> &nbsp; &nbsp; &nbsp;\/\/ \u521b\u5efa\u51e0\u4f55\u4f53<br> &nbsp; &nbsp; &nbsp;const cubeGeometry = new THREE.BoxGe<br> &nbsp; &nbsp; &nbsp;ometry();<br> &nbsp; &nbsp; &nbsp;const subeMaterial = new THREE.MeshBasicMaterial({color:0xff0000})<br> &nbsp; &nbsp; &nbsp;\/\/ \u6839\u636e\u51e0\u4f55\u4f53\u548c\u6750\u8d28\u521b\u5efa\u7269\u4f53<br> &nbsp; &nbsp; &nbsp;const code = new THREE.Mesh(cubeGeometry,subeMaterial)<br> &nbsp; &nbsp; &nbsp;\/\/ \u51e0\u4f55\u4f53\u51e0\u4f55\u4f53\u548c\u6750\u8d28\u653e\u5728\u573a\u666f\u4e2d<br> &nbsp; &nbsp; &nbsp;scene.add(code)<br>    <br> &nbsp; &nbsp; &nbsp;\/\/ \u521d\u59cb\u5316\u6e32\u67d3\u5668<br> &nbsp; &nbsp; &nbsp;const renderer = new THREE.WebGLRenderer();<br> &nbsp; &nbsp; &nbsp;\/\/ \u6e32\u67d3\u7684\u5c3a\u5bf8\u5927\u5c0f<br> &nbsp; &nbsp; &nbsp;renderer.setSize(window.innerWidth,window.innerHeight);<br> &nbsp; &nbsp; &nbsp;\/\/ \u5c06webGl\u6e32\u67d3\u7684canvas\u5185\u5bb9\u6e32\u67d3\u5230body<br> &nbsp; &nbsp; &nbsp;document.body.appendChild(renderer.domElement)<br>\u200b<br> &nbsp; &nbsp; &nbsp;\/\/ \u4f7f\u7528\u6e32\u67d3\u5668\u5c06\u573a\u666f\u6e32\u67d3<br> &nbsp; &nbsp; &nbsp;renderer.render(scene,camera)<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-\u521b\u5efa\u8f68\u9053\u5668\">2. \u521b\u5efa\u8f68\u9053\u5668<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import {OrbitControls} from \"three\/examples\/jsm\/controls\/OrbitControls.js\"<br>\/*<br>* \u7b2c\u4e00\u4e2a\u53c2\u6570 \u4e3a\u76f8\u673a\u7684\u5b9e\u4f8b<br>* \u7b2c\u4e8c\u4e2a\u53c2\u6570 \u6e32\u67d3\u5668\u5143\u7d20<br>*\/<br>const controls = new OrbitControls(camera,renderer.domElement)<br>renderer.render(scene,camera)<br>\/\/ \u4e0b\u4e00\u5e27\u7684\u65f6\u5019\u8c03\u7528render\u51fd\u6570<br>requestAnimationFrame(this.render) \/\/ \u4f18\u5316\u7684API,\u7528\u6237\u8df3\u51fa\u8be5\u9875\u9762\u65f6\u4e0d\u8fdb\u884c\u6e32\u67d3<br>\/\/ \u63a7\u5236\u89c6\u89d2\u8303\u56f4<br>controls.maxPolarAngle = Math.PI \/ 2;<br>controls.minPolarAngle = 0;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-\u6dfb\u52a0\u5750\u6807\u8f85\u52a9\u5668\">3. \u6dfb\u52a0\u5750\u6807\u8f85\u52a9\u5668<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>const axesHelper = new THREE.AxesHelper(5);<br>scene.add( axesHelper );<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-\u7269\u4f53\u7684\u79fb\u52a8-\u65cb\u8f6c-\u7f29\u653e\">4.\u7269\u4f53\u7684\u79fb\u52a8&amp;\u65cb\u8f6c&amp;\u7f29\u653e<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u7269\u4f53\u79fb\u52a8<br>code.rotation.set(Math.PI\/4,0,0)<br>code.position.x += 0.01;<br>\/\/ \u7269\u4f53\u7f29\u653e<br>scale<br>\/\/ \u65cb\u8f6c<br>rotation<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5-\u6e32\u67d3\u5668\u4f18\u5316\">5. \u6e32\u67d3\u5668\u4f18\u5316<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>enderer = new THREE.WebGLRenderer({ antialias: true });<br>renderer.logarithmicDepthBuffer = true; \/\/ \u5f00\u542f\u6df1\u5ea6\u4f18\u5316<br>renderer.physicallyCorrectLights = true; \/\/ \u5f00\u542f\u7269\u7406\u5149\u7167(\u6027\u80fd\u4f18\u5316)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. \u521b\u5efa\u573a\u666f 2. \u521b\u5efa\u8f68\u9053\u5668 3. \u6dfb\u52a0\u5750\u6807\u8f85\u52a9\u5668 4.\u7269\u4f53\u7684\u79fb\u52a8&amp;\u65cb\u8f6c&amp;\u7f29\u653e 5. \u6e32\u67d3 [&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-444","post","type-post","status-publish","format-standard","hentry","category-three"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/444","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=444"}],"version-history":[{"count":2,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/444\/revisions"}],"predecessor-version":[{"id":446,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/444\/revisions\/446"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}