voxel-texture-shader
Shaders for texturing voxels in voxel.js
Based on voxel-texture by @shama, mostly compatible but several differences:
- Supports greedy meshing, tiling the voxel textures appropriately (using techniques by @mikolalysenko in Texture atlases, wrapping and mip mapping)
- Supports optional four-tap sampling to fix texture seams (also based on @mikolalysenko's work)
- Loads textures using artpacks (instead of individual files in
texturePath
)
Experimental toggling between voxel-texture-shader and voxel-texture: https://github.com/deathcap/voxel-debug
example
// create a material enginevar textureEngine = // a copy of your voxel.js game game: game // artpacks instance artPacks: artPacks; // load textures and it returns textures just loadedtextureEngine;
api
require('voxel-texture-shader')(options)
Returns a new texture engine instance. Must pass a copy of your voxel.js
game
. options
defaults to:
artPacks: artPacks materialParams: ambient: 0xbbbbbb materialType: THREEMeshLambertMaterial { mapmagFilter = thisTHREENearestFilter; mapminFilter = thisTHREELinearMipMapLinearFilter; }
textureEngine.load(textures, callback)
Loads textures onto the atlas by expanding the texture names:
textureEngine;
textureEngine;
textureEngine;
textureEngine.find(name)
Finds the type of block by texture name:
// Find and change the center block to grassgame;
Although this is built into the voxel engine so you could just do:
game;
textureEngine.paint(mesh, textures)
Modifies the UV mapping of given mesh
to the textures
names supplied:
// create a custom mesh and load all materialsvar mesh = textureEnginematerial; // paint the geometrytextureEngine;
Or if you have the face.color
set on the faces of your geometry (such as how
voxel-mesh does it) then omit the textures
argument. It will select the
texture based on color from all the previously loaded textures:
textureEngine;
textureEngine.sprite(name, w, h, callback)
Create textures from a sprite map. If you have a single image with a bunch of textures do:
// load terrain.png, it is 512x512// each texture is 32x32textureEngine;
The width and height default to 16x16
.
textureEngine.animate(mesh, textures, delay)
Create an animated material. A material that after each delay will paint the
mesh by iterating through textures
. Must run textureEngine.tick()
to
actually animate.
var mesh = ;meshmaterial = textureEngine;
textureEngine.tick(delta)
Run the animations for any animated materials.
game;
license
Copyright (c) 2013 Kyle Robinson Young
Licensed under the MIT license.