当前位置:网站首页>Threejs Part 2: vertex concept, geometry structure
Threejs Part 2: vertex concept, geometry structure
2022-07-03 16:20:00 【Nanchen_ forty-two】
ThreeJS Second articles : Vertex concept 、 Geometry structure
One 、 Vertex position data parsing and rendering
The focus of this lesson is to establish the concept of vertex . If you establish the concept of vertex , So for your in-depth understanding and learning Three.js Very helpful .
( One )、JavaScript Typed array
( Two )、 Custom Geometry
Can be called directly BoxGeometry Directly create a cube geometry , call SphereGeometry Create a sphere geometry .
The following code passes Threejs Engine BufferGeometry and BufferAttribute Two API Customized a geometry with six vertex data .
var scene = new THREE.Scene();
var geometry = new THREE.BufferGeometry(); // Create a Buffer Type geometry object
var vertices = new Float32Array([
0,
0,
0, // The vertices 1 coordinate
50,
0,
0, // The vertices 2 coordinate
0,
100,
0, // The vertices 3 coordinate
0,
0,
10, // The vertices 4 coordinate
0,
0,
100, // The vertices 5 coordinate
50,
0,
10, // The vertices 6 coordinate
]);
// Create an attribute buffer object
var attribue = new THREE.BufferAttribute(vertices, 3); //3 One for a group , Representing a vertex xyz coordinate
// Set up the geometry attributes The location of the property
geometry.attributes.position = attribue;
// Trigonometry ( grid ) Rendering mode
var material = new THREE.MeshBasicMaterial({
color: 0x0000ff, // Triangle color
side: THREE.DoubleSide, // You can see it on both sides
}); // Material object
var mesh = new THREE.Mesh(geometry, material); // Mesh model objects Mesh
// Point source
scene.add(mesh); // Grid models are added to the scene
( 3、 ... and )、 Point model Points
Three points render triangles as a group
// Point rendering mode
var material = new THREE.PointsMaterial({
color: 0xff0000,
size: 10.0, // Point object pixel size
}); // Material object
var points = new THREE.Points(geometry, material); // Point model object
scene.add(points); // Point objects are added to the scene
( Four )、 Line model Line
You can connect the points above
// Line rendering mode
var material = new THREE.LineBasicMaterial({
color: 0xff0000, // line color
}); // Material object
var line = new THREE.Line(geometry, material); // Line model object
scene.add(line); // Line objects are added to the scene
( 5、 ... and )、 The essence of geometry
A cube mesh model , Yes 6 Face to face , At least two triangles on each face form a rectangular plane , Each triangle consists of three vertices , For the sphere mesh model , It is also through triangles to spell out a sphere , The more triangles , The closer the mesh model surface is to the sphere .
Rectangular vertex line
var scene = new THREE.Scene();
var geometry = new THREE.BoxGeometry(100, 100, 100);
var material = new THREE.PointsMaterial({
color: 0xff0000,
size: 10.0 // Point object pixel size
}); // Material object
// var mesh = new THREE.Mesh(geometry, material); // Mesh model objects Mesh
var line = new THREE.Line(geometry, material);// Line model object
scene.add(line);
Sphere vertex line
var scene = new THREE.Scene();
var geometry = new THREE.BoxGeometry(100, 100, 100);
var material = new THREE.PointsMaterial({
color: 0xff0000,
size: 10.0 // Point object pixel size
}); // Material object
// var mesh = new THREE.Mesh(geometry, material); // Mesh model objects Mesh
var line = new THREE.Line(geometry, material);// Line model object
scene.add(line);
Two 、 Vertex color data interpolation calculation
( One )、 Vertex color data interpolation calculation
This section introduces the vertex color of geometry
Vertex one has a coordinate data , Then he also has the corresponding vertex color data … And so on
( Two )、 Set a color for each vertex
var scene = new THREE.Scene();
var geometry = new THREE.BufferGeometry(); // Declare a buffer geometry object
// Type array creates vertex positions position data
var vertices = new Float32Array([
0, 0, 0, // The vertices 1 coordinate
50, 0, 0, // The vertices 2 coordinate
0, 100, 0, // The vertices 3 coordinate
0, 0, 10, // The vertices 4 coordinate
0, 0, 100, // The vertices 5 coordinate
50, 0, 10, // The vertices 6 coordinate
]);
// Create an attribute buffer object
var attribue = new THREE.BufferAttribute(vertices, 3); //3 One for a group , As a vertex xyz coordinate
// Set up the geometry attributes Location of attributes position attribute
geometry.attributes.position = attribue;
// Type array creates vertex colors color data
var colors = new Float32Array([
1, 0, 0, // The vertices 1 Color
0, 1, 0, // The vertices 2 Color
0, 0, 1, // The vertices 3 Color
1, 1, 0, // The vertices 4 Color
0, 1, 1, // The vertices 5 Color
1, 0, 1, // The vertices 6 Color
]);
// Set up the geometry attributes The color of the attribute color attribute
geometry.attributes.color = new THREE.BufferAttribute(colors, 3); //3 One for a group , Represents the color data of a vertex RGB
// Material object
var material = new THREE.PointsMaterial({
// Render the model using vertex color data , There is no need to define color attribute
// color: 0xff0000,
vertexColors: THREE.VertexColors, // Based on the vertex color
size: 10.0 // Point object pixel size
});
// Point rendering mode Point model object Points
var points = new THREE.Points(geometry, material); // Point model object
scene.add(points); // Point objects are added to the scene
var axisHelper = new THREE.AxisHelper(250);
scene.add(axisHelper);
( 3、 ... and )、 Material properties .vertexColors
Through the color attribute of the material color Set the model color , This case is not set like this , Instead, you set the material properties .vertexColors.
var material = new THREE.PointsMaterial({
// Render the model using vertex color data , There is no need to define color attribute
// color: 0xff0000,
vertexColors: THREE.VertexColors, // Based on the vertex color
size: 10.0 // Point object pixel size
});
About the properties of materials .vertexColors You can see Material file Introduce , attribute .vertexColors The default value of is THREE.NoColors, This means that the color rendering effect of the model depends on the material properties .color, If the material properties .vertexColors Is set to THREE.VertexColors,threejs The vertex color data of the geometry is used when rendering the model geometry.attributes.color.
( Four )、 Color interpolation
var scene = new THREE.Scene();
var geometry = new THREE.BufferGeometry(); // Declare a buffer geometry object
// Type array creates vertex positions position data
var vertices = new Float32Array([
0, 0, 0, // The vertices 1 coordinate
50, 0, 0, // The vertices 2 coordinate
0, 100, 0, // The vertices 3 coordinate
0, 0, 10, // The vertices 4 coordinate
0, 0, 100, // The vertices 5 coordinate
50, 0, 10, // The vertices 6 coordinate
]);
// Create an attribute buffer object
var attribue = new THREE.BufferAttribute(vertices, 3); //3 One for a group , As a vertex xyz coordinate
// Set up the geometry attributes Location of attributes position attribute
geometry.attributes.position = attribue;
// Type array creates vertex colors color data
var colors = new Float32Array([
1, 0, 0, // The vertices 1 Color
0, 1, 0, // The vertices 2 Color
0, 0, 1, // The vertices 3 Color
1, 1, 0, // The vertices 4 Color
0, 1, 1, // The vertices 5 Color
1, 0, 1, // The vertices 6 Color
]);
// Set up the geometry attributes The color of the attribute color attribute
geometry.attributes.color = new THREE.BufferAttribute(colors, 3);
// Material object
var material = new THREE.PointsMaterial({
vertexColors: THREE.VertexColors,
size: 10.0 // Point object pixel size
});
// Point rendering mode Point model object Points
var line = new THREE.Line(geometry, material);// Line model object
scene.add(line);
The reason for the gradient is Threejs Through the ground floor WebGL When rendering, the color data of vertices will be interpolated . Color interpolation calculation is simple , For example, the endpoint of a straight line 1 Set to red , Endpoint 2 Set it to blue , The whole line will appear from the point 1 To the red dot 2 Blue color gradient , For mesh models Mesh for , That is, the three vertices of the triangle set a color respectively , The area pixels inside the triangle will be interpolated according to the colors of the three vertices .
边栏推荐
- Effect of ARP package on FTP dump under vxworks-6.6 system
- 切入点表达式
- ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
- Mixlab编辑团队招募队友啦~~
- 远程办公之大家一同实现合作编辑资料和开发文档 | 社区征文
- Is it safe to open an account with flush?
- 【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
- Go language self-study series | if else statement in golang
- Deep understanding of grouping sets statements in SQL
- [web security] - [SQL injection] - error detection injection
猜你喜欢
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (I)
[200 opencv routines] 217 Mouse interaction to obtain polygon area (ROI)
Remote file contains actual operation
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)
Colab works with Google cloud disk
[statement] about searching sogk1997 and finding many web crawler results
近视:摘镜or配镜?这些问题必须先了解清楚
[combinatorics] non descending path problem (outline of non descending path problem | basic model of non descending path problem | non descending path problem expansion model 1 non origin starting poi
Mb10m-asemi rectifier bridge mb10m
随机推荐
【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
PHP二级域名session共享方案
六月 致 -.-- -..- -
深入理解 SQL 中的 Grouping Sets 语句
From "zero sum game" to "positive sum game", PAAS triggered the third wave of cloud computing
Pandora IOT development board learning (HAL Library) - Experiment 5 external interrupt experiment (learning notes)
请求头不同国家和语言的表示
[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)
Pychart error updating package list: connect timed out
Caching mechanism of Hibernate / session level caching mechanism
Initial test of scikit learn Library
Expression of request header in different countries and languages
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
Persisting in output requires continuous learning
Myopia: take off or match glasses? These problems must be understood clearly first
程序猿如何快速成长
How to use AAB to APK and APK to AAB of Google play apps on the shelves
First knowledge of database
Why can't strings be directly compared with equals; Why can't some integers be directly compared with the equal sign
【声明】关于检索SogK1997而找到诸多网页爬虫结果这件事