-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.js
More file actions
119 lines (94 loc) · 2.63 KB
/
Copy pathobjects.js
File metadata and controls
119 lines (94 loc) · 2.63 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict';
function getcubedata() {
const normals2 = [
0.0, 0.0, -1.0,
0.0, 0.0, 1.0,
0.0, -1.0, 0.0,
0.0, 1.0, 0.0,
-1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
];
var normals = new Float32Array(72);
for (var a = 0; a < 6; a++) {
for (var b = 0; b < 4; b++) {
for (var c = 0; c < 3; c++) {
normals[a*4*3+b*3+c] = normals2[a*3+c];
}
}
}
const positions = new Float32Array([
0, 0, 0,
0, 1, 0,
1, 0, 0,
1, 1, 0,
0, 0, 1,
1, 0, 1,
0, 1, 1,
1, 1, 1,
0, 0, 0,
1, 0, 0,
0, 0, 1,
1, 0, 1,
0, 1, 0,
0, 1, 1,
1, 1, 0,
1, 1, 1,
0, 0, 0,
0, 0, 1,
0, 1, 0,
0, 1, 1,
1, 0, 0,
1, 1, 0,
1, 0, 1,
1, 1, 1,
]);
/* 0,2,4,5, 1,6,3,7, 0,4,1,6, 2,3,5,7 */
const indices2 = [
0,1,2,1,3,2
];
var indices = new Uint16Array(36);
for (var i = 0; i < 6; i++) {
for (var j = 0; j < 6; j++) {
indices[i*6+j] = indices2[j]+i*4;
}
}
return {
attribs: {
a_position: {data: positions, size: 3, normalize: false, type: gl.FLOAT},
a_normal: {data:normals, size: 3, normalize: false, type: gl.FLOAT}
},
indices: indices,
program: "character",
count: 36
}
}
function vao(data) {
this.vao = gl.createVertexArray();
this.program = data.program;
this.count = data.count;
gl.bindVertexArray(this.vao);
this.attribs = {};
for (var attribname in data.attribs) {
var attrib = data.attribs[attribname];
attrib.location = gl.getAttribLocation(programs[this.program].program, attribname);
gl.enableVertexAttribArray(attrib.location);
attrib.buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, attrib.buffer);
gl.bufferData(gl.ARRAY_BUFFER, attrib.data, gl.STATIC_DRAW);
var size = attrib.size;
var type = attrib.type;
var normalize = attrib.normalize;
var stride = 0;
var offset = 0;
gl.vertexAttribPointer(
attrib.location, size, type, normalize, stride, offset);
this.attribs[attribname] = attrib;
}
this.indices = data.indices;
this.indiceBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indiceBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
}
var vaos = {
cube: new vao(getcubedata()),
}