three.js一步一步来--如何画出构造辅助线
可以参考下面代码,粘贴上去就有了~
<template>
<div class="container">
<h1>初步构造出辅助线</h1>
<canvas ref="mainCanvas"></canvas>
</div>
</template>
<script>
import * as THREE from 'three'
const OrbitControls = require('three-orbit-controls')(THREE)
export default {
props: {},
data() {
return {
// 公共项目1
scene: new THREE.Scene(),
camera: null,
renderer: new THREE.WebGLRenderer(), // 渲染器
directionalLight: new THREE.DirectionalLight(0xff0000, 1.0, 0),
controls: OrbitControls,
cars: [],
width: '',
height: '',
config: {
isMobile: false,
background: 0x282828
}
// 公共项目2
}
},
computed: {},
watch: {},
created() {},
mounted() {
this.width = window.innerWidth
this.height = window.innerHeight
this.scene = new THREE.Scene()
this.camera = new THREE.PerspectiveCamera(
45, // 视野角fov
this.width / this.height,
1,
5000
)
this.camera.position.set(330, 330, 330)
this.camera.lookAt(this.scene.position)
this.canvas = this.$refs.mainCanvas
this.renderer = new THREE.WebGLRenderer({
antialias: true, // antialias:true/false是否开启反锯齿
canvas: this.canvas
})
this.renderer.setSize(this.width, this.height)
this.renderer.setClearColor(this.config.background)
this.renderer.shadowMap.enabled = true // 輔助線
this.renderer.shadowMap.type = THREE.PCFSoftShadowMap // 柔化边缘的软阴影映射
this.checkUserAgent() // 检测浏览器类型
this.bulidAuxSystem() // 构建辅助系统
this.buildLightSystem() // 光线
this.loop()
},
methods: {
// 检测浏览器类型1
checkUserAgent() {
const n = navigator.userAgent
if (
n.match(/Android/i) ||
n.match(/webOs/i) ||
n.match(/iPhone/i) ||
n.match(/iPad/i) ||
n.match(/iPod/i) ||
n.match(/BlackBerry/i)
) {
this.config.isMobile = true
this.camera.position.set(420, 420, 420)
this.renderer.shadowMap.enabled = false // 輔助線
}
},
// 检测浏览器类型2
// 构建辅助系统1
bulidAuxSystem() {
const gridHelper = new THREE.GridHelper(320, 32)
this.scene.add(gridHelper)
this.controls = new OrbitControls(this.camera, this.renderer.domElement)
this.controls.enableDamping = true
this.controls.dampingFactor = 0.25
this.controls.rotateSpeed = 0.35
},
// 构建辅助系统2
buildLightSystem() {
console.log('是否手机', this.config.isMobile)
if (!this.config.isMobile) {
console.log('是否手机11')
this.directionalLight.position.set(300, 1000, 500)
this.directionalLight.target.position.set(0, 0, 0)
this.directionalLight.castShadow = true
const d = 300
this.directionalLight.shadow.camera = new THREE.OrthographicCamera(
-d,
d,
d,
-d,
500,
1600
)
this.directionalLight.shadow.bias = 0.0001
this.directionalLight.shadow.mapSize.width = this.directionalLight.shadow.mapSize.height = 1024
this.scene.add(this.directionalLight)
const light = new THREE.AmbientLight(0xffffff, 0.3)
this.scene.add(light)
} else {
console.log('是否手机22')
const hemisphereLight = new THREE.HemisphereLight(0xffffff, 1)
this.scene.add(hemisphereLight)
this.scene.add(new THREE.AmbientLight(0xffffff, 0.15))
}
},
loop() {
this.renderer.render(this.scene, this.camera)
requestAnimationFrame(this.loop)
}
}
}
</script>
<style scoped lang="less">
</style>
three.js一步一步来--如何画出构造辅助线的更多相关文章
- 一步一步搭建客服系统 (4) 客户列表 - JS($.ajax)调用WCF 遇到的各种坑
本文以一个生成.获取“客户列表”的demo来介绍如何用js调用wcf,以及遇到的各种问题. 1 创建WCF服务 1.1 定义接口 创建一个接口,指定用json的格式: [ServiceContra ...
- 一步一步教你用 Vue.js + Vuex 制作专门收藏微信公众号的 app
一步一步教你用 Vue.js + Vuex 制作专门收藏微信公众号的 app 转载 作者:jrainlau 链接:https://segmentfault.com/a/1190000005844155 ...
- 基于JS的event-manage事件管理库(一步一步实现)
关于文章 最近在提升个人技能的同时,决定把自己为数不多的沉淀记录下来,让自己理解的更加深刻,同时也欢迎各位看官指出不足之处. 随着node.js的盛行,引领着Javascript上天下地无所不能啊,本 ...
- 一步一步搭建客服系统 (3) js 实现“截图粘贴”及“生成网页缩略图”
最近在做一个客服系统的demo,在聊天过程中,我们经常要发一些图片,而且需要用其它工具截图后,直接在聊天窗口里粘贴,就可以发送:另外用户输入一个网址后,把这个网址先转到可以直接点击的link,并马上显 ...
- C#进阶系列——一步一步封装自己的HtmlHelper组件:BootstrapHelper(三:附源码)
前言:之前的两篇封装了一些基础的表单组件,这篇继续来封装几个基于bootstrap的其他组件.和上篇不同的是,这篇的有几个组件需要某些js文件的支持. 本文原创地址:http://www.cnblog ...
- 大流量网站性能优化:一步一步打造一个适合自己的BigRender插件
BigRender 当一个网站越来越庞大,加载速度越来越慢的时候,开发者们不得不对其进行优化,谁愿意访问一个需要等待 10 秒,20 秒才能出现的网页呢? 常见的也是相对简单易行的一个优化方案是 图片 ...
- 一步一步搭框架(asp.netmvc+easyui+sqlserver)-02
一步一步搭框架(asp.netmvc+easyui+sqlserver)-02 我们期望简洁带前台代码,如下: <table id="dataGrid" class=&quo ...
- 一步一步跟我学DeviceOne开发 - 仿微信应用(一,二,三)
这是一个系列的文档,长期目标是利用DeviceOne开发一些目前使用广泛的优质手机应用,我们会最大化的实现这些应用的每一个功能和细节,不只停留在简单的UI模仿和Demo阶段,而是一个基本可以使用的实际 ...
- (转) 一步一步学习ASP.NET 5 (二)- 通过命令行和sublime创建项目
转发:微软MVP 卢建晖 的文章,希望对大家有帮助. 注:昨天转发之后很多朋友指出了vNext的命名问题,原文作者已经做出了修改,后面的标题都适用 asp.net 5这个名称. 编者语 : 昨天发了第 ...
随机推荐
- 1.WEB应用模式
1. Web应用模式 在开发Web应用中,有两种应用模式: 前后端不分离[客户端看到的内容和所有界面效果都是由服务端提供出来的.] 前后端分离[把前端的界面效果(html,css,js分离到另一个服务 ...
- mlflow详细安装部署
1.安装docker # 安装工具 sudo yum install -y yum-utils # 添加yum仓库配置 sudo yum-config-manager --add-repo https ...
- 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(济南)-L Bit Sequence
题意 给你两个数l,m,大小为m的数组a,求[0,l]之间满足以下条件的数x的个数: 对于任何i输入[0,m-1],f(x+i)%2=a[i]:f(k):代表k在二进制下1的个数 m的范围<=1 ...
- iview table json数据里的num排序问题
title: 'Num', key: 'num', sortable: true, sortMethod:function(a,b,type){ //可以用Number()或者parseInt(a)转 ...
- 关于C#Section配置未初始化的问题
转载 https://www.cnblogs.com/lxshwyan/p/10828305.html 如果使用了configSection节点,则configSection必须位于根节点的第0个.A ...
- 删除redis对应key的缓存
[root@zhyly-pre-002 ~]# /usr/local/redis/bin/redis-cli -p 6379 #登录redis 127.0.0.1:6379> auth 'Red ...
- 【大数据-课程】高途-天翼云侯圣文-Day3-实时计算原理解析
〇.老师及课程介绍 一.今日内容 二.实时计算理论解析 1.什么是实时计算 微批处理.流式处理.实时计算 水流和车流的例子 spark streaming就是一种微批处理,水满了才处理,进入下一个地方 ...
- 记录一次 MyBatis 批量插入的优化-BatchInsert
记录在一次项目问题排查过程中,遇到在数据量大的情况下,向数据库批量插入非常耗时长的问题. 1.分析 首先,代码是在 service 中,采用的是 for 循环调用 insert 语句的方式: for( ...
- 基于Nginx搭建WebDAV服务
title: 基于Nginx搭建WebDAV服务 categories: - [IT,网络,服务] tags: - WebDAV - Nginx comments: true date: 2022-1 ...
- VSCode解决Python中空格和制表符混用报错
Python对缩进的要求非常严格,缩进控制不正确可能会造成代码执行不正确甚至报错. 遇到报错"TabError: inconsistent use of tabs and spaces in ...