Announcement

Collapse
No announcement yet.

Generate Procedural Mesh

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

    #76
    Originally posted by Eclipsed View Post
    My bad, the code is correct and there's nothing special to do.

    I had some stale code rebuilding the original mesh right after the code I use to modify it, thus voiding any modification

    Sorry if I wasted you time
    Cool, just glad to see u got it working.
    FluidSurface Plugin: https://github.com/Ehamloptiran/UnrealEngine/releases
    TextureMovie Plugin: https://github.com/Ehamloptiran/TextureMoviePlugin

    Comment


      #77
      Originally posted by Ehamloptiran View Post
      I've just copied the code from the wiki example into my project and can create the lathed object in my map. However, it shows up with the default grey material rather than the black which it should have. My code includes the ColorComponent by Ryvar above but it makes no difference. Has anyone else seen this or can anyone offer any advice?

      Cheers.
      I also haven't been able to change the color of the generated mesh.
      Any help would be appreciate, as my project relies on custom lighting. If I can't solve this, I will have to give up with unreal engine.
      https://answers.unrealengine.com/que...component.html

      Also has anyone been able to create a physics composite shape for a simple cube yet?
      https://www.youtube.com/watch?featur...&v=ZgQxWQ9oWoQ
      I see rama(the magician) has :/ i have had no luck.... I guess ill keep researching.. But I would love a tutorial, or some basic code for this, if anyone has succeeded. Custom physics would be amazing.

      Comment


        #78
        Originally posted by Deus0 View Post
        I also haven't been able to change the color of the generated mesh.
        Any help would be appreciate, as my project relies on custom lighting. If I can't solve this, I will have to give up with unreal engine.
        https://answers.unrealengine.com/que...component.html
        Do you strictly need vertex color?

        If not (and a material is enough for you) just declare the GeneratedMeshComponent as a UPROPERTY in the .h file and then you can assign a material to it through the editor or BluePrint.

        Comment


          #79
          Strictly yes.
          Since I want to have custom lighting, or tinting per vertex.
          I'm Using the code provided here on the forums and wiki:
          Inside(GeneratedMesh.h):

          USTRUCT(BlueprintType)
          struct FCustomMeshTriangleVertex
          {
          GENERATED_USTRUCT_BODY()

          UPROPERTY(EditAnywhere, Category = Triangle)
          FVector Position;

          UPROPERTY(EditAnywhere, Category = Triangle)
          FColor Color; // 4 inputs

          UPROPERTY(EditAnywhere, Category = Triangle)
          float U;

          UPROPERTY(EditAnywhere, Category = Triangle)
          float V;
          };

          And the color doesn't change the rendered mesh.
          I even modified the FGeneratedMeshSceneProxy class to test if it works:
          Inside(GeneratedMesh.cpp):

          for (int TriIdx = 0; TriIdx<Component->GeneratedMeshTris.Num(); TriIdx++)
          {
          const FColor VertexColor(255, 0, 0, 255); // test to see if vertex is rendered red

          FCustomMeshTriangle& Tri = Component->GeneratedMeshTris[TriIdx];

          const FVector Edge01 = (Tri.Vertex1.Position - Tri.Vertex0.Position);
          const FVector Edge02 = (Tri.Vertex2.Position - Tri.Vertex0.Position);

          const FVector TangentX = Edge01.SafeNormal();
          const FVector TangentZ = (Edge02 ^ Edge01).SafeNormal();
          const FVector TangentY = (TangentX ^ TangentZ).SafeNormal();

          FDynamicMeshVertex Vert0;
          Vert0.Position = Tri.Vertex0.Position;
          //Vert0.Color = Tri.Vertex0.Color;
          Vert0.Color = VertexColor;
          Vert0.SetTangents(TangentX, TangentY, TangentZ);
          Vert0.TextureCoordinate.Set(Tri.Vertex0.U, Tri.Vertex0.V);
          int32 VIndex = VertexBuffer.Vertices.Add(Vert0);
          IndexBuffer.Indices.Add(VIndex);

          ... etc

          Also, if you seen my links, the first one is the question I posted. The picture in it is the game im working on. As you can tell I've already added the material to it using cpp. I am trying to make lighting effects similar to BrickGame:
          https://github.com/AndrewScheidecker/BrickGame
          I just need a basic example to work.
          Also if you enable physics in the custom mesh:

          TSubobjectPtr<UGeneratedMesh> Mesh;
          FBodyInstance* BodyInst = Mesh->GetBodyInstance();
          BodyInst->bSimulatePhysics = true;
          It for some reason destroys the actor. Still not sure why.

          Also debugged the ReceiveHit function, and the GeneratedMesh recieves a collision response from everything besides itself. So yes colllision works with custom mesh, but not with other custom meshes. That's what i've discovered so far.
          Last edited by Deus0; 09-07-2014, 10:19 PM.

          Comment


            #80
            Originally posted by dmacesic View Post
            Anyone know how to make a mesh from vertices and triangles, attach it to an object and spawn it?

            I looked into FDynamicMeshBuilder, but that's only for drawing.

            Are we still using GeneratedMeshComponent.h ?

            I was hoping that I could just use the official plugin. However, the editor is unable to locate CustomMeshComponent.h . The plug-in is for sure enabled. Have they not been able to get this working since March?

            Comment


              #81
              I was noticing that the collision mesh was lagging behind when changed dynamically, I originally thought it was the cooking time as it returns automatically if already cooking a previous change. However after a little experimentation the problem was solved by making the change below. Now the collision generates correctly after updates to the procedural mesh and I haven't noticed any errors because of it so far.


              From:

              Code:
              void UGeneratedMeshComponent::UpdateCollision() {
              	if (bPhysicsStateCreated) {
              		DestroyPhysicsState();
              		UpdateBodySetup();
              		CreatePhysicsState();
               
                              ModelBodySetup->InvalidatePhysicsData();
              		ModelBodySetup->CreatePhysicsMeshes();
              	}
              }
              To:

              Code:
              void UGeneratedMeshComponent::UpdateCollision() {
              	if (bPhysicsStateCreated) {
              		DestroyPhysicsState();
              		UpdateBodySetup();
              
               
                              ModelBodySetup->InvalidatePhysicsData();
              		ModelBodySetup->CreatePhysicsMeshes();
              		CreatePhysicsState();
              	}
              }


              Consider supporting me on patreon

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

              Comment


                #82
                Hey guys!

                Thanks to Ori Cohen we got PhysX Cooking in runtime:
                * https://github.com/EpicGames/UnrealE...7c4a408b3ea73b
                * https://github.com/EpicGames/UnrealE...3c991751e59e72

                This is still in the master though, but you should be able to integrate it into your code without effort.

                Cheers,
                Moss
                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


                  #83
                  As a proof of concept, i´ve created a procedural city (screenshot attached).
                  You can choose how many roads, buildings, parks and so on you want, and my class spawns them in the editor.

                  As far as i can see, FGeneratedMeshVertexFactory is not compatible with static lighting, because it crashes when i hit the Rebuild-button.

                  Click image for larger version

Name:	Crash.PNG
Views:	1
Size:	14.5 KB
ID:	1057272

                  Is there a trick, to use static lighting never the less?
                  Attached Files

                  Comment


                    #84
                    Originally posted by Mars007 View Post
                    As a proof of concept, i´ve created a procedural city (screenshot attached).
                    You can choose how many roads, buildings, parks and so on you want, and my class spawns them in the editor.

                    As far as i can see, FGeneratedMeshVertexFactory is not compatible with static lighting, because it crashes when i hit the Rebuild-button.

                    [ATTACH=CONFIG]12969[/ATTACH]

                    Is there a trick, to use static lighting never the less?
                    Yeah as it shows in the screenshot itself it is an ASSERT that throws if the process is trying to initialize the vertex factory inside the rendering thread. You can remove the assert and handle that part of the code getting called cleanly instead.

                    I ran into that awhile ago and changed it so it worked with what I was doing.

                    Code:
                    	/** Initialization */
                    	void Init(const FGeneratedMeshVertexBuffer* VertexBuffer)
                    	{
                    		check(!IsInRenderingThread());
                     
                    		ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
                    			InitGeneratedMeshVertexFactory,
                    			FGeneratedMeshVertexFactory*,VertexFactory,this,
                    			const FGeneratedMeshVertexBuffer*,VertexBuffer,VertexBuffer,
                    		{
                    			// Initialize the vertex factory's stream components.
                    			DataType NewData;
                    			NewData.PositionComponent = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer,FDynamicMeshVertex,Position,VET_Float3);
                    			NewData.TextureCoordinates.Add(
                    				FVertexStreamComponent(VertexBuffer,STRUCT_OFFSET(FDynamicMeshVertex,TextureCoordinate),sizeof(FDynamicMeshVertex),VET_Float2)
                    				);
                    			NewData.TangentBasisComponents[0] = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer,FDynamicMeshVertex,TangentX,VET_PackedNormal);
                    			NewData.TangentBasisComponents[1] = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer,FDynamicMeshVertex,TangentZ,VET_PackedNormal);
                    			NewData.ColorComponent = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer, FDynamicMeshVertex, Color, VET_Color);
                    			VertexFactory->SetData(NewData);
                    		});
                    	}


                    Consider supporting me on patreon

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

                    Comment


                      #85
                      James Golding (Epic) stated previously that dynamic meshes are not compatible with static lighting:
                      Originally posted by JamesG View Post
                      Right now this geometry is slightly slower than a regular static mesh, and doesn't support things like precomputed lighting.
                      Originally posted by mordentral View Post
                      You can remove the assert and handle that part of the code getting called cleanly instead.
                      So how do you do that? I mean, after removing the assert on line 44, what do you change on the code to make it support precomputed lighting?

                      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


                        #86
                        This was an easy fix
                        I thought this check prevents the engine from doing something bad.
                        But as i removed the IsInRenderingThread check, i got back static lighting for static meshes.
                        Dynamic meshes have to use dynamic lighting, as stated above.

                        Comment


                          #87
                          Originally posted by SRombauts View Post
                          James Golding (Epic) stated previously that dynamic meshes are not compatible with static lighting:



                          So how do you do that? I mean, after removing the assert on line 44, what do you change on the code to make it support precomputed lighting?

                          Cheers!
                          The reason it doesn't work normally is because the example loads after the game has loaded so any baked lighting will obviously be incorrect, also if it changes then the baked lighting will also be wrong. If you have a mesh that is generated and never changes and is generated in engine prior to the baking process then it works just fine.
                          Last edited by mordentral; 10-01-2014, 07:43 PM.


                          Consider supporting me on patreon

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

                          Comment


                            #88
                            Hey guys! I've been trying to get this to work because it is critical for the game I'd like to start building. Basically I'm recreating a Tychoon-style terrain system and a procedural mesh with collision is the core component.

                            In Unity cranking out a procedural mesh was a piece of cake. So far in Unreal it's been impossible. I've tried tinkering with as much stuff as I can but nothing seems to work. I keep getting the following error:

                            Code:
                            Error	2	error C2664: 'FVertexBufferRHIRef RHICreateVertexBuffer(uint32,uint32,FRHIResourceCreateInfo &)' : cannot convert argument 3 from 'EBufferUsageFlags' to 'FRHIResourceCreateInfo &'	C:\Users\[...]\Source\ProMesh43\GeneratedMeshComponent.cpp	19	1	ProMesh43
                            I've tried fiddling with things, but I either get linking errors or errors that all kinds of behind the scenes functions take different arguments. I've tried this with 4.3, 4.4 and the 4.5 preview.

                            I realize this isn't exactly plug and play, but has anyone else had these problems? (I'm new to C++ and don't have the skills to get elbow deep in UE4)

                            Comment


                              #89
                              Nevermind... I forgot to add RHI, RenderCore and ShadeCore modules to my build file. Derp.

                              Comment


                                #90
                                Originally posted by Moss View Post
                                Hey guys!

                                Thanks to Ori Cohen we got PhysX Cooking in runtime:
                                * https://github.com/EpicGames/UnrealE...7c4a408b3ea73b
                                * https://github.com/EpicGames/UnrealE...3c991751e59e72

                                This is still in the master though, but you should be able to integrate it into your code without effort.

                                Cheers,
                                Moss
                                Thanks for sharing those links Moss!

                                I've been hoping and wishing for this since 4.0 !

                                Fully functional dynamic meshes at runtime, runtime collision changes, yaaaay!

                                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

                                Working...
                                X