Generate Procedural Mesh

Hi again guys,

Has anyone tried to assign multiple UVs to the generated mesh? In the code I’ve found a possibility to assign only one TextureCoordinate. Can we somehow access more than one texture coordinate and therefore generate multiple UVs?

thanks

Hi
I try this tutorial from this linkwiki.unrealengine.com/Procedural_Mesh_Generation#Update_6
and after fixing warnings and syntax error I try to build and run but there is nothing show at screen.
I add actor manually and with level blueprint but there is no mesh at screen

Hi, I don’t know why the wiki tutorial is not working anymore, but you could look at the project with full source code and Blueprint to get something working:https://.com//UE4ProceduralMesh/tree/master/Source/ProceduralMesh
Cheers!

Thanks. I will.

[=;263655]
Hi , you must not try to build static lighting with dynamic components, they are incompatible by nature. This had been stated at the beginning of this thread by an UE engineer.

But we have made a modification to the code (see the wiki or my copy of it) so that it does not crash anymore (it still does not participate in static lighting)
[/]

Hi,

I look into the Wiki and the code that fails on my side is there:
check(!IsInRenderingThread()); inside void Init(const FGeneratedMeshVertexBuffer* VertexBuffer)

Did I miss something?

Could you tell me how to “remove” the dynamic mesh from staticlight?

Thanks for the awesome work, you’ve really enabled a lot of people to get started with procedural mesh generation.

I’ve kind of hit a wall when it comes to tessellation though, the material DX11 tessellation won’t tessellate the generated mesh at all, and “Crack Free Displacement” completely breaks it.
The world displacement works fine though.

Anyone have an idea as to what information is missing from the generated mesh that prevents it from being tessellated?

[=Grimeh;266006]
Thanks for the awesome work, you’ve really enabled a lot of people to get started with procedural mesh generation.

I’ve kind of hit a wall when it comes to tessellation though, the material DX11 tessellation won’t tessellate the generated mesh at all, and “Crack Free Displacement” completely breaks it.
The world displacement works fine though.

Anyone have an idea as to what information is missing from the generated mesh that prevents it from being tessellated?
[/]

You need to generate adjacency data and then check the material if it has tessellation and set the primitive type to the correct PT type. There is a function in MeshUtilities that can be used for generating the adjacency index buffer from positional data: BuildStaticAdjacencyIndexBuffer.

Hi All, thanks to whos worked on this. It’s been a real help in my project.

I’m currently working on a procedural spline mesh which is generated from a spline component. I’ve got it working pretty well:

I’m playing around with the vertex colors, I want to be able to use them to drive the emissive output of the mesh with alpha controlling the intensity. The problem I’m facing is that currently vertex colors use FColor instead of FLinearColor. I want to be able to have values of more than 1.f for my vertex colors so I can create bloom. Does anyone know if it’s possible to change the procedural mesh so that it will use FLinearColors for the vertex color values instead? Or any other way to pass per vertex data into the material?

Edit:
I’ve dug around in the engine code a bit and found this comment in FLocalVertexFactory::SetData()



void FLocalVertexFactory::SetData(const DataType& InData)
{
	check(IsInRenderingThread());

	// The shader code makes assumptions that the color component is a FColor, performing swizzles on ES2 and Metal platforms as necessary
	// If the color is sent down as anything other than VET_Color then you'll get an undesired swizzle on those platforms
	check((InData.ColorComponent.Type == VET_None) || (InData.ColorComponent.Type == VET_Color));

	Data = InData;
	UpdateRHI();
}


So it looks like it’s not possible to use a float4 for vertex color at the moment with out modifying the engine code significantly.

@: How to use more than one TextureCoordinate:



struct FTerrainMeshVertex
{
	...
	FVector2D TextureCoordinate[2];
	...
}


VertexFactory:



DataType NewData;
...
NewData.TextureCoordinates.Add( FVertexStreamComponent(VertexBuffer, STRUCT_OFFSET(FTerrainMeshVertex, TextureCoordinate[0]), sizeof(FTerrainMeshVertex), VET_Float2) );
NewData.TextureCoordinates.Add( FVertexStreamComponent(VertexBuffer, STRUCT_OFFSET(FTerrainMeshVertex, TextureCoordinate[1]), sizeof(FTerrainMeshVertex), VET_Float2) );
...


But there is one thing you need to know: In the material you have to select “Coordinate Index” 2 for TextureCoordinate[1], 4 for TextureCoordinate[2] etc…

[=;266830]
Hi All, thanks to whos worked on this. It’s been a real help in my project.

I’m currently working on a procedural spline mesh which is generated from a spline component. I’ve got it working pretty well:

I’m playing around with the vertex colors, I want to be able to use them to drive the emissive output of the mesh with alpha controlling the intensity. The problem I’m facing is that currently vertex colors use FColor instead of FLinearColor. I want to be able to have values of more than 1.f for my vertex colors so I can create bloom. Does anyone know if it’s possible to change the procedural mesh so that it will use FLinearColors for the vertex color values instead? Or any other way to pass per vertex data into the material?

Edit:
I’ve dug around in the engine code a bit and found this comment in FLocalVertexFactory::SetData()



void FLocalVertexFactory::SetData(const DataType& InData)
{
	check(IsInRenderingThread());

	// The shader code makes assumptions that the color component is a FColor, performing swizzles on ES2 and Metal platforms as necessary
	// If the color is sent down as anything other than VET_Color then you'll get an undesired swizzle on those platforms
	check((InData.ColorComponent.Type == VET_None) || (InData.ColorComponent.Type == VET_Color));

	Data = InData;
	UpdateRHI();
}


So it looks like it’s not possible to use a float4 for vertex color at the moment with out modifying the engine code significantly.
[/]

Hi
Is it possible to share some code or info how to make custom spline component or extend existing one ?

Hey Kalin,

Check out my fork of the tutorial code on git hub for the code. https://.com/-malakoff/UE4ProceduralMesh.

Please note that I’ve significantly changed the definition of the procedural mesh vertices for my use so you will need to use all my modified files for it to work, don’t just copy my new files into example project.

I have an array of shared vertices and then index them in the triangles. This is so I can change the color of vertices more easily, if you don’t want to do this it should be fairly trivial to change it back to the way does it. Also there’s some testing code for colors you might want to get rid of.

Let me know if you have any questions!

Hi All,

I managed to get linear colors passed in though custom UV channels in the end to achieve bloom with a nice gradient:

Now I’m having a really odd problem though. When I started changing the mesh in the editor was also refreshing the physics mesh no problems. However now whenever I modify a spline and refresh it the physics stays the same. This happens on new instances and the ones that were previously updating fine.

The really odd thing is as far as I can tell this isn’t anything that I did. Even when I revert as far back in my git repository as I could, to a point where I know it was all working, it still fails. This happened before and after the 4.7.5 hotfix as well. I’ve followed some of the suggestions in this thread regarding physics but to no avail.

A bit of debugging showed that when the below function is hit on the refresh bPhysicsStateCreated is somehow 0. Has anyone else experienced similar problems to this?



void UProceduralMeshComponent::UpdateCollision()
{
	if(bPhysicsStateCreated)
	{
		DestroyPhysicsState();
		UpdateBodySetup();

		// Works in Packaged build only since UE4.5:
		ModelBodySetup->InvalidatePhysicsData();
		ModelBodySetup->CreatePhysicsMeshes();

		CreatePhysicsState();
	}
}


Edit: A bit more experimentation has shown that I can change the physics state in game by putting an UpdateCollision() call in BeginPlay() but it’s no longer updating in the editor.

Raycasting crash

Hello . I took a few days playing with this, but I have a problem with raycasting.

After many tests, always crash, except when the mesh has only one triangle.

Do any advice?

Thanks.

[=;268748]
Physics problems
[/]

**** yeah I JUST ran into this and fixed it, when I was setting up an object pool I was creating the object prior to begin play and they were generating an empty physics state for some reason. I had to move my object creation TO begin play to correct it without forcing it to re-create. I’m assuming that some part of the program that bakes the physics information isn’t actually initialized until after that time in the programs load, I didn’t look into it any further after getting it to work.

Any examples for skeletal meshes / characters?

Generating skeletal meshes/animations, while conceptional possible, would be extremely difficult. As far as I can tell the current code wouldn’t support this as it inherits from StaticMeshCompoment.

It would probably be possible to make something similar inheriting from Skeletal Mesh but to make something as complex as a humanoid character would be so difficult I wouldn’t even bother. Might be ok for simple stuff though.

If you just want to use a generated mesh with the existing character class you can just add a static mesh component and ignore the skeletal mesh component.

@mordentral Yeah, what’s weird is though it was working for ages then it just suddenly stopped! I know it was working cause as I went back though my Git commits there were meshes that generated collisions fine. But even at those revisions new meshes still didn’t generate collisions properly.

I don’t want to generate the character. I would like to load an existing skeletal mesh and apply it to a skeleton, possibly run-time without setting it up in the editor.
I hoping that i am not miss-using this class.

Do you just want to apply a already existing mesh to a skeleton? Then I think you are currently looking at the completly wrong class. If you also want to change the existing skeletal mesh, yes you can try to find a solution to do this starting from this class, but as already explained, this would be extremly difficult and probably not worth the effort. What do you want to do exactly? May be blendshapes an easier way to achieve it?

About the miss-use: I used this class to import meshes from different file formats that are not supported by the engine. With (Assimp) for example. But they are static meshes
What i want is to import skeletal meshes at runtime without rebuilding the whole game. And use the mesh with an existing skeleton.
I know this class will not fit to my needs ever. That’s why i am asking for help.

About the procedural generation part: I am not aiming high details, that would be pointless.
Generating characters like in minecraft is much simpler.

I think this is certainly possible and would be a pretty interesting project. I would have a look though the USkeletalMeshComponent code to see how it provides it’s primitive data (vertexes, collisions etc), using the generated mesh class as a starting point it’s probably possible to make something similar.