当前位置:网站首页>Three.js基本元素使用
Three.js基本元素使用
2022-07-17 11:36:00 【七号公园的忧伤】
一、Scene
场景能够让你在什么地方、摆放什么东西来交给three.js来渲染,这是你放置物体、灯光和摄像机的地方。
//创建一个场景
const scene = new THREE.Scene();
//场景背景色
scene.background = new THREE.Color(0xffffff);
//雾
scene.fog = new THREE.Fog(0xffffff, 0, 750);二、camera
创建相机后都需要添加到场景中,scene.add(camera);
2.1透视相机(PerspectiveCamera)
这一投影模式被用来模拟人眼所看到的景象,它是3D场景的渲染中使用得最普遍的投影模式。
const camera = new THREE.PerspectiveCamera(75, element.offsetWidth / element.offsetHeight, 1, 1000);
//设置摄像机的位置(x,y,z)
camera.position.set(0, 10, 0);PerspectiveCamera( fov : Number, aspect : Number, near : Number, far : Number )
fov — 摄像机视锥体垂直视野角度
aspect — 摄像机视锥体长宽比
near — 摄像机视锥体近端面
far — 摄像机视锥体远端面2.2正交相机(OrthographicCamera)
在这种投影模式下,无论物体距离相机距离远或者近,在最终渲染的图片中物体的大小都保持不变。
三、WebGLRenderer渲染器
3.1构造函数:WebGLRenderer( parameters : Object )
parameters参数可选:
- antialias:抗锯齿,默认为false
- depth: 绘图缓存是否有一个至少6位的深度缓存。 默认是true
const renderer = new THREE.WebGLRenderer({ antialias: true });3.1方法
setPixelRatio(value: number)设置设备像素比。通常用于避免HiDPI设备上绘图模糊
setSize(width : Integer, height : Integer, updateStyle : Boolean)将输出canvas的大小调整为(width, height)并考虑设备像素比,且将视口从(0, 0)开始调整到适合大小 将updateStyle设置为false以阻止对canvas的样式做任何改变。
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(element.offsetWidth, element.offsetHeight);render( scene : Object3D, camera : Camera )用相机渲染一个场景
边栏推荐
- Rasa 3.x 学习系列-Rasa 3.1.5 版本发布
- 在线教育知识付费网站源码系统+直播+小程序,安装教程
- Among China's top ten national snacks, it is actually the first
- 上学=挣钱?无需缴纳学费的神仙院校!
- SSH Connection Huawei modelarts Notebook
- Clwy authority management (II) -- user module
- rhcsa 第一天 7.11
- redis缓存雪崩
- Huawei wireless devices are configured with static load balancing
- 华为昇思MindSpore详细教程
猜你喜欢

【C语言】浅涉选择、循环语句、函数及数组

Online education knowledge payment website source code system + live broadcast + applet, installation tutorial

标准化、归一化和正则化的关系

SSH連接華為ModelArts notebook

Fiddler replay attack, simple simulated replay attack

标准化、归一化和正则化的关系

【森城市】GIS数据漫谈(四)— 坐标系统

金纳米粒子修饰MIL-101骨架材料(AuNPs/MIL-101)/负载COF-TpPa-1(Au NPs/COF-TpPa-1)|齐岳试剂

mof定制材料|超薄MOF纳米带|磁性Fe3O4 @Cd-MOF纳米复合材料|ZIF-8/石墨烯复合纳米颗粒
![[C language] involves constants and variables](/img/4c/1ec1a47865eeccfb490ebf4732256f.png)
[C language] involves constants and variables
随机推荐
面向6G的智能反射面无线通信综述
What is the product power of lantu dreamer?
Learning summary of MySQL advanced Chapter 11: locate SQL methods with slow execution and analyze the use of query statement explain
卫星网络中基于时变图的节能资源分配策略
node+express搭建服务器环境
On the problem of dependency invalidation when the dependency in the basic module is inherited by the sub module in the microservice
网络安全学习(千锋网络安全笔记)1--搭建虚拟机
【摸鱼神器】UI库秒变低代码工具——表单篇(二)子控件
SSH Connection Huawei modelarts Notebook
流量排名100W网站
数组模拟队列
[C language] string, escape character and comment
Huawei wireless device configuration dynamic load balancing
镧系金属有机骨架([email protected])|罗丹明6G修饰MOF材料|过氧化氢酶@ZIF复合材料|mof材料
Mysql高级篇学习总结11:定位执行慢的sql方法、分析查询语句EXPLAIN的使用
硫化镉负载MIL-125(Ti)|链霉亲和素(SA)-锆基卟啉MOF复合材料([email protected])|壳核结构
es索引、类型(mapping)、文档、ik分词器
Among China's top ten national snacks, it is actually the first
PTA 1037 change at Hogwarts
测试vector、list、set调用empty和size的耗时是否为常数