• threejs简单demo


    用的cnpm安装

    cnpm install three

     

    <template>
    <div id="demo" style="600px;height:600px;"/>
    </template>

    <script>
    import * as THREE from 'three'
    export default {
    data () {
    return {
    cube: undefined,
    scene: undefined,
    camera: undefined,
    renderer: undefined,
    floorTexture: undefined
    }
    },
    mounted () {
    this.initThree()
    this.animate()
    },
    methods: {
    initThree () {
    // 创建场景
    this.scene = new THREE.Scene()
    // 创建相机
    this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
    // 渲染器
    this.renderer = new THREE.WebGLRenderer()
    // 设置背景颜色 最新版目前默认为黑色
    this.renderer.setClearColor(0xffffff)
    this.renderer.shadowMap.enabled = true
    this.renderer.setSize(window.innerWidth, window.innerHeight)
    document.getElementById('demo').appendChild(this.renderer.domElement)
    // 加载图片
    const geometry = new THREE.BoxGeometry()
    var texture = new THREE.TextureLoader().load('static/img/123.png', () => {
    this.renderer.render(this.scene, this.camera)
    })
    // 沿x方向和Y方向都重复填充
    texture.wrapS = texture.wrapT = THREE.RepeatWrapping
    // 每面4*4
    texture.repeat.set(4, 4)
    var material = new THREE.MeshBasicMaterial({ map: texture })
    this.cube = new THREE.Mesh(geometry, material)
    this.cube.position.set(1, 0, 0)
    this.scene.add(this.cube)
    this.camera.position.z = 5
    this.renderer.render(this.scene, this.camera)
    },
    animate: function () {
    requestAnimationFrame(this.animate)
    this.cube.rotation.x += 0.12
    this.cube.rotation.y += 0.02
    this.renderer.render(this.scene, this.camera)
    }
    }
    }
    </script>

    <style>
    .mod-home {
    line-height: 1.5;
    }
    </style>


  • 相关阅读:
    在ubuntu下递归追索一个包的所有必要依赖项apt_dep.sh
    龙芯系统下,GTK与OPENGL共舞
    Linux应用程序自行开启Core Dump生成功能
    Daliy Algorithm -- day 102
    Daliy Algorithm -- day 101
    Daliy Algorithm -- day 100
    Daliy Algorithm -- day 99
    Daliy Algorithm -- day 98
    Daliy Algorithm -- day 97
    使用R语言进行简单的线性回归
  • 原文地址:https://www.cnblogs.com/xiaokangk/p/14086183.html
Copyright © 2020-2023  润新知