Download

Convert a static mesh into procedural mesh?

Here’s what I’m trying to accomplish:
I need to be able to deform a static mesh, but because a static mesh is a static mesh by definition it can’t be deformed. So my plan is to use a procedural mesh component, and somehow convert my static mesh into a procedural mesh so I can then play with the vertex positions. Can someone tell me if this plan is impossible/crazy? I found a function in ProceduralMeshComponent.h that might help me out (line 127):


/**
	 *	Create/replace a section for this procedural mesh component.
	 *	@param	SectionIndex		Index of the section to create or replace.
	 *	@param	Vertices			Vertex buffer of all vertex positions to use for this mesh section.
	 *	@param	Triangles			Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
	 *	@param	Normals				Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array.
	 *	@param	UV0					Optional array of texture co-ordinates for each vertex. If supplied, must be same length as Vertices array.
	 *	@param	VertexColors		Optional array of colors for each vertex. If supplied, must be same length as Vertices array.
	 *	@param	Tangents			Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array.
	 *	@param	bCreateCollision	Indicates whether collision should be created for this section. This adds significant cost.
	 */
	UFUNCTION(BlueprintCallable, Category = "Components|ProceduralMesh", meta = (AutoCreateRefTerm = "Normals,UV0,VertexColors,Tangents"))
	void CreateMeshSection(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals, const TArray<FVector2D>& UV0, const TArray<FColor>& VertexColors, const TArray<FProcMeshTangent>& Tangents, bool bCreateCollision);

The issue is, there is some information I can’t find how to get from a static mesh component, such as: triangles. Does anyone have an easier way to deform a static mesh? Or, can anyone help me use this method? Thanks to anyone who read this whole thing, I really appreciate it.

FYI: I am an ex-Unity user and I just got into Unreal C++ about a month ago.

Ok, I have obtained some information that some else might find useful as well… :slight_smile:
This post explains how to get the triangle strip(what verts make up each triangle) and how to get vertex positions. Sadly the module that gives out vertex positions is only designed to function in the editor not in build. So I have to save that information somehow so I can use it in the build.
https://answers.unrealengine.com/questions/93554/frawmesh-data-froma-static-mesh.html

Don’t hesitate to correct me if I’m wrong about anything.

I am really liking the unreal engine so far. :cool:

Hi, did you have some success with it? Does it make some performance impact? Is it good with setting materials to procedural mesh? What about UVs?