forked from Orillusion/orillusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TriGeometry.ts
62 lines (53 loc) · 1.94 KB
/
TriGeometry.ts
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
import { GeometryBase } from "../core/geometry/GeometryBase";
import { VertexAttributeName } from "../core/geometry/VertexAttributeName";
/**
* Plane geometry
* @group Geometry
*/
export class TriGeometry extends GeometryBase {
private faceCount: number = 0;
/**
*
* @constructor
*/
constructor(count: number) {
super();
this.faceCount = count;
this.buildGeometry();
}
private buildGeometry(): void {
let indices_arr = new Uint32Array(this.faceCount * 3);
let position_arr = new Float32Array(this.faceCount * 3 * 3);
let normal_arr = new Float32Array(this.faceCount * 3 * 3);
let uv_arr = new Float32Array(this.faceCount * 3 * 2);
let meshIndexList = new Float32Array(this.faceCount * 3 * 1);
// for (let index = 0; index < this.faceCount * 3; index++) {
// position_arr[index * 3 + 0] = Math.random() * 100;
// position_arr[index * 3 + 1] = Math.random() * 100;
// position_arr[index * 3 + 2] = Math.random() * 100;
// }
for (let index = 0; index < this.faceCount; index++) {
let i1 = index * 3 + 0;
let i2 = index * 3 + 1;
let i3 = index * 3 + 2;
indices_arr[i1] = i1;
indices_arr[i2] = i2;
indices_arr[i3] = i3;
}
this.setIndices(indices_arr);
this.setAttribute(VertexAttributeName.position, position_arr);
this.setAttribute(VertexAttributeName.normal, normal_arr);
this.setAttribute(VertexAttributeName.uv, uv_arr);
this.setAttribute(VertexAttributeName.TEXCOORD_1, uv_arr);
this.setAttribute(VertexAttributeName.vIndex, meshIndexList);
this.addSubGeometry({
indexStart: 0,
indexCount: indices_arr.length,
vertexStart: 0,
vertexCount: 0,
firstStart: 0,
index: 0,
topology: 0
});
}
}