public void OnSceneGUI()
    {
        MegaLoftLayerMultiMatComplex layer = (MegaLoftLayerMultiMatComplex)target;
        MegaShapeLoft loft = layer.gameObject.GetComponent <MegaShapeLoft>();

        if (loft == null)
        {
            return;
        }

        if (layer.layerPath == null)
        {
            return;
        }

        if (!layer.showsections)
        {
            return;
        }

        MegaSpline pathspline = layer.layerPath.splines[layer.curve];

        Matrix4x4 pathtm = Matrix4x4.identity;

        //if ( layer.SnapToPath )
        //	pathtm = layer.layerPath.transform.localToWorldMatrix;

        Matrix4x4 twisttm = Matrix4x4.identity;
        Matrix4x4 tm;

        float offx = 0.0f;
        float offy = 0.0f;
        float offz = 0.0f;

        Vector3 lastup = locup;

        for (int i = 1; i < layer.loftsections.Count - 1; i++)
        {
            MegaLoftSection section = layer.loftsections[i];

            float alpha = section.alpha;

            if (layer.useOffsetX)
            {
                offx = layer.offsetCrvX.Evaluate(alpha);
            }

            if (layer.useOffsetY)
            {
                offy = layer.offsetCrvY.Evaluate(alpha);
            }

            if (layer.useOffsetZ)
            {
                offz += layer.offsetCrvZ.Evaluate(alpha);
            }

            //if ( layer.useTwistCrv )
            //{
            //	float twist = layer.twistCrv.Evaluate(alpha);
            //	MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * twist);
            //	tm = pathtm * layer.GetDeformMat(pathspline, alpha, layer.layerPath.normalizedInterp) * twisttm;
            //}
            //else
            //	tm = pathtm * layer.GetDeformMat(pathspline, alpha, layer.layerPath.normalizedInterp);

            if (layer.useTwistCrv)
            {
                float twist = layer.twistCrv.Evaluate(section.alpha);
                float tw1   = layer.layerPath.splines[layer.curve].GetTwist(section.alpha);
                MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1));
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], section.alpha, layer.layerPath.normalizedInterp) * twisttm;
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(layer.layerPath.splines[layer.curve], section.alpha, layer.layerPath.normalizedInterp, ref lastup) * twisttm;
                }
            }
            else
            {
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], section.alpha, layer.layerPath.normalizedInterp);
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(layer.layerPath.splines[layer.curve], section.alpha, layer.layerPath.normalizedInterp, ref lastup);
                }
            }


            //Debug.Log("section meshes " + section.meshsections.Count);
            //Debug.Log("verts " + section.meshsections[0].cverts.Count);
            Vector3 p = section.meshsections[0].cverts[0];
            //if ( layer.useScaleXCrv )
            //	p.x *= layer.scaleCrvX.Evaluate(alpha);

            //if ( layer.useScaleYCrv )
            //	p.y *= layer.scaleCrvY.Evaluate(alpha);

            p.x += offx;
            p.y += offy;
            p.z += offz;

            Vector3 tp = p;
            p = tm.MultiplyPoint3x4(p);

            p += layer.offset;

            Matrix4x4 tantm = pathtm * layer.GetDeformMat(pathspline, alpha + 0.01f, layer.layerPath.normalizedInterp);
            Vector3   tan   = tantm.MultiplyPoint3x4(tp);
            tan += layer.offset;

            tan = (tan - p).normalized;

            MegaMeshSection ms = section.meshsections[section.meshsections.Count - 1];
            Vector3         p1 = ms.cverts[ms.cverts.Count - 1];
            //if ( layer.useScaleXCrv )
            //	p1.x *= layer.scaleCrvX.Evaluate(alpha);

            //if ( layer.useScaleYCrv )
            //	p1.y *= layer.scaleCrvY.Evaluate(alpha);

            p1.x += offx;
            p1.y += offy;
            p1.z += offz;

            tp = p1;
            p1 = tm.MultiplyPoint3x4(p1);

            p1           += layer.offset;
            Handles.color = Color.green;
            p             = loft.transform.TransformPoint(p);
            //Vector3 pn = Handles.Slider(p, tan, layer.handlesize, Handles.SphereCap, 0.0f);
            Vector3 pn = Slider(p, tan, layer.handlesize);
            pn = pn - p;
            float delta = pn.magnitude;

            if (Vector3.Dot(tan, pn) < 0.0f)
            {
                delta = -delta;
            }

            section.alpha += delta * 0.0005f;

            float al = section.alpha;                   // + delta * 0.0005f;

            if (al != layer.loftsections[i].alpha)
            {
                if (i > 0)
                {
                    if (al < layer.loftsections[i - 1].alpha)
                    {
                        al = layer.loftsections[i - 1].alpha;
                    }
                }

                if (i < layer.loftsections.Count - 1)
                {
                    if (al > layer.loftsections[i + 1].alpha)
                    {
                        al = layer.loftsections[i + 1].alpha;
                    }
                }

                layer.loftsections[i].alpha = al;
            }

            if (delta != 0.0f)
            {
                GUI.changed  = true;
                loft.rebuild = true;
                EditorUtility.SetDirty(target);
            }

            tan  = tantm.MultiplyPoint3x4(tp);
            tan += layer.offset;
            tan  = (tan - p1).normalized;

            p1 = loft.transform.TransformPoint(p1);

            //pn = Handles.Slider(p1, tan, layer.handlesize, Handles.SphereCap, 0.0f);
            pn = Slider(p1, tan, layer.handlesize);

            pn = pn - p1;

            delta = pn.magnitude;               //Vector3.Distance(p, pn);

            if (Vector3.Dot(tan, pn) < 0.0f)
            {
                delta = -delta;
            }

            al = section.alpha + delta * 0.0005f;

            if (al != layer.loftsections[i].alpha)
            {
                if (i > 0)
                {
                    if (al < layer.loftsections[i - 1].alpha)
                    {
                        al = layer.loftsections[i - 1].alpha;
                    }
                }

                if (i < layer.loftsections.Count - 1)
                {
                    if (al > layer.loftsections[i + 1].alpha)
                    {
                        al = layer.loftsections[i + 1].alpha;
                    }
                }

                layer.loftsections[i].alpha = al;
            }

            if (delta != 0.0f)
            {
                GUI.changed  = true;
                loft.rebuild = true;
                EditorUtility.SetDirty(target);
            }
        }

        if (layer.loftsections.Count > 0)
        {
            if (layer.loftsections[0].alpha != 0.0f)
            {
                layer.loftsections[0].alpha = 0.0f;
            }

            for (int i = 1; i < layer.loftsections.Count - 1; i++)
            {
                if (layer.loftsections[i].alpha <= layer.loftsections[i - 1].alpha)
                {
                    layer.loftsections[i - 1].alpha = layer.loftsections[i].alpha;
                }

                if (layer.loftsections[i].alpha >= layer.loftsections[i + 1].alpha)
                {
                    layer.loftsections[i].alpha = layer.loftsections[i + 1].alpha;
                }
            }

            if (layer.loftsections[layer.loftsections.Count - 1].alpha != 1.0f)
            {
                layer.loftsections[layer.loftsections.Count - 1].alpha = 1.0f;
            }
        }
    }
    static void DrawPath(MegaLoftLayerMultiMatComplex layer)
    {
        MegaShapeLoft loft = layer.gameObject.GetComponent <MegaShapeLoft>();

        if (loft == null)
        {
            return;
        }

        if (layer.layerPath == null)
        {
            return;
        }

        if (layer.loftsections == null || layer.loftsections.Count < 2)
        {
            return;
        }

        // Needs changing
        for (int i = 0; i < layer.loftsections.Count; i++)
        {
            if (layer.loftsections[i].meshsections == null || layer.loftsections[i].meshsections.Count == 0)
            {
                return;
            }
        }

        MegaSpline pathspline = layer.layerPath.splines[layer.curve];

        Matrix4x4 pathtm = Matrix4x4.identity;

        //if ( layer.SnapToPath )
        //	pathtm = layer.layerPath.transform.localToWorldMatrix;

        Color col = Gizmos.color;

        Matrix4x4 twisttm = Matrix4x4.identity;
        Matrix4x4 tm;

        Vector3 lastup = locup;

        for (int i = 0; i < layer.loftsections.Count; i++)
        {
            MegaLoftSection section = layer.loftsections[i];

            //if ( layer.useTwistCrv )
            //{
            //	float twist = layer.twistCrv.Evaluate(section.alpha);
            //	MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * twist);
            //	tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp) * twisttm;	//loft.);
            //}
            //else
            //	tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp);	//loft.);

            if (layer.useTwistCrv)
            {
                float twist = layer.twistCrv.Evaluate(section.alpha);
                float tw1   = pathspline.GetTwist(section.alpha);
                MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1));
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp) * twisttm;
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup) * twisttm;
                }
            }
            else
            {
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp);
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup);
                }
            }

            Vector3 mp1 = Vector3.zero;
            Vector3 mp2 = Vector3.zero;

            for (int m = 0; m < section.meshsections.Count; m++)
            {
                MegaMeshSection ms = section.meshsections[m];
                Vector3         p1 = ms.cverts[0];

                float offx = 0.0f;
                float offy = 0.0f;
                float offz = 0.0f;
                float sclx = 1.0f;
                float scly = 1.0f;

                //if ( layer.useScaleXCrv )
                //	p1.x *= layer.scaleCrvX.Evaluate(section.alpha);

                //if ( layer.useScaleYCrv )
                //	p1.y *= layer.scaleCrvY.Evaluate(section.alpha);

                if (layer.useOffsetX)
                {
                    offx = layer.offsetCrvX.Evaluate(section.alpha);
                }

                if (layer.useOffsetY)
                {
                    offy = layer.offsetCrvY.Evaluate(section.alpha);
                }

                if (layer.useOffsetZ)
                {
                    offz = layer.offsetCrvZ.Evaluate(section.alpha);
                }

                //if ( layer.useScaleXCrv )
                //	sclx = layer.scaleCrvX.Evaluate(section.alpha);

                //if ( layer.useScaleYCrv )
                //	scly = layer.scaleCrvY.Evaluate(section.alpha);

                p1  = tm.MultiplyPoint3x4(p1);
                p1 += layer.offset;

                Gizmos.color = seccol;                  //Color.red;
                //Vector3 mid = Vector3.zero;

                if (m == 0)
                {
                    mp1 = p1;
                }

                for (int v = 1; v < ms.cverts.Count; v++)
                {
                    Vector3 p = ms.cverts[v];
                    p.x *= sclx;
                    p.y *= scly;

                    p.x += offx;
                    p.y += offy;
                    p.z += offz;

                    p  = tm.MultiplyPoint3x4(p);
                    p += layer.offset;

                    Gizmos.DrawLine(loft.transform.TransformPoint(p1), loft.transform.TransformPoint(p));

                    p1  = p;
                    mp2 = p;
                    //if ( v == ms.cverts.Count / 2 )
                    //mid = p;
                }

                //Vector3 mp1 = section.meshsections[0].cverts[0];
                //Vector3 mp2 = section.meshsections[section.meshsections.Count - 1].cverts[section.meshsections[section.meshsections.Count - 1].cverts.Count - 1];
            }

            Handles.color = Color.white;
            Handles.Label(loft.transform.TransformPoint((mp1 + mp2) * 0.5f), "Cross: " + i);
            Gizmos.color = col;
        }

        // Draw outside edge
        //Vector3 sclc = Vector3.one;
        float lerp = 0.0f;

        // The position stuff here is waht we could use instead of mesh verts
        Vector3 last  = Vector3.zero;
        Vector3 last1 = Vector3.zero;

        for (float alpha = 0.0f; alpha <= 1.0f; alpha += 0.005f)
        {
            //if ( layer.useScaleXCrv )
            //	sclc.x = layer.scaleCrvX.Evaluate(alpha);

            //if ( layer.useScaleYCrv )
            //	sclc.y = layer.scaleCrvY.Evaluate(alpha);

            //if ( layer.useTwistCrv )
            //{
            //	float twist = layer.twistCrv.Evaluate(alpha);
            //	MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * twist);
            //	tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp) * twisttm;	//loft.);
            //}
            //else
            //	tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp);	//loft.);

            if (layer.useTwistCrv)
            {
                float twist = layer.twistCrv.Evaluate(alpha);
                float tw1   = layer.layerPath.splines[layer.curve].GetTwist(alpha);
                MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1));
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp) * twisttm;
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp, ref lastup) * twisttm;
                }
            }
            else
            {
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp);
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp, ref lastup);
                }
            }


            // Need to get the crosssection for the given alpha and the lerp value
            int csect = layer.GetSection(alpha, out lerp);

            lerp = layer.ease.easing(0.0f, 1.0f, lerp);

            MegaLoftSection cs1 = layer.loftsections[csect];
            MegaLoftSection cs2 = layer.loftsections[csect + 1];

            MegaMeshSection ms1 = cs1.meshsections[0];
            MegaMeshSection ms2 = cs2.meshsections[0];

            MegaMeshSection ms3 = cs1.meshsections[cs1.meshsections.Count - 1];
            MegaMeshSection ms4 = cs2.meshsections[cs2.meshsections.Count - 1];

            Vector3 p  = Vector3.Lerp(ms1.cverts[0], ms2.cverts[0], lerp);                                       // * sclc;
            Vector3 p1 = Vector3.Lerp(ms3.cverts[ms3.cverts.Count - 1], ms4.cverts[ms4.cverts.Count - 1], lerp); // * sclc;
            //if ( layer.useScaleXCrv )
            //{
            //	p.x *= sclc.x;
            //	p1.x *= sclc.x;
            //}

            //if ( layer.useScaleYCrv )
            //{
            //	p.y *= sclc.y;
            //	p1.y *= sclc.y;
            //}

            if (layer.useOffsetX)
            {
                p.x  += layer.offsetCrvX.Evaluate(alpha);
                p1.x += layer.offsetCrvX.Evaluate(alpha);
            }

            if (layer.useOffsetY)
            {
                p.y  += layer.offsetCrvY.Evaluate(alpha);
                p1.y += layer.offsetCrvY.Evaluate(alpha);
            }

            if (layer.useOffsetZ)
            {
                p.z  += layer.offsetCrvZ.Evaluate(alpha);
                p1.z += layer.offsetCrvZ.Evaluate(alpha);
            }

            p  = tm.MultiplyPoint3x4(p);
            p += layer.offset;

            p1  = tm.MultiplyPoint3x4(p1);
            p1 += layer.offset;

            if (alpha > 0.0f)
            {
                Gizmos.DrawLine(loft.transform.TransformPoint(last), loft.transform.TransformPoint(p));
                Gizmos.DrawLine(loft.transform.TransformPoint(last1), loft.transform.TransformPoint(p1));
            }

            last  = p;
            last1 = p1;
        }
    }
	static void DrawPath(MegaLoftLayerMultiMatComplex layer)
	{
		MegaShapeLoft loft = layer.gameObject.GetComponent<MegaShapeLoft>();

		if ( loft == null )
			return;

		if ( layer.layerPath == null )
			return;

		if ( layer.loftsections == null || layer.loftsections.Count < 2 )
			return;

		// Needs changing
		for ( int i = 0; i < layer.loftsections.Count; i++ )
		{
			if ( layer.loftsections[i].meshsections == null || layer.loftsections[i].meshsections.Count == 0 )
				return;
		}

		MegaSpline	pathspline = layer.layerPath.splines[layer.curve];

		Matrix4x4 pathtm = Matrix4x4.identity;

		//if ( layer.SnapToPath )
		//	pathtm = layer.layerPath.transform.localToWorldMatrix;

		Color col = Gizmos.color;

		Matrix4x4 twisttm = Matrix4x4.identity;
		Matrix4x4 tm;

		Vector3 lastup = locup;

		for ( int i = 0; i < layer.loftsections.Count; i++ )
		{
			MegaLoftSection section = layer.loftsections[i];

			//if ( layer.useTwistCrv )
			//{
			//	float twist = layer.twistCrv.Evaluate(section.alpha);
			//	MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * twist);
			//	tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp) * twisttm;	//loft.);
			//}
			//else
			//	tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp);	//loft.);

			if ( layer.useTwistCrv )
			{
				float twist = layer.twistCrv.Evaluate(section.alpha);
				float tw1 = pathspline.GetTwist(section.alpha);
				MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1));
				if ( layer.frameMethod == MegaFrameMethod.Old )
					tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp) * twisttm;
				else
					tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup) * twisttm;
			}
			else
			{
				if ( layer.frameMethod == MegaFrameMethod.Old )
					tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp);
				else
					tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup);
			}

			Vector3 mp1 = Vector3.zero;
			Vector3 mp2 = Vector3.zero;

			for ( int m = 0; m < section.meshsections.Count; m++ )
			{
				MegaMeshSection ms = section.meshsections[m];
				Vector3 p1 = ms.cverts[0];

				float offx = 0.0f;
				float offy = 0.0f;
				float offz = 0.0f;
				float sclx = 1.0f;
				float scly = 1.0f;

				//if ( layer.useScaleXCrv )
				//	p1.x *= layer.scaleCrvX.Evaluate(section.alpha);

				//if ( layer.useScaleYCrv )
				//	p1.y *= layer.scaleCrvY.Evaluate(section.alpha);

				if ( layer.useOffsetX )
					offx = layer.offsetCrvX.Evaluate(section.alpha);

				if ( layer.useOffsetY )
					offy = layer.offsetCrvY.Evaluate(section.alpha);

				if ( layer.useOffsetZ )
					offz = layer.offsetCrvZ.Evaluate(section.alpha);

				//if ( layer.useScaleXCrv )
				//	sclx = layer.scaleCrvX.Evaluate(section.alpha);

				//if ( layer.useScaleYCrv )
				//	scly = layer.scaleCrvY.Evaluate(section.alpha);

				p1 = tm.MultiplyPoint3x4(p1);
				p1 += layer.offset;

				Gizmos.color = seccol;	//Color.red;
				//Vector3 mid = Vector3.zero;

				if ( m == 0 )
					mp1 = p1;

				for ( int v = 1; v < ms.cverts.Count; v++ )
				{
					Vector3 p = ms.cverts[v];
					p.x *= sclx;
					p.y *= scly;

					p.x += offx;
					p.y += offy;
					p.z += offz;

					p = tm.MultiplyPoint3x4(p);
					p += layer.offset;

					Gizmos.DrawLine(loft.transform.TransformPoint(p1), loft.transform.TransformPoint(p));

					p1 = p;
					mp2 = p;
					//if ( v == ms.cverts.Count / 2 )
						//mid = p;
				}

				//Vector3 mp1 = section.meshsections[0].cverts[0];
				//Vector3 mp2 = section.meshsections[section.meshsections.Count - 1].cverts[section.meshsections[section.meshsections.Count - 1].cverts.Count - 1];
			}

			Handles.color = Color.white;
			Handles.Label(loft.transform.TransformPoint((mp1 + mp2) * 0.5f), "Cross: " + i);
			Gizmos.color = col;
		}

		// Draw outside edge
		//Vector3 sclc = Vector3.one;
		float lerp = 0.0f;

		// The position stuff here is waht we could use instead of mesh verts
		Vector3 last = Vector3.zero;
		Vector3 last1 = Vector3.zero;

		for ( float alpha = 0.0f; alpha <= 1.0f; alpha += 0.005f )
		{
			//if ( layer.useScaleXCrv )
			//	sclc.x = layer.scaleCrvX.Evaluate(alpha);

			//if ( layer.useScaleYCrv )
			//	sclc.y = layer.scaleCrvY.Evaluate(alpha);

			//if ( layer.useTwistCrv )
			//{
			//	float twist = layer.twistCrv.Evaluate(alpha);
			//	MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * twist);
			//	tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp) * twisttm;	//loft.);
			//}
			//else
			//	tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp);	//loft.);

			if ( layer.useTwistCrv )
			{
				float twist = layer.twistCrv.Evaluate(alpha);
				float tw1 = layer.layerPath.splines[layer.curve].GetTwist(alpha);
				MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1));
				if ( layer.frameMethod == MegaFrameMethod.Old )
					tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp) * twisttm;
				else
					tm = pathtm * layer.GetDeformMatNewMethod(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp, ref lastup) * twisttm;
			}
			else
			{
				if ( layer.frameMethod == MegaFrameMethod.Old )
					tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp);
				else
					tm = pathtm * layer.GetDeformMatNewMethod(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp, ref lastup);
			}


			// Need to get the crosssection for the given alpha and the lerp value
			int csect = layer.GetSection(alpha, out lerp);

			lerp = layer.ease.easing(0.0f, 1.0f, lerp);

			MegaLoftSection cs1 = layer.loftsections[csect];
			MegaLoftSection cs2 = layer.loftsections[csect + 1];

			MegaMeshSection ms1 = cs1.meshsections[0];
			MegaMeshSection ms2 = cs2.meshsections[0];

			MegaMeshSection ms3 = cs1.meshsections[cs1.meshsections.Count - 1];
			MegaMeshSection ms4 = cs2.meshsections[cs2.meshsections.Count - 1];

			Vector3 p = Vector3.Lerp(ms1.cverts[0], ms2.cverts[0], lerp);	// * sclc;
			Vector3 p1 = Vector3.Lerp(ms3.cverts[ms3.cverts.Count - 1], ms4.cverts[ms4.cverts.Count - 1], lerp);	// * sclc;
			//if ( layer.useScaleXCrv )
			//{
			//	p.x *= sclc.x;
			//	p1.x *= sclc.x;
			//}

			//if ( layer.useScaleYCrv )
			//{
			//	p.y *= sclc.y;
			//	p1.y *= sclc.y;
			//}

			if ( layer.useOffsetX )
			{
				p.x += layer.offsetCrvX.Evaluate(alpha);
				p1.x += layer.offsetCrvX.Evaluate(alpha);
			}

			if ( layer.useOffsetY )
			{
				p.y += layer.offsetCrvY.Evaluate(alpha);
				p1.y += layer.offsetCrvY.Evaluate(alpha);
			}

			if ( layer.useOffsetZ )
			{
				p.z += layer.offsetCrvZ.Evaluate(alpha);
				p1.z += layer.offsetCrvZ.Evaluate(alpha);
			}

			p = tm.MultiplyPoint3x4(p);
			p += layer.offset;

			p1 = tm.MultiplyPoint3x4(p1);
			p1 += layer.offset;

			if ( alpha > 0.0f )
			{
				Gizmos.DrawLine(loft.transform.TransformPoint(last), loft.transform.TransformPoint(p));
				Gizmos.DrawLine(loft.transform.TransformPoint(last1), loft.transform.TransformPoint(p1));
			}

			last = p;
			last1 = p1;
		}
	}