How do i Achieve mesh Extrusion?

Hello i’m having a lot of trouble with mesh extrusion, iv’e gone to the mesh API and the procedural geometry tutorial with Joachim Holmér, but i still do not understand it so if any of you guys know any good e-books or tutorials on achieving Extrusion please tell me.

2 Answers

2

Have you tried studying the source code of Unity Asset Store - The Best Assets for Game Making ?

Yes i have had a look at that but i don't understand it, i'm looking for tutorials so i can understand it.

Here you have a simple example, this code is added to a Unity plane primitive mesh:

srcMesh = (GetComponent < MeshFilter> ()).sharedMesh;
		 precomEdges = MeshExtrusion.BuildManifoldEdges (srcMesh);
		
		Matrix4x4[] sections = new Matrix4x4[3];
		
		sections[0]=transform.worldToLocalMatrix* Matrix4x4.TRS(transform.position,Quaternion.identity,Vector3.one);
		sections[1]=transform.worldToLocalMatrix*Matrix4x4.TRS (transform.position+4f*Vector3.up, Quaternion.identity, Vector3.one);
		sections[2]=transform.worldToLocalMatrix*Matrix4x4.TRS (transform.position+6f*Vector3.up, Quaternion.identity, Vector3.one);
		
		MeshExtrusion.ExtrudeMesh (srcMesh, (GetComponent < MeshFilter> ()).mesh, sections, precomEdges, false);
	
This code simply elevates the plane (creates a box), with two sections. You have use the transformation matrix (Matrix4x4) to tell the script where your sections end, so first you get a transformation matrix to convert your world position to local coordinates (transform.worldToLocalMatrix), then you apply (by multiplying) another transformation  to tell where you want to end up from your local point of view (Matrix4x4.TRS (transform.position+4f*Vector3.up, Quaternion.identity, Vector3.one)).