Code Monkey home page Code Monkey logo

fast-voxel-raycast's Introduction

fast-voxel-raycast

Fast raycasting through voxels.

This is a fork of voxel-raycast, using the faster, simpler algorithm described in this paper by Amanatides and Woo.

In general it functions equivalently to the parent library, except for edge cases (e.g. when the raycast precisely touches the corner of a solid voxel), in which case no particular behavior is defined.

For 2D raycasting, also see noffle's wrapped implementation of this module.

Installation

npm install fast-voxel-raycast

Usage

var raycast = require('fast-voxel-raycast')

raycast( getVoxel, start, direction, distance, hit_position, hit_normal )
  • getVoxel - a function(x,y,z) that returns a truthy value for whether each voxel should block the raycast
  • start - origin of the ray
  • direction - direction of the ray
  • distance - how far to check the ray before giving up
  • hit_position - result array, gets populated with the point of impact
  • hit_normal - gets populated with a normal vector pointing away from the voxel that was struck

Returns: whatever value was returned by the getVoxel function for the struck voxel, or 0 if no voxel was struck.

Example

var raycast = require('fast-voxel-raycast')

var getVoxel = function(x,y,z) {
    // return a truthy value here for voxels that block the raycast
    return (y<0) ? 1 : 0
}

var hit_position = []
var hit_normal = []

var result = raycast( getVoxel, [3,4,5], [1,-1,-1], 20, hit_position, hit_normal )

if (result != 0) {
    console.log('hit:', result, hit_position, hit_normal)
} else {
    console.log('no truthy voxel was struck')
}

fast-voxel-raycast's People

Contributors

fenomas avatar guckstift avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fast-voxel-raycast's Issues

Non-full blocks

Non-full blocks seem to work in noa, but I can't see how to make them work with this. Would it be possible to add support for non-full blocks or documentation for it if it's already possible? Thank you

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.