Going back to it now, the problem seems to be that the KDTree finds a vertex that is closest, but doesnt take into account that there can be vertices that are in the exact same spot. That post by andeeee had a method for getting the closest point with a KDTree, but I think at the time I had some issues with it. I remembered in the past when searching for a way to get the closest point to a mesh, I ran into this thread The bsp tree also seems to sometimes include triangles that are way out of range of the sphere, so doing a boundingbox check of the triangles can also help with that. By using a hashset instead of a list we can try to help the issue, but it isnt perfect. Also, due to the nature of the bsptree splitting between triangles, there are a lot of duplicate triangles being checked over. This means the kdtree is not accurate depending on the mesh. Were you using a terrain collider? I never used / tested on those.Įdit - The reason the KDTree seems to perform better than the bsptree is because the kdtree is only searching for the closest vertex and not all the triangles that are touching the sphere. How did you have things setup? Just to be sure, you werent doing a bunch of Debug.Logs right? Those cause a bunch of lag. This might not be to much of a concern for me since I am just using this for a single player and its not like I am going to be intersecting over 100 meshes or a ton of triangles, but I guess maybe in your case it might be different. The framerate is a lot better though with only 4 triangles.Įdit - Its not necessarily the amount of triangles that we calculate on that causes the lag, but how much work the bsptree needs to do to get those triangles. I am not sure if thats considered good or bad as I never made a bsptree. The thing is, even if I make my sphere small and place it in between one triangle, the bsp is still doing the calculations on like 4 triangles. However, if I use 100 of the default blender monkey mesh, which I think imported into unity it has like 950 or so triangles, I get like 5 fps if my sphere is overlapping a lot of triangles. If I use a regular unity cube with a mesh collider, then with 100 of those cubes spawned I get about 100 frames while doing calculations where I get about 150 frames where there is no calculations being done, which seems fine. Im thinking the BSPTree might not be doing to well. I also disabled the meshrenderers and got rid of lights so that they wouldnt mess up the test. I didnt use your code above, but I took from the github and got rid of some garbage causing things and did some profiling.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |