I'm using the extrusion routine in the Unity3D procedural examples. I have a path of points along which I am extruding a "tube" based on a circle profile.
I get these ugly "turnovers" (pictures below) that I reckon are a result of this section of the extrusion code:
if (sections.length < 2) return;
var worldToLocal = transform.worldToLocalMatrix;
var finalSections = new Matrix4x4[sections.length];
var previousRotation : Quaternion;
for (var i=0;i<sections.length;i++)
{
if (autoCalculateOrientation)
{
if (i == 0)
{
var direction = sections[0].point - sections[1].point;
var rotation = Quaternion.LookRotation(direction, Vector3.up);
previousRotation = rotation;
finalSections _= worldToLocal * Matrix4x4.TRS(newPosition, rotation, Vector3.one);_
*}*
*else if (i != sections.length - 1)*
*{*
_direction = sections*.point - sections[i+1].point;*_
_*rotation = Quaternion.LookRotation(direction, Vector3.up);*_
_*if (Quaternion.Angle (previousRotation, rotation) > 20)*_
_*rotation = Quaternion.Slerp(previousRotation, rotation, 0.5);*_
_*previousRotation = rotation;*_
<em><em>finalSections _= worldToLocal * Matrix4x4.TRS(sections*.point, rotation, Vector3.one);*_</em></em>
<em><em>_*}*_</em></em>
<em><em><em>_else finalSections *= finalSections[i-1];*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*else*_</em></em></em>
<em><em><em>_*{*_</em></em></em>
<em><em><em>_*if (i == 0)*_</em></em></em>
<em><em><em>_*{*_</em></em></em>
<em><em><em><em>_finalSections *= Matrix4x4.identity;*_</em></em></em></em>
<em><em><em><em>_*}*_</em></em></em></em>
<em><em><em><em><em><em>else finalSections _= worldToLocal * sections*.matrix;*_</em></em></em></em></em></em>
<em><em><em><em><em><em>_*}*_</em></em></em></em></em></em>
<em><em><em><em><em><em>_*}*_</em></em></em></em></em></em>
<em><em><em><em><em><em>_*```*_</em></em></em></em></em></em>
<em><em><em><em><em><em>_*<p><img src="http://img138.imageshack.us/img138/8603/uglyturnover.png" alt="alt text"></p>*_</em></em></em></em></em></em>
<em><em><em><em><em><em>_*<p><img src="http://img231.imageshack.us/img231/4564/uglyturnover02.png" alt="alt text"></p>*_</em></em></em></em></em></em>
<em><em><em><em><em><em>_*<p>I'm wondering if there's a way to prevent these turnovers. Possibly reverse the rotation specified by the Quaternion? I've tried changing the parameter of the quaternion - vector.right, vector.up, vector.forward, etc. That doesn't correct anything.</p>*_</em></em></em></em></em></em>
<em><em><em><em><em><em>_*<p>Thanks for any suggestions or corrections!</p>*_</em></em></em></em></em></em>