-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.js
44 lines (37 loc) · 1.04 KB
/
index.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
global.THREE = require('three');
const path = require('path');
const fs = require('fs');
const createApp = require('./createApp');
const createBunnyGeometry = require('./createBunnyGeometry');
const createLoop = require('raf-loop');
// Create our basic ThreeJS application
const {
renderer,
camera,
scene,
updateControls
} = createApp();
// Get a nicely prepared geometry
const geometry = createBunnyGeometry({ flat: true });
// Create our vertex/fragment shaders
const material = new THREE.RawShaderMaterial({
vertexShader: fs.readFileSync(path.join(__dirname, 'shader.vert'), 'utf8'),
fragmentShader: fs.readFileSync(path.join(__dirname, 'shader.frag'), 'utf8'),
uniforms: {
time: { type: 'f', value: 0 }
}
});
// Setup our mesh
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
// Time since beginning
let time = 0;
// Start our render loop
createLoop((dt) => {
// update time
time += dt / 1000;
material.uniforms.time.value = time;
// render
updateControls();
renderer.render(scene, camera);
}).start();