Creating Cubes with Jagged Edges

I have a fairly efficient grid generation routine now for a Dungeon Keeper-esq map. In the spirit of that game, I want the wall cubes not to have straight lines. The cubes don’t have to have extremely jagged edges, but just enough to break up the straight lines a bit. Check out the walls in this picture:

alt text

Edit: A Solution:
After getting advice from many people in this thread (especially @flaviusxvii and @Warwick Allison), I finally came up with this result. This will make a cube distort slightly, and every adjacent cube will have a matching edge. This makes the cubes look rough, but still seamless. For a picture, check out the awesome example provided by @flaviusxvii.

To make this work, you will need the Perlin script provided in Unity’s Procedural Examples

function UpdateMesh (myGameObject : Transform){
    var mesh : Mesh = myGameObject.GetComponent(MeshFilter).mesh;
    var vertices : Vector3[] = mesh.vertices;
		
    for (var i : int =0 ; i < mesh.vertexCount ; i++)
    {
		// Distills the vector down into one position-relative number
		var vectorSum : float = (myGameObject.transform.position + vertices*).x +* 

(myGameObject.transform.position + vertices_).y + (myGameObject.transform.position + vertices*).z;*_

* var rawp : float = perlin.Noise(vectorSum, 2, 3);*
_ var p : float = rawp * Mathf.PI * 2f;
var myVector3 : Vector3 = new Vector3(Mathf.Sin(p), Mathf.Cos(p), Mathf.Sin(-p * 47.5454f));_

* // Adjusts the vertices*
vertices += myVector3 * vertices_.y * .1f;
}_

mesh.vertices = vertices;
mesh.RecalculateNormals();
}
The only thing I don’t understand yet is why this doesn’t work to alter planes.

You could use Perlin noise to perturb the vertexes of your level geometry a bit.

2ND EDIT: Ok, I have a better screenshot, there were actually a couple of cubes in the last screenshot that had messed up perturbation because I rotated them. The new version of the UpdateMesh function below fixes that.

EDIT: Ok so I had an early answer but I guess it wasn’t inspirational enough to merit some research, so here’s a simple example. The screenshot is a bunch of cubes that have their mesh perturbed in Start(). It doesn’t matter where they are in the world, they get a nice little jostle that works seamlessly with their neighbors.
![alt text][1]

void UpdateMesh ()
{
    Mesh mesh = GetComponent<MeshFilter>().mesh;
    Vector3[] vertices = mesh.vertices;
    for (int i=0 ; i<mesh.vertexCount ; i++)
    {
        Vector3 offset = SimplexNoise.Get().onUnitSphere(transform.TransformPoint(vertices_)) * 0.05f;_

vertices += transform.InverseTransformDirection(offset);
}
mesh.vertices = vertices;
mesh.RecalculateNormals();
}
SimplexNoise is my noise class (Invented by Ken Perlin). onUnitSphere is overloaded but this one takes a Vector3 and returns a noise Vector3, which I add to the vertex.
_*[1]: http://i.imgur.com/Pj37g.jpg*_

I’m doing something similar right now, but not with dungeon walls, I am working with hex tiles in an outdoor setting.

However, what I have learned can be applied to your project, too.

function UpdateMesh ()
{
	var mesh : Mesh = GetComponent(MeshFilter).mesh;
	var vertices : Vector3[] = mesh.vertices;
        var randomX : float;
        var randomY : float;
        var randomZ : float;
    for (i=0 ; i<mesh.vertexCount ; i++)
    {
        randomX = Random.Range(-1 , 1);
        randomY = Random.Range(-1 , 1);
        randomZ = Random.Range(-1 , 1);
        vertices *= new Vector3(* 

(vertices*.x + randomX),*
(vertices*.y + randomY),*
(vertices*.z + randomZ) );*
}
* mesh.vertices = vertices;*
* mesh.RecalculateNormals();*
}
Make sure that gets run once and only once on each new Wall GameObject, and you’re golden.
You might have to play around with the random values to get the look you are looking for, I don’t know anything about your scale…
Oh, and you will probably want to not manipulate the Y on the bottom of the cubes.
I leave that to you to figure out.
You’ll have to determine the actual vertex numbers to exclude certain ones from the warp.
I did this by making a new scene with only the object I wanted to warp, and making a script similar to the one above that moved one vertex at a time, and Debug.Log’ed the vertex numbers as it was doing it.
I wrote down my vertex numbers and plugged them into the script in my original scene.
The trickiest part of this was that where you have a hard edge (like the edges of the cubes), there are actually two or three verts that will have to move together, or it will create a gap.
When you have verts that meet at a soft edge, the vertex is shared, and you only have to move one…

Quick and dirty: model your walls crookedly. For re-use, ensure that the connecting points are always in the same position - that way you can have them zig-zag all you want and still know that they’ll connect.