예제 #1
0
    public Quaternion GetRot(MegaSpline spline, float alpha, bool interp, ref Vector3 lastup)
    {
        int k = -1;

        Vector3 ps;
        Vector3 ps1;
        Vector3 ps2;

        if (spline.closed)
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
            ps    = spline.Interpolate(alpha, interp, ref k);
        }
        else
        {
            ps = spline.InterpCurve3D(alpha, interp, ref k);
        }

        alpha += tangentDist / target.GetCurveLength(curve);            //0.01f;
        if (spline.closed)
        {
            alpha = alpha % 1.0f;

            ps1 = spline.Interpolate(alpha, interp, ref k);
        }
        else
        {
            ps1 = spline.InterpCurve3D(alpha, interp, ref k);
        }

        ps1.x = ps2.x = ps1.x - ps.x;
        ps1.y = ps2.y = ps1.y - ps.y;
        ps1.z = ps2.z = ps1.z - ps.z;
        //ps1.x -= ps.x;
        //ps1.y -= ps.y;	// * align;
        //ps1.z -= ps.z;

        //Debug.Log("lupin: " + lastup);
        //wtm.SetTRS(ps, Quaternion.LookRotation(ps1, up), Vector3.one);
        //MegaMatrix.SetTR(ref wtm, ps, Quaternion.LookRotation(ps1, lastup));

        Quaternion rot = Quaternion.LookRotation(ps1, lastup);

        // calc new up value
        ps2 = ps2.normalized;
        Vector3 cross = Vector3.Cross(ps2, lastup);

        lastup = Vector3.Cross(cross, ps2);

        //Debug.Log("lupout: " + lastup);
        return(rot);
    }
예제 #2
0
    // Find nearest point
    public Vector3 FindNearestPoint(Vector3 p, int iterations, ref float alpha)
    {
        int kt = 0;

        Find(p);
        MegaSpline spl = shape.splines[curve];

        for (int j = 0; j < itercount; j++)
        {
            float num6 = 0.01f * Mathf.Pow(10.0f, -((float)j));
            float num7 = num6 * 0.1f;
            for (float k = Mathf.Clamp01(num2 - num6); k <= Mathf.Clamp01(num2 + num6); k += num7)
            {
                Vector3 vector2 = spl.Interpolate(k, true, ref kt) - p;
                float   num9    = vector2.sqrMagnitude;

                if (positiveInfinity > num9)
                {
                    positiveInfinity = num9;
                    num2             = k;
                }
            }
        }

        alpha = num2;
        return(shape.InterpCurve3D(curve, num2, true));
    }
예제 #3
0
    public Matrix4x4 GetDeformMatNew(MegaSpline spline, float alpha, bool interp, float align)
    {
        int k = -1;

        Vector3 ps;
        Vector3 ps1;

        if (spline.closed)
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
            ps    = spline.Interpolate(alpha, interp, ref k);
        }
        else
        {
            ps = spline.InterpCurve3D(alpha, interp, ref k);
        }

        alpha += tangent;               //0.01f;
        if (spline.closed)
        {
            alpha = alpha % 1.0f;

            ps1 = spline.Interpolate(alpha, interp, ref k);
        }
        else
        {
            ps1 = spline.InterpCurve3D(alpha, interp, ref k);
        }

        ps1.x -= ps.x;
        ps1.y -= ps.y;          // * align;
        ps1.z -= ps.z;

        ps1.y *= align;
        //wtm.SetTRS(ps, Quaternion.LookRotation(ps1, up), Vector3.one);

        Quaternion rot = lastrot;

        if (ps1 != Vector3.zero)
        {
            rot = Quaternion.LookRotation(ps1, up);
        }

        MegaMatrix.SetTR(ref wtm, ps, rot);
        lastrot = rot;
        return(wtm);
    }
예제 #4
0
    public bool UseDistance = true; // use distance method

    #endregion Fields

    #region Methods

    public Quaternion GetRot(MegaSpline spline, float alpha, bool interp, ref Vector3 lastup)
    {
        int k = -1;

        Vector3 ps;
        Vector3 ps1;
        Vector3 ps2;

        if ( spline.closed )
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
            ps = spline.Interpolate(alpha, interp, ref k);
        }
        else
            ps = spline.InterpCurve3D(alpha, interp, ref k);

        alpha += tangentDist / target.GetCurveLength(curve);	//0.01f;
        if ( spline.closed )
        {
            alpha = alpha % 1.0f;

            ps1 = spline.Interpolate(alpha, interp, ref k);
        }
        else
            ps1 = spline.InterpCurve3D(alpha, interp, ref k);

        ps1.x = ps2.x = ps1.x - ps.x;
        ps1.y = ps2.y = ps1.y - ps.y;
        ps1.z = ps2.z = ps1.z - ps.z;
        //ps1.x -= ps.x;
        //ps1.y -= ps.y;	// * align;
        //ps1.z -= ps.z;

        //Debug.Log("lupin: " + lastup);
        //wtm.SetTRS(ps, Quaternion.LookRotation(ps1, up), Vector3.one);
        //MegaMatrix.SetTR(ref wtm, ps, Quaternion.LookRotation(ps1, lastup));

        Quaternion rot = Quaternion.LookRotation(ps1, lastup);

        // calc new up value
        ps2 = ps2.normalized;
        Vector3 cross = Vector3.Cross(ps2, lastup);
        lastup = Vector3.Cross(cross, ps2);

        //Debug.Log("lupout: " + lastup);
        return rot;
    }
예제 #5
0
    // Should be a spline method
    public Matrix4x4 GetDeformMat(MegaSpline spline, float alpha, bool interp)
    {
        int k = -1;

        Vector3 ps;
        Vector3 ps1;

        if (spline.closed)
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
            ps    = spline.Interpolate(alpha, interp, ref k);
        }
        else
        {
            ps = spline.InterpCurve3D(alpha, interp, ref k);
        }

        alpha += tangent;               //0.01f;
        if (spline.closed)
        {
            alpha = alpha % 1.0f;

            ps1 = spline.Interpolate(alpha, interp, ref k);
        }
        else
        {
            ps1 = spline.InterpCurve3D(alpha, interp, ref k);
        }

        ps1.x -= ps.x;
        ps1.y  = 0.0f;          //ps.y;
        ps1.z -= ps.z;

        //wtm.SetTRS(ps, Quaternion.LookRotation(ps1, up), Vector3.one);
        MegaMatrix.SetTR(ref wtm, ps, Quaternion.LookRotation(ps1, up));

        return(wtm);
    }
예제 #6
0
    static void DrawGizmos(MegaTracks track, Color modcol1)
    {
        Matrix4x4 RingTM = Matrix4x4.identity;
        Matrix4x4 tm     = track.transform.localToWorldMatrix;

        if (track.shape == null)
        {
            return;
        }

        MegaSpline spl   = track.shape.splines[track.curve];
        float      ldist = 1.0f * 0.1f;

        if (ldist < 0.01f)
        {
            ldist = 0.01f;
        }

        Color modcol = modcol1;

        if (spl.length / ldist > 500.0f)
        {
            ldist = spl.length / 500.0f;
        }

        float ds = spl.length / (spl.length / ldist);

        if (ds > spl.length)
        {
            ds = spl.length;
        }

        int c  = 0;
        int k  = -1;
        int lk = -1;

        Vector3 first = spl.Interpolate(0.0f, true, ref lk);

        RingTM = tm * RingTM;

        for (float dist = ds; dist < spl.length; dist += ds)
        {
            float alpha = dist / spl.length;

            Vector3 pos = spl.Interpolate(alpha, true, ref k);

            if ((c & 1) == 1)
            {
                Gizmos.color = Color.black * modcol;
            }
            else
            {
                Gizmos.color = Color.yellow * modcol;
            }

            if (k != lk)
            {
                for (lk = lk + 1; lk <= k; lk++)
                {
                    Gizmos.DrawLine(RingTM.MultiplyPoint(first), RingTM.MultiplyPoint(spl.knots[lk].p));
                    first = spl.knots[lk].p;
                }
            }

            lk = k;

            Gizmos.DrawLine(RingTM.MultiplyPoint(first), RingTM.MultiplyPoint(pos));

            c++;

            first = pos;
        }

        if ((c & 1) == 1)
        {
            Gizmos.color = Color.blue * modcol;
        }
        else
        {
            Gizmos.color = Color.yellow * modcol;
        }

        Vector3 lastpos;

        if (spl.closed)
        {
            lastpos = spl.Interpolate(0.0f, true, ref k);
        }
        else
        {
            lastpos = spl.Interpolate(1.0f, true, ref k);
        }

        Gizmos.DrawLine(RingTM.MultiplyPoint(first), RingTM.MultiplyPoint(lastpos));
    }
예제 #7
0
    // Keep track of up method

    public Matrix4x4 GetDeformMatNewMethod(MegaSpline spline, float alpha, bool interp, float align, ref Vector3 lastup)
    {
        int k = -1;

        Vector3 ps;
        Vector3 ps1;
        Vector3 ps2;

        if (spline.closed)
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
            ps    = spline.Interpolate(alpha, interp, ref k);
        }
        else
        {
            ps = spline.InterpCurve3D(alpha, interp, ref k);
        }

        alpha += tangent;               //0.01f;
        if (spline.closed)
        {
            alpha = alpha % 1.0f;

            ps1 = spline.Interpolate(alpha, interp, ref k);
        }
        else
        {
            ps1 = spline.InterpCurve3D(alpha, interp, ref k);
        }

        ps1.x = ps2.x = ps1.x - ps.x;
        ps1.y = ps2.y = ps1.y - ps.y;
        ps1.z = ps2.z = ps1.z - ps.z;
        //ps1.x -= ps.x;
        //ps1.y -= ps.y;	// * align;
        //ps1.z -= ps.z;


        ps1.y *= align;


        Quaternion rot = lastrot;

        if (ps1 != Vector3.zero)
        {
            rot = Quaternion.LookRotation(ps1, lastup);
        }

        //wtm.SetTRS(ps, Quaternion.LookRotation(ps1, up), Vector3.one);
        //Debug.Log("lupin: " + lastup);
        MegaMatrix.SetTR(ref wtm, ps, rot);             //Quaternion.LookRotation(ps1, lastup));

        lastrot = rot;

        // calc new up value
        ps2 = ps2.normalized;
        Vector3 cross = Vector3.Cross(ps2, lastup);

        lastup = Vector3.Cross(cross, ps2);

        //Debug.Log("lupout: " + lastup);
        return(wtm);
    }
예제 #8
0
	//public MegaTriangulator(MegaKnot[] points)
	//{
	//	m_points = new List<Vector2>();	//points);
	//
	//}
   
	static public List<int> Triangulate(MegaShape shape, MegaSpline spline, float dist, ref List<Vector3> verts, ref List<Vector2> uvs, ref List<int> indices, Vector3 pivot)
	{
		// Find 
		m_points.Clear();

		List<MegaKnot> knots = spline.knots;

		Vector3 min = knots[0].p;
		Vector3 max = knots[0].p;

		for ( int i = 1; i < knots.Count; i++ )
		{
			Vector3 p1 = knots[i].p;

			if ( p1.x < min.x )	min.x = p1.x;
			if ( p1.y < min.y ) min.y = p1.y;
			if ( p1.z < min.z ) min.z = p1.z;

			if ( p1.x > max.x ) max.x = p1.x;
			if ( p1.y > max.y ) max.y = p1.y;
			if ( p1.z > max.z ) max.z = p1.z;
		}

		Vector3 size = max - min;

		int removeaxis = 0;

		if ( Mathf.Abs(size.x) < Mathf.Abs(size.y) )
		{
			if ( Mathf.Abs(size.x) < Mathf.Abs(size.z) )
				removeaxis = 0;
			else
				removeaxis = 2;
		}
		else
		{
			if ( Mathf.Abs(size.y) < Mathf.Abs(size.z) )
				removeaxis = 1;
			else
				removeaxis = 2;
		}

		Vector3 tp = Vector3.zero;
#if false
		for ( int i = 0; i < knots.Count; i++ )
		{
			for ( int a = 0; a < steps; a ++ )
			{
				float alpha = (float)a / (float)steps;
				Vector3 p = spline.knots[i].Interpolate(alpha, spline.knots[i]);
				switch ( removeaxis )
				{
					case 0:	tp.x = p.y; tp.y = p.z;	break;
					case 1: tp.x = p.x; tp.y = p.z; break;
					case 2: tp.x = p.x; tp.y = p.y; break;
				}
				verts.Add(p);
				m_points.Add(tp);
			}
		}
#endif
		float ds = spline.length / (spline.length / dist);

		if ( ds > spline.length )
			ds = spline.length;

		//int c	= 0;
		int k	= -1;
		//int lk	= -1;

		//Vector3 first = spline.Interpolate(0.0f, shape.normalizedInterp, ref lk);
		Vector3 p = Vector3.zero;

		for ( float dst = 0.0f; dst < spline.length; dst += ds )
		{
			float alpha = dst / spline.length;
			p = spline.Interpolate(alpha, shape.normalizedInterp, ref k) + pivot;

			switch ( removeaxis )
			{
				case 0: tp.x = p.y; tp.y = p.z; break;
				case 1: tp.x = p.x; tp.y = p.z; break;
				case 2: tp.x = p.x; tp.y = p.y; break;
			}
			tp.z = dst;
			verts.Add(p);
			m_points.Add(tp);

			// Dont need this here as can do in post step
			//tp.x = (tp.x - min.x) / size.x;
			//tp.y = (tp.y - min.z) / size.z;
			tp.x = (tp.x - min.x);	// / size.x;
			tp.y = (tp.y - min.z);	// / size.z;
			uvs.Add(tp);
		}

		//if ( spline.closed )
		//	p = spline.Interpolate(0.0f, shape.normalizedInterp, ref k);
		//else
		//	p = spline.Interpolate(1.0f, shape.normalizedInterp, ref k);

		//switch ( removeaxis )
		//{
		//	case 0: tp.x = p.y; tp.y = p.z; break;
		//	case 1: tp.x = p.x; tp.y = p.z; break;
		//	case 2: tp.x = p.x; tp.y = p.y; break;
		//}

		//verts.Add(p);
		//m_points.Add(tp);

		return Triangulate(indices);
	}
예제 #9
0
	static public float veccalc(float angstep)
	{
		if ( lastin == angstep )
			return lastout;

		float totdist;
		float sinfac = Mathf.Sin(angstep);
		float cosfac = Mathf.Cos(angstep);
		float test;
		int ix;
		MegaSpline work = new MegaSpline();
		Vector3 k1 = new Vector3(Mathf.Cos(0.0f), Mathf.Sin(0.0f), 0.0f);
		Vector3 k2 = new Vector3(cosfac, sinfac, 0.0f);

		float hi = 1.5f;
		float lo = 0.0f;
		int count = 200;

		// Loop thru test vectors
	loop:
		work.knots.Clear();
		test = (hi + lo) / 2.0f;
		Vector3 outv = k1 + new Vector3(0.0f, test, 0.0f);
		Vector3 inv = k2 + new Vector3(sinfac * test, -cosfac * test, 0.0f);

		work.AddKnot(k1, k1, outv);
		work.AddKnot(k2, inv, k2);

		totdist = 0.0f;
		int k = 0;
		//totdist = work.CalcLength(10);
		for ( ix = 0; ix < 10; ++ix )
		{
			Vector3 terp = work.Interpolate((float)ix / 10.0f, false, ref k);
			totdist += Mathf.Sqrt(terp.x * terp.x + terp.y * terp.y);
		}

		totdist /= 10.0f;
		count--;

		if ( totdist == 1.0f || count <= 0 )
			goto done;

		if ( totdist > 1.0f )
		{
			hi = test;
			goto loop;
		}
		lo = test;
		goto loop;

	done:
		lastin = angstep;
		lastout = test;
		return test;
	}
예제 #10
0
    static public float veccalc(float angstep)
    {
        if (lastin == angstep)
        {
            return(lastout);
        }

        float      totdist;
        float      sinfac = Mathf.Sin(angstep);
        float      cosfac = Mathf.Cos(angstep);
        float      test;
        int        ix;
        MegaSpline work = new MegaSpline();
        Vector3    k1   = new Vector3(Mathf.Cos(0.0f), Mathf.Sin(0.0f), 0.0f);
        Vector3    k2   = new Vector3(cosfac, sinfac, 0.0f);

        float hi    = 1.5f;
        float lo    = 0.0f;
        int   count = 200;

        // Loop thru test vectors
loop:
        work.knots.Clear();
        test = (hi + lo) / 2.0f;
        Vector3 outv = k1 + new Vector3(0.0f, test, 0.0f);
        Vector3 inv  = k2 + new Vector3(sinfac * test, -cosfac * test, 0.0f);

        work.AddKnot(k1, k1, outv);
        work.AddKnot(k2, inv, k2);

        totdist = 0.0f;
        int k = 0;

        //totdist = work.CalcLength(10);
        for (ix = 0; ix < 10; ++ix)
        {
            Vector3 terp = work.Interpolate((float)ix / 10.0f, false, ref k);
            totdist += Mathf.Sqrt(terp.x * terp.x + terp.y * terp.y);
        }

        totdist /= 10.0f;
        count--;

        if (totdist == 1.0f || count <= 0)
        {
            goto done;
        }

        if (totdist > 1.0f)
        {
            hi = test;
            goto loop;
        }
        lo = test;
        goto loop;

done:
        lastin  = angstep;
        lastout = test;
        return(test);
    }
예제 #11
0
    //public MegaTriangulator(MegaKnot[] points)
    //{
    //	m_points = new List<Vector2>();	//points);
    //
    //}

    static public List <int> Triangulate(MegaShape shape, MegaSpline spline, float dist, ref List <Vector3> verts, ref List <Vector2> uvs, ref List <int> indices, Vector3 pivot)
    {
        // Find
        m_points.Clear();

        List <MegaKnot> knots = spline.knots;

        Vector3 min = knots[0].p;
        Vector3 max = knots[0].p;

        for (int i = 1; i < knots.Count; i++)
        {
            Vector3 p1 = knots[i].p;

            if (p1.x < min.x)
            {
                min.x = p1.x;
            }
            if (p1.y < min.y)
            {
                min.y = p1.y;
            }
            if (p1.z < min.z)
            {
                min.z = p1.z;
            }

            if (p1.x > max.x)
            {
                max.x = p1.x;
            }
            if (p1.y > max.y)
            {
                max.y = p1.y;
            }
            if (p1.z > max.z)
            {
                max.z = p1.z;
            }
        }

        Vector3 size = max - min;

        int removeaxis = 0;

        if (Mathf.Abs(size.x) < Mathf.Abs(size.y))
        {
            if (Mathf.Abs(size.x) < Mathf.Abs(size.z))
            {
                removeaxis = 0;
            }
            else
            {
                removeaxis = 2;
            }
        }
        else
        {
            if (Mathf.Abs(size.y) < Mathf.Abs(size.z))
            {
                removeaxis = 1;
            }
            else
            {
                removeaxis = 2;
            }
        }

        Vector3 tp = Vector3.zero;

#if false
        for (int i = 0; i < knots.Count; i++)
        {
            for (int a = 0; a < steps; a++)
            {
                float   alpha = (float)a / (float)steps;
                Vector3 p     = spline.knots[i].Interpolate(alpha, spline.knots[i]);
                switch (removeaxis)
                {
                case 0: tp.x = p.y; tp.y = p.z; break;

                case 1: tp.x = p.x; tp.y = p.z; break;

                case 2: tp.x = p.x; tp.y = p.y; break;
                }
                verts.Add(p);
                m_points.Add(tp);
            }
        }
#endif
        float ds = spline.length / (spline.length / dist);

        if (ds > spline.length)
        {
            ds = spline.length;
        }

        //int c	= 0;
        int k = -1;
        //int lk	= -1;

        //Vector3 first = spline.Interpolate(0.0f, shape.normalizedInterp, ref lk);
        Vector3 p = Vector3.zero;

        for (float dst = 0.0f; dst < spline.length; dst += ds)
        {
            float alpha = dst / spline.length;
            p = spline.Interpolate(alpha, shape.normalizedInterp, ref k) + pivot;

            switch (removeaxis)
            {
            case 0: tp.x = p.y; tp.y = p.z; break;

            case 1: tp.x = p.x; tp.y = p.z; break;

            case 2: tp.x = p.x; tp.y = p.y; break;
            }
            tp.z = dst;
            verts.Add(p);
            m_points.Add(tp);

            // Dont need this here as can do in post step
            //tp.x = (tp.x - min.x) / size.x;
            //tp.y = (tp.y - min.z) / size.z;
            tp.x = (tp.x - min.x);              // / size.x;
            tp.y = (tp.y - min.z);              // / size.z;
            uvs.Add(tp);
        }

        //if ( spline.closed )
        //	p = spline.Interpolate(0.0f, shape.normalizedInterp, ref k);
        //else
        //	p = spline.Interpolate(1.0f, shape.normalizedInterp, ref k);

        //switch ( removeaxis )
        //{
        //	case 0: tp.x = p.y; tp.y = p.z; break;
        //	case 1: tp.x = p.x; tp.y = p.z; break;
        //	case 2: tp.x = p.x; tp.y = p.y; break;
        //}

        //verts.Add(p);
        //m_points.Add(tp);

        return(Triangulate(indices));
    }
예제 #12
0
    // Keep track of up method
    public Matrix4x4 GetDeformMatNewMethod(MegaSpline spline, float alpha, bool interp, float align, ref Vector3 lastup)
    {
        int k = -1;

        Vector3 ps;
        Vector3 ps1;
        Vector3 ps2;

        if ( spline.closed )
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
            ps = spline.Interpolate(alpha, interp, ref k);
        }
        else
            ps = spline.InterpCurve3D(alpha, interp, ref k);

        alpha += tangent;	//0.01f;
        if ( spline.closed )
        {
            alpha = alpha % 1.0f;

            ps1 = spline.Interpolate(alpha, interp, ref k);
        }
        else
            ps1 = spline.InterpCurve3D(alpha, interp, ref k);

        ps1.x = ps2.x = ps1.x - ps.x;
        ps1.y = ps2.y = ps1.y - ps.y;
        ps1.z = ps2.z = ps1.z - ps.z;
        //ps1.x -= ps.x;
        //ps1.y -= ps.y;	// * align;
        //ps1.z -= ps.z;

        ps1.y *= align;

        Quaternion rot = lastrot;
        if ( ps1 != Vector3.zero )
            rot = Quaternion.LookRotation(ps1, lastup);

        //wtm.SetTRS(ps, Quaternion.LookRotation(ps1, up), Vector3.one);
        //Debug.Log("lupin: " + lastup);
        MegaMatrix.SetTR(ref wtm, ps, rot);	//Quaternion.LookRotation(ps1, lastup));

        lastrot = rot;

        // calc new up value
        ps2 = ps2.normalized;
        Vector3 cross = Vector3.Cross(ps2, lastup);
        lastup = Vector3.Cross(cross, ps2);

        //Debug.Log("lupout: " + lastup);
        return wtm;
    }
예제 #13
0
    public Matrix4x4 GetDeformMatNew(MegaSpline spline, float alpha, bool interp, float align)
    {
        int k = -1;

        Vector3 ps;
        Vector3 ps1;

        if ( spline.closed )
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
            ps = spline.Interpolate(alpha, interp, ref k);
        }
        else
            ps = spline.InterpCurve3D(alpha, interp, ref k);

        alpha += tangent;	//0.01f;
        if ( spline.closed )
        {
            alpha = alpha % 1.0f;

            ps1 = spline.Interpolate(alpha, interp, ref k);
        }
        else
            ps1 = spline.InterpCurve3D(alpha, interp, ref k);

        ps1.x -= ps.x;
        ps1.y -= ps.y;	// * align;
        ps1.z -= ps.z;

        ps1.y *= align;
        //wtm.SetTRS(ps, Quaternion.LookRotation(ps1, up), Vector3.one);

        Quaternion rot = lastrot;
        if ( ps1 != Vector3.zero )
            rot = Quaternion.LookRotation(ps1, up);

        MegaMatrix.SetTR(ref wtm, ps, rot);
        lastrot = rot;
        return wtm;
    }
예제 #14
0
    // Should be a spline method
    public Matrix4x4 GetDeformMat(MegaSpline spline, float alpha, bool interp)
    {
        int k = -1;

        Vector3 ps;
        Vector3 ps1;

        if ( spline.closed )
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
            ps	= spline.Interpolate(alpha, interp, ref k);
        }
        else
            ps	= spline.InterpCurve3D(alpha, interp, ref k);

        alpha += tangent;	//0.01f;
        if ( spline.closed )
        {
            alpha = alpha % 1.0f;

            ps1	= spline.Interpolate(alpha, interp, ref k);
        }
        else
            ps1	= spline.InterpCurve3D(alpha, interp, ref k);

        ps1.x -= ps.x;
        ps1.y = 0.0f;	//ps.y;
        ps1.z -= ps.z;

        //wtm.SetTRS(ps, Quaternion.LookRotation(ps1, up), Vector3.one);
        MegaMatrix.SetTR(ref wtm, ps, Quaternion.LookRotation(ps1, up));

        return wtm;
    }