ursina
ursina copied to clipboard
Implementation to handle collision for 'ngon' mesh
Hey pokepetter
i adapt the code in the collision.py to add collisions for ngon mesh (e.g. by using circles).
im not allowed to push the code, so i will push it in this issue ;)
class MeshCollider(Collider):
def __init__(self, entity, mesh=None, center=(0, 0, 0)):
...
elif mesh.mode == 'triangle':
....
elif mesh.mode == 'ngon':
# NOTE: does not support vertices len < 3. Is already being intercepted by pandas3D
for i in range(2, len(mesh.vertices)):
poly = CollisionPolygon(
Vec3(mesh.vertices[i]),
Vec3(mesh.vertices[i - 1]),
Vec3(mesh.vertices[0]),
)
self.collision_polygons.append(poly)
...
The idea behind: I i create a triangle which always starts at vertice 0 For the first triangle, the next two vertices will be used. For all other triangles i use the last vertice from the triangle before and add the next vertice.

@pokepetter should i move this to Discussions -> Idea ?
I think ngons are so rarely used and rarely useful, so I'm not sure how useful it. I'm not against it though. This is how Circle() and such works, and probably ngons internally too. You can't push the code directly, but you can make a pull request.