下面是画出线的代码,可以参考一下哟~~

<template>
<div style="width:1000px; height:800px">
<p>点、线、面</p>
<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(
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: {
consoleObj() {
console.log(THREE.REVISION)
console.log(OBJLoader)
console.log(MTLLoader)
console.log(CSS2DRenderer)
console.log(CSS2DObject)
},
initThree() {
this.renderer = new THREE.WebGLRenderer({
antialias: true
})
this.renderer.setSize(window.innerWidth, window.innerHeight) // 渲染器窗口大小
this.$refs.myBody.appendChild(this.renderer.domElement) // 将东西放到界面
this.renderer.setClearColor(0xffffff, 1.0) // 渲染器背景色
},
initCamera() {
this.camera = new THREE.PerspectiveCamera(45, 1.5, 1, 10000)
this.camera.position.x = 0
this.camera.position.y = 1000
this.camera.position.z = 0
this.camera.up.x = 0
this.camera.up.y = 0
this.camera.up.z = 1
this.camera.lookAt(0, 0, 0)
},
initScene() {
this.scene = new THREE.Scene()
},
initLight() {
this.light = new THREE.DirectionalLight(0xff0000, 1.0, 0)
this.light.position.set(100, 100, 200)
this.scene.add(this.light)
},
initObject() {
var color1 = new THREE.Color(0x444444)
var color2 = new THREE.Color(0xff0000)
// 设置材质
var p1 = new THREE.Vector3(-100, 0, 100)
var p2 = new THREE.Vector3(100, 0, -100)
this.geometry.vertices.push(p1, p2)
this.geometry.colors.push(color1, color2)
var line = new THREE.Line(
this.geometry,
this.material,
THREE.LineSegments
)
this.scene.add(line)
},
threeStart() {
this.initThree()
this.initCamera()
this.initScene()
this.initLight()
this.initObject()
// this.renderer.clear()
this.renderer.render(this.scene, this.camera)
}
}
}
</script>
<style lang="less" scoped></style>

最新文章

  1. java 导出数据为word文档(保持模板格式)
  2. rake :You have already activated rake 10.1.0
  3. MySQL- 锁(1)
  4. OpenStack Hacker养成指南
  5. 【TopCoder】SRM 680 DIV 2
  6. 【Java基础】增强for循环要注意陷阱
  7. .net线程入门1-进程
  8. Ubuntu 下 JDK+Tomcat+MySql 环境的搭建
  9. Wikioi 1080一维树状数组
  10. SVM(三)—Kernels(核函数)
  11. Conversion to Dalvik format failed: Unable to execute dex
  12. 前端——CSS笔记
  13. 201521123085 《Java程序设计》第11周学习总结
  14. gunicorn syncworker 源码解析
  15. linux添加超级管理员用户,修改,删除用户
  16. nohup.out文件过大解决方法 定时任务清空
  17. pandas 处理文本数据
  18. caffe运行报错:datum channel&gt;0(0:0)
  19. Java中A instanceof B是什么意思?
  20. UICollectionView setPrefetchingEnabled

热门文章

  1. SQL中事务以及全局变量的使用
  2. spalsh安装及简单使用
  3. VBA---文件操作
  4. C#实践炸飞机socket通信
  5. 小巧快速的ZooKeeper可视化管理+实时监控工具
  6. laravel的_token传值 ; header中传_token
  7. php统一的gocheck方法
  8. Java-数组工具类Arrays
  9. pagehelper踩坑记之分页乱套
  10. 【Java并发入门】03 互斥锁(上):解决原子性问题