Beispiel #1
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);
    }
Beispiel #2
0
    public void CalcMatrix(ref Matrix4x4 mat, float incr)
    {
#if false
        Matrix4x4 RingTM    = Matrix4x4.identity;
        Matrix4x4 invRingTM = Matrix4x4.identity;

        int     k            = 0;
        Vector3 ThisPosition = hosespline.InterpCurve3D(incr, true, ref k);
        Vector3 ThisZAxis    = (hosespline.InterpCurve3D(incr + 0.001f, true, ref k) - ThisPosition).normalized;

        Vector3 ThisYAxis = starty;
        if (yangle > EPSILON)
        {
            RotateOnePoint(ref ThisYAxis, Vector3.zero, roty, incr * yangle);
        }

        Vector3 ThisXAxis = Vector3.Cross(ThisYAxis, ThisZAxis).normalized;

        ThisYAxis = Vector3.Cross(ThisZAxis, ThisXAxis);

        RingTM.SetColumn(0, ThisXAxis);
        RingTM.SetColumn(1, ThisYAxis);
        RingTM.SetColumn(2, ThisZAxis);
        MegaMatrix.SetTrans(ref RingTM, ThisPosition);
#endif
        mat = Tlocal;           // * RingTM;
    }
    public override bool Prepare(MegaModContext mc)
    {
        if (path != null)
        {
            usepercent = percent / 100.0f;
            ovlen      = (1.0f / path.splines[0].length);               // * stretch;
            usetan     = (tangent * 0.01f);

            mat = Matrix4x4.identity;

            switch (axis)
            {
            case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;

            case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

            case MegaAxis.Z: break;
            }

            MegaMatrix.RotateZ(ref mat, Mathf.Deg2Rad * rotate);

            SetAxis(mat);

            mat = transform.localToWorldMatrix.inverse * path.transform.localToWorldMatrix;
            return(true);
        }

        return(false);
    }
    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);
    }
Beispiel #5
0
    public override bool Prepare(MegaModContext mc)
    {
        Vector3 s = LatticeSize();

        for (int i = 0; i < 3; i++)
        {
            if (s[i] == 0.0f)
            {
                s[i] = 1.0f;
            }
            else
            {
                s[i] = 1.0f / s[i];
            }
        }

        Vector3 c = MegaMatrix.GetTrans(ref tm);

        MegaMatrix.SetTrans(ref tm, c - bbox.min - Offset);

        MegaMatrix.Scale(ref tm, s, false);

        invtm = tm.inverse;
        return(true);
    }
Beispiel #6
0
    public override bool Prepare(MegaModContext mc)
    {
        mat = Matrix4x4.identity;

        //SetTM1();
        switch (axis)
        {
        case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

        case MegaAxis.Z: break;
        }

        SetAxis(mat);

        float xsize = bbox.max.x - bbox.min.x;
        float zsize = bbox.max.z - bbox.min.z;

        size = (xsize > zsize) ? xsize : zsize;

        // Get the percentage to spherify at this time
        per = Percent / 100.0f;

        return(true);
    }
    public override bool Prepare(float decay)
    {
        tm    = transform.worldToLocalMatrix;
        invtm = tm.inverse;

        mat = Matrix4x4.identity;

        switch (axis)
        {
        case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

        case MegaAxis.Z: break;
        }

        SetAxis(mat);
        CalcBulge(axis, amount, amplify);

        totaldecay = Decay + decay;
        if (totaldecay < 0.0f)
        {
            totaldecay = 0.0f;
        }

        return(true);
    }
    public override bool Prepare(MegaModContext mc)
    {
        switch (EAxis)
        {
        case MegaEffectAxis.X:  doX = true;             doY = false;    break;

        case MegaEffectAxis.Y:  doX = false;    doY = true;             break;

        case MegaEffectAxis.XY: doX = true;             doY = true;             break;
        }

        mat = Matrix4x4.identity;
        switch (axis)
        {
        case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f);  l = bbox.max[0] - bbox.min[0];  break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); l = bbox.max[2] - bbox.min[2];  break;

        case MegaAxis.Z: l = bbox.max[1] - bbox.min[1]; break;
        }

        if (l != 0.0f)
        {
            ovl = 1.0f / l;
        }

        MegaMatrix.RotateY(ref mat, Mathf.Deg2Rad * dir);

        SetAxis(mat);
        SetK(amount, crv);

        return(true);
    }
Beispiel #9
0
    public override void DrawGizmo(MegaModContext context)
    {
        Gizmos.color = Color.yellow;

        Matrix4x4 gtm = Matrix4x4.identity;
        Vector3   pos = gizmoPos;

        pos.x = -pos.x;
        pos.y = -pos.y;
        pos.z = -pos.z;

        Vector3 scl = gizmoScale;

        scl.x = 1.0f - (scl.x - 1.0f);
        scl.y = 1.0f - (scl.y - 1.0f);
        gtm.SetTRS(pos, Quaternion.Euler(gizmoRot), scl);

        Matrix4x4 tm = Matrix4x4.identity;

        switch (axis)
        {
        case MegaAxis.X:
            MegaMatrix.RotateZ(ref tm, 90.0f * Mathf.Deg2Rad);
            break;

        case MegaAxis.Z:
            MegaMatrix.RotateX(ref tm, 90.0f * Mathf.Deg2Rad);
            break;
        }

        Gizmos.matrix = transform.localToWorldMatrix * gtm * tm;

        BuildMesh();
    }
Beispiel #10
0
    public override bool Prepare(MegaModContext mc)
    {
        if (path != null)
        {
            if (curve >= path.splines.Count)
            {
                curve = 0;
            }

            usepercent = percent / 100.0f;
            ovlen      = (1.0f / path.splines[curve].length);           // * stretch;
            usetan     = (tangent * 0.01f);
            //Debug.Log("PathLength " + path.splines[0].length);
            //path.CalcLength(0, 5);
            //Debug.Log("CalcPathLength " + path.splines[0].length);

            //return false;
            //if ( path.beendrawn == false )
            //return false;

            mat = Matrix4x4.identity;
            switch (axis)
            {
            case MegaAxis.Z: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;
            }
            MegaMatrix.RotateZ(ref mat, Mathf.Deg2Rad * rotate);

            SetAxis(mat);

            start = path.splines[curve].knots[0].p;

            Vector3 p1 = path.InterpCurve3D(0, 0.01f, path.normalizedInterp);

            Vector3 up = Vector3.zero;

            switch (axis)
            {
            case MegaAxis.X: up = Vector3.left; break;

            case MegaAxis.Y: up = Vector3.back; break;

            case MegaAxis.Z: up = Vector3.up; break;
            }

            Quaternion lrot = Quaternion.identity;

            if (flip)
            {
                up = -up;
            }

            lrot = Quaternion.FromToRotation(p1 - start, up);

            mat.SetTRS(Vector3.zero, lrot, Vector3.one);
            return(true);
        }

        return(false);
    }
Beispiel #11
0
    public override bool Prepare(float decay)
    {
        tm    = transform.worldToLocalMatrix;
        invtm = tm.inverse;

        mat = Matrix4x4.identity;

        switch (axis)
        {
        case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

        case MegaAxis.Z: break;
        }

        SetAxis(mat);

        if (Bias != 0.0f)
        {
            bias = 1.0f - (Bias + 100.0f) / 200.0f;
            if (bias < 0.00001f)
            {
                bias = 0.00001f;
            }

            if (bias > 0.99999f)
            {
                bias = 0.99999f;
            }

            bias   = Mathf.Log(bias) / Mathf.Log(0.5f);
            doBias = true;
        }
        else
        {
            bias   = 1.0f;
            doBias = false;
        }

        CalcHeight(axis, angle);

        totaldecay = Decay + decay;
        if (totaldecay < 0.0f)
        {
            totaldecay = 0.0f;
        }

        if (from > to)
        {
            from = to;
        }
        if (to < from)
        {
            to = from;
        }

        return(true);
    }
    void Calc()
    {
        //if ( from > 0.0f)	from = 0.0f;
        //if ( to < 0.0f )	to = 0.0f;

        tm    = transform.worldToLocalMatrix;
        invtm = tm.inverse;

        mat = Matrix4x4.identity;

        switch (axis)
        {
        case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

        case MegaAxis.Z: break;
        }

        MegaMatrix.RotateY(ref mat, Mathf.Deg2Rad * dir);
        SetAxis(mat);

        CalcR(axis, Mathf.Deg2Rad * -angle);

        if (doRegion)
        {
            doRegion = false;
            float len = to - from;
            float rat1, rat2;

            if (len == 0.0f)
            {
                rat1 = rat2 = 1.0f;
            }
            else
            {
                rat1 = to / len;
                rat2 = from / len;
            }

            Vector3 pt;
            tmAbove = Matrix4x4.identity;
            MegaMatrix.Translate(ref tmAbove, 0.0f, -to, 0.0f);
            MegaMatrix.RotateZ(ref tmAbove, -Mathf.Deg2Rad * angle * rat1);
            MegaMatrix.Translate(ref tmAbove, 0.0f, to, 0.0f);
            pt = new Vector3(0.0f, to, 0.0f);
            MegaMatrix.Translate(ref tmAbove, tm.MultiplyPoint3x4(Map(0, invtm.MultiplyPoint3x4(pt))) - pt);

            tmBelow = Matrix4x4.identity;
            MegaMatrix.Translate(ref tmBelow, 0.0f, -from, 0.0f);
            MegaMatrix.RotateZ(ref tmBelow, -Mathf.Deg2Rad * angle * rat2);
            MegaMatrix.Translate(ref tmBelow, 0.0f, from, 0.0f);
            pt = new Vector3(0.0f, from, 0.0f);
            MegaMatrix.Translate(ref tmBelow, tm.MultiplyPoint3x4(Map(0, invtm.MultiplyPoint3x4(pt))) - pt);

            doRegion = true;
        }
    }
Beispiel #13
0
	// TODO: If we draw like warps do we know if we are the current edited script?
	public virtual void DrawGizmo(MegaModContext context)
	{
		tm = Matrix4x4.identity;
		MegaMatrix.Translate(ref tm, context.Offset);
		invtm = tm.inverse;

		if ( !Prepare(context) )
			return;

		Vector3 min = context.bbox.min;
		Vector3 max = context.bbox.max;

		Matrix4x4 gtm = Matrix4x4.identity;
		Vector3 pos = gizmoPos;
		pos.x = -pos.x;
		pos.y = -pos.y;
		pos.z = -pos.z;

		Vector3 scl = gizmoScale;
		scl.x = 1.0f - (scl.x - 1.0f);
		scl.y = 1.0f - (scl.y - 1.0f);
		gtm.SetTRS(pos, Quaternion.Euler(gizmoRot), scl);

		// put sourceObj into context
		if ( context.mod.sourceObj != null )
			Gizmos.matrix = context.mod.sourceObj.transform.localToWorldMatrix * gtm;
		else
			Gizmos.matrix = context.go.transform.localToWorldMatrix * gtm;

		//Gizmos.color = ModCol();	//Color.yellow;
		corners[0] = new Vector3(min.x, min.y, min.z);
		corners[1] = new Vector3(min.x, max.y, min.z);
		corners[2] = new Vector3(max.x, max.y, min.z);
		corners[3] = new Vector3(max.x, min.y, min.z);

		corners[4] = new Vector3(min.x, min.y, max.z);
		corners[5] = new Vector3(min.x, max.y, max.z);
		corners[6] = new Vector3(max.x, max.y, max.z);
		corners[7] = new Vector3(max.x, min.y, max.z);

		DrawEdge(corners[0], corners[1]);
		DrawEdge(corners[1], corners[2]);
		DrawEdge(corners[2], corners[3]);
		DrawEdge(corners[3], corners[0]);

		DrawEdge(corners[4], corners[5]);
		DrawEdge(corners[5], corners[6]);
		DrawEdge(corners[6], corners[7]);
		DrawEdge(corners[7], corners[4]);

		DrawEdge(corners[0], corners[4]);
		DrawEdge(corners[1], corners[5]);
		DrawEdge(corners[2], corners[6]);
		DrawEdge(corners[3], corners[7]);

		ExtraGizmo(context);
	}
Beispiel #14
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);
    }
Beispiel #15
0
    Vector3 Deform(Vector3 p, float off, MegaRope rope, float alpha)
    {
        Vector3 np = rope.Interp(alpha);                //tm.MultiplyPoint3x4(rope.Interp(alpha));

        T   = rope.Velocity(alpha).normalized;
        wtm = rope.CalcFrame(T, ref N, ref B);
        //wtm.SetRow(3, np);
        MegaMatrix.SetTrans(ref wtm, np);

        return(p);
    }
    public void SetTM1()
    {
        tm = Matrix4x4.identity;

        MegaMatrix.RotateZ(ref tm, -gizmoRot.z * Mathf.Deg2Rad);
        MegaMatrix.RotateY(ref tm, -gizmoRot.y * Mathf.Deg2Rad);
        MegaMatrix.RotateX(ref tm, -gizmoRot.x * Mathf.Deg2Rad);

        MegaMatrix.SetTrans(ref tm, gizmoPos + Offset);

        invtm = tm.inverse;
    }
Beispiel #17
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);
    }
Beispiel #18
0
    public override bool Prepare(MegaModContext mc)
    {
        if (from > 0.0f)
        {
            from = 0.0f;
        }

        if (to < 0.0f)
        {
            to = 0.0f;
        }

        mat = Matrix4x4.identity;

        switch (axis)
        {
        case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f);  break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

        case MegaAxis.Z: break;
        }

        MegaMatrix.RotateY(ref mat, Mathf.Deg2Rad * dir);
        SetAxis(mat);

        float len = 0.0f;

        if (!doRegion)
        {
            switch (axis)
            {
            case MegaAxis.X: len = bbox.max.x - bbox.min.x; break;

            case MegaAxis.Z: len = bbox.max.y - bbox.min.y; break;

            case MegaAxis.Y: len = bbox.max.z - bbox.min.z; break;
            }
        }
        else
        {
            len = to - from;
        }

        if (len == 0.0f)
        {
            len = 0.000001f;
        }

        amountOverLength = amount / len;
        return(true);
    }
Beispiel #19
0
    void Calc()
    {
        tm    = transform.worldToLocalMatrix;
        invtm = tm.inverse;

        mat = Matrix4x4.identity;

        tm1    = tm;
        invtm1 = invtm;

        switch (axis)
        {
        case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

        case MegaAxis.Z: break;
        }

        MegaMatrix.RotateY(ref mat, Mathf.Deg2Rad * dir);
        SetAxis(mat);

        mat = Matrix4x4.identity;

        switch (axis1)
        {
        case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

        case MegaAxis.Z: break;
        }

        MegaMatrix.RotateY(ref mat, Mathf.Deg2Rad * dir1);
        //SetAxis(mat);
        Matrix4x4 itm = mat.inverse;

        tm1    = mat * tm1;
        invtm1 = invtm1 * itm;

        r = -radius;

        if (linkRadii)
        {
            r1 = -radius;
        }
        else
        {
            r1 = -radius1;
        }
    }
Beispiel #20
0
    public void SetTM1()
    {
        tm = Matrix4x4.identity;
        //Quaternion rot = Quaternion.Euler(-gizmoRot);

        MegaMatrix.RotateZ(ref tm, -gizmoRot.z * Mathf.Deg2Rad);
        MegaMatrix.RotateY(ref tm, -gizmoRot.y * Mathf.Deg2Rad);
        MegaMatrix.RotateX(ref tm, -gizmoRot.x * Mathf.Deg2Rad);

        MegaMatrix.SetTrans(ref tm, gizmoPos + Offset);

        //tm.SetTRS(gizmoPos + Offset, rot, gizmoScale);
        invtm = tm.inverse;
    }
    public override bool Prepare(MegaModContext mc)
    {
        mat = Matrix4x4.identity;

        switch (axis)
        {
        case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

        case MegaAxis.Z: break;
        }

        SetAxis(mat);

        if (Bias != 0.0f)
        {
            bias = 1.0f - (Bias + 100.0f) / 200.0f;
            if (bias < 0.00001f)
            {
                bias = 0.00001f;
            }

            if (bias > 0.99999f)
            {
                bias = 0.99999f;
            }

            bias   = Mathf.Log(bias) / Mathf.Log(0.5f);
            doBias = true;
        }
        else
        {
            bias   = 1.0f;
            doBias = false;
        }

        if (from > to)
        {
            from = to;
        }
        if (to < from)
        {
            to = from;
        }

        CalcHeight(axis, angle, mc.bbox);
        return(true);
    }
    public override bool Prepare(MegaModContext mc)
    {
        if (path != null)
        {
            if (usedist)
            {
                percent = distance / path.splines[curve].length * 100.0f;
            }

            if (curve >= path.splines.Count)
            {
                curve = 0;
            }

            usepercent = percent / 100.0f;

            switch (loopmode)
            {
            case MegaLoopMode.Clamp: usepercent = Mathf.Clamp01(usepercent); break;

            case MegaLoopMode.Loop: usepercent = Mathf.Repeat(usepercent, 1.0f); break;

            case MegaLoopMode.PingPong: usepercent = Mathf.PingPong(usepercent, 1.0f); break;
            }

            ovlen  = (1.0f / path.splines[curve].length);               // * stretch;
            usetan = (tangent * 0.01f);

            mat = Matrix4x4.identity;

            switch (axis)
            {
            case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;

            case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

            case MegaAxis.Z: break;
            }

            MegaMatrix.RotateZ(ref mat, Mathf.Deg2Rad * rotate);

            SetAxis(mat);

            mat = transform.localToWorldMatrix.inverse * path.transform.localToWorldMatrix;
            return(true);
        }

        return(false);
    }
Beispiel #23
0
    public Matrix4x4 GetMatrix()
    {
        Matrix4x4 tm = Matrix4x4.identity;

        switch (axis)
        {
        case MegaAxis.X: MegaMatrix.RotateY(ref tm, Mathf.PI * 0.5f); break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref tm, Mathf.PI * 0.5f); break;

        case MegaAxis.Z: break;                 //Matrix.RotateY(ref tm, Mathf.PI * 0.5f); break;
        }

        return(tm);
    }
Beispiel #24
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);
    }
    //Matrix4x4 tmm = Matrix4x4.identity;

    public override bool Prepare(float decay)
    {
        if (bsize.x != Width || bsize.y != Height || bsize.z != Length)
        {
            Init();
        }

        Vector3 s = LatticeSize();

        for (int i = 0; i < 3; i++)
        {
            if (s[i] == 0.0f)
            {
                s[i] = 1.0f;
            }
            else
            {
                s[i] = 1.0f / s[i];
            }
        }

        tm = transform.worldToLocalMatrix;
        //Matrix4x4 tmm = Matrix4x4.TRS(bsize * 0.5f, Quaternion.identity, Vector3.one);
        Vector3 c = MegaMatrix.GetTrans(ref tm);

        MegaMatrix.SetTrans(ref tm, c - (-bsize * 0.5f));               //Vector3.zero);	//c - bbox.min - Offset);

        MegaMatrix.Scale(ref tm, s, false);

        invtm = tm.inverse;

        //tm = tmm * transform.worldToLocalMatrix;
        //invtm = tm.inverse;

        totaldecay = Decay + decay;
        if (totaldecay < 0.0f)
        {
            totaldecay = 0.0f;
        }

        hw = Width * 0.5f;
        hh = Height * 0.5f;
        hl = Length * 0.5f;


        return(true);
    }
Beispiel #26
0
    public override bool Prepare(MegaModContext mc)
    {
        mat = Matrix4x4.identity;

        switch (axis)
        {
        case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

        case MegaAxis.Z: break;
        }

        SetAxis(mat);
        CalcBulge(axis, amount, amplify);
        return(true);
    }
Beispiel #27
0
    public override bool Prepare(MegaModContext mc)
    {
        mat = Matrix4x4.identity;

        MegaMatrix.RotateZ(ref mat, Mathf.Deg2Rad * dir);
        SetAxis(mat);

        dy = Decay / 1000.0f;

        dist = (wave / 10.0f) * 4.0f * 5.0f;            //float(numSides);

        if (dist == 0.0f)
        {
            dist = 1.0f;
        }

        return(true);
    }
    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));
    }
Beispiel #29
0
    Vector3 GetCross(int csect, float ca, Vector3 off)
    {
        MegaLoftSection lsection = loftsections[csect];

        int       curve = lsection.curve;
        int       k     = -1;
        Matrix4x4 tm1   = Matrix4x4.identity;

        float start = crossStart;
        float len   = crossEnd;

        if (lsection.uselen)
        {
            start = lsection.start;
            len   = lsection.length;
        }

        MegaShape shape = lsection.shape;

        MegaMatrix.Translate(ref tm1, pivot);
        Vector3 rot = crossRot + lsection.rot;

        MegaMatrix.Rotate(ref tm1, new Vector3(Mathf.Deg2Rad * rot.x, Mathf.Deg2Rad * rot.y, Mathf.Deg2Rad * rot.z));

        float alpha = start + (ca * len);

        //float alpha = start + ca;

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

        Vector3 pos = tm1.MultiplyPoint3x4(shape.splines[curve].InterpCurve3D(alpha, shape.normalizedInterp, ref k) + off + lsection.offset);

        pos.x *= lsection.scale.x;
        pos.y *= lsection.scale.y;
        pos.z *= lsection.scale.z;

        return(pos);
    }
    public override bool Prepare(float decay)
    {
        totaldecay = Decay + decay;
        if (totaldecay < 0.0f)
        {
            totaldecay = 0.0f;
        }

        tm    = transform.worldToLocalMatrix;
        invtm = tm.inverse;

        //size = bbox.Size();
        //size.x = Width;
        //size.y = Height;
        //size.z = Length;

        mat = Matrix4x4.identity;

        //SetTM1();
        switch (axis)
        {
        case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;

        case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;

        case MegaAxis.Z: break;
        }

        SetAxis(mat);

        float xsize = Width;            //bbox.max.x - bbox.min.x;
        float zsize = Length;           //bbox.max.z - bbox.min.z;

        size1 = (xsize > zsize) ? xsize : zsize;

        // Get the percentage to spherify at this time
        per = Percent / 100.0f;

        return(true);
    }