Code Monkey home page Code Monkey logo

voxel-forest's Introduction

voxel-forest

generate voxel trees

example

Run this example.

var createTerrain = require('voxel-perlin-terrain');

var createEngine = require('voxel-engine');
var game = createEngine({
    generateVoxelChunk: createTerrain(2, 32),
    chunkDistance: 2,
    materials: [ 'grass_top', 'tree_side', 'leaves_opaque' ],
    texturePath: './textures/'
});
game.controls.pitchObject.rotation.x = -1.5;
game.appendTo('#container');
window.game = game;

var createTree = require('voxel-forest');
for (var i = 0; i < 250; i++) {
    createTree(game, { bark: 2, leaves: 3 });
}

var explode = require('voxel-debris')(game);
game.on('mousedown', function (pos) {
    if (erase) explode(pos)
    else game.createBlock(pos, 1)
});

window.addEventListener('keydown', ctrlToggle);
window.addEventListener('keyup', ctrlToggle);

var erase = true
function ctrlToggle (ev) { erase = !ev.ctrlKey }
game.requestPointerLock('canvas');

methods

var createTree = require('voxel-forest')

createTree(game, opts)

Create a tree for the voxel-engine instance game and options opts.

opts.bark and opts.leaves are the voxel data values to use for the tree materials.

opts.height is the number of blocks for the tree to grow up to.

opts.base is the block height to start putting foliage around the trunk.

opts.position is an object with x, y, and z fields that describes where to put the tree. If opts.position.y is inside of terrain or suspended in the air, the y will be cast upward or downward to the terrain surface.

If opts.position isn't given, a random location on the voxel terrain will be chosen.

install

With npm do:

npm install voxel-forest

Use browserify to require('voxel-forest') in the browser.

license

MIT

voxel-forest's People

Contributors

jashmenn avatar

Watchers

James Cloos avatar Mhd Sami Al Mouhtaseb avatar satnami-bot avatar

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.