示例#1
0
    public override int[] GetTris(int i)
    {
        MegaLoftSection ls = loftsections[0];

        //Debug.Log("tris " + ls.meshsections[i].tris.Count);
        return(ls.meshsections[i].tris.ToArray());              //.tris;
    }
示例#2
0
    public override int NumMaterials()
    {
        MegaLoftSection ls = loftsections[0];

        //Debug.Log("materials " + ls.meshsections.Count);
        return(ls.meshsections.Count);
    }
示例#3
0
    public override MegaLoftLayerBase Copy(GameObject go)
    {
        MegaLoftLayerMultiMatComplex layer = go.AddComponent <MegaLoftLayerMultiMatComplex>();

        //meshsections = new List<MegaMeshSection>();	//null;	//.Clear();

        Copy(this, layer);

        for (int i = 0; i < layer.loftsections.Count; i++)
        {
            MegaLoftSection ls = layer.loftsections[i];
            ls.meshsections = new List <MegaMeshSection>();
        }
        layer.meshsections = new List <MegaMeshSection>();              //.Clear();
        loftverts          = null;
        loftverts1         = null;
        loftuvs            = null;
        loftcols           = null;
        capStartVerts      = null;
        capStartUVS        = null;
        capStartCols       = null;
        capEndVerts        = null;
        capEndUVS          = null;
        capEndCols         = null;
        capStartTris       = null;
        capEndTris         = null;
        lofttris           = null;

        return(null);
    }
示例#4
0
    // Get the different id sections
    public void FindSections(MegaLoftSection lsection, MegaSpline spline)
    {
        if (spline != null)
        {
            lsection.meshsections.Clear();

            int id = spline.knots[0].id - 1;

            MegaMeshSection msect = null;

            for (int i = 0; i < spline.knots.Count; i++)
            {
                if (spline.knots[i].id != id)
                {
                    id = spline.knots[i].id;
                    if (msect != null)
                    {
                        msect.lastknot = i;
                    }

                    msect = new MegaMeshSection();

                    msect.firstknot = i;
                    msect.mat       = FindMaterial(id);

                    lsection.meshsections.Add(msect);
                }
            }

            lsection.meshsections[lsection.meshsections.Count - 1].lastknot = spline.knots.Count - 1;
        }
    }
示例#5
0
    public override void CopyVertData(ref Vector3[] verts, ref Vector2[] uvs, ref Color[] cols, int offset)
    {
        MegaLoftSection ls = loftsections[0];

        for (int i = 0; i < ls.meshsections.Count; i++)
        {
            MegaMeshSection ms = ls.meshsections[i];
            Array.Copy(ms.verts.ToArray(), 0, verts, offset, ms.verts.Count);
            Array.Copy(ms.uvs.ToArray(), 0, uvs, offset, ms.uvs.Count);
            Array.Copy(ms.cols.ToArray(), 0, cols, offset, ms.cols.Count);
            offset += ms.verts.Count;
        }
    }
示例#6
0
    public override int NumVerts()
    {
        int num = 0;

        MegaLoftSection ls = loftsections[0];

        for (int i = 0; i < ls.meshsections.Count; i++)
        {
            num += ls.meshsections[i].cverts.Count * crosses;
        }

        //Debug.Log("num verts " + num + " crosses " + crosses);
        return(num);
    }
示例#7
0
    public override Material GetMaterial(int i)
    {
        MegaLoftSection ls = loftsections[0];

        if (i >= 0 && i < ls.meshsections.Count)
        {
            int id = ls.meshsections[i].mat;

            if (id >= 0 && id < sections.Count)
            {
                return(sections[ls.meshsections[i].mat].mat);
            }
        }

        return(null);
    }
    private static int CompareOrder(MegaLoftSection m1, MegaLoftSection m2)
    {
        if (m1.alpha > m2.alpha)
        {
            return(1);
        }
        else
        {
            if (m1.alpha == m2.alpha)
            {
                return(0);
            }
        }

        return(-1);
    }
示例#9
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);
    }
示例#10
0
    void GetSectionVerts(float pathalpha, ref Vector3[] verts)
    {
        float lerp  = 0.0f;
        int   csect = GetSection(pathalpha, out lerp);

        lerp = ease.easing(0.0f, 1.0f, lerp);

        MegaLoftSection cs1 = sections[csect];
        MegaLoftSection cs2 = sections[csect + 1];

        if (verts == null || verts.Length != cs1.crossverts.Length)
        {
            verts = new Vector3[cs1.crossverts.Length];
        }

        for (int v = 0; v < cs1.crossverts.Length; v++)
        {
            Vector3 p = Vector3.Lerp(cs1.crossverts[v], cs2.crossverts[v], lerp);
            verts[v] = p;
        }
    }
    public void DisplayGUI()
    {
        MegaLoftLayerComplex layer = (MegaLoftLayerComplex)target;

        //MegaShapeLoft loft = layer.GetComponent<MegaShapeLoft>();

        SetLimits(layer.gameObject);
        MegaShapeLoftEditor.PushCols();

        GUI.color           = Color.white;
        GUI.backgroundColor = layer.paramcol;
        GUI.contentColor    = Color.white;

        EditorGUILayout.BeginVertical("TextArea");

        layer.LayerName = EditorGUILayout.TextField(MegaToolTip.LayerName, layer.LayerName);

        layer.LayerEnabled = EditorGUILayout.Toggle(MegaToolTip.Enabled, layer.LayerEnabled);
        layer.paramcol     = EditorGUILayout.ColorField(MegaToolTip.ParamCol, layer.paramcol);

        if (layer.LayerEnabled)
        {
            layer.Lock = EditorGUILayout.Toggle(MegaToolTip.Lock, layer.Lock);

            if (!layer.Lock)
            {
                layer.material  = (Material)EditorGUILayout.ObjectField(MegaToolTip.Material, layer.material, typeof(Material), true);
                layer.layerPath = (MegaShape)EditorGUILayout.ObjectField(MegaToolTip.Path, layer.layerPath, typeof(MegaShape), true);

                if (layer.layerPath && layer.layerPath.splines != null)
                {
                    if (layer.layerPath.splines.Count > 1)
                    {
                        layer.curve = EditorGUILayout.IntSlider(MegaToolTip.Curve, layer.curve, 0, layer.layerPath.splines.Count - 1);
                    }
                    if (layer.curve < 0)
                    {
                        layer.curve = 0;
                    }
                    if (layer.curve > layer.layerPath.splines.Count - 1)
                    {
                        layer.curve = layer.layerPath.splines.Count - 1;
                    }
                }

                layer.SnapToPath = EditorGUILayout.Toggle("Snap To Path", layer.SnapToPath);
                layer.pathStart  = EditorGUILayout.Slider(MegaToolTip.Start, layer.pathStart, sl, sh);
                layer.pathLength = EditorGUILayout.Slider(MegaToolTip.Length, layer.pathLength, ll, lh);
                layer.pathDist   = EditorGUILayout.FloatField(MegaToolTip.Dist, layer.pathDist);
                layer.pathDist   = Mathf.Clamp(layer.pathDist, dl, dh);                 //0.05f, 1.0f);

                EditorGUILayout.BeginVertical("Box");
                layer.offset = EditorGUILayout.Vector3Field("Offset", layer.offset);

                layer.useOffsetX = EditorGUILayout.BeginToggleGroup(MegaToolTip.UseOffsetX, layer.useOffsetX);
                layer.offsetCrvX = EditorGUILayout.CurveField(MegaToolTip.OffsetCrvX, layer.offsetCrvX);
                EditorGUILayout.EndToggleGroup();

                layer.useOffsetY = EditorGUILayout.BeginToggleGroup(MegaToolTip.UseOffsetY, layer.useOffsetY);
                layer.offsetCrvY = EditorGUILayout.CurveField(MegaToolTip.OffsetCrvY, layer.offsetCrvY);
                EditorGUILayout.EndToggleGroup();

                layer.useOffsetZ = EditorGUILayout.BeginToggleGroup(MegaToolTip.UseOffsetZ, layer.useOffsetZ);
                layer.offsetCrvZ = EditorGUILayout.CurveField(MegaToolTip.OffsetCrvZ, layer.offsetCrvZ);
                EditorGUILayout.EndToggleGroup();
                EditorGUILayout.EndVertical();

                layer.frameMethod = (MegaFrameMethod)EditorGUILayout.EnumPopup("Frame Method", layer.frameMethod);
                layer.flip        = EditorGUILayout.Toggle(MegaToolTip.Flip, layer.flip);

                layer.PathSteps = EditorGUILayout.IntField("Path Steps", layer.PathSteps);
                if (layer.PathSteps < 1)
                {
                    layer.PathSteps = 1;
                }

                layer.PathTeeter = EditorGUILayout.Slider("Path Teeter", layer.PathTeeter, 0.0f, 1.0f);

                layer.advancedParams = MegaFoldOut.Start("Advanced Params", layer.advancedParams, new Color(0.5f, 0.5f, 1.0f));
                //layer.advancedParams = MegaFoldOut.Foldout("Advanced Params", layer.advancedParams, new Color(0.5f, 0.5f, 1.0f));
                //layer.advancedParams = EditorGUILayout.Foldout(layer.advancedParams, MegaToolTip.AdvancedParams);

                if (layer.advancedParams)
                {
                    layer.easeType = (MegaLoftEaseType)EditorGUILayout.EnumPopup("Ease Type", layer.easeType);

                    layer.useTwistCrv = EditorGUILayout.BeginToggleGroup("Use Twist", layer.useTwistCrv);
                    layer.twistCrv    = EditorGUILayout.CurveField("Twist Curve", layer.twistCrv);
                    EditorGUILayout.EndToggleGroup();

                    layer.useScaleXCrv = EditorGUILayout.BeginToggleGroup("Use ScaleX", layer.useScaleXCrv);
                    layer.scaleCrvX    = EditorGUILayout.CurveField("Scale X Curve", layer.scaleCrvX);
                    EditorGUILayout.EndToggleGroup();
                    layer.useScaleYCrv = EditorGUILayout.BeginToggleGroup("Use ScaleY", layer.useScaleYCrv);
                    layer.scaleCrvY    = EditorGUILayout.CurveField("Scale Y Curve", layer.scaleCrvY);
                    EditorGUILayout.EndToggleGroup();
                }
                MegaFoldOut.End(layer.advancedParams);

                //layer.showcrossparams = EditorGUILayout.Foldout(layer.showcrossparams, "Cross Params");
                layer.showcrossparams = MegaFoldOut.Start("Cross Params", layer.showcrossparams, new Color(0.5f, 1.0f, 0.5f));

                if (layer.showcrossparams)
                {
                    //EditorGUILayout.BeginVertical("Box");
                    layer.crossStart = EditorGUILayout.Slider(MegaToolTip.CrossStart, layer.crossStart, csl, csh);
                    layer.crossEnd   = EditorGUILayout.Slider(MegaToolTip.CrossLength, layer.crossEnd, cll, clh);
                    layer.CrossSteps = EditorGUILayout.IntField("Cross Steps", layer.CrossSteps);
                    if (layer.CrossSteps < 1)
                    {
                        layer.CrossSteps = 1;
                    }
                    layer.crossRot         = EditorGUILayout.Vector3Field("Cross Rotate", layer.crossRot);
                    layer.crossScale       = EditorGUILayout.Vector3Field("Cross Scale", layer.crossScale);
                    layer.pivot            = EditorGUILayout.Vector3Field("Pivot", layer.pivot);
                    layer.useCrossScaleCrv = EditorGUILayout.BeginToggleGroup("Use Scale Curve", layer.useCrossScaleCrv);
                    layer.crossScaleCrv    = EditorGUILayout.CurveField("Scale", layer.crossScaleCrv);
                    EditorGUILayout.EndToggleGroup();

                    //EditorGUILayout.EndVertical();
                }
                MegaFoldOut.End(layer.showcrossparams);

                //layer.showuvparams = EditorGUILayout.Foldout(layer.showuvparams, MegaToolTip.UVParams);
                layer.showuvparams = MegaFoldOut.Start("UV Params", layer.showuvparams, new Color(1.0f, 0.5f, 0.5f));

                if (layer.showuvparams)
                {
                    //EditorGUILayout.BeginVertical("Box");
                    MegaShapeLoftEditor.PushCols();
                    GUI.color = Color.white;

                    layer.UVOffset = EditorGUILayout.Vector2Field("UV Offset", layer.UVOffset);
                    layer.UVRotate = EditorGUILayout.Vector2Field("UV Rotate", layer.UVRotate);
                    layer.UVScale  = EditorGUILayout.Vector2Field("UV Scale", layer.UVScale);

                    layer.swapuv   = EditorGUILayout.Toggle(MegaToolTip.SwapUV, layer.swapuv);
                    layer.physuv   = EditorGUILayout.Toggle(MegaToolTip.PhysicalUV, layer.physuv);
                    layer.planaruv = EditorGUILayout.Toggle("Planar UV", layer.planaruv);
                    layer.UVOrigin = (MegaLoftUVOrigin)EditorGUILayout.EnumPopup("UV Origin", layer.UVOrigin);
                    MegaShapeLoftEditor.PopCols();
                    //EditorGUILayout.EndVertical();
                }
                MegaFoldOut.End(layer.showuvparams);

                //layer.showCapParams = EditorGUILayout.Foldout(layer.showCapParams, MegaToolTip.CapParams);
                layer.showCapParams = MegaFoldOut.Start("Cap Params", layer.showCapParams, new Color(1.0f, 1.0f, 0.5f));

                if (layer.showCapParams)
                {
                    layer.capflip = EditorGUILayout.Toggle("Flip Caps", layer.capflip);

                    layer.capStart         = EditorGUILayout.BeginToggleGroup(MegaToolTip.CapStart, layer.capStart);
                    layer.capStartMat      = (Material)EditorGUILayout.ObjectField(MegaToolTip.CapStartMat, layer.capStartMat, typeof(Material), true);
                    layer.capStartUVOffset = EditorGUILayout.Vector2Field("UV Offset", layer.capStartUVOffset);
                    layer.capStartUVScale  = EditorGUILayout.Vector2Field("UV Scale", layer.capStartUVScale);
                    layer.capStartUVRot    = EditorGUILayout.FloatField(MegaToolTip.CapStartRot, layer.capStartUVRot);
                    EditorGUILayout.EndToggleGroup();

                    layer.capEnd         = EditorGUILayout.BeginToggleGroup(MegaToolTip.CapEnd, layer.capEnd);
                    layer.capEndMat      = (Material)EditorGUILayout.ObjectField(MegaToolTip.CapEndMat, layer.capEndMat, typeof(Material), true);
                    layer.capEndUVOffset = EditorGUILayout.Vector2Field("UV Offset", layer.capEndUVOffset);
                    layer.capEndUVScale  = EditorGUILayout.Vector2Field("UV Scale", layer.capEndUVScale);
                    layer.capEndUVRot    = EditorGUILayout.FloatField(MegaToolTip.CapEndRot, layer.capEndUVRot);
                    EditorGUILayout.EndToggleGroup();
                }
                MegaFoldOut.End(layer.showCapParams);

                //layer.showsections = EditorGUILayout.Foldout(layer.showsections, "Cross Sections");
                layer.showsections = MegaFoldOut.Start("Cross Sections", layer.showsections, new Color(0.5f, 1.0f, 1.0f));

                if (layer.showsections)
                {
                    if (layer.sections == null || layer.sections.Count < 2)
                    {
                        EditorGUILayout.LabelField("At least 2 cross sections are required to build the loft");
                    }

                    seccol           = EditorGUILayout.ColorField("Sections", seccol);
                    layer.handlesize = EditorGUILayout.FloatField("Handle Size", layer.handlesize);

                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Reset Sections"))
                    {
                        for (int i = 0; i < layer.sections.Count; i++)
                        {
                            layer.sections[i].alpha = (float)i / (float)(layer.sections.Count - 1);
                        }

                        GUI.changed = true;
                    }

                    if (layer.sections.Count == 0)
                    {
                        if (GUILayout.Button("Add Section"))
                        {
                            MegaLoftSection lsect = new MegaLoftSection();
                            layer.sections.Add(lsect);
                            GUI.changed = true;
                        }
                    }

                    EditorGUILayout.EndHorizontal();

                    for (int i = 0; i < layer.sections.Count; i++)
                    {
                        EditorGUILayout.BeginVertical("Box");
                        EditorGUILayout.LabelField("Cross " + i, "");

                        float min = 0.0f;
                        float max = 1.0f;
                        if (i > 0)
                        {
                            min = layer.sections[i - 1].alpha;
                        }

                        if (i < layer.sections.Count - 1)
                        {
                            max = layer.sections[i + 1].alpha;
                        }

                        float alpha = 0.0f;
                        if (i == 0)
                        {
                            alpha = 0.0f;
                        }
                        else
                        {
                            if (i == layer.sections.Count - 1)
                            {
                                alpha = 1.0f;
                            }
                            else
                            {
                                alpha = EditorGUILayout.Slider("Alpha", layer.sections[i].alpha, min, max);
                            }
                        }
                        if (alpha != layer.sections[i].alpha)
                        {
                            if (i > 0)
                            {
                                if (alpha < layer.sections[i - 1].alpha)
                                {
                                    alpha = layer.sections[i - 1].alpha;
                                }
                            }

                            if (i < layer.sections.Count - 1)
                            {
                                if (alpha > layer.sections[i + 1].alpha)
                                {
                                    alpha = layer.sections[i + 1].alpha;
                                }
                            }

                            layer.sections[i].alpha = alpha;
                        }

                        layer.sections[i].shape = (MegaShape)EditorGUILayout.ObjectField("Section", layer.sections[i].shape, typeof(MegaShape), true);

                        if (layer.sections[i].shape != null)
                        {
                            if (layer.sections[i].shape.splines.Count > 1)
                            {
                                layer.sections[i].curve = EditorGUILayout.IntSlider("Curve", layer.sections[i].curve, 0, layer.sections[i].shape.splines.Count - 1);
                            }

                            layer.sections[i].snap = EditorGUILayout.Toggle("Snap", layer.sections[i].snap);

                            if (layer.sections[i].curve < 0)
                            {
                                layer.sections[i].curve = 0;
                            }

                            if (layer.sections[i].curve > layer.sections[i].shape.splines.Count - 1)
                            {
                                layer.sections[i].curve = layer.sections[i].shape.splines.Count - 1;
                            }
                        }

                        layer.sections[i].offset = EditorGUILayout.Vector3Field("Offset", layer.sections[i].offset);
                        layer.sections[i].rot    = EditorGUILayout.Vector3Field("Rotate", layer.sections[i].rot);
                        layer.sections[i].scale  = EditorGUILayout.Vector3Field("Scale", layer.sections[i].scale);

                        layer.sections[i].uselen = EditorGUILayout.Toggle("Use Section Len", layer.sections[i].uselen);

                        if (layer.sections[i].uselen)
                        {
                            layer.sections[i].start  = EditorGUILayout.Slider("Start", layer.sections[i].start, csl, csh);
                            layer.sections[i].length = EditorGUILayout.Slider("Length", layer.sections[i].length, cll, clh);
                        }

                        EditorGUILayout.BeginHorizontal();
                        if (GUILayout.Button("Add Section"))
                        {
                            MegaLoftSection lsect = new MegaLoftSection();

                            lsect.shape = layer.sections[i].shape;
                            lsect.curve = layer.sections[i].curve;
                            lsect.scale = layer.sections[i].scale;

                            if (i == layer.sections.Count - 1)
                            {
                                int pi = i - 1;
                                if (pi >= 0)
                                {
                                    lsect.alpha = (layer.sections[pi].alpha + layer.sections[i].alpha) * 0.5f;
                                }
                                else
                                {
                                    lsect.alpha = 1.0f;
                                }

                                layer.sections.Add(lsect);
                            }
                            else
                            {
                                int pi = i + 1;

                                if (pi < layer.sections.Count - 1)
                                {
                                    lsect.alpha = (layer.sections[pi].alpha + layer.sections[i].alpha) * 0.5f;
                                }
                                else
                                {
                                    lsect.alpha = 1.0f;
                                }
                                layer.sections.Insert(i + 1, lsect);
                            }
                            GUI.changed = true;
                        }

                        if (GUILayout.Button("Delete Section"))
                        {
                            layer.sections.RemoveAt(i);
                            i--;
                            GUI.changed = true;
                        }

                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.EndVertical();
                    }
                    MegaFoldOut.End(layer.showsections);

                    if (layer.sections.Count > 0)
                    {
                        if (layer.sections[0].alpha != 0.0f)
                        {
                            layer.sections[0].alpha = 0.0f;
                        }

                        for (int i = 1; i < layer.sections.Count - 1; i++)
                        {
                            if (layer.sections[i].alpha <= layer.sections[i - 1].alpha)
                            {
                                layer.sections[i - 1].alpha = layer.sections[i].alpha;
                            }

                            if (layer.sections[i].alpha >= layer.sections[i + 1].alpha)
                            {
                                layer.sections[i].alpha = layer.sections[i + 1].alpha;
                            }
                        }

                        if (layer.sections[layer.sections.Count - 1].alpha != 1.0f)
                        {
                            layer.sections[layer.sections.Count - 1].alpha = 1.0f;
                        }
                    }
                }
            }

            //EditorGUILayout.EndVertical();
            //MegaShapeLoftEditor.PopCols();
        }
        EditorGUILayout.EndVertical();
        MegaShapeLoftEditor.PopCols();
    }
示例#12
0
    void BuildPolyShape(MegaLoftSection lsection, int steps, Vector3 off, float width)
    {
        int			curve	= lsection.curve;
        int			k		= -1;
        Matrix4x4	tm1		= Matrix4x4.identity;
        Vector2		uv		= Vector2.zero;

        float start = crossStart;
        float len = crossEnd;

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

        MegaShape shape = lsection.shape;

        verts.Clear();
        uvs.Clear();
        norms.Clear();

        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));

        svert = verts.Count;

        float alpha = start;

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

        uv.y = start;

        float dist = 0.0f;
        Vector3 last = Vector3.zero;

        for ( int i = 0; i <= steps; i++ )
        {
            alpha = start + (((float)i / (float)steps) * len);

            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;
            verts.Add(pos);

            if ( physuv )
            {
                if ( i > 0 )
                    dist += Vector3.Distance(pos, last);

                last = pos;
                uv.x = (dist / width);
            }
            else
                uv.x = alpha;

            uvs.Add(uv);
        }

        evert = verts.Count - 1;

        uv.y = start + len;

        lsection.crossverts = verts.ToArray();
        lsection.crossuvs = uvs.ToArray();

        lsection.crosssize = MegaUtils.Extents(lsection.crossverts, out lsection.crossmin, out lsection.crossmax);
    }
示例#13
0
    public override int BuildMesh(MegaShapeLoft loft, int triindex)
    {
        if (Lock)
        {
            return(triindex);
        }

        if (layerPath == null || layerPath.splines == null || layerPath.splines.Count == 0)
        {
            return(triindex);
        }

        if (sections.Count < 2)                 //== 0 )
        {
            return(triindex);
        }

        Vector2 uv = Vector2.zero;
        Vector3 p  = Vector3.zero;

        int   wc   = ActualCrossVerts;
        float lerp = 0.0f;

        Matrix4x4 pathtm = Matrix4x4.identity;

        if (SnapToPath)
        {
            pathtm = layerPath.transform.localToWorldMatrix;
        }

        Matrix4x4 twisttm = Matrix4x4.identity;

        Vector3   sclc = Vector2.one;
        Matrix4x4 tm;

        float offx = 0.0f;
        float offy = 0.0f;
        float offz = 0.0f;

        bool clsd = layerPath.splines[curve].closed;

        float uvstart = pathStart;

        if (UVOrigin == MegaLoftUVOrigin.SplineStart)
        {
            uvstart = 0.0f;
        }

        Vector3 lastup = locup;

        for (int pi = 0; pi < PathSteps + 1; pi++)
        {
            float alpha     = (float)pi / (float)PathSteps;
            float pathalpha = pathStart + (pathLength * alpha);

            if (clsd)
            {
                pathalpha = Mathf.Repeat(pathalpha, 1.0f);
            }

            if (useScaleXCrv)
            {
                sclc.x = scaleCrvX.Evaluate(pathalpha);
            }

            if (useScaleYCrv)
            {
                sclc.y = scaleCrvY.Evaluate(pathalpha);
            }

            if (useTwistCrv)
            {
                float twist = twistCrv.Evaluate(pathalpha);
                float tw1   = layerPath.splines[curve].GetTwist(pathalpha);
                MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1));
                if (frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * GetDeformMat(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp) * twisttm;
                }
                else
                {
                    tm = pathtm * GetDeformMatNewMethod(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp, ref lastup) * twisttm;
                }
            }
            else
            {
                if (frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * GetDeformMat(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp);
                }
                else
                {
                    tm = pathtm * GetDeformMatNewMethod(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp, ref lastup);
                }
            }
            // Need to get the crosssection for the given alpha and the lerp value
            int csect = GetSection(pathalpha, out lerp);

            lerp = ease.easing(0.0f, 1.0f, lerp);

            MegaLoftSection cs1 = sections[csect];
            MegaLoftSection cs2 = sections[csect + 1];

            if (useOffsetX)
            {
                offx = offsetCrvX.Evaluate(pathalpha);
            }

            if (useOffsetY)
            {
                offy = offsetCrvY.Evaluate(pathalpha);
            }

            if (useOffsetZ)
            {
                offz = offsetCrvZ.Evaluate(pathalpha);
            }

            if (planaruv)
            {
                float size = 1.0f / layerPath.splines[curve].length;

                Matrix4x4 uvtm = Matrix4x4.TRS(new Vector3(UVOffset.x, 0.0f, UVOffset.y), Quaternion.Euler(UVRotate.x, UVRotate.y, 0.0f), new Vector3(size * UVScale.x, 1.0f, size * UVScale.y));
                for (int v = 0; v < cs1.crossverts.Length; v++)
                {
                    p = Vector3.Lerp(cs1.crossverts[v], cs2.crossverts[v], lerp);
                    if (useScaleXCrv)
                    {
                        p.x *= sclc.x;
                    }

                    if (useScaleYCrv)
                    {
                        p.y *= sclc.y;
                    }

                    p.x += offx;
                    p.y += offy;
                    p.z += offz;

                    p = tm.MultiplyPoint3x4(p);

                    p += offset;
                    int ix = (pi * wc) + v;
                    loftverts[ix] = p;

                    p.y = 0.0f;
                    p   = uvtm.MultiplyPoint(p);

                    loftuvs[ix].x = p.x;
                    loftuvs[ix].y = p.z;
                }
            }
            else
            {
                for (int v = 0; v < cs1.crossverts.Length; v++)
                {
                    p = Vector3.Lerp(cs1.crossverts[v], cs2.crossverts[v], lerp);
                    if (useScaleXCrv)
                    {
                        p.x *= sclc.x;
                    }

                    if (useScaleYCrv)
                    {
                        p.y *= sclc.y;
                    }

                    p.x += offx;
                    p.y += offy;
                    p.z += offz;

                    p = tm.MultiplyPoint3x4(p);

                    p += offset;

                    int ix = (pi * wc) + v;
                    loftverts[ix] = p;
                    uv            = Vector3.Lerp(cs1.crossuvs[v], cs2.crossuvs[v], lerp);
                    uv.y          = uvstart + alpha;

                    uv.x *= UVScale.x;
                    uv.y *= UVScale.y;

                    uv.x += UVOffset.x;
                    uv.y += UVOffset.y;

                    loftuvs[ix] = uv;
                }
            }
        }

        // Now need to build faces, normal grid face builder
        int fi    = 0;
        int index = triindex;

        if (flip)               //Tris )
        {
            for (int iz = 0; iz < ActualPathSteps - 1; iz++)
            {
                int kv = iz * (ActualCrossVerts) + index;
                for (int ix = 0; ix < ActualCrossVerts - 1; ix++)
                {
                    lofttris[fi + 0] = kv;
                    lofttris[fi + 1] = kv + wc;
                    lofttris[fi + 2] = kv + wc + 1;

                    lofttris[fi + 3] = kv + wc + 1;
                    lofttris[fi + 4] = kv + 1;
                    lofttris[fi + 5] = kv;

                    fi += 6;
                    kv++;
                }
            }
        }
        else
        {
            for (int iz = 0; iz < ActualPathSteps - 1; iz++)
            {
                int kv = iz * (ActualCrossVerts) + index;
                for (int ix = 0; ix < ActualCrossVerts - 1; ix++)
                {
                    lofttris[fi + 2] = kv;
                    lofttris[fi + 1] = kv + wc;
                    lofttris[fi + 0] = kv + wc + 1;

                    lofttris[fi + 5] = kv + wc + 1;
                    lofttris[fi + 4] = kv + 1;
                    lofttris[fi + 3] = kv;

                    fi += 6;
                    kv++;
                }
            }
        }

        index = triindex + loftverts.Length;

        if (capStart)
        {
            Matrix4x4 uvtm = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0.0f, 0.0f, capStartUVRot), Vector3.one);

            // Do uvs here from end points, as we do some clipping in here
            for (int i = 0; i < capStartVerts.Length; i++)
            {
                Vector3 lp = loftverts[i];

                capStartVerts[i] = lp;

                Vector3 uv1 = crossverts[i];
                uv1.y = lp.y;

                uv1 = uvtm.MultiplyPoint(uv1);
                capStartUVS[i].x = (uv1.x * capStartUVScale.x) + capStartUVOffset.x;
                capStartUVS[i].y = (uv1.y * capStartUVScale.y) + capStartUVOffset.y;
            }

            if (capflip)
            {
                for (int i = 0; i < capfaces.Count; i += 3)
                {
                    capStartTris[i + 2] = capfaces[i + 0] + index;
                    capStartTris[i + 1] = capfaces[i + 1] + index;
                    capStartTris[i + 0] = capfaces[i + 2] + index;
                }
            }
            else
            {
                for (int i = 0; i < capfaces.Count; i += 3)
                {
                    capStartTris[i + 0] = capfaces[i + 0] + index;
                    capStartTris[i + 1] = capfaces[i + 1] + index;
                    capStartTris[i + 2] = capfaces[i + 2] + index;
                }
            }
            fi    += capfaces.Count;
            index += capStartVerts.Length;
        }

        if (capEnd)
        {
            Matrix4x4 uvtm = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0.0f, 0.0f, capEndUVRot), Vector3.one);

            int ix = loftverts.Length - capEndVerts.Length;
            for (int i = 0; i < capEndVerts.Length; i++)
            {
                Vector3 lp = loftverts[ix + i];

                capEndVerts[i] = lp;

                Vector3 uv1 = crossvertsend[i];
                uv1.y = lp.y;

                uv1            = uvtm.MultiplyPoint(uv1);
                capEndUVS[i].x = (uv1.x * capEndUVScale.x) + capEndUVOffset.x;
                capEndUVS[i].y = (uv1.y * capEndUVScale.y) + capEndUVOffset.y;
            }

            if (capflip)
            {
                for (int i = 0; i < capfacesend.Count; i += 3)
                {
                    capEndTris[i + 0] = capfacesend[i + 0] + index;
                    capEndTris[i + 1] = capfacesend[i + 1] + index;
                    capEndTris[i + 2] = capfacesend[i + 2] + index;
                }
            }
            else
            {
                for (int i = 0; i < capfacesend.Count; i += 3)
                {
                    capEndTris[i + 2] = capfacesend[i + 0] + index;
                    capEndTris[i + 1] = capfacesend[i + 1] + index;
                    capEndTris[i + 0] = capfacesend[i + 2] + index;
                }
            }
            fi += capfacesend.Count;
        }

        return(triindex + fi);          //triindex;
    }
示例#14
0
    // Get the different id sections
    public void FindSections(MegaLoftSection lsection, MegaSpline spline)
    {
        if ( spline != null )
        {
            lsection.meshsections.Clear();

            int id = spline.knots[0].id - 1;

            MegaMeshSection msect = null;

            for ( int i = 0; i < spline.knots.Count; i++ )
            {
                if ( spline.knots[i].id != id )
                {
                    id = spline.knots[i].id;
                    if ( msect != null )
                        msect.lastknot = i;

                    msect = new MegaMeshSection();

                    msect.firstknot = i;
                    msect.mat = FindMaterial(id);

                    lsection.meshsections.Add(msect);
                }
            }

            lsection.meshsections[lsection.meshsections.Count - 1].lastknot = spline.knots.Count - 1;
        }
    }
示例#15
0
    void BuildPolyShape(MegaLoftSection lsection, int steps, Vector3 off, float width)
    {
        int       curve = lsection.curve;
        int       k     = -1;
        Matrix4x4 tm1   = Matrix4x4.identity;
        Vector2   uv    = Vector2.zero;

        float start = crossStart;
        float len   = crossEnd;

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

        MegaShape shape = lsection.shape;

        verts.Clear();
        uvs.Clear();
        norms.Clear();

        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));

        svert = verts.Count;

        float alpha = start;

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

        uv.y = start;

        float   dist = 0.0f;
        Vector3 last = Vector3.zero;

        for (int i = 0; i <= steps; i++)
        {
            alpha = start + (((float)i / (float)steps) * len);

            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;
            verts.Add(pos);

            if (physuv)
            {
                if (i > 0)
                {
                    dist += Vector3.Distance(pos, last);
                }

                last = pos;
                uv.x = (dist / width);
            }
            else
            {
                uv.x = alpha;
            }

            uvs.Add(uv);
        }

        evert = verts.Count - 1;

        uv.y = start + len;

        lsection.crossverts = verts.ToArray();
        lsection.crossuvs   = uvs.ToArray();

        lsection.crosssize = MegaUtils.Extents(lsection.crossverts, out lsection.crossmin, out lsection.crossmax);
    }
示例#16
0
    public override Vector3 GetPos(MegaShapeLoft loft, float ca, float a)
    {
        ca = Mathf.Repeat(ca, 1.0f);
        a  = Mathf.Repeat(a, 1.0f);

        // first need to find the material section we are in from ca
        MegaMeshSection ms       = null;
        MegaLoftSection lsection = loftsections[0];

        for (int i = 0; i < lsection.meshsections.Count; i++)
        {
            ms = lsection.meshsections[i];
            if (ca >= ms.castart && ca <= ms.caend)
            {
                //Debug.Log("ms " + i);
                break;
            }
        }

        ca = (ca - ms.castart) / (ms.caend - ms.castart);

        // Ok got the section
        float findex = (ms.cverts.Count - 1) * ca;
        int   cindex = (int)findex;
        float interp = findex - cindex;

        int cindex1 = cindex + 1;

        bool  flip = false;
        int   pindex;
        int   pindex1;
        float pinterp;

        if (pathLength < 0.9999f || layerPath.splines[curve].closed == false)
        {
            if (a < 0.0f)
            {
                pindex  = 0;
                pindex1 = 1;
                pinterp = a * GetLength(loft);                  // / crosses);
            }
            else
            {
                if (a >= 0.9999f)
                {
                    pindex  = crosses - 1;
                    pindex1 = crosses - 2;
                    pinterp = (a - 1.0f) * GetLength(loft);
                    flip    = true;
                }
                else
                {
                    float pfindex = (crosses - 1) * a;
                    pindex  = (int)pfindex;
                    pinterp = pfindex - pindex;
                    pindex1 = pindex + 1;
                }
            }
        }
        else
        {
            a = Mathf.Repeat(a, 0.9999f);

            float pfindex = (crosses - 1) * a;
            pindex  = (int)pfindex;
            pinterp = pfindex - pindex;
            pindex1 = pindex + 1;
        }

        Vector3 p1 = ms.verts[(pindex * ms.cverts.Count) + cindex];
        Vector3 p2 = ms.verts[(pindex * ms.cverts.Count) + cindex1];
        Vector3 p3 = ms.verts[(pindex1 * ms.cverts.Count) + cindex];
        Vector3 p4 = ms.verts[(pindex1 * ms.cverts.Count) + cindex1];

        Vector3 pm1 = Vector3.Lerp(p1, p2, interp);
        Vector3 pm2 = Vector3.Lerp(p3, p4, interp);

        Vector3 delta = pm2 - pm1;

        if (flip)
        {
            p3.x = pm2.x + (delta.x * pinterp);
            p3.y = pm2.y + (delta.y * pinterp);
            p3.z = pm2.z + (delta.z * pinterp);
        }
        else
        {
            p3.x = pm1.x + (delta.x * pinterp);
            p3.y = pm1.y + (delta.y * pinterp);
            p3.z = pm1.z + (delta.z * pinterp);
        }

        return(p3);             //Vector3.Lerp(pm1, pm2, pinterp);
    }
示例#17
0
    public override Vector3 GetPosAndLook(MegaShapeLoft loft, float ca, float a, float at, out Vector3 p)
    {
        MegaMeshSection ms       = null;
        MegaLoftSection lsection = loftsections[0];

        //Debug.Log("cain " + ca);
        ca = Mathf.Clamp(ca, 0.0f, 0.9999f);

        for (int i = 0; i < lsection.meshsections.Count; i++)
        {
            ms = lsection.meshsections[i];
            if (ca >= ms.castart && ca <= ms.caend)
            {
                break;
            }
        }

        //Debug.Log("start " + ms.castart + " end " + ms.caend);
        ca = (ca - ms.castart) / (ms.caend - ms.castart);

        ca = Mathf.Clamp(ca, 0.0f, 0.9999f);

        //Debug.Log("ca " + ca);
        float findex  = (ms.cverts.Count - 1) * ca;
        int   cindex  = (int)findex;
        float interp  = findex - cindex;
        int   cindex1 = cindex + 1;

        bool  flip = false;
        int   pindex;
        int   pindex1;
        float pinterp;

        if (pathLength < 0.9999f || layerPath.splines[curve].closed == false)
        {
            if (a < 0.0f)
            {
                pindex  = 0;
                pindex1 = 1;
                pinterp = a * GetLength(loft);                  // / crosses);
            }
            else
            {
                if (a >= 0.9999f)
                {
                    pindex  = crosses - 1;
                    pindex1 = crosses - 2;
                    pinterp = (a - 1.0f) * GetLength(loft);
                    flip    = true;
                }
                else
                {
                    float pfindex = (crosses - 1) * a;
                    pindex  = (int)pfindex;
                    pinterp = pfindex - pindex;
                    pindex1 = pindex + 1;
                }
            }
        }
        else
        {
            a = Mathf.Repeat(a, 0.9999f);

            float pfindex = (crosses - 1) * a;
            pindex  = (int)pfindex;
            pinterp = pfindex - pindex;
            pindex1 = pindex + 1;
        }

        //Debug.Log("cindex " + cindex + " interp " + interp + " verts " + ms.cverts.Count);
        Vector3 p1 = ms.verts[(pindex * ms.cverts.Count) + cindex];
        Vector3 p2 = ms.verts[(pindex * ms.cverts.Count) + cindex1];
        Vector3 p3 = ms.verts[(pindex1 * ms.cverts.Count) + cindex];
        Vector3 p4 = ms.verts[(pindex1 * ms.cverts.Count) + cindex1];

        float pa = pinterp + at;

        p1.x = p1.x + (p2.x - p1.x) * interp;
        p1.y = p1.y + (p2.y - p1.y) * interp;
        p1.z = p1.z + (p2.z - p1.z) * interp;

        p2.x = p3.x + (p4.x - p3.x) * interp;
        p2.y = p3.y + (p4.y - p3.y) * interp;
        p2.z = p3.z + (p4.z - p3.z) * interp;

        if (flip)
        {
            p2.x = p1.x - p2.x;
            p2.y = p1.y - p2.y;
            p2.z = p1.z - p2.z;
        }
        else
        {
            p2.x = p2.x - p1.x;
            p2.y = p2.y - p1.y;
            p2.z = p2.z - p1.z;
        }

        p3.x = p1.x + (p2.x * pinterp);
        p3.y = p1.y + (p2.y * pinterp);
        p3.z = p1.z + (p2.z * pinterp);

        p.x = p1.x + (p2.x * pa);
        p.y = p1.y + (p2.y * pa);
        p.z = p1.z + (p2.z * pa);

        return(p3);             //Vector3.Lerp(pm1, pm2, pinterp);
    }
    public void OnSceneGUI()
    {
        MegaLoftLayerComplex layer = (MegaLoftLayerComplex)target;
        MegaShapeLoft        loft  = layer.gameObject.GetComponent <MegaShapeLoft>();

        if (loft == null)
        {
            return;
        }

        if (layer.layerPath == null)
        {
            return;
        }

        if (!layer.showsections)
        {
            return;
        }

        MegaSpline pathspline = layer.layerPath.splines[layer.curve];

        Matrix4x4 pathtm = Matrix4x4.identity;

        if (layer.SnapToPath)
        {
            pathtm = layer.layerPath.transform.localToWorldMatrix;
        }

        Matrix4x4 twisttm = Matrix4x4.identity;
        Matrix4x4 tm;

        float offx = 0.0f;
        float offy = 0.0f;
        float offz = 0.0f;

        Vector3 lastup = locup;

        for (int i = 1; i < layer.sections.Count - 1; i++)
        {
            MegaLoftSection section = layer.sections[i];

            float alpha = section.alpha;

            if (layer.useOffsetX)
            {
                offx = layer.offsetCrvX.Evaluate(alpha);
            }

            if (layer.useOffsetY)
            {
                offy = layer.offsetCrvY.Evaluate(alpha);
            }

            if (layer.useOffsetZ)
            {
                offz += layer.offsetCrvZ.Evaluate(alpha);
            }

            //if ( layer.useTwistCrv )
            //{
            //	float twist = layer.twistCrv.Evaluate(alpha);
            //	MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * twist);
            //	tm = pathtm * layer.GetDeformMat(pathspline, alpha, layer.layerPath.normalizedInterp) * twisttm;
            //}
            //else
            //	tm = pathtm * layer.GetDeformMat(pathspline, alpha, layer.layerPath.normalizedInterp);

            if (layer.useTwistCrv)
            {
                float twist = layer.twistCrv.Evaluate(section.alpha);
                float tw1   = pathspline.GetTwist(section.alpha);
                MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1));
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp) * twisttm;
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup) * twisttm;
                }
            }
            else
            {
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp);
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup);
                }
            }

            Vector3 p = section.crossverts[0];
            if (layer.useScaleXCrv)
            {
                p.x *= layer.scaleCrvX.Evaluate(alpha);
            }

            if (layer.useScaleYCrv)
            {
                p.y *= layer.scaleCrvY.Evaluate(alpha);
            }

            p.x += offx;
            p.y += offy;
            p.z += offz;

            Vector3 tp = p;
            p = tm.MultiplyPoint3x4(p);

            p += layer.offset;

            Matrix4x4 tantm = pathtm * layer.GetDeformMat(pathspline, alpha + 0.01f, layer.layerPath.normalizedInterp);
            Vector3   tan   = tantm.MultiplyPoint3x4(tp);
            tan += layer.offset;

            tan = (tan - p).normalized;

            Vector3 p1 = section.crossverts[section.crossverts.Length - 1];
            if (layer.useScaleXCrv)
            {
                p1.x *= layer.scaleCrvX.Evaluate(alpha);
            }

            if (layer.useScaleYCrv)
            {
                p1.y *= layer.scaleCrvY.Evaluate(alpha);
            }

            p1.x += offx;
            p1.y += offy;
            p1.z += offz;

            tp = p1;
            p1 = tm.MultiplyPoint3x4(p1);

            p1           += layer.offset;
            Handles.color = Color.yellow;
            p             = loft.transform.TransformPoint(p);
            //Vector3 pn = Handles.Slider(p, tan, layer.handlesize, Handles.SphereCap, 0.0f);
            Vector3 pn = Slider(p, tan, layer.handlesize);
            pn = pn - p;
            float delta = pn.magnitude;

            if (Vector3.Dot(tan, pn) < 0.0f)
            {
                delta = -delta;
            }

            section.alpha += delta * 0.0005f;

            float al = section.alpha;                   // + delta * 0.0005f;

            if (al != layer.sections[i].alpha)
            {
                if (i > 0)
                {
                    if (al < layer.sections[i - 1].alpha)
                    {
                        al = layer.sections[i - 1].alpha;
                    }
                }

                if (i < layer.sections.Count - 1)
                {
                    if (al > layer.sections[i + 1].alpha)
                    {
                        al = layer.sections[i + 1].alpha;
                    }
                }

                layer.sections[i].alpha = al;
            }

            if (delta != 0.0f)
            {
                GUI.changed  = true;
                loft.rebuild = true;
                EditorUtility.SetDirty(target);
            }

            tan  = tantm.MultiplyPoint3x4(tp);
            tan += layer.offset;
            tan  = (tan - p1).normalized;

            p1 = loft.transform.TransformPoint(p1);

            //pn = Handles.Slider(p1, tan, layer.handlesize, Handles.SphereCap, 0.0f);
            pn = Slider(p1, tan, layer.handlesize);

            pn = pn - p1;

            delta = pn.magnitude;               //Vector3.Distance(p, pn);

            if (Vector3.Dot(tan, pn) < 0.0f)
            {
                delta = -delta;
            }

            al = section.alpha + delta * 0.0005f;

            if (al != layer.sections[i].alpha)
            {
                if (i > 0)
                {
                    if (al < layer.sections[i - 1].alpha)
                    {
                        al = layer.sections[i - 1].alpha;
                    }
                }

                if (i < layer.sections.Count - 1)
                {
                    if (al > layer.sections[i + 1].alpha)
                    {
                        al = layer.sections[i + 1].alpha;
                    }
                }

                layer.sections[i].alpha = al;
            }

            if (delta != 0.0f)
            {
                GUI.changed  = true;
                loft.rebuild = true;
                EditorUtility.SetDirty(target);
            }
        }

        if (layer.sections.Count > 0)
        {
            if (layer.sections[0].alpha != 0.0f)
            {
                layer.sections[0].alpha = 0.0f;
            }

            for (int i = 1; i < layer.sections.Count - 1; i++)
            {
                if (layer.sections[i].alpha <= layer.sections[i - 1].alpha)
                {
                    layer.sections[i - 1].alpha = layer.sections[i].alpha;
                }

                if (layer.sections[i].alpha >= layer.sections[i + 1].alpha)
                {
                    layer.sections[i].alpha = layer.sections[i + 1].alpha;
                }
            }

            if (layer.sections[layer.sections.Count - 1].alpha != 1.0f)
            {
                layer.sections[layer.sections.Count - 1].alpha = 1.0f;
            }
        }
    }
    static void DrawPath(MegaLoftLayerComplex layer)
    {
        MegaShapeLoft loft = layer.gameObject.GetComponent <MegaShapeLoft>();

        if (loft == null)
        {
            return;
        }

        if (layer.layerPath == null)
        {
            return;
        }

        if (layer.sections == null || layer.sections.Count < 2)
        {
            return;
        }


        for (int i = 0; i < layer.sections.Count; i++)
        {
            if (layer.sections[i].crossverts == null || layer.sections[i].crossverts.Length == 0)
            {
                return;
            }
        }

        MegaSpline pathspline = layer.layerPath.splines[layer.curve];

        Matrix4x4 pathtm = Matrix4x4.identity;

        if (layer.SnapToPath)
        {
            pathtm = layer.layerPath.transform.localToWorldMatrix;
        }

        Color col = Gizmos.color;

        Matrix4x4 twisttm = Matrix4x4.identity;
        Matrix4x4 tm;

        Vector3 lastup = locup;

        for (int i = 0; i < layer.sections.Count; i++)
        {
            MegaLoftSection section = layer.sections[i];

            //if ( layer.useTwistCrv )
            //{
            //	float twist = layer.twistCrv.Evaluate(section.alpha);
            //	MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * twist);
            //	tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp) * twisttm;	//loft.);
            //}
            //else
            //	tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp);	//loft.);

            if (layer.useTwistCrv)
            {
                float twist = layer.twistCrv.Evaluate(section.alpha);
                float tw1   = pathspline.GetTwist(section.alpha);
                MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1));
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp) * twisttm;
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup) * twisttm;
                }
            }
            else
            {
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp);
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup);
                }
            }

            Vector3 p1 = section.crossverts[0];

            float offx = 0.0f;
            float offy = 0.0f;
            float offz = 0.0f;
            float sclx = 1.0f;
            float scly = 1.0f;

            if (layer.useScaleXCrv)
            {
                p1.x *= layer.scaleCrvX.Evaluate(section.alpha);
            }

            if (layer.useScaleYCrv)
            {
                p1.y *= layer.scaleCrvY.Evaluate(section.alpha);
            }

            if (layer.useOffsetX)
            {
                offx = layer.offsetCrvX.Evaluate(section.alpha);
            }

            if (layer.useOffsetY)
            {
                offy = layer.offsetCrvY.Evaluate(section.alpha);
            }

            if (layer.useOffsetZ)
            {
                offz = layer.offsetCrvZ.Evaluate(section.alpha);
            }

            if (layer.useScaleXCrv)
            {
                sclx = layer.scaleCrvX.Evaluate(section.alpha);
            }

            if (layer.useScaleYCrv)
            {
                scly = layer.scaleCrvY.Evaluate(section.alpha);
            }

            p1  = tm.MultiplyPoint3x4(p1);
            p1 += layer.offset;

            Gizmos.color = seccol;              //Color.red;
            Vector3 mid = Vector3.zero;

            for (int v = 1; v < section.crossverts.Length; v++)
            {
                Vector3 p = section.crossverts[v];
                p.x *= sclx;
                p.y *= scly;

                p.x += offx;
                p.y += offy;
                p.z += offz;

                p  = tm.MultiplyPoint3x4(p);
                p += layer.offset;

                Gizmos.DrawLine(loft.transform.TransformPoint(p1), loft.transform.TransformPoint(p));

                p1 = p;

                if (v == section.crossverts.Length / 2)
                {
                    mid = p;
                }
            }

            Handles.color = Color.white;
            Handles.Label(loft.transform.TransformPoint(mid), "Cross: " + i);
            Gizmos.color = col;
        }

        // Draw outside edge
        Vector3 sclc = Vector3.one;
        float   lerp = 0.0f;

        // The position stuff here is waht we could use instead of mesh verts
        Vector3 last  = Vector3.zero;
        Vector3 last1 = Vector3.zero;

        lastup = locup;

        for (float alpha = 0.0f; alpha <= 1.0f; alpha += 0.005f)
        {
            if (layer.useScaleXCrv)
            {
                sclc.x = layer.scaleCrvX.Evaluate(alpha);
            }

            if (layer.useScaleYCrv)
            {
                sclc.y = layer.scaleCrvY.Evaluate(alpha);
            }

            //if ( layer.useTwistCrv )
            //{
            //	float twist = layer.twistCrv.Evaluate(alpha);
            //	MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * twist);
            //	tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp) * twisttm;	//loft.);
            //}
            //else
            //	tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp);	//loft.);

            if (layer.useTwistCrv)
            {
                float twist = layer.twistCrv.Evaluate(alpha);
                float tw1   = pathspline.GetTwist(alpha);
                MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1));
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(pathspline, alpha, layer.layerPath.normalizedInterp) * twisttm;
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(pathspline, alpha, layer.layerPath.normalizedInterp, ref lastup) * twisttm;
                }
            }
            else
            {
                if (layer.frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * layer.GetDeformMat(pathspline, alpha, layer.layerPath.normalizedInterp);
                }
                else
                {
                    tm = pathtm * layer.GetDeformMatNewMethod(pathspline, alpha, layer.layerPath.normalizedInterp, ref lastup);
                }
            }

            // Need to get the crosssection for the given alpha and the lerp value
            int csect = layer.GetSection(alpha, out lerp);

            lerp = layer.ease.easing(0.0f, 1.0f, lerp);

            MegaLoftSection cs1 = layer.sections[csect];
            MegaLoftSection cs2 = layer.sections[csect + 1];

            Vector3 p  = Vector3.Lerp(cs1.crossverts[0], cs2.crossverts[0], lerp);                                                 // * sclc;
            Vector3 p1 = Vector3.Lerp(cs1.crossverts[cs1.crossverts.Length - 1], cs2.crossverts[cs2.crossverts.Length - 1], lerp); // * sclc;
            if (layer.useScaleXCrv)
            {
                p.x  *= sclc.x;
                p1.x *= sclc.x;
            }

            if (layer.useScaleYCrv)
            {
                p.y  *= sclc.y;
                p1.y *= sclc.y;
            }

            if (layer.useOffsetX)
            {
                p.x  += layer.offsetCrvX.Evaluate(alpha);
                p1.x += layer.offsetCrvX.Evaluate(alpha);
            }

            if (layer.useOffsetY)
            {
                p.y  += layer.offsetCrvY.Evaluate(alpha);
                p1.y += layer.offsetCrvY.Evaluate(alpha);
            }

            if (layer.useOffsetZ)
            {
                p.z  += layer.offsetCrvZ.Evaluate(alpha);
                p1.z += layer.offsetCrvZ.Evaluate(alpha);
            }

            p  = tm.MultiplyPoint3x4(p);
            p += layer.offset;

            p1  = tm.MultiplyPoint3x4(p1);
            p1 += layer.offset;

            if (alpha > 0.0f)
            {
                Gizmos.DrawLine(loft.transform.TransformPoint(last), loft.transform.TransformPoint(p));
                Gizmos.DrawLine(loft.transform.TransformPoint(last1), loft.transform.TransformPoint(p1));
            }

            last  = p;
            last1 = p1;
        }
    }
示例#20
0
    // Do these from sample splines now?
    public override Vector3 GetPosAndUp(MegaShapeLoft loft, float ca, float a, float at, out Vector3 p, out Vector3 up)
    {
        MegaMeshSection ms       = null;
        MegaLoftSection lsection = loftsections[0];

        ca = Mathf.Clamp(ca, 0.0f, 0.9999f);

        for (int i = 0; i < lsection.meshsections.Count; i++)
        {
            ms = lsection.meshsections[i];
            if (ca >= ms.castart && ca <= ms.caend)
            {
                break;
            }
        }

        ca = (ca - ms.castart) / (ms.caend - ms.castart);

        ca = Mathf.Clamp(ca, 0.0f, 0.9999f);
        //ca = Mathf.Repeat(ca, 0.9999f);
        a = Mathf.Repeat(a, 0.9999f);

        float findex = (float)(ms.cverts.Count - 1) * ca;
        int   cindex = (int)findex;
        float interp = findex - cindex;

        int cindex1 = cindex + 1;

        int   pindex;
        int   pindex1;
        bool  flip = false;
        float pinterp;

        if (pathLength < 0.9999f || layerPath.splines[curve].closed == false)
        {
            if (a < 0.0f)
            {
                pindex  = 0;
                pinterp = a * GetLength(loft);
                pindex1 = pindex + 1;
            }
            else
            {
                if (a >= 0.999f)
                {
                    pindex  = crosses - 2;
                    pindex1 = crosses - 1;
                    pinterp = (a - 1.0f) * GetLength(loft);
                    flip    = true;
                }
                else
                {
                    float pfindex = (crosses - 1) * a;
                    pindex  = (int)pfindex;
                    pinterp = pfindex - pindex;
                    pindex1 = pindex + 1;
                }
            }
        }
        else
        {
            a = Mathf.Repeat(a, 0.9999f);

            float pfindex = (float)(crosses - 1) * a;
            pindex  = (int)pfindex;
            pinterp = pfindex - pindex;

            pindex1 = pindex + 1;
        }

        Vector3 p1 = ms.verts[(pindex * ms.cverts.Count) + cindex];
        Vector3 p2 = ms.verts[(pindex * ms.cverts.Count) + cindex1];
        Vector3 p3 = ms.verts[(pindex1 * ms.cverts.Count) + cindex];
        Vector3 p4 = ms.verts[(pindex1 * ms.cverts.Count) + cindex1];

        Vector3 pm1   = Vector3.Lerp(p1, p2, interp);
        Vector3 pm2   = Vector3.Lerp(p3, p4, interp);
        Vector3 delta = pm2 - pm1;

        float pa = pinterp + at;

        // Quick calc of face normal
        Vector3 n1 = p2 - p1;           // right
        Vector3 n2 = p3 - p1;           // forward

        up = Vector3.Cross(n1, n2).normalized;

        if (flip)
        {
            p.x = pm2.x + (delta.x * pa);
            p.y = pm2.y + (delta.y * pa);
            p.z = pm2.z + (delta.z * pa);

            p3.x = pm2.x + (delta.x * pinterp);
            p3.y = pm2.y + (delta.y * pinterp);
            p3.z = pm2.z + (delta.z * pinterp);
        }
        else
        {
            p.x = pm1.x + (delta.x * pa);
            p.y = pm1.y + (delta.y * pa);
            p.z = pm1.z + (delta.z * pa);

            p3.x = pm1.x + (delta.x * pinterp);
            p3.y = pm1.y + (delta.y * pinterp);
            p3.z = pm1.z + (delta.z * pinterp);
        }

        return(p3);
    }
示例#21
0
    private static int CompareOrder(MegaLoftSection m1, MegaLoftSection m2)
    {
        if ( m1.alpha > m2.alpha )
            return 1;
        else
        {
            if ( m1.alpha == m2.alpha )
                return 0;
        }

        return -1;
    }
示例#22
0
    void BuildPolyShape(MegaLoftSection lsection, int steps, Vector3 off1, float width)
    {
        int       curve = lsection.curve;
        int       lk    = -1;
        Matrix4x4 tm1   = Matrix4x4.identity;
        MegaShape shape = lsection.shape;

        //verts.Clear();
        //uvs.Clear();
        //norms.Clear();

        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));

        svert = verts.Count;

        {
            float dst = crossDist;

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

            svert = verts.Count;

            float alpha = crossStart;
            float cend  = crossStart + crossEnd;

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

            if (cend > 1.0f)
            {
                cend = 1.0f;
            }

            MegaSpline cspl = shape.splines[curve];

            if (cspl.closed)
            {
                if (alpha < 0.0f)
                {
                    alpha += 1.0f;
                }
            }

            Vector3 off = off1;                 //Vector3.zero;
            if (snap)
            {
                off = cspl.knots[0].p - cspl.knots[0].p;
            }

            if (cspl.closed)
            {
                alpha = Mathf.Repeat(alpha, 1.0f);
            }

            lsection.meshsections.Clear();
            FindSections(lsection, cspl);

            Vector3 pos = tm1.MultiplyPoint3x4(cspl.InterpCurve3D(alpha, shape.normalizedInterp, ref lk) + off);

            //Debug.Log("MeshSections " + lsection.meshsections.Count);

            for (int i = 0; i < lsection.meshsections.Count; i++)
            {
                MegaMeshSection     ms = lsection.meshsections[i];              //new MegaMeshSection();
                MegaMaterialSection s  = sections[ms.mat];

                int   k1 = ms.firstknot;
                int   k2 = ms.lastknot;
                float l1 = 0.0f;
                float l2 = 0.0f;

                //Debug.Log("k1 " + k1 + " k2 " + k2);
                if (k1 > 0)
                {
                    l1 = cspl.knots[k1 - 1].length;
                }
                else
                {
                    l1 = 0.0f;
                }

                if (k2 < cspl.knots.Count - 1)
                {
                    l2 = cspl.knots[k2 - 1].length;
                }
                else
                {
                    l2 = cspl.length;
                }

                //float slen = l2 - l1;
                //Debug.Log("l1 " + l1 + " l2 " + l2);

                float a1 = l1 / cspl.length;
                float a2 = l2 / cspl.length;
                ms.castart = a1;
                ms.caend   = a2;

                for (int kn = k1; kn < k2; kn++)
                {
                    pos = cspl.knots[kn].Interpolate(0.0f, cspl.knots[kn + 1]) + lsection.offset;

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

                    pos = tm1.MultiplyPoint3x4(pos + off);
                    ms.cverts.Add(pos);

                    for (int j = 1; j < s.steps; j++)
                    {
                        float ka = (float)j / (float)s.steps;
                        pos = cspl.knots[kn].Interpolate(ka, cspl.knots[kn + 1]) + lsection.offset;

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

                        pos = tm1.MultiplyPoint3x4(pos + off);
                        ms.cverts.Add(pos);
                    }
                }

                pos = cspl.knots[k2 - 1].Interpolate(1.0f, cspl.knots[k2]) + lsection.offset;

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

                pos = tm1.MultiplyPoint3x4(pos + off);
                ms.cverts.Add(pos);
                //pos = tm1.MultiplyPoint3x4(cspl.knots[k2].p + off);
                //ms.cverts.Add(pos);
            }

            // Do uv and col now
            for (int i = 0; i < lsection.meshsections.Count; i++)
            {
                MegaMeshSection ms1 = lsection.meshsections[i];

                ms1.len = 0.0f;
                //int k1 = ms1.firstknot;
                //int k2 = ms1.lastknot;

                //Debug.Log("k1 " + k1 + " k2 " + k2);
                //float l1 = cspl.knots[k2].length - cspl.knots[k1].length;

                Vector2 uv1 = Vector2.zero;
                ms1.cuvs.Add(uv1);
                ms1.ccols.Add(Color.white);

                for (int v = 1; v < ms1.cverts.Count; v++)
                {
                    ms1.len += Vector3.Distance(ms1.cverts[v], ms1.cverts[v - 1]);
                }

                for (int v = 1; v < ms1.cverts.Count; v++)
                {
                    uv1.y += Vector3.Distance(ms1.cverts[v], ms1.cverts[v - 1]) / ms1.len;
                    //uv1.y /= len;	//Vector3.Distance(ms1.cverts[v], ms1.cverts[v - 1]);
                    ms1.cuvs.Add(uv1);
                    ms1.ccols.Add(Color.white);
                }
            }

            // Add end point
            if (cspl.closed)
            {
                alpha = Mathf.Repeat(cend, 1.0f);
            }
        }

        // Calc normals
        Vector3 up = Vector3.zero;
        Vector3 n1 = Vector3.zero;

        for (int i = 0; i < lsection.meshsections.Count; i++)
        {
            MegaMeshSection ms1 = lsection.meshsections[i];

            if (ms1.cverts.Count > 1)
            {
                for (int v = 0; v < ms1.cverts.Count; v++)
                {
                    if (v < ms1.cverts.Count - 1)
                    {
                        n1 = (ms1.cverts[v + 1] - ms1.cverts[v]);
                    }
                    else
                    {
                        n1 = (ms1.cverts[v] - ms1.cverts[v - 1]);
                    }

                    up.x = -n1.y;
                    up.y = n1.x;
                    up.z = 0.0f;
                    ms1.cnorms.Add(up);
                }
            }
        }
    }
示例#23
0
    public void DisplayGUI()
    {
        MegaLoftLayerComplex layer = (MegaLoftLayerComplex)target;

        //MegaShapeLoft loft = layer.GetComponent<MegaShapeLoft>();

        SetLimits(layer.gameObject);
        MegaShapeLoftEditor.PushCols();

        GUI.color = Color.white;
        GUI.backgroundColor = layer.paramcol;
        GUI.contentColor = Color.white;

        EditorGUILayout.BeginVertical("TextArea");

        layer.LayerName = EditorGUILayout.TextField(MegaToolTip.LayerName, layer.LayerName);

        layer.LayerEnabled = EditorGUILayout.Toggle(MegaToolTip.Enabled, layer.LayerEnabled);
        layer.paramcol = EditorGUILayout.ColorField(MegaToolTip.ParamCol, layer.paramcol);

        if ( layer.LayerEnabled )
        {
            layer.Lock = EditorGUILayout.Toggle(MegaToolTip.Lock, layer.Lock);

            if ( !layer.Lock )
            {
                layer.material = (Material)EditorGUILayout.ObjectField(MegaToolTip.Material, layer.material, typeof(Material), true);
                layer.layerPath = (MegaShape)EditorGUILayout.ObjectField(MegaToolTip.Path, layer.layerPath, typeof(MegaShape), true);

                if ( layer.layerPath && layer.layerPath.splines != null )
                {
                    if ( layer.layerPath.splines.Count > 1 )
                        layer.curve = EditorGUILayout.IntSlider(MegaToolTip.Curve, layer.curve, 0, layer.layerPath.splines.Count - 1);
                    if ( layer.curve < 0 ) layer.curve = 0;
                    if ( layer.curve > layer.layerPath.splines.Count - 1 )
                        layer.curve = layer.layerPath.splines.Count - 1;
                }

                layer.SnapToPath = EditorGUILayout.Toggle("Snap To Path", layer.SnapToPath);
                layer.pathStart = EditorGUILayout.Slider(MegaToolTip.Start, layer.pathStart, sl, sh);
                layer.pathLength = EditorGUILayout.Slider(MegaToolTip.Length, layer.pathLength, ll, lh);
                layer.pathDist = EditorGUILayout.FloatField(MegaToolTip.Dist, layer.pathDist);
                layer.pathDist = Mathf.Clamp(layer.pathDist, dl, dh);	//0.05f, 1.0f);

                EditorGUILayout.BeginVertical("Box");
                layer.offset = EditorGUILayout.Vector3Field("Offset", layer.offset);

                layer.useOffsetX = EditorGUILayout.BeginToggleGroup(MegaToolTip.UseOffsetX, layer.useOffsetX);
                layer.offsetCrvX = EditorGUILayout.CurveField(MegaToolTip.OffsetCrvX, layer.offsetCrvX);
                EditorGUILayout.EndToggleGroup();

                layer.useOffsetY = EditorGUILayout.BeginToggleGroup(MegaToolTip.UseOffsetY, layer.useOffsetY);
                layer.offsetCrvY = EditorGUILayout.CurveField(MegaToolTip.OffsetCrvY, layer.offsetCrvY);
                EditorGUILayout.EndToggleGroup();

                layer.useOffsetZ = EditorGUILayout.BeginToggleGroup(MegaToolTip.UseOffsetZ, layer.useOffsetZ);
                layer.offsetCrvZ = EditorGUILayout.CurveField(MegaToolTip.OffsetCrvZ, layer.offsetCrvZ);
                EditorGUILayout.EndToggleGroup();
                EditorGUILayout.EndVertical();

                layer.frameMethod = (MegaFrameMethod)EditorGUILayout.EnumPopup("Frame Method", layer.frameMethod);
                layer.flip = EditorGUILayout.Toggle(MegaToolTip.Flip, layer.flip);

                layer.PathSteps = EditorGUILayout.IntField("Path Steps", layer.PathSteps);
                if ( layer.PathSteps < 1 )
                    layer.PathSteps = 1;

                layer.PathTeeter = EditorGUILayout.Slider("Path Teeter", layer.PathTeeter, 0.0f, 1.0f);

                layer.advancedParams = MegaFoldOut.Start("Advanced Params", layer.advancedParams, new Color(0.5f, 0.5f, 1.0f));
                //layer.advancedParams = MegaFoldOut.Foldout("Advanced Params", layer.advancedParams, new Color(0.5f, 0.5f, 1.0f));
                //layer.advancedParams = EditorGUILayout.Foldout(layer.advancedParams, MegaToolTip.AdvancedParams);

                if ( layer.advancedParams )
                {
                    layer.easeType = (MegaLoftEaseType)EditorGUILayout.EnumPopup("Ease Type", layer.easeType);

                    layer.useTwistCrv = EditorGUILayout.BeginToggleGroup("Use Twist", layer.useTwistCrv);
                    layer.twistCrv = EditorGUILayout.CurveField("Twist Curve", layer.twistCrv);
                    EditorGUILayout.EndToggleGroup();

                    layer.useScaleXCrv = EditorGUILayout.BeginToggleGroup("Use ScaleX", layer.useScaleXCrv);
                    layer.scaleCrvX = EditorGUILayout.CurveField("Scale X Curve", layer.scaleCrvX);
                    EditorGUILayout.EndToggleGroup();
                    layer.useScaleYCrv = EditorGUILayout.BeginToggleGroup("Use ScaleY", layer.useScaleYCrv);
                    layer.scaleCrvY = EditorGUILayout.CurveField("Scale Y Curve", layer.scaleCrvY);
                    EditorGUILayout.EndToggleGroup();
                }
                MegaFoldOut.End(layer.advancedParams);

                //layer.showcrossparams = EditorGUILayout.Foldout(layer.showcrossparams, "Cross Params");
                layer.showcrossparams = MegaFoldOut.Start("Cross Params", layer.showcrossparams, new Color(0.5f, 1.0f, 0.5f));

                if ( layer.showcrossparams )
                {
                    //EditorGUILayout.BeginVertical("Box");
                    layer.crossStart = EditorGUILayout.Slider(MegaToolTip.CrossStart, layer.crossStart, csl, csh);
                    layer.crossEnd = EditorGUILayout.Slider(MegaToolTip.CrossLength, layer.crossEnd, cll, clh);
                    layer.CrossSteps = EditorGUILayout.IntField("Cross Steps", layer.CrossSteps);
                    if ( layer.CrossSteps < 1 )
                        layer.CrossSteps = 1;
                    layer.crossRot = EditorGUILayout.Vector3Field("Cross Rotate", layer.crossRot);
                    layer.crossScale = EditorGUILayout.Vector3Field("Cross Scale", layer.crossScale);
                    layer.pivot = EditorGUILayout.Vector3Field("Pivot", layer.pivot);
                    layer.useCrossScaleCrv = EditorGUILayout.BeginToggleGroup("Use Scale Curve", layer.useCrossScaleCrv);
                    layer.crossScaleCrv = EditorGUILayout.CurveField("Scale", layer.crossScaleCrv);
                    EditorGUILayout.EndToggleGroup();

                    //EditorGUILayout.EndVertical();
                }
                MegaFoldOut.End(layer.showcrossparams);

                //layer.showuvparams = EditorGUILayout.Foldout(layer.showuvparams, MegaToolTip.UVParams);
                layer.showuvparams = MegaFoldOut.Start("UV Params", layer.showuvparams, new Color(1.0f, 0.5f, 0.5f));

                if ( layer.showuvparams )
                {
                    //EditorGUILayout.BeginVertical("Box");
                    MegaShapeLoftEditor.PushCols();
                    GUI.color = Color.white;

                    layer.UVOffset = EditorGUILayout.Vector2Field("UV Offset", layer.UVOffset);
                    layer.UVRotate = EditorGUILayout.Vector2Field("UV Rotate", layer.UVRotate);
                    layer.UVScale = EditorGUILayout.Vector2Field("UV Scale", layer.UVScale);

                    layer.swapuv = EditorGUILayout.Toggle(MegaToolTip.SwapUV, layer.swapuv);
                    layer.physuv = EditorGUILayout.Toggle(MegaToolTip.PhysicalUV, layer.physuv);
                    layer.planaruv = EditorGUILayout.Toggle("Planar UV", layer.planaruv);
                    layer.UVOrigin = (MegaLoftUVOrigin)EditorGUILayout.EnumPopup("UV Origin", layer.UVOrigin);
                    MegaShapeLoftEditor.PopCols();
                    //EditorGUILayout.EndVertical();
                }
                MegaFoldOut.End(layer.showuvparams);

                //layer.showCapParams = EditorGUILayout.Foldout(layer.showCapParams, MegaToolTip.CapParams);
                layer.showCapParams = MegaFoldOut.Start("Cap Params", layer.showCapParams, new Color(1.0f, 1.0f, 0.5f));

                if ( layer.showCapParams )
                {
                    layer.capflip = EditorGUILayout.Toggle("Flip Caps", layer.capflip);

                    layer.capStart = EditorGUILayout.BeginToggleGroup(MegaToolTip.CapStart, layer.capStart);
                    layer.capStartMat = (Material)EditorGUILayout.ObjectField(MegaToolTip.CapStartMat, layer.capStartMat, typeof(Material), true);
                    layer.capStartUVOffset = EditorGUILayout.Vector2Field("UV Offset", layer.capStartUVOffset);
                    layer.capStartUVScale = EditorGUILayout.Vector2Field("UV Scale", layer.capStartUVScale);
                    layer.capStartUVRot = EditorGUILayout.FloatField(MegaToolTip.CapStartRot, layer.capStartUVRot);
                    EditorGUILayout.EndToggleGroup();

                    layer.capEnd = EditorGUILayout.BeginToggleGroup(MegaToolTip.CapEnd, layer.capEnd);
                    layer.capEndMat = (Material)EditorGUILayout.ObjectField(MegaToolTip.CapEndMat, layer.capEndMat, typeof(Material), true);
                    layer.capEndUVOffset = EditorGUILayout.Vector2Field("UV Offset", layer.capEndUVOffset);
                    layer.capEndUVScale = EditorGUILayout.Vector2Field("UV Scale", layer.capEndUVScale);
                    layer.capEndUVRot = EditorGUILayout.FloatField(MegaToolTip.CapEndRot, layer.capEndUVRot);
                    EditorGUILayout.EndToggleGroup();
                }
                MegaFoldOut.End(layer.showCapParams);

                //layer.showsections = EditorGUILayout.Foldout(layer.showsections, "Cross Sections");
                layer.showsections = MegaFoldOut.Start("Cross Sections", layer.showsections, new Color(0.5f, 1.0f, 1.0f));

                if ( layer.showsections )
                {
                    if ( layer.sections == null || layer.sections.Count < 2 )
                    {
                        EditorGUILayout.LabelField("At least 2 cross sections are required to build the loft");
                    }

                    seccol = EditorGUILayout.ColorField("Sections", seccol);
                    layer.handlesize = EditorGUILayout.FloatField("Handle Size", layer.handlesize);

                    EditorGUILayout.BeginHorizontal();
                    if ( GUILayout.Button("Reset Sections") )
                    {
                        for ( int i = 0; i < layer.sections.Count; i++ )
                            layer.sections[i].alpha = (float)i / (float)(layer.sections.Count - 1);

                        GUI.changed = true;
                    }

                    if ( layer.sections.Count == 0 )
                    {
                        if ( GUILayout.Button("Add Section") )
                        {
                            MegaLoftSection lsect = new MegaLoftSection();
                            layer.sections.Add(lsect);
                            GUI.changed = true;
                        }
                    }

                    EditorGUILayout.EndHorizontal();

                    for ( int i = 0; i < layer.sections.Count; i++ )
                    {
                        EditorGUILayout.BeginVertical("Box");
                        EditorGUILayout.LabelField("Cross " + i, "");

                        float min = 0.0f;
                        float max = 1.0f;
                        if ( i > 0 )
                            min = layer.sections[i - 1].alpha;

                        if ( i < layer.sections.Count - 1 )
                            max = layer.sections[i + 1].alpha;

                        float alpha = 0.0f;
                        if ( i == 0 )
                            alpha = 0.0f;
                        else
                        {
                            if ( i == layer.sections.Count - 1 )
                                alpha = 1.0f;
                            else
                                alpha = EditorGUILayout.Slider("Alpha", layer.sections[i].alpha, min, max);
                        }
                        if ( alpha != layer.sections[i].alpha )
                        {
                            if ( i > 0 )
                            {
                                if ( alpha < layer.sections[i - 1].alpha )
                                    alpha = layer.sections[i - 1].alpha;
                            }

                            if ( i < layer.sections.Count - 1 )
                            {
                                if ( alpha > layer.sections[i + 1].alpha )
                                    alpha = layer.sections[i + 1].alpha;
                            }

                            layer.sections[i].alpha = alpha;
                        }

                        layer.sections[i].shape = (MegaShape)EditorGUILayout.ObjectField("Section", layer.sections[i].shape, typeof(MegaShape), true);

                        if ( layer.sections[i].shape != null )
                        {
                            if ( layer.sections[i].shape.splines.Count > 1 )
                                layer.sections[i].curve = EditorGUILayout.IntSlider("Curve", layer.sections[i].curve, 0, layer.sections[i].shape.splines.Count - 1);

                            layer.sections[i].snap = EditorGUILayout.Toggle("Snap", layer.sections[i].snap);

                            if ( layer.sections[i].curve < 0 )
                                layer.sections[i].curve = 0;

                            if ( layer.sections[i].curve > layer.sections[i].shape.splines.Count - 1 )
                                layer.sections[i].curve = layer.sections[i].shape.splines.Count - 1;
                        }

                        layer.sections[i].offset = EditorGUILayout.Vector3Field("Offset", layer.sections[i].offset);
                        layer.sections[i].rot = EditorGUILayout.Vector3Field("Rotate", layer.sections[i].rot);
                        layer.sections[i].scale = EditorGUILayout.Vector3Field("Scale", layer.sections[i].scale);

                        layer.sections[i].uselen = EditorGUILayout.Toggle("Use Section Len", layer.sections[i].uselen);

                        if ( layer.sections[i].uselen )
                        {
                            layer.sections[i].start = EditorGUILayout.Slider("Start", layer.sections[i].start, csl, csh);
                            layer.sections[i].length = EditorGUILayout.Slider("Length", layer.sections[i].length, cll, clh);
                        }

                        EditorGUILayout.BeginHorizontal();
                        if ( GUILayout.Button("Add Section") )
                        {
                            MegaLoftSection lsect = new MegaLoftSection();

                            lsect.shape = layer.sections[i].shape;
                            lsect.curve = layer.sections[i].curve;
                            lsect.scale = layer.sections[i].scale;

                            if ( i == layer.sections.Count - 1 )
                            {
                                int pi = i - 1;
                                if ( pi >= 0 )
                                    lsect.alpha = (layer.sections[pi].alpha + layer.sections[i].alpha) * 0.5f;
                                else
                                    lsect.alpha = 1.0f;

                                layer.sections.Add(lsect);
                            }
                            else
                            {
                                int pi = i + 1;

                                if ( pi < layer.sections.Count - 1 )
                                    lsect.alpha = (layer.sections[pi].alpha + layer.sections[i].alpha) * 0.5f;
                                else
                                    lsect.alpha = 1.0f;
                                layer.sections.Insert(i + 1, lsect);
                            }
                            GUI.changed = true;
                        }

                        if ( GUILayout.Button("Delete Section") )
                        {
                            layer.sections.RemoveAt(i);
                            i--;
                            GUI.changed = true;
                        }

                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.EndVertical();
                    }
                    MegaFoldOut.End(layer.showsections);

                    if ( layer.sections.Count > 0 )
                    {
                        if ( layer.sections[0].alpha != 0.0f )
                            layer.sections[0].alpha = 0.0f;

                        for ( int i = 1; i < layer.sections.Count - 1; i++ )
                        {
                            if ( layer.sections[i].alpha <= layer.sections[i - 1].alpha )
                                layer.sections[i - 1].alpha = layer.sections[i].alpha;

                            if ( layer.sections[i].alpha >= layer.sections[i + 1].alpha )
                                layer.sections[i].alpha = layer.sections[i + 1].alpha;
                        }

                        if ( layer.sections[layer.sections.Count - 1].alpha != 1.0f )
                            layer.sections[layer.sections.Count - 1].alpha = 1.0f;
                    }
                }
            }

            //EditorGUILayout.EndVertical();
            //MegaShapeLoftEditor.PopCols();
        }
        EditorGUILayout.EndVertical();
        MegaShapeLoftEditor.PopCols();
    }
示例#24
0
    public override int BuildMesh(MegaShapeLoft loft, int triindex)
    {
        if (Lock)
        {
            return(triindex);
        }

        if (layerPath == null || layerPath.splines == null || layerPath.splines.Count == 0)
        {
            return(triindex);
        }

        if (loftsections.Count < 2)             //== 0 )
        {
            return(triindex);
        }

        Vector2 uv = Vector2.zero;
        Vector3 p  = Vector3.zero;

        //int wc = 1;	//ActualCrossVerts;
        float lerp = 0.0f;

        Matrix4x4 pathtm = Matrix4x4.identity;

        //if ( SnapToPath )
        //	pathtm = layerPath.transform.localToWorldMatrix;

        Matrix4x4 twisttm = Matrix4x4.identity;

        //Vector3 sclc = Vector2.one;
        Matrix4x4 tm;

        float offx = 0.0f;
        float offy = 0.0f;
        float offz = 0.0f;

        MegaSpline pathspline = layerPath.splines[curve];

        //bool clsd = layerPath.splines[curve].closed;

        float uvstart = pathStart;

        if (UVOrigin == MegaLoftUVOrigin.SplineStart)
        {
            uvstart = 0.0f;
        }

        Vector3 lastup = locup;

        Color col1 = color;

        float calpha = 0.0f;

        //float uvalpha = 0.0f;

        for (int pi = 0; pi < crosses; pi++)
        {
            float alpha     = (float)pi / (float)(crosses - 1);         //PathSteps;
            float pathalpha = pathStart + (pathLength * alpha);

            //uvalpha = pathalpha;
            //if ( clsd )
            //	pathalpha = Mathf.Repeat(pathalpha, 1.0f);

            //if ( useScaleXCrv )
            //	sclc.x = scaleCrvX.Evaluate(pathalpha);

            //if ( useScaleYCrv )
            //	sclc.y = scaleCrvY.Evaluate(pathalpha);

            if (useTwistCrv)
            {
                float twist = twistCrv.Evaluate(pathalpha);
                float tw1   = layerPath.splines[curve].GetTwist(pathalpha);
                MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1));
                if (frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * GetDeformMat(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp) * twisttm;
                }
                else
                {
                    tm = pathtm * GetDeformMatNewMethod(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp, ref lastup) * twisttm;
                }
            }
            else
            {
                if (frameMethod == MegaFrameMethod.Old)
                {
                    tm = pathtm * GetDeformMat(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp);
                }
                else
                {
                    tm = pathtm * GetDeformMatNewMethod(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp, ref lastup);
                }
            }
            // Need to get the crosssection for the given alpha and the lerp value
            int csect = GetSection(pathalpha, out lerp);

            lerp = ease.easing(0.0f, 1.0f, lerp);

            MegaLoftSection cs1 = loftsections[csect];
            MegaLoftSection cs2 = loftsections[csect + 1];

            //MegaSpline sectionspline = cs1.shape.splines[cs1.curve];

            if (useOffsetX)
            {
                offx = offsetCrvX.Evaluate(pathalpha);
            }

            if (useOffsetY)
            {
                offy = offsetCrvY.Evaluate(pathalpha);
            }

            if (useOffsetZ)
            {
                offz = offsetCrvZ.Evaluate(pathalpha);
            }

            for (int i = 0; i < cs1.meshsections.Count; i++)
            {
                MegaMeshSection ms0 = loftsections[0].meshsections[i];

                //float slen = sectionspline.knots[ms0.lastknot].length - sectionspline.knots[ms0.firstknot].length;

                MegaMaterialSection mats = sections[ms0.mat];

                if (mats.Enabled)
                {
                    MegaMeshSection ms1 = cs1.meshsections[i];
                    MegaMeshSection ms2 = cs2.meshsections[i];

                    if (loft.useColors)
                    {
                        if (mats.colmode == MegaLoftColMode.Loft)
                        {
                            calpha = alpha;
                        }
                        else
                        {
                            calpha = pathalpha;
                        }

                        calpha = Mathf.Repeat(calpha + mats.coloffset, 1.0f);
                        col1.r = mats.colR.Evaluate(calpha);
                        col1.g = mats.colG.Evaluate(calpha);
                        col1.b = mats.colB.Evaluate(calpha);
                        col1.a = mats.colA.Evaluate(calpha);
                    }

                    for (int v = 0; v < ms1.cverts.Count; v++)
                    {
                        p = Vector3.Lerp(ms1.cverts[v], ms2.cverts[v], lerp);                           // Easing here?
                        //if ( useScaleXCrv )
                        //	p.x *= sclc.x;

                        //if ( useScaleYCrv )
                        //	p.y *= sclc.y;

                        p.x += offx;
                        p.y += offy;
                        p.z += offz;

                        p = tm.MultiplyPoint3x4(p);

                        p += offset;

                        //int ix = (pi * wc) + v;
                        if (conform)
                        {
                            ms0.verts1.Add(p);
                        }
                        else
                        {
                            ms0.verts.Add(p);
                        }

                        uv.y = Mathf.Lerp(ms1.cuvs[v].y, ms2.cuvs[v].y, lerp);

                        uv.x = alpha - uvstart;                         //pathStart;
                        //uv.y = ms.cuvs[v].y;	// - crossStart;	// again not sure here start;

                        if (mats.physuv)
                        {
                            uv.x *= pathspline.length;
                            uv.y *= ms0.len;                                    //sectionspline.length;
                        }
                        else
                        {
                            if (mats.uvcalcy)
                            {
                                //uv.x = ((alpha * LoftLength) / sectionspline.length) - uvstart;
                                uv.x = ((alpha * pathspline.length) / ms0.len) - uvstart;
                            }
                        }

                        if (mats.swapuv)
                        {
                            float ux = uv.x;
                            uv.x = uv.y;
                            uv.y = ux;
                        }

                        uv.x *= mats.UVScale.x;
                        uv.y *= mats.UVScale.y;

                        uv.x += mats.UVOffset.x;
                        uv.y += mats.UVOffset.y;

                        ms0.uvs.Add(uv);                                //[vi] = uv;

                        if (loft.useColors)
                        {
                            ms0.cols.Add(col1);
                        }

#if false
                        uv.y = uvstart + alpha;

                        uv.x *= UVScale.x;
                        uv.y *= UVScale.y;

                        uv.x += UVOffset.x;
                        uv.y += UVOffset.y;
#endif
                        //ms0.uvs.Add(uv);
                    }
                }
            }
        }

        int index = triindex;
        int fi    = 0;          // Calc this

        if (enabled)
        {
            if (flip)
            {
                for (int m = 0; m < loftsections[0].meshsections.Count; m++)
                {
                    MegaMeshSection     ms   = loftsections[0].meshsections[m];
                    MegaMaterialSection mats = sections[ms.mat];

                    if (mats.Enabled)
                    {
                        for (int cr = 0; cr < crosses - 1; cr++)
                        {
                            for (int f = 0; f < ms.cverts.Count - 1; f++)
                            {
                                ms.tris.Add(index + f);
                                ms.tris.Add(index + f + 1);
                                ms.tris.Add(index + f + 1 + ms.cverts.Count);

                                ms.tris.Add(index + f);
                                ms.tris.Add(index + f + 1 + ms.cverts.Count);
                                ms.tris.Add(index + f + ms.cverts.Count);

                                fi += 6;
                            }

                            index += ms.cverts.Count;
                        }
                        index += ms.cverts.Count;
                    }
                }
            }
            else
            {
                for (int m = 0; m < loftsections[0].meshsections.Count; m++)
                {
                    MegaMeshSection     ms   = loftsections[0].meshsections[m];
                    MegaMaterialSection mats = sections[ms.mat];

                    if (mats.Enabled)
                    {
                        for (int cr = 0; cr < crosses - 1; cr++)
                        {
                            for (int f = 0; f < ms.cverts.Count - 1; f++)
                            {
                                ms.tris.Add(index + f + 1 + ms.cverts.Count);
                                ms.tris.Add(index + f + 1);
                                ms.tris.Add(index + f);

                                ms.tris.Add(index + f + ms.cverts.Count);
                                ms.tris.Add(index + f + 1 + ms.cverts.Count);
                                ms.tris.Add(index + f);

                                fi += 6;
                            }

                            index += ms.cverts.Count;
                        }

                        index += ms.cverts.Count;
                    }
                }
            }
        }

        if (conform)
        {
            CalcBounds();
            DoConform(loft);
        }

        return(triindex + fi);          //triindex;
    }
示例#25
0
    void BuildPolyShape(MegaLoftSection lsection, int steps, Vector3 off1, float width)
    {
        int			curve	= lsection.curve;
        int			lk		= -1;
        Matrix4x4	tm1		= Matrix4x4.identity;
        MegaShape shape = lsection.shape;

        //verts.Clear();
        //uvs.Clear();
        //norms.Clear();

        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));

        svert = verts.Count;

        {
            float dst = crossDist;

            if ( dst < 0.01f )
                dst = 0.01f;

            svert = verts.Count;

            float alpha = crossStart;
            float cend = crossStart + crossEnd;

            if ( alpha < 0.0f )
                alpha = 0.0f;

            if ( cend > 1.0f )
                cend = 1.0f;

            MegaSpline cspl = shape.splines[curve];

            if ( cspl.closed )
            {
                if ( alpha < 0.0f )
                    alpha += 1.0f;
            }

            Vector3 off = off1;	//Vector3.zero;
            if ( snap )
                off = cspl.knots[0].p - cspl.knots[0].p;

            if ( cspl.closed )
                alpha = Mathf.Repeat(alpha, 1.0f);

            lsection.meshsections.Clear();
            FindSections(lsection, cspl);

            Vector3 pos = tm1.MultiplyPoint3x4(cspl.InterpCurve3D(alpha, shape.normalizedInterp, ref lk) + off);

            //Debug.Log("MeshSections " + lsection.meshsections.Count);

            for ( int i = 0; i < lsection.meshsections.Count; i++ )
            {
                MegaMeshSection ms = lsection.meshsections[i];	//new MegaMeshSection();
                MegaMaterialSection s = sections[ms.mat];

                int k1 = ms.firstknot;
                int k2 = ms.lastknot;
                float l1 = 0.0f;
                float l2 = 0.0f;

                //Debug.Log("k1 " + k1 + " k2 " + k2);
                if ( k1 > 0 )
                    l1 = cspl.knots[k1 - 1].length;
                else
                    l1 = 0.0f;

                if ( k2 < cspl.knots.Count - 1 )
                    l2 = cspl.knots[k2 - 1].length;
                else
                    l2 = cspl.length;

                //float slen = l2 - l1;
                //Debug.Log("l1 " + l1 + " l2 " + l2);

                float a1 = l1 / cspl.length;
                float a2 = l2 / cspl.length;
                ms.castart = a1;
                ms.caend = a2;

                for ( int kn = k1; kn < k2; kn++ )
                {
                    pos = cspl.knots[kn].Interpolate(0.0f, cspl.knots[kn + 1]) + lsection.offset;

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

                    pos = tm1.MultiplyPoint3x4(pos + off);
                    ms.cverts.Add(pos);

                    for ( int j = 1; j < s.steps; j++ )
                    {
                        float ka = (float)j / (float)s.steps;
                        pos = cspl.knots[kn].Interpolate(ka, cspl.knots[kn + 1]) + lsection.offset;

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

                        pos = tm1.MultiplyPoint3x4(pos + off);
                        ms.cverts.Add(pos);
                    }
                }

                pos = cspl.knots[k2 - 1].Interpolate(1.0f, cspl.knots[k2]) + lsection.offset;

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

                pos = tm1.MultiplyPoint3x4(pos + off);
                ms.cverts.Add(pos);
                //pos = tm1.MultiplyPoint3x4(cspl.knots[k2].p + off);
                //ms.cverts.Add(pos);
            }

            // Do uv and col now
            for ( int i = 0; i < lsection.meshsections.Count; i++ )
            {
                MegaMeshSection ms1 = lsection.meshsections[i];

                ms1.len = 0.0f;
                //int k1 = ms1.firstknot;
                //int k2 = ms1.lastknot;

                //Debug.Log("k1 " + k1 + " k2 " + k2);
                //float l1 = cspl.knots[k2].length - cspl.knots[k1].length;

                Vector2 uv1 = Vector2.zero;
                ms1.cuvs.Add(uv1);
                ms1.ccols.Add(Color.white);

                for ( int v = 1; v < ms1.cverts.Count; v++ )
                    ms1.len += Vector3.Distance(ms1.cverts[v], ms1.cverts[v - 1]);

                for ( int v = 1; v < ms1.cverts.Count; v++ )
                {
                    uv1.y += Vector3.Distance(ms1.cverts[v], ms1.cverts[v - 1]) / ms1.len;
                    //uv1.y /= len;	//Vector3.Distance(ms1.cverts[v], ms1.cverts[v - 1]);
                    ms1.cuvs.Add(uv1);
                    ms1.ccols.Add(Color.white);
                }
            }

            // Add end point
            if ( cspl.closed )
                alpha = Mathf.Repeat(cend, 1.0f);
        }

        // Calc normals
        Vector3 up = Vector3.zero;
        Vector3 n1 = Vector3.zero;

        for ( int i = 0; i < lsection.meshsections.Count; i++ )
        {
            MegaMeshSection ms1 = lsection.meshsections[i];

            if ( ms1.cverts.Count > 1 )
            {
                for ( int v = 0; v < ms1.cverts.Count; v++ )
                {
                    if ( v < ms1.cverts.Count - 1 )
                        n1 = (ms1.cverts[v + 1] - ms1.cverts[v]);
                    else
                        n1 = (ms1.cverts[v] - ms1.cverts[v - 1]);

                    up.x = -n1.y;
                    up.y = n1.x;
                    up.z = 0.0f;
                    ms1.cnorms.Add(up);
                }
            }
        }
    }