Announcement

Collapse
No announcement yet.

Generate Procedural Mesh

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

    Quite an interesting topic and it's kind of weird to see the engine doesn't have support for modifying terrain during runtime.

    I've spent about a week with the engine now, hands on running through tutorials and examples and I'm very impressed (coming from Unity). This one thing worries me though because I know I'll have to tackle this at one point or another.
    I'm talking about having a large terrain, generated on demand from source data (heightmaps, textures, masks) with tiles being generated and shown where ever the camera happens to move. I could accomplish that with ease in Unity previously, I simply had a grid of terrain instances that I could move around and just assign them new heightmaps and textures when needed. But trying to accomplish the same in UE4 seems rather difficult. I've checked the code on this thread and it seems quite low-level, I'm a little surprised there isn't any higher level solution available. Since we can't use the built-in terrain we're missing on a lot of extremely nice-to-have features - having to build everything from ground up seems quite a daunting task.

    I'd like to ask for a little advice here: how should I proceed? I have a need for ~1000km x 1000km sized terrain area, impossible to implement with a single terrain (and I'm aware of the floating point accuracy problems, previously I overcame this with floating origin). How huge of a task do you think it would be to implement a terrain system by taking advantage of the code presented here? Also, how to deal with LODding since we don't have the advantages of the native terrain system?

    Also there was a related question asked before and answered: https://answers.unrealengine.com/que...landscape.html
    It appears there was an open feature request for allowing runtime landscape modifications - but I haven't read anything about any plans to do that so far, and the roadmap has no mention of it: https://trello.com/b/gHooNW9I/ue4-roadmap
    I just hope this feature request isn't forgotten. I see it as a pretty important feature.
    // Jusasi
    SQLite3 Plugin for UE4 - Forum thread - Github link

    Comment


      I get an error:

      Error 1 error C2079: 'AProceduralTriangleActor' uses undefined class 'PROCEDURALMESH_API'

      In the proceduralcubeactor.h, proceduraltriangleactor.h, etc classes. Deleting the PROCEDURALMESH_API declaration in the header files fixes this, but I don't like deleting things that might be important. I was wondering what the PROCEDURALMESH_API does.

      Comment


        ElectricSauce, I had to do the same thing. Working so far but yeah bothers me too. This thread and the wiki article have been so helpful to me. I feel I have to contribute.

        There's a bug in ProceduralMeshComponent.cpp
        Code:
        bool UProceduralMeshComponent::GetPhysicsTriMeshData(struct FTriMeshCollisionData* CollisionData, bool InUseAllTriData)
        ...
        CollisionData->MaterialIndices.Add(i);
        will cause a crash if doing a linetrace sample with bReturnPhysicalMaterial = true;

        It should be set to the material index of the object or triangle or just
        Code:
        CollisionData->MaterialIndices.Add(0);
        Here's my progress on this, Marching Cubes Voxel system with realtime Simplex noise generation (takes about 0.5 sec. per mesh).
        Last edited by Xilverback; 01-03-2015, 10:35 PM.

        Comment


          So you got this with the project I hosted on GitHub: it is a flag named after the name of the module of code (here the name of the UE4 project, ProceduralMesh). It tell the Unreal Build Tool or the compiler to export those symbols as a public API for other modules of your project.

          So if you import the sample code into one of your project that you named otherwise, you have to Rename the flag accordingly.
          You can also remove it altogether if you don't need multiple game modules.

          Cheers!
          [Gamedev programmer at Darewise (Paris) - We are hiring]
          UE4 Git LFS 2.x Source Control Plugin 2.12-beta for UE4.22 - (v1 integrated by default in Beta status since UE4.7)
          UE4 Plastic SCM Source Control Plugin (1.4.5 for UE4.22)

          Comment


            Ok, makes sense now.

            1 more question - Is it yet possible to set the vertex normals?

            Comment


              The present code does some normal calculation.

              Also, someone else on this thread provided code snippets to do smooth normals, please check previous pages.
              Cheers.
              [Gamedev programmer at Darewise (Paris) - We are hiring]
              UE4 Git LFS 2.x Source Control Plugin 2.12-beta for UE4.22 - (v1 integrated by default in Beta status since UE4.7)
              UE4 Plastic SCM Source Control Plugin (1.4.5 for UE4.22)

              Comment


                Originally posted by SRombauts View Post
                The present code does some normal calculation.

                Also, someone else on this thread provided code snippets to do smooth normals, please check previous pages.
                Cheers.
                I found the code snippets that allow for smooth faces. It basically removes duplicate vertices in the vertex buffer which would automatically average the vertex normals. I think I would need to come up with a way to store the faces that need to be smoothed.

                Comment


                  I'm getting some normal wierdness with two triangles:



                  The winding order it the same, but it's calculating the normals backwards from each other.

                  Comment


                    Originally posted by electricsauce View Post
                    The winding order it the same, but it's calculating the normals backwards from each other.
                    I think your normals are okay, otherwise you would not even be able to see one of the triangles (except if you had a two-sided material).
                    Looks more like the texture tangents are not calculated correctly. Look where the TangentBasisComponents is set in the VertexFactory of your generated mesh.

                    I had the same problem and correctly calculating the tangents fixed it for me.
                    Particle Editor Extension: Marketplace Page | Documentation
                    Code plugin which extends your particle effect toolbox with new possibilities.


                    SVG Importer Plugin: Marketplace Page | Gumroad Page
                    Import SVG (scalable vector graphics) files as rasterized rendering or as multi-channel signed distance field.

                    Comment


                      That definitely the issue. I've modified the proceduralmeshcomponent files so that they now require tangent inputs.

                      On a side note, I tried out the merging vertex algorithm from page 2 but it doesn't work well with cubes that share verts (like a cabinet). I'm thinking that by averaging the normals and tangents of two verts that share the same space I can make the combined faces smooth.

                      Comment


                        It's might be a dump question.

                        But i wonder if there is a solution to asynchronously generate the mesh without blocking the render and the game thread?
                        Right now if i generate a bigger mesh, the editor freezes.

                        AndrewScheidecker did something to solve this issue:
                        https://github.com/AndrewScheidecker...mponent.h#L317

                        So is there any alternative? Like the level streaming in the engine?

                        Thanks!

                        Comment


                          Originally posted by Azarus View Post
                          But i wonder if there is a solution to asynchronously generate the mesh without blocking the render and the game thread?
                          Right now if i generate a bigger mesh, the editor freezes.
                          You can of course generate the mesh data (vertices, normals, etc) in a separate thread, but as far as I know, you can only push this data to the engine during the render thread. If the mesh you update is very big then the engine also has to do a lot of work (building geometry, collision data, apply materials, rendering, ...), which can cause a noticable stutter.

                          You can decrease the size of your updated mesh by dividing it into chunks (which is also what AndrewScheidecker did) and only update individual chunks. If you have to update all of them you can still spread the update over several frames so it is not as noticable to the player.
                          Particle Editor Extension: Marketplace Page | Documentation
                          Code plugin which extends your particle effect toolbox with new possibilities.


                          SVG Importer Plugin: Marketplace Page | Gumroad Page
                          Import SVG (scalable vector graphics) files as rasterized rendering or as multi-channel signed distance field.

                          Comment


                            Has anyone else run into issues with translucent materials not rendering in the right order? I know there is a bug with two-sided translucent materials, but I didn't expect an issue with single-sided translucent materials as well. Is there some sort of post-creation call I need to ensure the object is rendered on the correct pass?

                            update: I ended up setting up a translucency sort priority and sorting the few objects I had away from the camera every tick, very horrible hack and it is a shame there is no forward renderer for transparency yet, not sure if the new work on the water transparency will be applicable more generally or not.
                            Last edited by druidsbane; 01-25-2015, 01:04 AM. Reason: showing how I solved problem

                            Comment


                              I'm still having problems with the vertex tangents. The current algorithm seems to use 2 edge lengths to generate the tangents which give opposite results for 2 triangles that share the same edge. Can someone point me in the right direction for calculating tangents for a quad (or preferably several quads)? Thanks.

                              Comment


                                Hi,
                                I have problems to decide where to create my procedural mesh within my actor lifecycle. I need some information about the world around my object before I can create its mesh. So I decided to use PostInitializeComponents where I create the mesh in.

                                For testing I use this code:
                                Code:
                                void ATest::PostInitializeComponents()
                                {
                                	Super::PostInitializeComponents();
                                
                                	TArray<FProceduralMeshTriangle> triangles;
                                	FVector pos( 0, 0, 0 );	// generate cube triangles for every cube in this cunk
                                	GenerateCube( pos, 10.f, triangles );
                                	mesh->SetProceduralMeshTriangles( triangles );
                                
                                }
                                This creates me a single cube, but I don't get any collision detection. The cube does not collide with the scene.

                                I tested it using the same code in the constructor:
                                Code:
                                ATest::ATest( const class FObjectInitializer& PCIP ) : Super( PCIP )
                                {
                                	mesh = PCIP.CreateDefaultSubobject<UProceduralMeshComponent>( this, TEXT( "Test" ) );
                                
                                	static ConstructorHelpers::FObjectFinder<UMaterialInterface> Material( TEXT( "Material'/Game/Materials/BaseColor.BaseColor'" ) );
                                	mesh->SetMaterial( 0, Material.Object );
                                
                                	TArray<FProceduralMeshTriangle> triangles;
                                	FVector pos( 0, 0, 0 );	// generate cube triangles for every cube in this cunk
                                	GenerateCube( pos, 10.f, triangles );
                                	mesh->SetProceduralMeshTriangles( triangles );
                                
                                	RootComponent = mesh;
                                }
                                Spawning the Actor this way gets me collision detection and I cannot walk trough this cube anymore.

                                But for more complex objects I cannot create the whole mesh in the constructor. It seems that the collision object is built after construction and before PostInitialization. So is there a way to recreate the collision-object after creating my mesh in the PostInitializeComponents method?

                                Comment

                                Working...
                                X