Giter VIP home page Giter VIP logo

voxel-select's Introduction

voxel-select

work in progress -- not done yet

select a cube shaped group/region of voxels in game. useful for exporting parts of a world, etc

npm install voxel-select

example

var createSelector = require('voxel-select')

var selector = createSelector(game)

select.set(start, end) // bounding box positions

api

require('voxel-selector')

returns an initialization function that you must pass your game object into in order to get a selector instance

selector.set(start, end, visible)

sets the selection. start and end should be [x, y, z] vectors. visible is by default true and controls whether or not to draw a selection wireframe

selector.dimensions()

returns absolute [width, height, depth] of the current selection

selector.transform(function(x, y, z, idx) {})

run a function over each voxel in the current selection. idx is the voxel interchange format array index

selector.selection()

returns data in the voxel interchange format

selector.reset()

clears the current selection and removes the wireframe if present

license

BSD

voxel-select's People

Contributors

max-mapper avatar shama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

voxel-select's Issues

module idea: voxel-modifier

voxel-virus will remove neighboring voxels randomly at a given rate. To create water I changed the how to set a water type voxel if the voxel below is air or neighboring voxels are air.

Which got me thinking of a better way to abstract voxel manipulations. The goal: modify voxel interchange arrays over time and then return any modified voxels only when requested.

Example usage:

var voxelMod = require('voxel-modifier')(game);
var voxels = voxelMod
  // select voxels using voxel-select
  .select([0, 0, 0], [100, 100, 100])

  // apply noise modifier, randomly unselects voxels
  // 0 || null = happens only on a diff call
  .modify('noise', {amount: 0.3}, 0)

  // apply fluid modifier that flows at
  // every 300ms (based on delta) and applies water material
  .modify('fluid', {material: 'water'}, 300)

Which will start modifying voxels within the selected range by first randomly unselecting voxels and then adding voxels in a fluid like expansion.

// pass tick for timing rates at which voxels are modified
game.on('tick', voxels.tick.bind(voxels));

game.on('fire', function() {
  // only actually modify voxels when needed
  voxels.diff().forEach(function(v) {
    game.setBlock(v.position, v.type);
  });
});

Then for creating new modifiers:

// create a new modifier
voxels.modifier('explode', function(voxels, params) {
  /* calculate volume by params.radius
     and set voxels within the sphere to 0

     this function is only called at the given rate
     or only when diff() is called if null || 0
  */

  return voxels;
});

// add a modifier from npm
voxels.modifier('burn', require('voxel-burn'));

Unless something similar already exists or is planned. What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.