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);
    }
    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);
    }
예제 #3
0
    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;
        }
    }
    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;
    }
예제 #5
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);
    }
예제 #6
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;
        }
    }
예제 #7
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;
    }
예제 #8
0
    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);
    }
    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);
    }
예제 #10
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);
    }
예제 #11
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);
    }
예제 #12
0
    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);
    }
예제 #13
0
    public override bool Prepare(float decay)
    {
        tm    = transform.worldToLocalMatrix;
        invtm = tm.inverse;

        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 = Width; break;

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

        case MegaAxis.Z: l = Height; break;
        }

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

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

        totaldecay = Decay + decay;
        if (totaldecay < 0.0f)
        {
            totaldecay = 0.0f;
        }
        return(true);
    }
예제 #14
0
    public override bool Prepare(MegaModContext mc)
    {
        if (path != null)
        {
            if (curve >= path.splines.Count)
            {
                curve = 0;
            }

            if (usedist)
            {
                percent = distance / path.splines[curve].length * 100.0f;
            }

            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.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);
    }
예제 #15
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
    }
    public override bool Prepare(float decay)
    {
        tm    = transform.worldToLocalMatrix;
        invtm = tm.inverse;

        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 = Width; break;

            case MegaAxis.Z: len = Height; break;

            case MegaAxis.Y: len = Length; break;
            }
        }
        else
        {
            len = to - from;
        }

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

        amountOverLength = amount / len;

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

        return(true);
    }
예제 #17
0
    public void BuildMesh(Mesh mesh)
    {
        if (shape == null)
        {
            return;
        }

        verts.Clear();
        uvs.Clear();
        tris.Clear();
        dtris.Clear();
        //normals.Clear();

        pshape = MakePolyShape(shape, steps);

        Matrix4x4 axismat = Matrix4x4.identity;

        Quaternion q = Quaternion.identity;

        switch (direction)
        {
        case MegaAxis.X: q = Quaternion.Euler(90.0f, 0.0f, 0.0f); break;

        case MegaAxis.Y: q = Quaternion.Euler(0.0f, 90.0f, 0.0f); break;

        case MegaAxis.Z: q = Quaternion.Euler(0.0f, 0.0f, 90.0f); break;
        }

        int vertLevels = segments + 1;

        axismat.SetTRS(axis, q, Vector3.one);
        Matrix4x4 iaxis = axismat.inverse;

        Matrix4x4 rotmat = Matrix4x4.identity;

        float totlen = pshape.length[pshape.length.Count - 1];

        Vector2 uv  = Vector2.zero;
        Vector2 uv1 = uv;

        Matrix4x4 uvmat = Matrix4x4.identity;

        uvmat.SetTRS(Vector3.zero, Quaternion.Euler(0.0f, 0.0f, uvrotate), Vector3.one);

        Vector3 p   = Vector3.zero;
        Vector3 scl = scale;
        //Vector3 norm = Vector3.zero;
        Vector3 lsp = Vector3.zero;

        int   vindex   = 0;
        float alphasub = 0.0f;

        if (!pivotbase)
        {
            alphasub = 1.0f;
        }
        for (int level = 0; level < vertLevels; level++)
        {
            uv.y = (float)level / (float)segments;
            float ang = (uv.y * degrees) + startang;                    //360.0f;
            rotmat = Matrix4x4.identity;

            MegaMatrix.RotateZ(ref rotmat, ang * Mathf.Deg2Rad);

            Matrix4x4 tm = iaxis * rotmat * axismat;

            //Vector3 lp = Vector3.zero;

            float cumlen = 0.0f;

            //int nix = normals.Count;

            //Debug.Log("minz " + min.z + " limz " + limits.z);
            for (int v = 0; v < pshape.points.Count; v++)
            {
                lsp = pshape.points[v];                 //Vector3.Scale(pshape.points[v], scl);

                //float halpha = 1.0f - ((lsp.z - min.z) / limits.z);
                float halpha = alphasub - ((lsp.z - min.z) / limits.z);

                //lsp.x += profilecrv.Evaluate(halpha);
                //lsp.y += offsetycrv.Evaluate(halpha);

                if (usescalecrv)
                {
                    //float halpha = (lsp.z - min.z) / limits.z;

                    float adj = scaleamthgt.Evaluate(halpha) * globalscale;
                    scl.x = 1.0f + (scalexcrv.Evaluate(uv.y) * adj);
                    scl.y = 1.0f + (scaleycrv.Evaluate(uv.y) * adj);
                    scl.z = 1.0f + (scalezcrv.Evaluate(uv.y) * adj);
                }

                lsp.x *= scl.x;
                lsp.y *= scl.y;
                lsp.z *= scl.z;

                if (twist != 0.0f)
                {
                    float tang = ((twist * halpha * twistcrv.Evaluate(halpha)) + ang) * Mathf.Deg2Rad;
                    float c    = Mathf.Cos(tang);
                    float s    = Mathf.Sin(tang);

                    rotmat[0, 0] = c;
                    rotmat[0, 1] = s;
                    rotmat[1, 0] = -s;
                    rotmat[1, 1] = c;

                    tm = iaxis * rotmat * axismat;
                }
#if false
                norm.x = -(lsp.y - lp.y);
                norm.y = lsp.x - lp.x;
                norm.z = 0.0f;                  //lsp.z - lp.z;
#endif
                //norm.x = -(lsp.z - lp.z);	//- (lsp.y - lp.y);
                //norm.y = 0.0f;	//lsp.x - lp.x;
                //norm.z = lsp.x - lp.x; //0.0f;	//lsp.z - lp.z;

                //lp = lsp;

                p = tm * lsp;                   //Vector3.Scale(lsp, scl);

                //p.x += offsetxcrv.Evaluate(halpha);
                //p.y += offsetycrv.Evaluate(halpha);

                verts.Add(p);
#if false
                if (v == 0)
                {
                }
                else
                {
                    if (v == 1)
                    {
                        if (flip)
                        {
                            normals.Add(-tm.MultiplyVector(norm).normalized);
                        }
                        else
                        {
                            normals.Add(tm.MultiplyVector(norm).normalized);
                        }
                    }

                    if (flip)
                    {
                        normals.Add(-tm.MultiplyVector(norm).normalized);
                    }
                    else
                    {
                        normals.Add(tm.MultiplyVector(norm).normalized);
                    }
                }
#endif
                cumlen = pshape.length[v];

                uv.x   = cumlen / totlen;               // / cumlen;
                uv1    = uv;
                uv1.x *= uvscale.x;
                uv1.y *= uvscale.y;
                uv1   += uvoffset;

                uv1 = uvmat.MultiplyPoint(uv1);
                uvs.Add(uv1);
            }

            //if ( shape.splines[curve].closed )
            //{
            //normals[normals.Count - 1] = normals[nix];
            //}
        }

        // Faces
        int vcount = pshape.points.Count;

        for (int level = 0; level < vertLevels - 1; level++)
        {
            int voff = level * vcount;

            for (int p1 = 0; p1 < pshape.points.Count - 1; p1++)
            {
                int v1 = p1 + voff;
                int v2 = v1 + 1;
                int v3 = level == vertLevels - 1 ? p1 : v1 + vcount;
                int v4 = v3 + 1;

                if (flip)
                {
                    tris.Add(v1);
                    tris.Add(v4);
                    tris.Add(v2);

                    tris.Add(v1);
                    tris.Add(v3);
                    tris.Add(v4);
                }
                else
                {
                    tris.Add(v2);
                    tris.Add(v4);
                    tris.Add(v1);

                    tris.Add(v4);
                    tris.Add(v3);
                    tris.Add(v1);
                }
            }
        }

        if (doublesided)
        {
            int vc = verts.Count;

            for (int i = 0; i < vc; i++)
            {
                verts.Add(verts[i]);
                uvs.Add(uvs[i]);
                normals.Add(-normals[i]);
                vindex++;
            }

            for (int i = 0; i < tris.Count; i += 3)
            {
                int v1 = tris[i];
                int v2 = tris[i + 1];
                int v3 = tris[i + 2];

                dtris.Add(v3 + vc);
                dtris.Add(v2 + vc);
                dtris.Add(v1 + vc);
            }
        }

        //MeshFilter mf = GetComponent<MeshFilter>();
        //mesh = mf.sharedMesh;
        //if ( mesh == null )
        //{
        //	mesh = new Mesh();
        //	mesh.name = "Lathe";
        //	mf.sharedMesh = mesh;
        //}

        mesh.Clear();
        mesh.vertices = verts.ToArray();
        mesh.uv       = uvs.ToArray();

        if (doublesided)
        {
            mesh.subMeshCount = 2;
        }
        else
        {
            mesh.subMeshCount = 1;
        }

        mesh.SetTriangles(tris.ToArray(), 0);

        if (doublesided)
        {
            mesh.SetTriangles(dtris.ToArray(), 1);
        }

        mesh.RecalculateBounds();
        //mesh.normals = normals.ToArray();
        mesh.RecalculateNormals();

        if (degrees == 360.0f)
        {
            Vector3[] n = mesh.normals;

            for (int v = 0; v < pshape.points.Count; v++)
            {
                Vector3 nn = n[v] + n[n.Length - pshape.points.Count + v];
                n[v] = n[n.Length - pshape.points.Count + v] = nn.normalized;
            }

            mesh.normals = n;
        }

        if (buildTangents)
        {
            MegaUtils.BuildTangents(mesh);
        }
    }