Announcement

Collapse
No announcement yet.

How to create collision information for procedural geometry?

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

    #16
    Originally posted by dmacesic View Post
    As you saying that the modified CustomMeshComponent code I have posted cannot work without cooked content? If it can what am I missing?
    Under the covers, the engine does the PhysX cooking work when required. So your code may well work, but I have not tried it! We are making a change to disallow physics cooking on platforms that require cooked content, but this should be a fairly easy change to work around if your project requires it.
    Lead Programmer - UE4 Animation/Physics/Audio Team - Epic Games
    Twitter: @EpicJamesG

    Comment


      #17
      Originally posted by JamesG View Post
      Under the covers, the engine does the PhysX cooking work when required. So your code may well work, but I have not tried it! We are making a change to disallow physics cooking on platforms that require cooked content, but this should be a fairly easy change to work around if your project requires it.
      Any reason for this design decision? It just makes it harder to manage procedural meshes. Unity has this functionality out of the box, see this.

      I implore you to allow cooking at runtime in a more easy fashion than this roundabout way. At least provide an optional module that we can link to allowing cooking.

      I have started a Feedback thread on the subject, as I am disappointed in the direction you are taking.

      EDIT: James as responded in the Feedback Thread on this subject, and it is good news.
      Last edited by Andargor; 04-11-2014, 11:05 AM.
      It is by will alone I set my code in motion.
      It is by coding that thoughts acquire speed, the hands acquire shaking, the shaking becomes a warning.
      It is by will alone I set my code in motion.

      Comment


        #18
        @dmacesic IInterface_CollisionDataProvider/ GetPhysicsTriMeshData works with runtime collision data (triangle mesh from procedural terrain).

        You can starts with the code from UShapeComponent/UBoxComponent, with the relevant changes as below:
        Code:
        void UVoxelTerrainCollisionComponent::UpdateBodySetup()
        {
        	if (ShapeBodySetup == NULL)
        	{
        		ShapeBodySetup = ConstructObject<UBodySetup>(UBodySetup::StaticClass(), this);
        		ShapeBodySetup->CollisionTraceFlag = CTF_UseComplexAsSimple;
        		ShapeBodySetup->bMeshCollideAll = true;
        	}
        }
        // Called after the triangle mesh has been set to the component
        void UVoxelTerrainCollisionComponent::UpdateCollision()
        {
        	if (bPhysicsStateCreated)
        	{
        		DestroyPhysicsState();
        		UpdateBodySetup();
        		CreatePhysicsState();
        
        		ShapeBodySetup->InvalidatePhysicsData();
        		ShapeBodySetup->CreatePhysicsMeshes();
        	}
        }
        Not sure if it is necessary, but I also have:
        Code:
        	Mobility = EComponentMobility::Static;

        Comment


          #19
          Originally posted by jjouvie View Post
          @dmacesic IInterface_CollisionDataProvider/ GetPhysicsTriMeshData works with runtime collision data (triangle mesh from procedural terrain).

          You can starts with the code from UShapeComponent/UBoxComponent, with the relevant changes as below:
          Code:
          void UVoxelTerrainCollisionComponent::UpdateBodySetup()
          {
          	if (ShapeBodySetup == NULL)
          	{
          		ShapeBodySetup = ConstructObject<UBodySetup>(UBodySetup::StaticClass(), this);
          		ShapeBodySetup->CollisionTraceFlag = CTF_UseComplexAsSimple;
          		ShapeBodySetup->bMeshCollideAll = true;
          	}
          }
          // Called after the triangle mesh has been set to the component
          void UVoxelTerrainCollisionComponent::UpdateCollision()
          {
          	if (bPhysicsStateCreated)
          	{
          		DestroyPhysicsState();
          		UpdateBodySetup();
          		CreatePhysicsState();
          
          		ShapeBodySetup->InvalidatePhysicsData();
          		ShapeBodySetup->CreatePhysicsMeshes();
          	}
          }
          Not sure if it is necessary, but I also have:
          Code:
          	Mobility = EComponentMobility::Static;
          It works! Well, I need to fiddle a bit due to logic issues, but I have collisions! I will clean up my class and update the procedural mesh generation example on the wiki, since it's the same class.

          Thanks muchly
          It is by will alone I set my code in motion.
          It is by coding that thoughts acquire speed, the hands acquire shaking, the shaking becomes a warning.
          It is by will alone I set my code in motion.

          Comment


            #20
            Note that this will probably _not_ work in non-editor builds yet, because of the issues outlined in the other thread!
            Lead Programmer - UE4 Animation/Physics/Audio Team - Epic Games
            Twitter: @EpicJamesG

            Comment


              #21
              Originally posted by JamesG View Post
              Note that this will probably _not_ work in non-editor builds yet, because of the issues outlined in the other thread!
              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.
              It is by will alone I set my code in motion.
              It is by coding that thoughts acquire speed, the hands acquire shaking, the shaking becomes a warning.
              It is by will alone I set my code in motion.

              Comment


                #22
                @Dmacesic,

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



                Rama
                100+ UE4 C++ Tutorials on the UE4 Code Wiki, including UE4 Multi-Threading!

                UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

                Visit www.ue4code.com to see lots of videos about my C++ Creations! ♥ Rama

                Comment


                  #23
                  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!
                  It is by will alone I set my code in motion.
                  It is by coding that thoughts acquire speed, the hands acquire shaking, the shaking becomes a warning.
                  It is by will alone I set my code in motion.

                  Comment


                    #24
                    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.
                    100+ UE4 C++ Tutorials on the UE4 Code Wiki, including UE4 Multi-Threading!

                    UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

                    Visit www.ue4code.com to see lots of videos about my C++ Creations! ♥ Rama

                    Comment


                      #25
                      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.
                      It is by will alone I set my code in motion.
                      It is by coding that thoughts acquire speed, the hands acquire shaking, the shaking becomes a warning.
                      It is by will alone I set my code in motion.

                      Comment


                        #26
                        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
                        100+ UE4 C++ Tutorials on the UE4 Code Wiki, including UE4 Multi-Threading!

                        UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

                        Visit www.ue4code.com to see lots of videos about my C++ Creations! ♥ Rama

                        Comment


                          #27
                          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!

                          Comment


                            #28
                            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

                            Comment


                              #29
                              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
                              100+ UE4 C++ Tutorials on the UE4 Code Wiki, including UE4 Multi-Threading!

                              UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

                              Visit www.ue4code.com to see lots of videos about my C++ Creations! ♥ Rama

                              Comment


                                #30
                                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?

                                Comment

                                Working...
                                X