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

Is there support for rebuilding a concave/triangle mesh from previous collision mesh data? #530

Open
kunrii opened this issue Feb 10, 2022 · 3 comments

Comments

@kunrii
Copy link

kunrii commented Feb 10, 2022

Simple question really, if I have built a fairly large collision mesh but require changing it, is there an option to provide a previously created collision mesh to avoid a full (and lengthy) build process?

@kunrii kunrii changed the title Is there support for rebuilding a concave/triangle mesh from previous mesh data? Is there support for rebuilding a concave/triangle mesh from previous collision mesh data? Feb 10, 2022
@kstorey-nvidia
Copy link

kstorey-nvidia commented Feb 11, 2022

See SnippetDeformableMesh

void stepPhysics(bool /*interactive*/)
{
	{
		PxVec3* verts = gMesh->getVerticesForModification();
		gTime += 0.01f;
		updateVertices(verts, sinf(gTime)*20.0f);
		PxBounds3 newBounds = gMesh->refitBVH();
		PX_UNUSED(newBounds);

		// Reset filtering to tell the broadphase about the new mesh bounds.
		gScene->resetFiltering(*gActor);
	}
	gScene->simulate(1.0f/60.0f);
	gScene->fetchResults(true);
}

This update function deforms the vertices of a mesh and then calls refitBVH() to do a cheap update of just the bounds of the BVH without changing the structure of the hierarchy.

Hope this helps

@kunrii
Copy link
Author

kunrii commented Feb 11, 2022

Thank you for the code snippet. Unfortunately I'm introducing new geometry so deformations alone aren't enough. I guess I'll have to find some way to chunk up the mesh without introducing a lot of overhead with expensive scene objects (this is for use with a game engine).

Hopefully someone else will benefit from this option though, it's interesting there's a way to cheaply compute deformations that don't introduce new geometry.

@kstorey-nvidia
Copy link

Right. If you are changing the topology of the mesh rather than changing just the relative position of the vertices, the existing tree can't be reused/refit. Mesh cooking is reasonably fast, but it does depend on the hardware being used and how complex the meshes are.

If the changes are localized, then it would seem like a good idea to split a large mesh into a collection of smaller parts to minimize how large the models are that you have too cook at run-time.

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

No branches or pull requests

2 participants