Move Vertices / Vector3 Without Transform

This post is just a quick reminder to myself and for anyone else who’s brain seems to freeze when it comes to moving vertices / vector3 positions around in code for whatever reason without using a transform component, in this post i’m not going to write about any of the complexities or inner workings behind the readily available Unity3d Matrix functions, but the code below has proved usefull when writing import functions for 3d mesh/models. I’m sure there are quicker methods and i’d love to hear about them.

The code below takes a Vector3 (position.x,position.y,position.z) and translates, rotates and scales it according to your own input using a matrix (exactly like the Unity3d Transform in the inspector) you could run the code in a loop multiplying a sequence of vector3[] vertices through it and offset your mesh from its original (pivot point)/origin if you so wished. The code is a short example written in c#:-

(more…)

By |February 21st, 2011|Unity 3D|1 Comment

Normal / Bump Mesh Tangent Generation

If you are generating meshes or importing meshes at runtime you may stumble upon the problem of generating tangents for your mesh. Normal / bumped shaders require that tangent plane basis vectors be calculated for each vertex in your mesh to correctly light or effect your mesh in a consistant manner.

I did some digging and found this code on the unity3d forum (unfortunately their was a slight/tiny error on the c# version) so I thought I would post the working version here for reference. I have also added some ammendments which also apparently calculate bi-normals or bit-tangents should you ever find a need. I believe the code may have originated come from here: Lengyel, Eric. “Computing Tangent Space Basis Vectors for an Arbitrary Mesh”. Terathon Software 3D Graphics Library, 2001.

(more…)

By |February 16th, 2011|Unity 3D|3 Comments