Announcement

Collapse
No announcement yet.

How to create collision information for procedural geometry?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    Originally posted by Kaos Nova View Post
    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.

    Code:
    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.
    Thank you so much! This simple one-liner makes it work!

    Leave a comment:


  • replied
    @Kaos Nova

    Welcome to the forums Kaos Nova!

    Congrats on your first post!

    And thanks for sharing!



    Rama

    Leave a comment:


  • replied
    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.

    Code:
    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.

    Leave a comment:


  • replied
    Originally posted by sgorsten View Post
    Has anyone figured out how to get physics objects to collide with the actual triangles of a triangle mesh?
    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.

    Leave a comment:


  • replied
    Originally posted by sgorsten View Post
    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.

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

    Code:
    SetCollisionProfileName(UCollisionProfile::BlockAll_ProfileName);

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

    Leave a comment:


  • replied
    Originally posted by Rama View Post
    ~~~

    AggGeom

    you have to create AggGeom for your mesh component.

    See SphereComponent.cpp for example usage of AggGeom



    Rama
    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!

    Leave a comment:


  • replied
    ~~~

    AggGeom

    you have to create AggGeom for your mesh component.

    See SphereComponent.cpp for example usage of AggGeom



    Rama

    Leave a comment:


  • replied
    Originally posted by dmacesic View Post
    Code:
    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 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.
    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?

    Leave a comment:


  • replied
    Originally posted by sgorsten View Post
    I'd just like to take a moment to thank dmacesic, Rama, 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!
    Great to hear from you Sgorsten!



    Rama

    Leave a comment:


  • replied
    Originally posted by dmacesic View Post
    Code:
    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 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.
    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

    Leave a comment:


  • replied
    I'd just like to take a moment to thank dmacesic, Rama, 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!

    Leave a comment:


  • replied
    Originally posted by dmacesic View Post
    What is the gain to make it more precise?
    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


    Originally posted by dmacesic View Post
    Also you can get the list of points from GetPhysicsTriMeshData and pass the CollisionData->Vertices array to the FBox constructor for less code.
    oooh great idea!

    Rama

    Leave a comment:


  • replied
    Originally posted by Rama View Post
    Dear Dmacesic,

    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!
    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.

    Leave a comment:


  • replied
    Dear Dmacesic,

    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!

    Code:
    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;
    	*/
    }
    Last edited by Rama; 04-11-2014, 06:05 PM.

    Leave a comment:


  • replied
    Originally posted by Rama View Post
    @Dmacesic,

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



    Rama
    Thanks should go to all here that contributed!

    Leave a comment:

Working...
X