Git Product home page Git Product logo

emmetot / boundingvolumehierarchy Goto Github PK

View Code? Open in Web Editor NEW
46.0 4.0 8.0 41 KB

This is a port of Erin Catto/box2d's b2_dynamic_tree from C++ to C#, intended for use in Unity. It's a very faithful translation with a couple of additional C# creature comforts for usability.

License: MIT License

C# 100.00%
unity bounding-volume-hierarchy bounding-boxes physics aabb aabb-trees boundingbox data-structures unity3d game-development

boundingvolumehierarchy's Introduction

BoundingVolumeHierarchy

BoundingVolumeHierarchy

This is a port of Erin Catto/box2d's b2_dynamic_tree from C++ to C# (doc here), intended for use in Unity. It's a very faithful translation with a couple of additional C# creature comforts for usability.

The code has also been adapted to work in 3D. The main difference in that regard is that I use surface area rather than perimeter as a heuristic to minimize the internal nodes.

How to Use

The object to be stored in your tree must implement the interface IBVHClientObject:

IBVHClientObject

The bounds should be a tight fit around your object. For previous position, I recommend just caching the object's position every frame.

Next, create an instance of BoundingVolumeHierarchy with the appropriate type parameter. Your main forms of interaction with the tree are fairly self explanatory:

Methods

Call 'update' whenever an object's position/rotation/scale/bounds changes.

The simplest form of querying the tree involves just enumerating all nodes:

Enumeration

Naturally there is also a raycast method:

Raycast

boundingvolumehierarchy's People

Contributors

emmetot 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

Watchers

 avatar  avatar  avatar  avatar

boundingvolumehierarchy's Issues

Small suggestions: Leaf iterations, remove asserts on enumerate empty tree.

The title is pretty self-explanatory. I'm using your thing in my game, it's working well so far but I'm confused why it would throw an assert when trying to Enumerate on an empty tree. It would make more sense just to "yield break" and not enumerate on anything at all.

I'm also suggesting adding a leaf enumerator that returns the node's values directly. That way I can use the BVH tree as my collection to store my IBVH objects directly instead of letting the user manage two collections, one normal list/dictionary and a BVH.

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.