'use strict';

var createVoxelMesh = require('./mesh-buffer.js');

module.exports = function(game, opts) {
  return new MesherPlugin(game, opts);
};
module.exports.pluginInfo = {
  clientOnly: true,
  loadAfter: ['voxel-stitch']
};

function MesherPlugin(game, opts) {
  this.shell = game.shell;

  this.stitcher = game.plugins.get('voxel-stitch');
  if (!this.stitcher) throw new Error('voxel-mesher requires voxel-stitch plugin');

  this.enable();
};

MesherPlugin.prototype.enable = function() {
  //moved to voxel-engine
  // when ready stitcher.voxelSideTextureIDs and stitcher.voxelSideTextureSizes are ready,
  // the mesh can be created (requires texture IDs due to opacity and texturing)
  //this.stitcher.on('updatedSides', this.onUpdatedSides = this.createMeshes.bind(this));
};

MesherPlugin.prototype.disable = function() {
  //this.stitcher.removeListener('updatedSides', this.onUpdatedSides);
};

MesherPlugin.prototype.createMesh = function(voxelArray, position) {
  if (!this.stitcher.voxelSideTextureIDs || !this.stitcher.voxelSideTextureSizes)
    throw new Error('voxel-mesher createMesh() called before stitcher was ready (updatedSides event)');

  if (!this.shell.gl)
    throw new Error('voxel-mesher createMesh() called before this.shell.gl was ready');

  var mesh = createVoxelMesh(this.shell.gl, voxelArray, this.stitcher.voxelSideTextureIDs, this.stitcher.voxelSideTextureSizes, position);
  if (!mesh) return null; // no vertices

  return mesh;
};

@@ -194,39 +194,8 @@
 true
-,%0A  loadAfter: %5B'voxel-stitch'%5D
 %0A%7D;%0A
@@ -242,1207 +242,80 @@
 his.
-shell = game.shell;%0A%0A  this.stitcher = game.plugins.get('voxel-stitch');%0A  if (!this.stitcher) throw new Error('voxel-mesher requires voxel-stitch plugin');%0A%0A  this.enable();%0A%7D;%0A%0AMesherPlugin.prototype.enable = function() %7B%0A  //moved to voxel-engine%0A  // when ready stitcher.voxelSideTextureIDs and stitcher.voxelSideTextureSizes are ready,%0A  // the mesh can be created (requires texture IDs due to opacity and texturing)%0A  //this.stitcher.on('updatedSides', this.onUpdatedSides = this.createMeshes.bind(this));%0A%7D;%0A%0AMesherPlugin.prototype.disable = function() %7B%0A  //this.stitcher.removeListener('updatedSides', this.onUpdatedSides);%0A%7D;%0A%0AMesherPlugin.prototype.createMesh = function(voxelArray, position) %7B%0A  if (!this.stitcher.voxelSideTextureIDs %7C%7C !this.stitcher.voxelSideTextureSizes)%0A    throw new Error('voxel-mesher createMesh() called before stitcher was ready (updatedSides event)');%0A%0A  if (!this.shell.gl)%0A    throw new Error('voxel-mesher createMesh() called before this.shell.gl was ready');%0A%0A  var mesh = createVoxelMesh(this.shell.gl, voxelArray, this.stitcher.voxelSideTextureIDs, this.stitcher.voxelSideTextureSizes, position);%0A  if (!mesh) return null; // no vertices%0A%0A  return mesh;%0A%7D;
+game = game;%0A%7D;%0A%0AMesherPlugin.prototype.createVoxelMesh = createVoxelMesh;%0A
 %0A

Remove unnecessary plugin code