Last active
August 29, 2015 13:56
-
-
Save romainberger/9117621 to your computer and use it in GitHub Desktop.
Voxel Painter Core plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Stream = require('stream') | |
, stream = new Stream() | |
, numberVoxel = 0 | |
var voxelCount = function(studio) { | |
studio.on('addVoxel', function() { | |
numberVoxel++ | |
stream.emit('addVoxel', numberVoxel) | |
}) | |
return stream | |
} | |
module.exports = voxelCount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var voxelPainter = require('voxel-painter-core') | |
, voxelCount = require('./example-plugin') | |
var studio = voxelPainter({ | |
container: '#studio-container' | |
}) | |
voxelCount = studio.loadPlugin(voxelCount) | |
voxelCount.on('addVoxel', function(number) { | |
console.log(number+' voxels in the canvas') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Stream = require('stream') | |
, pluginStream = new Stream() | |
// [...] | |
/** | |
* Load a plugin | |
*/ | |
exports.loadPlugin = function(plugin) { | |
plugins.push(plugin) | |
return plugin(pluginStream) | |
} | |
// [...] | |
function addVoxel(x, y, z, c) { | |
pluginStream.emit('addVoxel', [x, y, z, c]) | |
// [...] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment