public Matrix4x4 GetDeformMat(MegaSpline spline, float alpha, bool interp)
    {
        int k = -1;

        //Vector3 ps	= spline.Interpolate(alpha, interp, ref k);
        Vector3 ps = spline.InterpCurve3D(alpha, interp, ref k);

        alpha += 0.01f;         // TODO: Tangent value
        if (spline.closed)
        {
            alpha = alpha % 1.0f;
        }

        //Vector3 ps1	= spline.Interpolate(alpha, interp, ref k);
        Vector3 ps1 = spline.InterpCurve3D(alpha, interp, ref k);

        ps1.x -= ps.x;
        ps1.y -= ps.y;
        ps1.z -= ps.z;

        ps1.y *= PathTeeter;

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

        return(wtm1);
    }
示例#2
0
    public Matrix4x4 GetSplineMat(MegaSpline spline, float alpha, bool interp, ref Vector3 lastup)
    {
        int k = -1;

        Vector3 ps = spline.InterpCurve3D(alpha, interp, ref k);

        alpha += 0.01f;         // TODO: Tangent value
        if (spline.closed)
        {
            alpha = alpha % 1.0f;
        }

        Vector3 ps1 = spline.InterpCurve3D(alpha, interp, ref k);
        Vector3 ps2;

        ps1.x = ps2.x = ps1.x - ps.x;
        ps1.y = ps2.y = ps1.y - ps.y;
        ps1.z = ps2.z = ps1.z - ps.z;

        MegaMatrix.SetTR(ref wtm1, ps, Quaternion.LookRotation(ps1, lastup));           //locup));

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

        lastup = Vector3.Cross(cross, ps2);

        return(wtm1);
    }
示例#3
0
    public override Vector3 Map(int i, Vector3 p)
    {
        p = tm.MultiplyPoint3x4(p);             // Dont need either, so saving 3 vector mat mults but gaining a mat mult

        float alpha;
        float tws = 0.0f;

        if (UseStretchCurve)
        {
            float str = stretchCurve.Evaluate(Mathf.Repeat(p.z * ovlen + usepercent, 1.0f)) * stretch;
            alpha = (p.z * ovlen * str) + usepercent;                   //(percent / 100.0f);	// can precalc this
        }
        else
        {
            alpha = (p.z * ovlen * stretch) + usepercent;                               //(percent / 100.0f);	// can precalc this
        }
        Vector3 ps  = path.InterpCurve3D(curve, alpha, path.normalizedInterp, ref tws); // - start;
        Vector3 ps1 = path.InterpCurve3D(curve, alpha + usetan, path.normalizedInterp); // - start;

        if (path.splines[curve].closed)
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
        }
        else
        {
            alpha = Mathf.Clamp01(alpha);
        }

        Quaternion tw = Quaternion.identity;

        if (UseTwistCurve)
        {
            float twst = twistCurve.Evaluate(alpha) * twist;
            tw = Quaternion.AngleAxis(twst + tws, Vector3.forward);
        }
        else
        {
            tw = Quaternion.AngleAxis((twist * alpha) + tws, Vector3.forward);
        }

        ps1.x -= ps.x;
        ps1.y -= ps.y;
        ps1.z -= ps.z;
        Quaternion rotation = Quaternion.LookRotation(ps1, Up) * tw;

        Matrix4x4 wtm = Matrix4x4.identity;

        MegaMatrix.SetTR(ref wtm, ps, rotation);
        wtm = mat * wtm;

        ps.x = (p.x * wtm[0]) + (p.y * wtm[4]) + wtm[12];
        ps.y = (p.x * wtm[1]) + (p.y * wtm[5]) + wtm[13];
        ps.z = (p.x * wtm[2]) + (p.y * wtm[6]) + wtm[14];

        return(ps);             //wtm.MultiplyPoint3x4(p);
    }
示例#4
0
    public override Vector3 Map(int i, Vector3 p)
    {
        p = tm.MultiplyPoint3x4(p);             // Dont need either, so saving 3 vector mat mults but gaining a mat mult

        float alpha;
        float tws = 0.0f;

        if (UseStretchCurve)
        {
            float str = stretchCurve.Evaluate(Mathf.Repeat(p.z * ovlen + usepercent, 1.0f)) * stretch;
            alpha = (p.z * ovlen * str) + usepercent;                   //(percent / 100.0f);	// can precalc this
        }
        else
        {
            alpha = (p.z * ovlen * stretch) + usepercent;               //(percent / 100.0f);	// can precalc this
        }
        //float alpha = ((p.z * stretch) / path.splines[0].length) + usepercent;	//(percent / 100.0f);	// can precalc this
        //alpha = (p.z * ovlen * stretch) + usepercent;	//(percent / 100.0f);	// can precalc this

        Vector3 ps  = path.InterpCurve3D(curve, alpha, path.normalizedInterp, ref tws) - start;
        Vector3 ps1 = path.InterpCurve3D(curve, alpha + usetan, path.normalizedInterp) - start;

        if (path.splines[curve].closed)
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
        }
        else
        {
            alpha = Mathf.Clamp01(alpha);
        }

        if (UseTwistCurve)
        {
            float twst = twistCurve.Evaluate(alpha) * twist;
            tw = Quaternion.AngleAxis(twst + tws, Vector3.forward);
        }
        else
        {
            tw = Quaternion.AngleAxis(tws + (twist * alpha), Vector3.forward);
        }

        Vector3    relativePos = ps1 - ps;
        Quaternion rotation    = Quaternion.LookRotation(relativePos, Up) * tw;
        //wtm.SetTRS(ps, rotation, Vector3.one);
        Matrix4x4 wtm = Matrix4x4.identity;

        MegaMatrix.SetTR(ref wtm, ps, rotation);

        wtm = mat * wtm;
        p.z = 0.0f;
        return(wtm.MultiplyPoint3x4(p));
        //return invtm.MultiplyPoint3x4(p);
    }
示例#5
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);
    }
    Vector3 Deform(Vector3 p, MegaShape path, float percent, float off, Vector3 scale, float removeDof, Vector3 locoff, Vector3 sploff)
    {
        p    = tm.MultiplyPoint3x4(p);
        p.x *= scale.x;
        p.y *= scale.y;
        p.z *= scale.z;

        p.z += off;
        p   += locoff;
        float alpha = (p.z / path.splines[curve].length) + percent;

        float   tw1 = 0.0f;
        Vector3 ps  = pathtm.MultiplyPoint(path.InterpCurve3D(curve, alpha, path.normalizedInterp, ref tw1) + sploff);
        Vector3 ps1 = pathtm.MultiplyPoint(path.InterpCurve3D(curve, alpha + (tangent * 0.001f), path.normalizedInterp) + sploff);

        if (path.splines[curve].closed)
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
        }
        else
        {
            alpha = Mathf.Clamp01(alpha);
        }

        if (useTwist)
        {
            //float tw1 = path.splines[curve].GetTwist(alpha);
            tw = meshrot * Quaternion.AngleAxis((twist * twistCrv.Evaluate(alpha)) + tw1, Vector3.forward);
        }

        Vector3 relativePos = ps1 - ps;

        relativePos.y *= removeDof;

        Quaternion rotation = Quaternion.LookRotation(relativePos) * tw;                // * meshrot;

        //wtm.SetTRS(ps, rotation, Vector3.one);
        MegaMatrix.SetTR(ref wtm, ps, rotation);

        wtm = mat * wtm;

        p.z = 0.0f;
        return(wtm.MultiplyPoint3x4(p));
    }
示例#7
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);
    }
    public Matrix4x4 GetDeformMatNewMethod(MegaSpline spline, float alpha, bool interp, ref Vector3 lastup)
    {
        int k = -1;

        //Vector3 ps	= spline.Interpolate(alpha, interp, ref k);
        Vector3 ps = spline.InterpCurve3D(alpha, interp, ref k);

        alpha += 0.01f;         // TODO: Tangent value
        if (spline.closed)
        {
            alpha = alpha % 1.0f;
        }

        //Vector3 ps1	= spline.Interpolate(alpha, interp, ref k);
        Vector3 ps1 = spline.InterpCurve3D(alpha, interp, ref k);
        Vector3 ps2;

        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;
        //ps1.z -= ps.z;

        ps1.y *= PathTeeter;

        //wtm1.SetTRS(ps, Quaternion.LookRotation(ps1, locup), Vector3.one);
        MegaMatrix.SetTR(ref wtm1, ps, Quaternion.LookRotation(ps1, lastup));           //locup));

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

        lastup = Vector3.Cross(cross, ps2);

        return(wtm1);
    }
示例#9
0
    Vector3 Deform(Vector3 p, MegaShapeLoft loft, MegaLoftLayerSimple layer, float percent, float ca, float off, Vector3 scale, float removeDof, Vector3 locoff)
    {
        p    = tm.MultiplyPoint3x4(p);
        p.x *= scale.x;
        p.y *= scale.y;
        p.z *= scale.z;
        p.z += off;

        p += locoff;
        float alpha = (p.z * LayerLength) + percent;

        if (useCrossCrv)
        {
            ca += CrossCrv.Evaluate(alpha);
        }

        Vector3 ps1;
        Vector3 ps;

        if (CalcUp)
        {
            Vector3 upv   = Vector3.zero;
            Vector3 right = Vector3.zero;
            Vector3 fwd   = Vector3.zero;

            ps = layer.GetPosAndFrame(loft, ca, alpha, (tangent * 0.001f), out ps1, out upv, out right, out fwd);

            tw = Quaternion.LookRotation(fwd, upv);

            Quaternion rot = tw * meshrot;
            if (useTwist)
            {
                rot *= Quaternion.AngleAxis(180.0f + (twist * twistCrv.Evaluate(alpha)), Vector3.forward);
            }
            else
            {
                rot *= Quaternion.AngleAxis(180.0f, Vector3.forward);
            }

            //wtm.SetTRS(ps, rot, Vector3.one);
            MegaMatrix.SetTR(ref wtm, ps, rot);
            wtm = mat * wtm;

            p.z = 0.0f;
            return(wtm.MultiplyPoint3x4(p));
        }
        else
        {
            ps = layer.GetPosAndLook(loft, ca, alpha, (tangent * 0.001f), out ps1);

            if (useTwist)
            {
                tw = meshrot * Quaternion.AngleAxis((twist * twistCrv.Evaluate(alpha)), Vector3.forward);                       // * meshrot;
            }
            else
            {
                tw = meshrot * Quaternion.AngleAxis(0.0f, Vector3.forward);                     // * meshrot;
            }
        }

        Vector3 relativePos = ps1 - ps;

        relativePos.y *= removeDof;

        if (relativePos == Vector3.zero)
        {
            relativePos = lastrel;              //Vector3.forward;
        }
        lastrel = relativePos;
        Quaternion rotation = Quaternion.LookRotation(relativePos) * tw;                // * meshrot;

        MegaMatrix.SetTR(ref wtm, ps, rotation);

        //wtm.SetTRS(ps, rotation, Vector3.one);

        wtm = mat * wtm;

        p.z = 0.0f;
        return(wtm.MultiplyPoint3x4(p));
    }
示例#10
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);
    }
    Vector3 DeformOld(Vector3 p, MegaShapeLoft loft, MegaLoftLayerSimple layer, float percent, float ca, float off, Vector3 scale, float removeDof, Vector3 locoff)
    {
        p    = tm.MultiplyPoint3x4(p);
        p.z += off;
        p.x *= scale.x;
        p.y *= scale.y;
        p.z *= scale.z;

        p += locoff;
        float alpha = (p.z * LayerLength) + percent;

        if (useCrossCrv)
        {
            ca += CrossCrv.Evaluate(alpha);
            if (ca < 0.0f)
            {
                ca = 0.0f;
            }
            if (ca > 0.999f)
            {
                ca = 0.999f;
            }
        }
        Vector3 ps1;
        Vector3 ps;

        if (CalcUp)
        {
            Vector3 newup;
            ps = layer.GetPosAndUp(loft, ca, alpha, 0.1f, out ps1, out newup);

            //newup = surfacetolofttm.MultiplyVector(newup);

            // May need this back in
            //if ( path.splines[0].closed )
            alpha = Mathf.Repeat(alpha, 1.0f);

            if (calcUpAmount < 0.999f)
            {
                newup = Vector3.Lerp(Vector3.up, newup, calcUpAmount);
            }

            Quaternion uprot = Quaternion.FromToRotation(Vector3.up, newup);
            if (useTwistCrv)
            {
                tw = uprot * Quaternion.AngleAxis(twist * twistCrv.Evaluate(alpha), Vector3.forward);
            }
            else
            {
                tw = uprot;
            }
        }
        else
        {
            ps = layer.GetPosAndLook(loft, ca, alpha, 0.1f, out ps1);

            alpha = Mathf.Repeat(alpha, 1.0f);

            if (useTwistCrv)
            {
                tw = Quaternion.AngleAxis(twist * twistCrv.Evaluate(alpha), Vector3.forward);
            }
        }

        Vector3 relativePos = ps1 - ps;

        relativePos.y *= removeDof;

        Quaternion rotation = tw * Quaternion.LookRotation(relativePos);

        //wtm.SetTRS(ps, rotation, Vector3.one);
        MegaMatrix.SetTR(ref wtm, ps, rotation);

        wtm = mat * wtm;

        p.z = 0.0f;
        return(wtm.MultiplyPoint3x4(p));
    }