How to create collision information for procedural geometry?



MainFrameActions: Packaging (Windows): UnrealBuildTool: C:\dev\Unreal\Projects\MyProject5\Source\MyProject5\GeneratedMeshComponent.cpp(221) : error C2039: 'InvalidatePhysicsData' : is not a member of 'UBodySetup'


You would be correct :slight_smile: I have updated the wiki with the new UGeneratedMeshComponent code, with the caveat that it will only work in the Editor until 4.2 or 4.3 as indicated in the Feedback Thread.

On my end, it allows me to progress with the development of my project until it can be packaged. Thanks JamesG for the feedback and support.

@,

Thank you for updating your wiki page with all of your research on collisions!

:slight_smile:

Thanks should go to all here that contributed! :slight_smile:

Dear ,

I have a contribution for your awesome class if you wish to check it out!

The original calcbounds code makes the bounds the size of the world, to ensure mesh is never obscured.

But if you are using a lot of these dynamic meshes you will want culling to work!

It is possible to initialize an FBox from an infinite number of vertex points!

Here is my code to get accurate bounds for each dynamic mesh based on its vertices

My code assumes vertex positions are in local space, you could remove the transform part if you are using world coordinates for vertex data.

Let me know if it works for you!


FBoxSphereBounds UGeneratedMeshComponent::CalcBounds(const FTransform & LocalToWorld) const
{
	TArray<FVector> Points;
	
	**//Generate Box from All Vertices, transformed into World Space**
	const int32 Total = GeneratedMeshTris.Num();
	for(int32 v= 0 ; v < Total; v++)
	{
		if( !GeneratedMeshTris.IsValidIndex(v)) return FBoxSphereBounds(); //vigorous crash protection
		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		Points.Add(GeneratedMeshTris[v].Vertex0);
		Points.Add(GeneratedMeshTris[v].Vertex1);
		Points.Add(GeneratedMeshTris[v].Vertex2);
	}
	return FBoxSphereBounds(**FBox(Points)**).TransformBy(LocalToWorld);
	
	**//Original code = size of entire world
	/*
	FBoxSphereBounds NewBounds;
	NewBounds.Origin = FVector::ZeroVector;
	NewBounds.BoxExtent = FVector(HALF_WORLD_MAX,HALF_WORLD_MAX,HALF_WORLD_MAX);
	NewBounds.SphereRadius = FMath::Sqrt(3.0f * FMath::Square(HALF_WORLD_MAX));
	return NewBounds;
	*/**
}

It is one of the things I wanted to look at. My first thought was simply to use an FBox with the maximum X/Y/Z of the vertices. What is the gain to make it more precise? Also you can get the list of points from GetPhysicsTriMeshData and pass the CollisionData->Vertices array to the FBox constructor for less code. :slight_smile:

I do know one concrete advantage, which is occlusion! With a size as big as the world the actor will never get properly occluded and is being rendered all over the world even if player is far far away.

I imagine it would help with touch events / collision detection somehow? Not really sure about that part :slight_smile:

oooh great idea!

Iā€™d just like to take a moment to thank , , and the UnrealEngine developers for taking this thread and running with it. You guys are incredible!

Itā€™ll be a few more days before I can get back to working on this, but I hope that by the time I do there are still a few unsolved problems in this space so that I can contribute something back to the community!

Do we know what the timescale for 4.2/4.3 is?

Are unreal planning a release each month? It would make version numbers easy to understand and a neat way to keep us on the subscription :slight_smile:

Great to hear from you Sgorsten!

:slight_smile:

Iā€™m now working off your latest code on the wiki. Collisions are working with pawns just fine, but donā€™t seem to be working with physics objects. Have you (or anyone else) gotten collisions with physics objects working yet?


AggGeom

you have to create AggGeom for your mesh component.

See SphereComponent.cpp for example usage of AggGeom

:)

If I fill out an AggGeom, I can get physics objects to collide with the shapes in the AggGeom. For instance, if I wrap my triangle mesh in a bounding box, I can get objects to bounce off of the bounding box.

However, I canā€™t seem to get physics objects to collide with the actual triangle mesh itself, even when I set the CollisionTraceFlag to CTF_UseComplexAsSimple. In that case, physics objects just fall right through my triangle mesh.

My geometry is basically environment geometry, there are many concavities and it does not obey any particular nice shape. I cannot construct a representation for it out of an aggregation of boxes, spheres, and cylinders.

It should totally be possible to throw a physically simulated sphere or something onto this environment and have it roll down hills and into valleys, etc., colliding with the actual triangles of the mesh, but so far, Iā€™m stuck with the choice of either wrapping my mesh in a convex volume that is far too large, or allowing physics objects to pass through my mesh altogether.

Has anyone figured out how to get physics objects to collide with the actual triangles of a triangle mesh? Thanks in advance!

Sorry I told you to post here in my message, but you already had. :slight_smile:

As I mention, maybe the mesh collision profile needs to be set:



SetCollisionProfileName(UCollisionProfile::BlockAll_ProfileName);


Otherwise, looking at the collision information in play mode with a spawned procedurally generated object might yield some clues.

For static geometry, setting ā€˜use complex as simpleā€™ as the Collision Complexity in the StaticMesh Editor will cause physics to collide with the graphics triangles. We do not support per-poly collision on the actual physics object - we need collision geometry with ā€˜volumeā€™ so we can calculate mass/inertia etc., and it would be too slow.

SetMobility(EComponentMobility::Stationary);

Hey sgorsten,

Yeah I was having the same problem myself for a while, an as usual the solution turned out to be a one line fix.

To get the generated mesh working with physics youā€™ll just need to make sure you set the mobility of the component to Static or Stationary as the component will default to movable.


SetMobility(EComponentMobility::Stationary);

This should get physics objects colliding with your generated mesh, its even happy if your deforming or updating the mesh while its colliding as Iā€™m using destructible terrain in some situations.

The Stationary mobility option still lets you move your component as well with collision working, but obviously that movement needs to be blueprint or code driven from JamesG comment above about per-poly on physics objects.

This all seems happy in the editor simulating and dropping to game, an hopefully with the work being done in the related thread weā€™ll have the cooked PhysX data in the built projects for 4.2 or 4.3.

@Kaos Nova

**[FONT=Comic Sans MS]Welcome to the forums Kaos Nova! **

Congrats on your first post!

And thanks for sharing!

:slight_smile:

Thank you so much! This simple one-liner makes it work!