Skew an imported mesh?

Using Unity free, I have a situation where I want to conform a mesh to a slope…which would be skewing the y coordinates. I -don’t- want to rotate it so that it fits the normal of the slope. Picture a segment of a brick wall…if you wanted to be able to dynamically place these on a terrain, it would need to skew, rotating it would leave weird gaps at the intersections.

The only way I can think to do this with an imported mesh would be to create a new mesh from the original, and for each y coordinate in its vertices, translate the y coordinate value appropriately.

Anyone know of a better way? I’m assuming I can easily create a new mesh from an imported one…haven’t tried it yet, though :slight_smile:

You could probably construct a skew matrix. Google what that is, and see http://unity3d.com/support/documentation/ScriptReference/Matrix4x4.html

If you need it to skew other-than around 0,0,0 you can first move it to 0,0,0, skew it, then move it back (and you do this by concatenating the matrices, not making calls to MoveTo or Translate, of course)

Well, i guess the easiest way to accomplish that is to modify a copied Mesh with a custom skew-matrix. Something like this:

1 0 0 0
S 1 0 0
0 0 1 0
0 0 0 1

where S is the tangens of the desired angle. This will skew coordinates along the x axis. So when the x coordinate increases it also increases the y coordinate. Íf S is 1.0f it would exactly by 45°.

Instead of the tangens you can of course use a x-y or x-z ratio. If one point is at 0,0,0 and the furthest point is at 100,0,0 which should be skewed upwards to 100,20,0 just do:

S = 20.0f / 100.0f;

Just keep in mind that scheme:

        1 0 0 0 --> x out
        0 1 0 0 --> y out
        0 0 1 0 --> z out
        0 0 0 1 --> w out
x in ___| | | |
y in _____| | |
z in _______| |
w in _________|

Well, it’s just basic matrix-math but a lot get confused with rows and columns since it depends on the multiplication order. However unity only supports this way.
Also keep in mind that the skewing will happen around 0,0,0