当前位置: 首页 > news >正文

从Unity到Three.js(画线组件line)

JavaScript 0基础,只是照着官方文档临摹了下,之后有时间再进行细节学习和功能封装。

import * as THREE from 'three'; //引入threejsconst renderer = new THREE.WebGLRenderer();//创建渲染器
//设置渲染范围,当前撑满全屏,屏幕左上角是(0,0)
let width = window.innerWidth;
let height = window.innerHeight;
renderer.setSize(width, height);document.body.appendChild(renderer.domElement);
//配置相机,对应unity中 camer组件的相关设置
const camera = new THREE.PerspectiveCamera(45,width/height,1,500);
camera.position.set(0,0,100);//设置相机位置,对应unity中配置camer坐标
camera.lookAt(0,0,0);//设置相机一直朝向的坐标点,对应unity中的相机观察中心点
//创建一个材质球
//const material = new THREE.LineBasicMaterial({color:new THREE.Color("rgb(0, 100, 150)")});//({color:0x0000ff});
const material = new THREE.LineBasicMaterial( {color: new THREE.Color("rgb(0, 100, 150)"),linewidth: 10,//官方文档告知 由于OpenGL Core Profile与 大多数平台上WebGL渲染器的限制,无论如何设置该值,线宽始终为1。linecap: 'bevel', //ignored by WebGLRendererlinejoin:  'bevel' //ignored by WebGLRenderer
} );
//配置画线经过的点,对应unity中的lineRenderer组件
//屏幕正中间是(0,0,0)
const points = [];
points.push(new THREE.Vector3(-10,0,0));
points.push(new THREE.Vector3(0,10,0));
points.push(new THREE.Vector3(10,0,0));
points.push(new THREE.Vector3(0,-10,0));
points.push(new THREE.Vector3(-10,0,0));
//传入点 创建几何体
const geometry = new THREE.BufferGeometry().setFromPoints(points);    
//设置直线类型,其他还没研究      
const line = new THREE.Line(geometry,material);//创建场景
const scene = new THREE.Scene();
scene.add(line);//把线加入场景
renderer.render(scene,camera);//设置要渲染的场景和相机
http://www.lryc.cn/news/297450.html

相关文章:

  • LCP 30. 魔塔游戏 - 力扣(LeetCode)
  • 数据结构——单向链表和双向链表的实现(C语言版)
  • TCP和UDP相关问题(重点)(4)——4.使用TCP的协议有哪些?使用UDP的协议有哪些?
  • Python进阶--爬取美女图片壁纸(基于回车桌面网的爬虫程序)
  • [office] excel如何计算毛重和皮重的时间间隔 excel计算毛重和皮重时间间隔方法 #笔记#学习方法
  • Pandas 对带有 Multi-column(多列名称) 的数据排序并写入 Excel 中
  • 如何为Kafka加上账号密码(一)
  • Elasticsearch的Index Lifecycle Management(ILM)
  • 2、学习 Nacos 注册中心
  • Java 如何操作 nginx 服务器上的文件?
  • 时序预测 | MATLAB实现基于CNN-GRU-AdaBoost卷积门控循环单元结合AdaBoost时间序列预测
  • 中创ET4410 台式LCR数字电桥 简单开箱测评
  • 格式化dingo返回内容
  • QGIS编译(跨平台编译)之四十六:minizip编译(Windows、Linux、MacOS环境下编译)
  • MySQL进阶查询篇(1)-索引的类型与创建
  • 【STL】list模拟实现
  • 常用的文件系统、存储类型小整理
  • Java写标准输出进度条
  • leetcode 算法 69.x的平方根(python版)
  • 【golang】24、go get 和 go mod:indrect 与 go mod tidy
  • AI算法工程师-非leetcode题目总结
  • 2.6:冒泡、简选、直插、快排,递归,宏
  • FastDFS安装并整合Openresty
  • 93 log4j-slf4j-impl 搭配上 log4j-to-slf4j 导致的 StackOverflow
  • 客户端会话技术-Cookie
  • rsa加密登录解决方案
  • 速盾:海外服务器用了cdn还是卡怎么办
  • [python-opencv] PNG 裁切物体
  • 机器学习——有监督学习和无监督学习
  • MySQL单主模式部署组复制集群