Generate Procedural Mesh

I can now confirm that, no, the dynamic mesh collision code has not yet been put in place / that issue is not fixed.

Which does mean we can’t yet have collision for dynamic meshes in fully packaged games.

Epic please address this soon as you can!

Thanks!

:slight_smile:

[=;76462]
I can now confirm that, no, the dynamic mesh collision code has not yet been put in place / that issue is not fixed.

Which does mean we can’t yet have collision for dynamic meshes in fully packaged games.

Epic please address this soon as you can!

Thanks!

:slight_smile:

[/]

It’s still slated for June, although more people should vote for it

Hey ,

Thank you for this awesome thread and the work you’ve been sharing.

I’ve currently run in to a snag and I’m wondering if anybody else is having the same problem. If I create a blueprint to run line traces agaisnt the dynamic meshes I’ll eventually get the following crash:


!Id:9807dac3b980b09e7b3092cc6049391b

Access violation - code c0000005 (first/second  not available)

UE4Editor-Engine.dll

UE4Editor_Engine + 11365999 bytes
UE4Editor_Engine + 11246153 bytes
UE4Editor_Engine + 11609624 bytes
UE4Editor_Engine + 11566745 bytes
UE4Editor_Engine + 4733635 bytes
UE4Editor_Engine + 4734271 bytes
UE4Editor_Engine + 21294089 bytes
UE4Editor_CoreUObject + 1314781 bytes
UE4Editor_CoreUObject + 1371986 bytes
UE4Editor_CoreUObject + 1457175 bytes
UE4Editor_CoreUObject + 1377083 bytes
UE4Editor_CoreUObject + 1316120 bytes
UE4Editor_CoreUObject + 1377083 bytes
UE4Editor_CoreUObject + 1375095 bytes
UE4Editor_Engine + 1765263 bytes
UE4Editor_Engine + 15382955 bytes
UE4Editor_Engine + 6018158 bytes
UE4Editor_Engine + 6012290 bytes
UE4Editor_Engine + 6055406 bytes
UE4Editor_Engine + 1656563 bytes
UE4Editor_Engine + 8617942 bytes
UE4Editor_Engine + 8688548 bytes
UE4Editor_Core + 462146 bytes
UE4Editor_Core + 462589 bytes
UE4Editor_Core + 524839 bytes
UE4Editor_Engine + 9015033 bytes
UE4Editor_Engine + 8917088 bytes
UE4Editor_Engine + 8960756 bytes
UE4Editor_Engine + 5129510 bytes
UE4Editor_Engine + 5156650 bytes
UE4Editor_UnrealEd + 1464870 bytes
UE4Editor_UnrealEd + 5375494 bytes
UE4Editor!FEngineLoop::Tick() + 3555 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.2\engine\source\runtime\launch\private\launchengineloop.cpp:2091]
UE4Editor!GuardedMain() + 476 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.2\engine\source\runtime\launch\private\launch.cpp:132]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.2\engine\source\runtime\launch\private\windows\launchwindows.cpp:125]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.2\engine\source\runtime\launch\private\windows\launchwindows.cpp:207]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]

I’ve confirmed that in other projects without the dynamic mesh instances that I cannot reproduce the crash. I’ve attempted to debug the issue by running the engine from VS with debugging on, however instead of a break it simply freezes and crashes to desktop. I’d be grateful if someone else who’s implemented the dynamic meshes would try and run a few line traces to see if they see the same thing. Otherwise it might be something on my side unrelated to the dynamic meshes. Here is my blueprint for reference:

The trace will fire and show up on the meshes a few times but eventually crash. Sometimes it crashes early other times I have to spam it about 20-30 times to get it to crash.

Thanks.

Ok, I’ve got a pretty good lead on my problem. I seem to have found a solution that works for me, but I don’t think it’s really 100% correct.

The crash was being caused from the following location in the engine in the SetHitResultFromShapeAndFaceIndex() function in Source\Runtime\Engine\Private\Collision\CollisionConversions.cpp



			// @fixme: only do this for InGameThread, otherwise, this will be done in AsyncTrace
			if ( IsInGameThread() )
			{
				// This function returns the single material in all cases other than trimesh or heightfield
				PxMaterial* PxMat = PShape->getMaterialFromInternalFaceIndex(FaceIndex);
				if(PxMat != NULL)
				{
					OutResult.PhysMaterial = FPhysxUserData::Get<UPhysicalMaterial>(PxMat->userData);
					FString name = OutResult.PhysMaterial->GetName();
				}
			}
			else
			{
				//@fixme: this will be fixed properly when we can make FBodyInstance to be TWeakPtr - TTP (263842)
			}


For certain FaceIndex the PxMat pointer returned from getMaterialFromInternalFaceIndex() would be garbage data (0xddddddddd…), this caused the deference PxMat->userData to crash the editor. It seems that for certain face indies we’re not setting the correct “Physics Material”…

After poking around in the GeneratedMeshComponent.cpp I found this (added comment to the suspicious line…)



bool UGeneratedMeshComponent::GetPhysicsTriMeshData(struct FTriMeshCollisionData* CollisionData, bool InUseAllTriData)
{
	FTriIndices Triangle;

	for (int32 i = 0; i<GeneratedMeshTris.Num(); i++) {
		const FGeneratedMeshTriangle& tri = GeneratedMeshTris*;

		Triangle.v0 = CollisionData->Vertices.Add(tri.Vertex0.Position);
		Triangle.v1 = CollisionData->Vertices.Add(tri.Vertex1.Position);
		Triangle.v2 = CollisionData->Vertices.Add(tri.Vertex2.Position);

		CollisionData->Indices.Add(Triangle);
		CollisionData->MaterialIndices.Add(i); //Why are we setting the Material index to the index of the triangle?
	}

	CollisionData->bFlipNormals = true;

	return true;
}


After using the static mesh as a reference: UStaticMesh::GetPhysicsTriMeshData | Unreal Engine Documentation
It looks like this should be the “index of the material” and not the index of the triangle. My guess is we’re looking for materials at indexies that don’t exist.

Changing the line:



CollisionData->MaterialIndices.Add(i);


To this:



CollisionData->MaterialIndices.Add(0);


Seems to have solved the crashing issue. I’ve probably broken material-based physics collision but since I don’t need that for now I’m going to work with this. Hopefully someone who knows more about this stuff than me can figure out what the proper fix is.

[=;76462]
I can now confirm that, no, the dynamic mesh collision code has not yet been put in place / that issue is not fixed.

Which does mean we can’t yet have collision for dynamic meshes in fully packaged games.

Epic please address this soon as you can!

Thanks!

:slight_smile:

[/]

Dear Epic / G,

Any update on the adding of Cooked Collision for the Dynamic Mesh Component?

**It would be incredibly useful for so very many projects to have cookable collision for dynamically generated meshes!
**
Thanks!

Hi,

I recently started on UDK to get a render of a procedural generation library. I tried to follow instructions on wiki but i get errors as i miss to link somethings. I suppose some obvious mistake from me but as i don’t dev in c++ long time ago, i’m appreciate some help.

Here the errors : Info Parsing headers for TutorialEditorInfo LogTextLocalizationManager:Warning - Pastebin.com

Hi HellFiveday,

Please make this a post on the answerhub at http://answers.unrealengine.com so we can track this and provide assistance. Thank you!

I think it’s more easy to provide solution in the same post. Anyway i found my misstake, i use the version 4.3.0 and the code provided require 4.2.1.

[=HellFiveDay;94210]
I think it’s more easy to provide solution in the same post. Anyway i found my misstake, i use the version 4.3.0 and the code provided require 4.2.1.
[/]

I won’t be back to work on this before a couple of weeks, but I’ll update the wiki once I get my stuff up to date.

In case anyone’s still fooling around with this tutorial, I’ve added a better CalcBounds(). It now seems to give you the same bounds as other meshes.

Hi,

I am having an issue with this, I created a very simple mesh which is just a flat plane made from 4 triangles. The issue I am having is when using one of the starter textures the M_cobblestone_rough. The problem is when I move the camera left and right while looking down on the texture the bumpmap is changing the material like I am moving the camera in a different direction, up\down.

I tracked it down to the tangents in this part of the code:-


GeneratedMeshComponent.cpp


			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();

If I change this to:-


			const FVector TangentX = FVector(1, 0, 0);
			const FVector TangentZ = FVector(0, 0, 1);
			const FVector TangentY = FVector(0, 1, 0);

It looks a bit odd, but its at least moving correctly.

So question is am I doing something wrong or is this not the correct way to calculate the tangents? if needed I can record a short vid of the problem as its not that easy to explain.

Thanks

Hi guys,

I’ve been following this thread and I managed to create a lot of geometry with collisions and textures so, THANKS A LOT!

I’m now stuck because I want to modify the mesh and collision at runtime, any idea about how can I achieve that?

I’ve been trying to delete and rebuild (with new data) the content of the GeneratedMeshComponent, but it doesn’t seem to have any effect in game.

Thanks a lot!

[=Eclipsed;130715]
Hi guys,

I’ve been following this thread and I managed to create a lot of geometry with collisions and textures so, THANKS A LOT!

I’m now stuck because I want to modify the mesh and collision at runtime, any idea about how can I achieve that?

I’ve been trying to delete and rebuild (with new data) the content of the GeneratedMeshComponent, but it doesn’t seem to have any effect in game.

Thanks a lot!
[/]

You need to call MarkRenderStateDirty from the component when you update any values to ensure that the Scene Proxy gets rebuilt with your new data.

Well, I do call UGeneratedMeshComponent::SetGeneratedMeshTriangles which marks the render state as dirty.

I’ll double-check when I’ll go back home, but I’m pretty sure I did that.

Btw, would this affect the collisions as well?

[=;130794]
You need to call MarkRenderStateDirty from the component when you update any values to ensure that the Scene Proxy gets rebuilt with your new data.
[/]

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 :wink:

Sorry if I wasted you time :slight_smile:

[=]
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 :wink:

Sorry if I wasted you time :slight_smile:
[/]

Cool, just glad to see u got it working.

[=;131940]
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.

Also has anyone been able to create a physics composite shape for a simple cube yet?
https://www…com/watch?feature=player_embedded&v=ZgQxWQ9oWoQ
I see (the magician) has :confused: 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.

[=Deus0;136336]
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.

[/]

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.

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&lt;Component-&gt;GeneratedMeshTris.Num(); TriIdx++)
		{
			const FColor VertexColor(255, 0, 0, 255); // test to see if vertex is rendered red

			FCustomMeshTriangle& Tri = Component-&gt;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://.com/AndrewScheidecker/BrickGame
I just need a basic example to work.
Also if you enable physics in the custom mesh:

TSubobjectPtr&lt;UGeneratedMesh&gt; Mesh;
FBodyInstance* BodyInst = Mesh-&gt;GetBodyInstance();
BodyInst-&gt;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.

[=dmacesic;8842]
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 . 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?