Code Monkey home page Code Monkey logo

Comments (4)

madmann91 avatar madmann91 commented on May 24, 2024

Hello, and thank you for your interest. The current API supports this, but you have to supply your own intersector. Something like:

template <typename Bvh, typename Primitive, bool Permuted = false>
struct AllHitsPrimitiveIntersector : public PrimitiveIntersector<Bvh, Primitive, Permuted, false> {
    using Scalar       = typename Primitive::ScalarType;
    using Intersection = typename Primitive::IntersectionType;

    struct Result {
        Scalar distance() const { return std::numeric_limits<Scalar>::max(); }
    };

    std::vector<std::pair<size_t, Intersection>> all_hits;

    AllHitsPrimitiveIntersector(const Bvh& bvh, const Primitive* primitives)
        : PrimitiveIntersector<Bvh, Primitive, Permuted, true>(bvh, primitives)
    {}

    std::optional<Result> intersect(size_t index, const Ray<Scalar>& ray) const {
        auto [p, i] = this->primitive_at(index);
        if (auto hit = p.intersect(ray))
            all_hits.emplace_back(i, *hit);
        return std::nullopt;
    }
};

from bvh.

madmann91 avatar madmann91 commented on May 24, 2024

Note that the code snippet above is untested. However, it never returns a result on purpose, so that the traversal goes through every primitive that is hit, and does not stop once an intersection is found. After traversing the BVH with this intersector, the member all_hits should contain all the primitive hits encountered during traversal.
Also note that this code is significantly slower than the other traversal versions, since it has to store potentially many intersections, and traverse way more nodes of the BVH.

from bvh.

OptimisticMonkey avatar OptimisticMonkey commented on May 24, 2024

Aweseome! Thank you :-) Going to try it out

from bvh.

madmann91 avatar madmann91 commented on May 24, 2024

I suppose that it must work, given you have not yet complained about it not working. I will then close the issue. Just re-open if I'm mistaken.

from bvh.

Related Issues (20)

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.