radiatoryang / hedera

paint 3D ivy in the Unity Editor, watch procedurally generated meshes simulate growth and clinging in real-time
GNU General Public License v2.0
783 stars 64 forks source link

Incorrect leaf placement on concave meshes (with solution discussed) #13

Closed alexjhetherington closed 2 years ago

alexjhetherington commented 3 years ago

First, thanks for this tool! It's incredible.

I am building a blocky environment out of mesh colliders. Painting Ivy works correctly, but ivy that grows around corners (say across a roof then down a wall) fails to respect the new surface and does not calculate the new adhesion normal.

It results in unrealistic looking growth, and leaves that only respect the initially painted normal.

leaf_flat

It's because of the "find closest point on a mesh collider" logic. It is looking at vertices, and in my case the nearest vertex is very far away (big blocks!).

I have coded a dirty solution for my case : to find the closest point on a mesh collider I send many ray casts outwards from the start point in a rough sphere.

It seems to fix the issue! But obviously it's even slower (by how much I'm not sure).

If you want me to make a PR with my dirty solution let me know :)

leaf_angle

radiatoryang commented 3 years ago

hmm yes, clearly this expensive calculation might be worthwhile sometimes?

I think I'd add this feature as "high detail mesh collider painting" checkbox or something in the inspector?

feel free to submit a PR and I can build off of that to handle the editor UI stuff... thanks!

Thundros commented 3 years ago

@alexjhetherington Please submit the PR.

radiatoryang commented 2 years ago

this is now integrated and will be part of the next release, v1.2.3 ... thanks for the PR!

image