• WebGL基础(1)一个基本的WebGL静态页面


     
    <template>
      <div class="home">
        <div id="threeContainer" class="threeContainer"></div>
      </div>
    </template>
    
    <script>
    import * as THREE from 'three'
    export default {
      name: 'Home',
      data () {
        return {
          scene: null,  //场景对象
          camera: null,  //相机对象
          renderer: null,  //渲染器对象
          mesh: null,  //网格模型对象Mesh
        }
      },
      mounted () {
        this.init()
      },
      methods: {
        init () {
          // 1. 创建场景
          this.scene = new THREE.Scene()
          
          // 2. 创建相机
          this.camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 )
          this.camera.position.set( 0, 0, 10 ) // 设置相机位置
          this.scene.add(this.camera)
    
          // 3. 添加物体
          // 创建几何体
          const geometry = new THREE.BoxGeometry()
          const material = new THREE.MeshBasicMaterial( {color: 0x00ff00} )
          // 根据几何体和材质创建物体
          const cube = new THREE.Mesh( geometry, material )
          // 将几何体添加到场景中
          this.scene.add( cube )
          
          // 4. 初始化渲染器
          this.renderer = new THREE.WebGLRenderer()
          // 设置渲染器的尺寸大小
          this.renderer.setSize( window.innerWidth, window.innerHeight )
          // 将webgl渲染的canvas内容添加到body中
          document.getElementById('threeContainer').appendChild( this.renderer.domElement )
          // // 使用渲染器 通过相机将场景渲染出来
          this.renderer.render( this.scene, this.camera )
        }
      }
    }
    </script>
    

      

  • 相关阅读:
    C# DataGridView搜索
    C# DataGridView插入DB
    C# 扩展类
    C# Clone控件
    C# 动态事件示例
    C# 遍历控件 示例
    c的详细学习(11)文件
    c的详细学习(10)结构体与共用体的学习(二)
    c的详细学习(9)结构体与共用体的学习(一)
    c的详细学习(8)指针学习(二)
  • 原文地址:https://www.cnblogs.com/yulingjia/p/16540258.html
Copyright © 2020-2023  润新知