<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Threejs - 幾行代碼帶你創(chuàng)建三維地球

          共 3058字,需瀏覽 7分鐘

           ·

          2021-07-11 13:31






          需要具備哪些知識 ?

          前端開發(fā)中的一些基礎(chǔ)知識,html,css,javascript

          vue 基本用法 (注意: 本實(shí)例是基于vue來做的,也可以采用原生js的方式開發(fā),看個人喜好)

          先來看下效果吧


          開發(fā)前準(zhǔn)備

          1. 一張地球全景平面圖

          2. 搭建一個三維場景,場景中添加網(wǎng)格模型(前面幾講有具體講到如何搭建一個三維場景以及添加網(wǎng)格模型,添加相機(jī),燈光,渲染器等)

          3. 紋理加載器 (TextureLoader


          廢話就講到這里了,直接上代碼看效果吧

          <template>  <div ref="content"></div></template>
          <script>// 引入threejsimport * as THREE from "../../public/build/three";//鼠標(biāo)控制import { OrbitControls } from "../../public/example/jsm/controls/OrbitControls.js";
          export default { components: {}, data() { return { // 創(chuàng)建一個場景 scene: null, // 創(chuàng)建一個相機(jī) camera: null, // 創(chuàng)建一個渲染器 renderer: null, // 模型對象 mesh: null, // 平面 plane: null, // 點(diǎn)光源 point: null,
          // step step:0 }; },
          mounted() { this.init(); }, methods: { // 初始化 init() { // 初始化容器 var content = this.$refs.content;
          // 創(chuàng)建一個場景 this.scene = new THREE.Scene(); this.scene.background = new THREE.Color("#000");
          // 創(chuàng)建幾何體 var geometry = new THREE.SphereGeometry(30, 50, 50); // 紋理加載器 ( 此處加載貼圖 ) var texture = new THREE.TextureLoader().load(require('./Earth.png'));    // 幾何體材質(zhì)對象 var material = new THREE.MeshLambertMaterial({ map: texture });
          // 創(chuàng)建網(wǎng)格模型對象 this.mesh = new THREE.Mesh(geometry, material); //設(shè)置幾何體位置 this.mesh.position.x = 0; this.mesh.position.y = 10; this.mesh.position.z = 0; this.scene.add(this.mesh);
          // 創(chuàng)建點(diǎn)光源 var point = new THREE.PointLight("#FFF"); point.position.set(40, 200, 30); this.point = point; this.scene.add(point);
          const sphereSize = 10; const pointLightHelper = new THREE.PointLightHelper(point, sphereSize); this.scene.add(pointLightHelper);
          //創(chuàng)建環(huán)境光 var ambient = new THREE.AmbientLight(0x444444); this.scene.add(ambient);
          // 創(chuàng)建一個相機(jī) this.camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 10000 ); this.camera.position.set(-50, 50, 50); this.camera.lookAt(0, 0, 0);
          //坐標(biāo)軸輔助器,X,Y,Z長度30 // var axes = new THREE.AxesHelper(300); // this.scene.add(axes); // 輔助網(wǎng)格 // let gridHelper = new THREE.GridHelper(100, 100); // this.scene.add(gridHelper);
          // 創(chuàng)建渲染器 this.renderer = new THREE.WebGLRenderer(); this.renderer.setSize(window.innerWidth, window.innerHeight); this.renderer.setClearColor(0xb9d3ff, 1); //插入 dom 元素 content.appendChild(this.renderer.domElement);
          let controls = new OrbitControls(this.camera, this.renderer.domElement); controls.addEventListener("resize", this.render(), false); },
          render() { this.renderer.render(this.scene, this.camera); // 自動旋轉(zhuǎn)動畫 this.mesh.rotateY(0.01); requestAnimationFrame(this.render); } }};</script>
          <style lang="scss" scoped></style>
          瀏覽 347
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  2024无码视频 | 性猛交XXXX乱大交孕妇 | 美女影视123区 | 免费黄色成人网站视频 | AV乱伦小说 |