代码如下

<template>
<div style="width:1000px; height:800px">
<p>逃跑的圆柱体</p>
<div ref="myBody" id="canvas-frame" style="width:1000px; height:800px" />
</div>
</template> <script>
import * as THREE from 'three'
import { OBJLoader, MTLLoader } from 'three-obj-mtl-loader'
import { CSS2DRenderer, CSS2DObject } from 'three-css2drender'
export default {
data() {
return {
scene: new THREE.Scene(), // 场景
camera: new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
1,
10000
), // 透视相机
renderer: new THREE.WebGLRenderer(), // 渲染器
geometry: new THREE.Geometry(), // 设置物体
material: new THREE.LineBasicMaterial({ vertexColors: true }), // 设置材料
cube: {}, // 合起来
// 开始设置线条
light: new THREE.DirectionalLight(0xff0000, 1.0, 0)
}
},
mounted() {
this.threeStart()
},
methods: {
initThree() {
const width = this.$refs.myBody.clientWidth
const height = this.$refs.myBody.clientHeight
this.renderer = new THREE.WebGLRenderer({ antialias: true })
this.renderer.setSize(width, height)
this.$refs.myBody.appendChild(this.renderer.domElement)
this.renderer.setClearColor(0xffffff, 1.0)
},
initCamera() {
this.camera = new THREE.PerspectiveCamera(130, 1.5, 1, 10000)
this.camera.position.x = 0
this.camera.position.y = 0
this.camera.position.z = 600
this.camera.up.x = 0
this.camera.up.y = 1
this.camera.up.z = 0
this.camera.lookAt(0, 0, 0)
},
initScene() {
this.scene = new THREE.Scene()
},
initLight() {
var light = new THREE.AmbientLight(0xffffff)
light.position.set(100, 100, 200)
this.scene.add(light)
var light1 = new THREE.PointLight(0x00ff00)
light1.position.set(0, 0, 300)
this.scene.add(light1)
},
initObject() {
var geometry = new THREE.CylinderGeometry(80, 100, 400)
var material = new THREE.MeshLambertMaterial({ color: 0x32d3eb })
var mesh = new THREE.Mesh(geometry, material)
this.scene.add(mesh)
},
animation() {
this.camera.position.x = this.camera.position.x += 3
this.camera.position.y = this.camera.position.y += 3
this.renderer.render(this.scene, this.camera)
requestAnimationFrame(this.animation)
},
threeStart() {
this.initThree()
this.initCamera()
this.initScene()
this.initLight()
this.initObject()
this.animation()
},
consoleObj() {
console.log(THREE.REVISION)
console.log(OBJLoader)
console.log(MTLLoader)
console.log(CSS2DRenderer)
console.log(CSS2DObject)
}
}
}
</script>
<style lang="less" scoped>
#canvas_frame {
border: none;
cursor: pointer;
width: 100%;
height: 600px;
background-color: #eeeeee;
}
</style>

最新文章

  1. [Tex学习]编号
  2. 第二百四十一天 how can I 坚持
  3. 设计模式之 State 状态模式
  4. Python开发【第二十一篇】:Web框架之Django【基础】
  5. PHP __autoload函数知识点
  6. gdb运行时结合汇编堆栈分析
  7. El表达式的用法个人总结
  8. CTF---Web入门第十四题 忘记密码了
  9. error: No rule to make target &#39;/usr/lib/libOpenNI.so&#39;, needed by &#39;bin/euroc_rectify&#39;。 停止。
  10. Yii2 验证规则
  11. Idea2018旗舰版破解方法
  12. git:当本地分支中的代码和develop分支上有很多冲突,希望删掉本地分支,重新建立新的分支,怎么解决?
  13. leetcode33
  14. Hibernate(二)
  15. 那些年,追寻JMeter的足迹,免费送&hellip;&hellip;
  16. POJ 1860 Currency Exchange(Bellman-Ford)
  17. Android之水波纹点击效果(RippleView)
  18. Python爬虫教程-07-post介绍(百度翻译)(上)
  19. linux rm指定的文件
  20. 人生苦短之我用Python篇(队列、生产者和消费者模型)

热门文章

  1. SQL--临时表的使用
  2. Spring三级缓存解决循环依赖
  3. 元数据性能大比拼:HDFS vs S3 vs JuiceFS
  4. java学习之socket编程
  5. 聊聊FASTER和进程内混合缓存
  6. 【iOS逆向】某车之家sign签名分析
  7. [排序算法] 简单选择排序 (C++)
  8. jquery组件解决option选项框的样式自定义方案
  9. IDEA项目下out与target目录的区别详解
  10. Windows机器下VSCode安装及使用CmakeLists编译工程demo