Skip to content

Instantly share code, notes, and snippets.

@romainberger
Last active August 29, 2015 13:56
Show Gist options
  • Save romainberger/9117621 to your computer and use it in GitHub Desktop.
Save romainberger/9117621 to your computer and use it in GitHub Desktop.
Voxel Painter Core plugins
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
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')
})
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