当前位置:网站首页>Three. JS basic element usage
Three. JS basic element usage
2022-07-19 11:46:00 【The sadness of No.7 Park】
One 、Scene
Where can the scene make you 、 Put something for three.js To render , This is where you place the object 、 Where the lights and cameras .
// Create a scene
const scene = new THREE.Scene();
// Scene background color
scene.background = new THREE.Color(0xffffff);
// Fog
scene.fog = new THREE.Fog(0xffffff, 0, 750);
Two 、camera
After you create a camera, you need to add it to the scene ,scene.add(camera);
2.1 Perspective camera (PerspectiveCamera)
This projection mode is used to simulate the scene seen by the human eye , It is 3D The most common projection mode used in scene rendering .
const camera = new THREE.PerspectiveCamera(75, element.offsetWidth / element.offsetHeight, 1, 1000);
// Set the camera position (x,y,z)
camera.position.set(0, 10, 0);
PerspectiveCamera( fov : Number, aspect : Number, near : Number, far : Number )
fov — Camera cone vertical field of view angle
aspect — Camera cone aspect ratio
near — Camera cone near end face
far — Far end of camera cone
2.2 Orthographic camera (OrthographicCamera)
In this projection mode , Whether the object is far or close to the camera , The size of the object remains the same in the final rendered image .
3、 ... and 、WebGLRenderer Renderers
3.1 Constructors :WebGLRenderer( parameters : Object )
parameters Parameters can be chosen :
- antialias: Anti-Aliasing , The default is false
- depth: Whether the drawing cache has at least 6 Bit deep cache . The default is true
const renderer = new THREE.WebGLRenderer({ antialias: true });
3.1 Method
setPixelRatio(value: number) Set the device pixel ratio . Usually used to avoid HiDPI The drawing on the device is blurred
setSize(width : Integer, height : Integer, updateStyle : Boolean) Will output canvas The size of is adjusted to (width, height) And consider the device pixel ratio , And change the viewport from (0, 0) Start adjusting to fit take updateStyle Set to false To prevent canvas Make any changes to the style of .
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(element.offsetWidth, element.offsetHeight);
render( scene : Object3D, camera : Camera ) Render a scene with a camera
边栏推荐
- Introduction and Simulation Implementation of string class
- [wechat applet] use a thousand hand float - rollback
- Configure spectrum navigation for Huawei wireless devices
- 委派双亲之类加载器
- Swift 二进制数据与16进制字符串的相互转换
- 2022 National latest fire-fighting facility operator (intermediate fire-fighting facility operator) simulation test questions and answers
- A simple websocket example
- Research on Wenhua commodity index
- TiKV 线程池性能调优
- JVM hook hooks function
猜你喜欢
Leetcode 1252. 奇数值单元格的数目
Developing those things: how to solve the problem of long-time encoding and decoding of RK chip video processing?
Will causal learning open the next generation of AI? Chapter 9 Yunji datacanvas officially released the open source project of ylarn causal learning
TCP congestion control details | 7 Surpass TCP
mysql show processlist 详解
Round table record: fireside dialogue -- how to realize innovation in Web3
Qt--优秀开源项目
Opencv draw a black rectangle and write the serial number
Leetcode 1304. 和为零的 N 个不同整数
Introduction to common distributed locks
随机推荐
03-1. Inline function, auto keyword, typeID, nullptr
机器人开发--机器人资料汇总
[unity technology accumulation] realize the mouse line drawing function &linerenderer
TiKV Follower Read
Region 性能调优
cv02-roge矩阵,旋转向量 ,角度
TiFlash 性能调优
Chapter 1 of creating virtual machine (vmvare virtual machine)
下推计算结果缓存
Leetcode 1252. 奇数值单元格的数目
Leetcode 1310. Subarray XOR query
What do you look at after climbing the wall? The most popular foreign website - website navigation over the wall
JVM hook hooks function
From "passive" to "active", how can zeta technology help to upgrade "rfid2.0"?
常见分布式锁介绍
Developing those things: how to solve the problem of long-time encoding and decoding of RK chip video processing?
High performance IO framework library libevent (III): overview of libevent framework functions
传输层 -------- TCP(一)
Why does the magnetic variable speed gear reverse?
qt 实现遍历文件夹