vanruesc / sparse-octree

A sparse octree data structure.
zlib License
117 stars 20 forks source link

`raycastOctant` being passed Tree instead of Node #41

Closed canadaduane closed 2 years ago

canadaduane commented 2 years ago

This may be related to #40, or it may be caused by it (I'm not sure yet).

What happens is when I call OctreeRaycaster's intersectOctree, the PointOctree raycast function returns an error: pointData is undefined:

if(pointData !== null) {

    pointData.testPoints(raycaster, result);

}

The problem is that pointData is undefined, and therefore passes the not-null check.

Would this be solved if the call to raycastOctant in intersectOctree passed the root node of the octree, rather than the octree itself?

    static intersectOctree(octree: Tree, ray: Ray): Node[] {

        const result: Node[] = [];
        const t = intersectOctree(octree, ray, flags);

        if(t !== null) {
            // Shouldn't raycastOctant take a Node here? --
            raycastOctant(octree, t[0], t[1], t[2], t[3], t[4], t[5], result);

        }

        return result;

    }
vanruesc commented 2 years ago

It seems that the octree itself is incorrectly treated as a PointOctant<T> although it doesn't implement DataContainer<T>.

Would this be solved if the call to raycastOctant in intersectOctree passed the root node of the octree, rather than the octree itself?

Yes, but I think it might be better to change the following line to pass in this.root instead of this:

https://github.com/vanruesc/sparse-octree/blob/4c9af67f3bdbddecb1840ce3b24101f9125dee5b/src/core/Octree.ts#L215

The type of the octree parameter in OctreeRaycaster.intersectOctree can be changed to the broader Node type.