Announcement

Collapse
No announcement yet.

Generate Procedural Mesh

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

    #91
    Hi, thank you all for the demo code of Procedural Mesh Generation !

    To help people get the code working quickly, I've created a simple "ProceduralMesh" project featuring the demo code shown on the Wiki; its here on Github (UE4ProceduralMesh)

    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


      #92
      Originally posted by SRombauts View Post
      To help people get the code working quickly, I've created a simple "ProceduralMesh" project featuring the demo code shown on the Wiki; its here on Github (UE4ProceduralMesh)
      Cool! Hope we can use that one to improve the code!
      Sr. Engine Programmer @ www.playspace.com - moritzwundke.com
      Remember: be polite and respect other peoples opinions - Join the Unofficial Unreal Discord Channel - Found a bug? Then use the Bug Report Form to get it fixed ^^

      Comment


        #93
        This is great!

        Comment


          #94
          Hello, quick question. In my blueprint... If I call the below function at every tick, will this animate any changes I had made to the mesh? I mean, is this the right way to do it?

          void AGameGeneratedMesh::UpdateMesh(TArray<FAtom> theUniverse)
          {

          TArray<FCustomMeshTriangle> triangles;

          AGameGeneratedMesh::Cubing(triangles, theUniverse);

          mesh->SetCustomMeshTriangles(triangles);
          RootComponent = mesh;
          }

          Comment


            #95
            Hey,
            first a big thanks for the Procedural Mesh Tutorial and the code! As far as I can see we are using FDynamicMeshVertex inside the constructor of the scene proxy, therefore it should be possible to set the color of the vertices, which is done by "const FColor VertexColor(255, 255, 255);" in the wiki code, as VertexColor is later assigned to the vertices. But no matter what values i choose for VertexColor, my triangles stay black. Possibly I get the concept of vertex colors wrong, but shouldn't the whole triangle be like VertexColor if I'm assigning it to every vertice of the triangle?
            Alternatively I'll try to use a Texture for my mesh tomorrow, but as I only want the triangles/quads to have a single color it would be a bit "overpowered" to use a 1px*1px Texture (or 2*2 whatever, simply that 1 pixel on the texture will represent one color) I think and in addition it would be much more flexible to be able to use FColor or anything alike I can simply adjust in code. (I haven't got it working to get a MID on the mesh either).

            Thanks in advance,
            Taces

            Comment


              #96
              I have managed to generate a mesh using the tutorial, but I cannot get collision with it to work. The mesh is static and a big part of the level, which the ship will fly around in. But the ship doesn't collide with the mesh, it just flys through it. It does collide with other walls I have placed using the editor. I have enabled collision blocking for everything for the mesh. The ship has physics simulation enabled so I believe this may be the reason it doesn't collide, as on this page https://docs.unrealengine.com/latest...ion/index.html it says complex collision is never used when simulating physics, and I interpret that as it will never collide with the triangles of the generated mesh. So I guess I have to somehow generate a set of simplified collision primitives for the generated mesh. How would I go about doing this? Is the functionality of the editor for generating the k-DOP collision primitives available in the API somewhere?

              Thanks!

              Comment


                #97
                I now tried to assign a simple material to my mesh, but somehow it isn't rendered. If I check the size of Component->Materials inside the FPrimitiveSceneProxy* UGeneratedMeshComponent::CreateSceneProxy() function, it is 0, although I added the Material to the array before. This is the constructor of my Actor:

                Code:
                mesh = PCIP.CreateDefaultSubobject<UGeneratedMeshComponent>(this, TEXT("MeshComp"));
                
                	TArray<FGeneratedMeshTriangle> points;
                
                	FGeneratedMeshTriangle tri;
                
                	tri.Vertex0.Position = FVector(0, 0, 0);
                	tri.Vertex1.Position = FVector(100, 0, 100);
                	tri.Vertex2.Position = FVector(0, 0, 100);
                
                
                	//points.Add(tri);
                
                	tri.Vertex0.Position = FVector(100, 0, 100);
                	tri.Vertex1.Position = FVector(0, 0, 0);
                	tri.Vertex2.Position = FVector(100, 0, 0);
                
                
                	points.Add(tri);
                
                	mesh->SetGeneratedMeshTriangles(points);
                
                	static ConstructorHelpers::FObjectFinder<UMaterial> MatFinder(TEXT("Material'/Game/TestMaterial.TestMaterial'"));
                	UMaterial* Material = MatFinder.Object;
                	UMaterialInstanceDynamic* DynMat1 = UMaterialInstanceDynamic::Create(Material, this);
                	DynMat1->SetVectorParameterValue("Color", FLinearColor(1.f, 0.f, 0.f));
                        UE_LOG(LogTemp, Warning, TEXT("Terrain Before: %d"), mesh->Materials.Num());
                	mesh->SetMaterial(0, DynMat1);
                	if (DynMat1 == NULL)
                	{
                		UE_LOG(LogTemp, Warning, TEXT(" DMI NULL"));
                	}
                	else 
                	{
                		UE_LOG(LogTemp, Warning, TEXT(" DMI NOT NULL"));
                	}
                	UE_LOG(LogTemp, Warning, TEXT("Terrain: %d"), mesh->Materials.Num());
                	RootComponent = mesh;
                Here the log says:
                LogTemp:Warning: Terrain Before: 0
                LogTemp:Warning: DMI NOT NULL
                LogTemp:Warning: Terrain: 1
                And in the scene proxy:

                Code:
                UE_LOG(LogTemp, Warning, TEXT("GMC: %d"), Component->Materials.Num());
                			Material = Component->GetMaterial(0);
                			
                
                			if (Material == NULL)
                			{
                				UE_LOG(LogTemp, Warning, TEXT("NULL"));
                				Material = UMaterial::GetDefaultMaterial(MD_Surface);
                			}
                			else UE_LOG(LogTemp, Warning, TEXT("NOT NULL"));
                and it says:

                LogTemp:Warning: Ret: 0
                LogTemp:Warning: Ret: 0
                LogTemp:Warning: GMC: 0
                LogTemp:Warning: NULL
                LogTemp:Warning: Ret: 0
                "Ret: 0" comes from here:
                Code:
                int32 UGeneratedMeshComponent::GetNumMaterials() const
                {
                	UE_LOG(LogTemp, Warning, TEXT("Ret: %d"), Materials.Num());
                	return 1;
                }
                If I change this to "return Materials.Num()" the triangle isn't rendered at all, since it then always returns 0..



                Sorry for the much code, but do you have any idea how to fix this issue?

                Thanks,
                Taces
                Last edited by Taces; 10-16-2014, 05:03 PM.

                Comment


                  #98
                  Working with UE4.5

                  I'm working on getting this running with UE4.5...

                  I am getting the following errors:
                  Code:
                  Error	2	error C2660: 'UMeshComponent::GetMaterialRelevance' : function does not take 0 arguments	C:\[...]\GeneratedMeshComponent.cpp	118	1	MGTycoon
                  Error	3	error C2660: 'CreatePrimitiveUniformBufferImmediate' : function does not take 4 arguments	C:\[...]\GeneratedMeshComponent.cpp	209	1	MGTycoon
                  It seems like the signatures changed for these back-end functions?

                  Just stabbing around I got it to compile with:
                  Code:
                  118|			, MaterialRelevance(Component->GetMaterialRelevance(ERHIFeatureLevel::Num))
                  ...|
                  209|			BatchElement.PrimitiveUniformBuffer = CreatePrimitiveUniformBufferImmediate(GetLocalToWorld(), GetBounds(), GetLocalBounds(), true, true);
                  Since I don't know what this does exactly, I was wondering if anybody knows what I should actually be doing to solve this problem.

                  Comment


                    #99
                    Originally posted by Sgt_Ludwig View Post
                    I'm working on getting this running with UE4.5...

                    I am getting the following errors:
                    Code:
                    Error	2	error C2660: 'UMeshComponent::GetMaterialRelevance' : function does not take 0 arguments	C:\[...]\GeneratedMeshComponent.cpp	118	1	MGTycoon
                    Error	3	error C2660: 'CreatePrimitiveUniformBufferImmediate' : function does not take 4 arguments	C:\[...]\GeneratedMeshComponent.cpp	209	1	MGTycoon
                    It seems like the signatures changed for these back-end functions?
                    For the material relevance I pulled from the custom mesh plugin they package in with releases for this:
                    Code:
                    Component->GetMaterialRelevance(GetScene()->GetFeatureLevel())
                    For the final argument of 'CreatePrimitiveUniformBufferImmediate' I get sporadic crashes if I don't True it.
                    Last edited by mordentral; 10-17-2014, 09:04 AM.


                    Consider supporting me on patreon

                    My Open source tools and plugins
                    Advanced Sessions Plugin
                    VR Expansion Plugin

                    Comment


                      If anybody else has the same issue as I did (Material is not applied), I figured out how to do it: Instead of applying the material inside the constructor of my actor, I had to apply it in "PostInitializeComponents" - this way everything works fine! Although I don't really understand why it doesn't work in the constructor, it would be great if somebody could explan that? I'd suppose that the components are recreated after the constructor of my actor, but I dont' know why this should happen.

                      Comment


                        Thanks mordentral!

                        Comment


                          Apologies for the late reply, Taces, but I think my posts in this thread might clear up a few things for you re: VertexColor.

                          Hope that helps!
                          Former Technical Designer @ Irrational Games, gone Indie.
                          Technical Designer for: Bioshock Infinite, Mars 2030
                          Programmer/VFX for: Perception, The Black Glove's Kickstarter
                          Voiceover Editor for: Bioshock, Bioshock Infinite

                          Comment


                            Never mind, rather a late response than none! In the meantime I got Vertex colors working (I didn''t know, that there is an extra parameter for it) and tried around a bit, to understand how they are working. Now I'm setting the BaseColor of the Material to the VertexColor, which works well for what I want to do.

                            Comment


                              Originally posted by Taces View Post
                              Never mind, rather a late response than none! In the meantime I got Vertex colors working (I didn''t know, that there is an extra parameter for it) and tried around a bit, to understand how they are working. Now I'm setting the BaseColor of the Material to the VertexColor, which works well for what I want to do.
                              Yeah I've been using vertex color as a material base for awhile with custom mesh, I did notice however that FColor::toDwcolor seems to encode the blue channel incorrectly and I had to manually pack and unpack colors instead when saving the data outside of an FColor struct.


                              Consider supporting me on patreon

                              My Open source tools and plugins
                              Advanced Sessions Plugin
                              VR Expansion Plugin

                              Comment


                                Hey guys,

                                Thanks for keeping this going! I've been really busy on other stuff, so I haven't been able to make updates to the wiki. Please do not hesitate to update the wiki page: https://wiki.unrealengine.com/Proced...esh_Generation

                                I see that the project code has been linked and that's a great help! If anyone wishes to revamp the page be my guest.

                                My last version was 4.2.1, so I have a lot of catching up to do...
                                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

                                Working...
                                X