zoukankan      html  css  js  c++  java
  • three.js一步一步来--如何画出一个转动的正方体

    基础知识--正方体代码如下

    <template>
      <div style="1000px; height:800px">
        <h1>正方体</h1>
        <div ref="myBody" />
      </div>
    </template>
    
    <script>
    import * as THREE from 'three'
    import { OBJLoader, MTLLoader } from 'three-obj-mtl-loader'
    // import MTLLoader from  'three-mtl-loader';
    // import OBJLoader from  'three-obj-loader';
    import { CSS2DRenderer, CSS2DObject } from 'three-css2drender'
    // import { Geometry, Material, Scene, WebGLBufferRenderer } from 'three';
    // const OrbitControls = require('three-orbit-controls')(THREE);
    export default {
      data() {
        return {
          scene: new THREE.Scene(), // 场景
          camera: new THREE.PerspectiveCamera(
            75,
            window.innerWidth / window.innerHeight,
            1,
            1000
          ), // 透视相机
          renderer: new THREE.WebGLRenderer(), // 渲染器
          geometry: new THREE.BoxBufferGeometry(1, 1, 1), // 正方体
          material: new THREE.MeshBasicMaterial({ color: 0x00ff00 }), // 设置材料
          cube: new THREE.Mesh(this.geometry, this.material) // 合起來
        }
      },
      mounted() {
        this.init()
        this.render()
      },
      methods: {
        consoleObj() {
          console.log(THREE.REVISION)
          console.log(OBJLoader)
          console.log(MTLLoader)
          console.log(CSS2DRenderer)
          console.log(CSS2DObject)
        },
        init() {
          this.renderer.setClearColor('white') // 渲染器背景色
          this.renderer.setSize(window.innerWidth, window.innerHeight) // 渲染器窗口大小
          this.$refs.myBody.appendChild(this.renderer.domElement) // 放到界面
          this.cube = new THREE.Mesh(this.geometry, this.material) // 不能放在上面,要不然出不來
          this.scene.add(this.cube) // 不能放在上面,要不然出不來
          this.camera.position.z = 5
        },
        render() {
          requestAnimationFrame(this.render) // 游戏循环
          this.cube.rotation.x += 0.1
          this.cube.rotation.y += 0.1
          this.renderer.render(this.scene, this.camera) // 渲染
        }
      }
    }
    </script>
    <style lang="less" scoped></style>
    
    
  • 相关阅读:
    group by与聚合函数
    表联结
    项目延期 怎样规避风险
    虚拟机安装linux系统
    Cannot truncate a table referenced in a foreign key constraint
    李航--《统计学习方法总结》
    CART算法
    北航学长分享交流笔记
    CentOS7导入MySql数据表结构并显示表结构
    RedHat7安装mysql5.7数据库
  • 原文地址:https://www.cnblogs.com/sugartang/p/13605618.html
Copyright © 2011-2022 走看看