-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
geometry.js
96 lines (84 loc) · 1.98 KB
/
geometry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { Debug } from "../../core/debug.js";
import { calculateNormals, calculateTangents } from "./geometry-utils.js";
/**
* The Geometry class serves as a container for storing geometric information. It encapsulates data
* such as positions, normals, colors, and indices.
*
* @category Graphics
*/
class Geometry {
/**
* Positions.
*
* @type {number[]|undefined}
*/
positions;
/**
* Normals.
*
* @type {number[]|undefined}
*/
normals;
/**
* Colors.
*
* @type {number[]|undefined}
*/
colors;
/**
* UVs.
*
* @type {number[]|undefined}
*/
uvs;
/**
* Additional Uvs.
*
* @type {number[]|undefined}
*/
uvs1;
/**
* Blend indices.
*
* @type {number[]|undefined}
*/
blendIndices;
/**
* Blend weights.
*
* @type {number[]|undefined}
*/
blendWeights;
/**
* Tangents.
*
* @type {number[]|undefined}
*/
tangents;
/**
* Indices.
*
* @type {number[]|undefined}
*/
indices;
/**
* Generates normal information from the positions and triangle indices.
*/
calculateNormals() {
Debug.assert(this.positions, 'Geometry must have positions set');
Debug.assert(this.indices, 'Geometry must have indices set');
this.normals = calculateNormals(this.positions, this.indices);
}
/**
* Generates tangent information from the positions, normals, texture coordinates and triangle
* indices.
*/
calculateTangents() {
Debug.assert(this.positions, 'Geometry must have positions set');
Debug.assert(this.normals, 'Geometry must have normals set');
Debug.assert(this.uvs, 'Geometry must have uvs set');
Debug.assert(this.indices, 'Geometry must have indices set');
this.tangents = calculateTangents(this.positions, this.normals, this.uvs, this.indices);
}
}
export { Geometry };