Skip to content

Instantly share code, notes, and snippets.

@brunofarache
Forked from anonymous/y3d-script.js
Last active December 18, 2015 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunofarache/5819876 to your computer and use it in GitHub Desktop.
Save brunofarache/5819876 to your computer and use it in GitHub Desktop.
/**
* y3d is a WebGL library built with yui3
*
* https://github.com/brunofarache/y3d
*/
/**
* Examples: load y3d scripts from gists, click on it to see more examples
* Save: saves code to anonymous public gist
* Run: runs code (Crtl+U shortcut)
* Reset: resets changes
*/
YUI().use('y3d-scene', 'y3d-camera', 'y3d-geometry-box', 'y3d-geometry-grid', function(Y) {
var scene = new Y.Scene({
camera: new Y.Camera({
position: {
y: 2,
z: 20
}
}),
background: '#272822'
});
var grid = new Y.Grid({ size: 50 })
scene.add(grid);
var box = new Y.Box({
color: '#ff7700',
position: {
y: 1
}
});
scene.add(box);
scene.render();
controls.render();
// Color
controls.color.onChange(function(value) {
box.set('color', value);
scene.render();
});
// Grid
controls.grid.onChange(function(value) {
value ? scene.add(grid) : scene.remove(grid);
scene.render();
});
// Wireframe
controls.wireframe.onChange(function(value) {
box.set('wireframe', value);
scene.render();
});
// Position
controls.position.x.onChange(function(value) {
box.set('position.x', value);
scene.render();
});
controls.position.y.onChange(function(value) {
box.set('position.y', value);
scene.render();
});
controls.position.z.onChange(function(value) {
box.set('position.z', value);
scene.render();
});
// Rotation
controls.rotation.x.onChange(function(value) {
box.set('rotation.x', value);
scene.render();
});
controls.rotation.y.onChange(function(value) {
box.set('rotation.y', value);
scene.render();
});
controls.rotation.z.onChange(function(value) {
box.set('rotation.z', value);
scene.render();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment