ndthree
The unholy union of three.js and Mikola Lysenko's ndarrays.
It's far more efficient to just use gl-now. See the voxel-mipmap-demo. But if you would like to use ndarrays with three.js then this is the library for you.
example
See http://shama.github.io/ndthree.
// initialize our modulesvar ndthree = var ndarray = var fill = var terrain = var THREE = // Create some random voxels in a spherevar voxels = // Create our buffer geometry and shader materialvar geometry = var material = // Populate the geometry and material // Restructure terrain ([256,256,4]) into a tile map shape ([16, 16, 16, 16, 4])var tiles = // Use helper for creating a mesh (optional)var mesh = ndthree
api
var ndthree = require('ndthree')
ndthree(ndarray, geometry, material)
ndarray
should be 3 dimensional, eg[32, 32, 32]
.geometry
can be just an object but easier if aTHREE.BufferGeometry
.material
can be just an object but easier if aTHREE.ShaderMaterial
.
ndthree.createMesh(options)
A helper for creating a three.js mesh from the previously created geometry and material.
options
THREE
Pass in the instance of three.js. Requiredgeometry
Pass in aTHREE.BufferGeometry
. Requiredmaterial
Pass in aTHREE.ShaderMaterial
. Requiredmap|texture
Pass in a ndarray texture tile map in the shape of[16, 16, 16, 16, 4]
.offset
Offset the mesh with this array. Default: [1, 1, 1]pad
Boolean whether to pad tile map. Default: true
Returns: A three.js mesh.
install
With npm do:
npm install ndthree
Use browserify to require('ndthree')
.
release history
- 0.2.0 - Memory fixes. createMesh option changes.
- 0.1.0 - initial release
license
Copyright (c) 2013 Kyle Robinson Young
Licensed under the MIT license.