-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathskelly.js
54 lines (53 loc) · 1.21 KB
/
skelly.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
var regl = require('regl')()
var mesh = require('./skelly.json')
var mat4 = require('gl-mat4')
var normals = require('angle-normals')
var camera = require('regl-camera')(regl, {
center: [0, 20, 0],
distance: 50
})
function skelly (regl){
return regl({
frag: `
precision mediump float;
varying vec3 vnormal;
void main () {
gl_FragColor = vec4(abs(vnormal), 1.0);
}`,
vert: `
precision mediump float;
uniform mat4 model, projection, view;
attribute vec3 position, normal;
varying vec3 vnormal;
void main () {
vnormal = normal;
gl_Position = projection * view * model * vec4(position, 1.0);
}`,
attributes: {
position: mesh.positions,
normal: normals(mesh.cells, mesh.positions)
},
elements: mesh.cells,
uniforms: {
model: function(context, props){
var rmat = []
var rmati = mat4.identity(rmat)
var theta = context.time
mat4.rotateY(rmati, rmati, theta)
return rmat
}
},
primitive: "triangles"
})
}
var draw = {
skelly: skelly(regl)
}
regl.frame(function() {
regl.clear({
color: [0, 0, 0, 1]
})
camera(function() {
draw.skelly()
})
})