Пример #1
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);
    }
    //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);
    }
Пример #3
0
    public override void BuildMesh(MegaRope rope)
    {
        BuildObjectLinks(rope);
#if false
        float len = rope.RopeLength;

        float linklen = (linkOff1.y - linkOff.y) * linkScale.y;         //Length - linkOff.y
        int   lc      = (int)(len / linklen);

        if (lc != linkcount)
        {
            InitLinkMesh(rope);
        }

        int vi = 0;

        mat = Matrix4x4.identity;

        Matrix4x4 linkrot1 = Matrix4x4.identity;
        Matrix4x4 linkrot2 = Matrix4x4.identity;

        MegaMatrix.RotateY(ref linkrot2, Mathf.PI * 0.5f);

        MegaMatrix.RotateY(ref linkrot1, Mathf.PI * 0.5f);
        MegaMatrix.RotateZ(ref linkrot1, Mathf.PI * 0.5f);

        MegaMatrix.Scale(ref linkrot1, linkScale, false);
        MegaMatrix.Scale(ref linkrot2, linkScale, false);

        // Last off1 becomes next link pos
        // Again uvs and tris are a one off, its just verts that change
        float lastalpha = 0.0f;
        for (int i = 0; i < linkcount; i++)
        {
            //Debug.Log("alpha " + alpha);
            if (LinkMat)
            {
                float alpha = (float)(i + 1) / (float)linkcount;
                wtm       = GetLinkMat(alpha, lastalpha, rope);
                lastalpha = alpha;
            }
            else
            {
                float alpha = (float)(i) / (float)linkcount;
                wtm = rope.GetDeformMat(alpha);                 // Different mat needed, not current vel bu vel to the next point
            }

            if ((i & 1) == 1)
            {
                wtm = wtm * linkrot1;
            }
            else
            {
                wtm = wtm * linkrot2;
            }

            for (int v = 0; v < lverts.Length; v++)
            {
                verts[vi + v] = wtm.MultiplyPoint3x4(lverts[v]);
            }

            vi += lverts.Length;
        }

        rope.mesh.vertices = verts;
        rope.mesh.RecalculateBounds();
        rope.mesh.RecalculateNormals();
#endif
    }