Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: octree examples #27786

Closed
wants to merge 2 commits into from
Closed

Examples: octree examples #27786

wants to merge 2 commits into from

Conversation

CahierX
Copy link
Contributor

@CahierX CahierX commented Feb 21, 2024

Add octree examples

image

examples/webgl_octree.html Outdated Show resolved Hide resolved
@CahierX
Copy link
Contributor Author

CahierX commented Feb 22, 2024

In this example, I used octree.rayIntersect and raycaster.intersectObject for comparison. Octree can maintain 60 frames in 60000 Mesh, while raycaster can only maintain 40 frames.

ps: MacBook Pro Intel Core i7, AMD Radeon Pro 5300M 4 GB

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 22, 2024

Thanks for you contribution but I'm not sure we need a separate Octree example in context of ray casting since we already have webgl_raycaster_bvh.

three-mesh-bvh is an external package that can be used to perform spatial queries/optimizing ray casting and I think one example that demonstrates this is sufficient. In other words: If users want to optimize their ray casting, it's better to guide them towards three-mesh-bvh, not Octree.

It's important to understand that Octree was not added by its own. It was part of a more complex PR that added games_fps and it's used there for collision detection of spheres and capsules. As previously discussed, I think it's better to move Octree into an external repository three-octree and develop it there (see #26923 (comment)).

@CahierX
Copy link
Contributor Author

CahierX commented Feb 22, 2024

Thanks for you contribution but I'm not sure we need a separate Octree example in context of ray casting since we already have webgl_raycaster_bvh.

three-mesh-bvh is an external package that can be used to perform spatial queries/optimizing ray casting and I think one example that demonstrates this is sufficient. In other words: If users want to optimize their ray casting, it's better to guide them towards three-mesh-bvh, not Octree.

It's important to understand that Octree was not added by its own. It was part of a more complex PR that added games_fps and it's used there for collision detection of spheres and capsules. As previously discussed, I think it's better to move Octree into an external repository three-octree and develop it there (see #26923 (comment)).

For me, BVH might be too heavy, and I can efficiently accomplish ray casting using the built-in Octree.

Moreover, I have numerous but relatively simple meshes, and I cannot effectively use instancedMesh or mergeGeometries or other methods to merge them. When I render all meshes at once, it causes lag. I want to render only the elements within a 100m range of the current view and hide the rest. By using Octree, I can set triangle.object = object when addTriangle to bind the object to the triangle. I can then obtain all triangles within a certain range and their objects using the getSphereTriangles, and control the display of these elements. This solution was just my approach to the problem I encountered in my project at the time. Due to the lack of docs, I am not sure if there is a better way to use Octree, but this solution met my needs and worked well and efficiently in my project!

When searching on Google, I found that the related information is about three-octree, which is only suitable for r60. I also discovered that Threejs has Octree.js embedded, but it lacks docs and examples.

In summary, I think that Octree is a very useful and streamlined tool, and I hope to see more documentation and examples added to fully showcase and utilize its potential.

@CahierX
Copy link
Contributor Author

CahierX commented Feb 22, 2024

three-mesh-bvh does not support PointsBVH or LineBVH (see: issues/243). However, you can achieve this using Octree.

For a line, let PointA be the first point of the line and PointB be the second point of the line. You can use the following code:

const pointC = pointA.clone().add(pointB).multiplyScalar(0.5);
const triangle = new THREE.Triangle(pointA, pointB, pointC);

For points, you can use the following code:

const triangle = new THREE.Triangle(pointA, pointA, pointA);

This allows you to use Octree for both lines and points, enabling efficient ray casting.

This solution might be rough, but it indeed works well for my project. 😄

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 4, 2024

Sorry, but the example is not a worthwhile addition. The way it renders its objects potentially produce thousands of draw calls which degrades the performance to a minimum. This is no ideal setup for demonstrating the performance gains of spatial indices in context of ray casting. Moreover, we would not advocate users to render this kind of scene without instancing, batching or merging.

If you want to demonstrate the performance benefits of spatial indices with ray casting, it's best to use a similar scene setup like webgl_raycaster_bvh. But as said above, there is currently no intention to further enhance or showcase Octree in this repository.

@Mugen87 Mugen87 closed this Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants