Skip to content

Instantly share code, notes, and snippets.

@mathdoodle
Created August 2, 2015 15:49
Show Gist options
  • Save mathdoodle/6cea570d2557510e9112 to your computer and use it in GitHub Desktop.
Save mathdoodle/6cea570d2557510e9112 to your computer and use it in GitHub Desktop.
EIGHT Template
{
"uuid": "a2d59298-4019-48d8-a785-91f3e80469e0",
"description": "EIGHT Template",
"dependencies": {
"DomReady": "latest",
"davinci-blade": "1.1.1",
"davinci-eight": "latest",
"gl-matrix": "2.2.1"
},
"operatorOverloading": true
}
<!doctype html>
<html>
<head>
<style>
/* STYLE-MARKER */
</style>
<script id='vs' type='x-shader/x-vertex'>
attribute vec3 aVertexPosition;
void main(void) {
gl_Position = vec4(aVertexPosition, 1.0);
}
</script>
<script id='fs' type='x-shader/x-fragment'>
void main(void) {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
</script>
<!-- SCRIPTS-MARKER -->
</head>
<body>
<script>
// CODE-MARKER
</script>
<canvas id='my-canvas' width='400' height='300'>
Your browser does not support the canvas element.
</canvas>
</body>
</html>
DomReady.ready(function() {
try {
main();
}
catch(e) {
console.error(e);
}
});
var e1 = blade.e3ga.e1;
var e2 = blade.e3ga.e2;
var e3 = blade.e3ga.e3;
function main() {
var scene = EIGHT.drawList();
var canvas = <HTMLCanvasElement>document.getElementById('my-canvas');
var renderer = EIGHT.webGLRenderer(canvas);
renderer.clearColor(0.3, 0.3, 0.3, 1.0);
var monitor = EIGHT.contextMonitor(canvas).addContextUser(renderer).start();
var perspective = EIGHT.perspective().setAspect(canvas.clientWidth / canvas.clientHeight).setEye(e1 + 3.0 * e3);
var ambients = EIGHT.uniforms([perspective]);
var mesh = new EIGHT.BoxBuilder().buildMesh();
var model = new EIGHT.Node();
var shaders = EIGHT.smartProgram(mesh.getAttribMeta(), [model.getUniformMeta(), ambients.getUniformMeta()])
var cube = EIGHT.drawableModel(mesh, shaders, model);
cube.model.color = EIGHT.Color.fromRGB(1, 1, 0);
scene.add(cube);
EIGHT.animation((time: number) => {
renderer.render(scene, ambients);
}).start();
}
body { margin: 0; }
canvas { width: 100%; height: 100% }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment