Generate Procedural Mesh

[]
You need to set the collision channels up correctly.
[/]

I apologize for my lack of understanding, but I’m not sure what you mean. I’ve tried the collision presets BlockAll and BlockAllDynamic, both fall through the floor. Could you expand on your answer or point me to the documentation where I can learn why this is happening?

Am I correct that the mesh returned in CollisionData in GetPhysicsTriMeshData is used for detecting collisions?

In the static mesh editor you can auto-generate a convex decomposition mesh for collision. Is that code available in the engine at runtime, and could it be used within this function to generate a simplified collision mesh? What other functions are available in the engine at runtime to produce a simplified mesh? Something like LOD functions?

I apologize as I’ve seen similar questions, but I haven’t seen any direct answers.

[=ScottMG;240407]
Am I correct that the mesh returned in CollisionData in GetPhysicsTriMeshData is used for detecting collisions?

In the static mesh editor you can auto-generate a convex decomposition mesh for collision. Is that code available in the engine at runtime, and could it be used within this function to generate a simplified collision mesh? What other functions are available in the engine at runtime to produce a simplified mesh? Something like LOD functions?

I apologize as I’ve seen similar questions, but I haven’t seen any direct answers.
[/]

I have this on any generated physics components that I have in its constructor.


	VoxelComponent->SetSimulatePhysics(true);
	VoxelComponent->SetCollisionObjectType(ECollisionChannel::ECC_PhysicsBody);
	VoxelComponent->SetCollisionProfileName(TEXT("PhysicsActor"));
	VoxelComponent->SetCollisionResponseToAllChannels(ECR_Block);
	VoxelComponent->SetEnableGravity(true);
	this->SetActorEnableCollision(true);

I have the ProceduralMeshComponent and ProceduralLatheActor as GIT cloned from UE4ProceduralMesh. I’ve added this code into the constructor for AProceduralLatheActor:



	// turn on physics
	this->pMesh->SetSimulatePhysics(true);
	this->pMesh->SetEnableGravity(true);
	this->pMesh->SetCollisionObjectType(ECollisionChannel::ECC_PhysicsBody);
	this->pMesh->SetCollisionProfileName(TEXT("PhysicsActor"));
	this->pMesh->SetCollisionResponseToAllChannels(ECR_Block);
	this->SetActorEnableCollision(true);


I have a blueprint that spawns the lathe high above and just in front of the initial character position. When I run the game, it still just falls through the floor. I can run into the lathe with the character and it bounces off through a wall or through the floor.

I have to be missing something. Why is collision behaving differently from the character and the floor and walls (which are defaults from the c++ first-person template)?

And is this PhysX warning anything to worry about:


[2015.03.07-22.35.24:606][976]LogPhysics:Warning: PHYSX: ..\..\PhysX\src\NpShape.cpp (657) 4 : NpShape::setFlag(s): triangle mesh, heightfield and plane shapes can only be simulation shapes if part of a PxRigidStatic!

[=ScottMG;240608]
And is this PhysX warning anything to worry about:


[2015.03.07-22.35.24:606][976]LogPhysics:Warning: PHYSX: ..\..\PhysX\src\NpShape.cpp (657) 4 : NpShape::setFlag(s): triangle mesh, heightfield and plane shapes can only be simulation shapes if part of a PxRigidStatic!

[/]

Does your terrain actually collide with physics objects? It also needs the channel set.

[]
Does your terrain actually collide with physics objects? It also needs the channel set.
[/]

Everything on my level except the lathe is exactly as generated by the 1st person c++ template (UE 4.7.2). There are several blocks in the room that have physics enabled; they seem to collide properly and never fall through the floor or walls.

Perhaps you could point me to the UE source I could step through to get an idea of what’s going on?

PhysX Mesh Creation

When I run the code from visual the function UProceduralMeshComponent::GetPhysicsTriMeshData is never called. I think this might be part of the issue. If you look at the code inside UBodySetup::GetCookedData you’ll see this:



#if WITH_EDITOR
	GetDerivedDataCacheRef().GetSynchronous(DerivedPhysXData, OutData);
#elif WITH_RUNTIME_PHYSICS_COOKING
	DerivedPhysXData->Build(OutData);
#endif


DerivedPhysXData->Build() is where the code would have called my GetPhysicsTriMeshData method, but I’m running with the editor. If I try any of the build configurations without the editor I get an error about requiring cooked data on startup.

So a couple of questions:

A) In editor builds, where is this cached PhysX data coming from?
B) How do I configure a non-editor build to run with uncooked physics? (Clearly it’s worth testing non-editor builds because there are compile-time differences.)

Procedural Mesh Generation/Dynamic/PhysX

After a bunch of debugging through the engine I’ve come to a simple conclusion:

Moveable (Dynamic/Physics) actors cannot use meshes for collision. They must use spheres, boxes, sphyls (I assume that’s a capsule) or (convex decomposition meshes?).


AddSpheresToRigidActor(PDestActor, RelativeTM, MinScale, MinScaleAbs, NewShapes);
AddBoxesToRigidActor(PDestActor, RelativeTM, Scale3D, Scale3DAbs, NewShapes);
AddSphylsToRigidActor(PDestActor, RelativeTM, Scale3D, Scale3DAbs, NewShapes);
AddConvexElemsToRigidActor(PDestActor, RelativeTM, Scale3D, Scale3DAbs, NewShapes);

It looks to me like this is a PhysX library limitation, not UE4. (The warning I cited above comes from calling PxShape::setFlag(eSIMULATION_SHAPE, true)).

This leads me back to another question: Is the code to create a convex decomposition mesh available at runtime? Anyone have an example?

One more update. In UProceduralMeshComponent::UpdateBodySetup() I changed to using CTF_UseSimpleAsComplex instead of CTF_UseComplexAsSimple. I then added a basic bounding box and the collision and physics work now.


void UProceduralMeshComponent::UpdateBodySetup()
{
	if (ModelBodySetup == NULL)
	{
		ModelBodySetup = ConstructObject<UBodySetup>(UBodySetup::StaticClass(), this);
		ModelBodySetup->CollisionTraceFlag = CTF_UseSimpleAsComplex;
		ModelBodySetup->bMeshCollideAll = true;

		FVector min, max;
		min.X = min.Y = min.Z = max.X = max.Y = max.Z = 0.0f;
	
		for (auto tri : this->ProceduralMeshTris)
		{
			GetMinMaxValue(tri, min, max);
		}

		FKBoxElem box;
		box.Center.X = box.Center.Y = box.Center.Z;
		box.X = max.X - min.X;
		box.Y = max.Y - min.Y;
		box.Z = max.Z - min.Z;

		ModelBodySetup->AggGeom.BoxElems.Add(box);
	}
}

I’d still like to know how to automatically generate some sort of convex decomposition.

Not sure what u mean by convex decomposition. But here is a snippet of my runtime collision generation for convex shapes:




FKConvexElem& ConvexElem = *new( BodySetup->AggGeom.ConvexElems ) FKConvexElem( );
CreateConvexElement( ConvexElem, ConvexShape->Vertices, LocalTransform );

CreateConvexElement( FKConvexElem& ConvexElem, TArray<FVector4>& Vertices, FMatrix LocalTransform )
{
	for( int32 i = 0; i < Vertices.Num( ); i++ )
	{
		ConvexElem.VertexData.Add( Vertices i ] );
	}

	ConvexElem.UpdateElemBox( );
	ConvexElem.SetTransform( FTransform( LocalTransform ) );
}


Not very exciting, but it does the job, creating a convex collision that is dynamically generated at runtime.

[=ScottMG;240912]

I’d still like to know how to automatically generate some sort of convex decomposition.
[/]

Oh yeah, i’m sorry I forgot all about the Collision Elements in physics objects, I could have saved you a lot of time. Galaxy man is correct though, for a naive convex collision just pass your vertice list to a FKConvexElem structure and add it to the collision elements. There are lots of ways to simplify meshes to reduce the collision mesh down but the one that UE4 has built in right now (Simplygon) requires a license I think.

I’m using this for the convex elem, but I don’t have to scale my mesh any with what I’m doing either.


				FKConvexElem el;

				for (int i = 0; i < VoxelMeshVerticesMain.Num(); i++)
				{
					el.VertexData.Add(VoxelMeshVerticesMain*.Position);
				}
				ModelBodySetup->AggGeom.ConvexElems.Add(el);

I would like to Thank who has contributed to this thread. It has been really helpful.

Is there a good way in the editor to check the memory usage of the ProceduralMeshActor instances, and the mesh that is generated? I am not seeing anything in the Statistics window. My C++ skills are not what they should be, and I need to make sure that I am not breaking anything with the changes that I make.

Hi all, I made a procedural terrain using an algorithm square

Then I tried smoothed as DayOfWar did in this post
https://forums.unrealengine.com/showthread.php?1552-Generate-Procedural-Mesh&p=55809&viewfull=1#post55809

But how to fix the shadows? may have some other way to smooth?



All my vertices have the color “static const FColor White(255, 255, 255, 50);”
Despite alpha value = 50, my triangles are opaque white.

Does anyone know how to draw transparent procedural meshes?

[=YuZ;244169]
All my vertices have the color “static const FColor White(255, 255, 255, 50);”
Despite alpha value = 50, my triangles are opaque white.

Does anyone know how to draw transparent procedural meshes?
[/]

Is the Blend Mode in your material set to be Translucent?

[=Syntopia;244066]
But how to fix the shadows? may have some other way to smooth?
[/]

What are you trying to “fix”? It isn’t obvious by looking at your screenshots. I don’t know what we’re looking at in each of the six images.

[=sinoth;244224]
Is the Blend Mode in your material set to be Translucent?
[/]

You’re right. I had to connect the opacity input with a parameter < 1.0 in the editor to make it transparent

[=sinoth;244229]
What are you trying to “fix”? It isn’t obvious by looking at your screenshots. I don’t know what we’re looking at in each of the six images.
[/]

I did smoothing right?
Terrain built from triangles each of which casts a shadow can this do anything? In general, how to improve the view of terrain to the natural as if I was doing from the height map? I am a beginner with UE.

my landscape and world machine without strange shadows
need to almost flat on the kind of surface do not cast shadows, and the shadow was not so black
sorry if the questions are obvious to you

Well, adding skybox shadows look more less fine, but now the problem with the material when I smoothing landscape material is also smoothed and lines appear around the edges. What advise?

And another question someone compiled this for android ? Here is the error of the assembly. Compile clean project from other projects compile and working fine.


C:\Users\Vadim\Documents\Unreal Projects\UE4ProceduralMesh-master\Source\ProceduralMesh\ProceduralMeshComponent.cpp(456,18) :  error: no member named 
'InvalidatePhysicsData' in 'UBodySetup' MainFrameActions: Packaging (Android (ETC1)): UnrealBuildTool: ModelBodySetup->InvalidatePhysicsData();