Exemple #1
0
        public void Evaluate(int SpreadMax)
        {
            this.FInvalidate = false;

            if (FUpdate != null && FUpdate[0])
            {
                this.FVertex.Clear();
                this.FIndices.Clear();

                FVertexPin.Sync();
                FNormalsPin.Sync();
                FTexPin.Sync();

                FIndexPin.Sync();

                int meshCount = Math.Max(FVertexPin.SliceCount, FTexPin.SliceCount);
                meshCount = Math.Max(meshCount, FNormalsPin.SliceCount);
                meshCount = Math.Max(meshCount, FIndexPin.SliceCount);

                for (int i = 0; i < meshCount; i++)
                {
                    int vertexCount = Math.Max(FVertexPin[i].SliceCount, FTexPin[i].SliceCount);

                    Pos4Norm3Tex2Vertex[] verts = new Pos4Norm3Tex2Vertex[Convert.ToInt32(vertexCount)];

                    for (int j = 0; j < vertexCount; j++)
                    {
                        verts[j].Position  = new Vector4(FVertexPin[i][j], 1.0f);
                        verts[j].Normals   = FNormalsPin[i][j];
                        verts[j].TexCoords = FTexPin[i][j];
                    }
                    this.FVertex.Add(verts);

                    List <int> inds = new List <int>();

                    for (int j = 0; j < FIndexPin[i].SliceCount; j++)
                    {
                        Vector3 triangle = FIndexPin[i][j];
                        inds.Add((int)triangle.X);
                        inds.Add((int)triangle.Y);
                        inds.Add((int)triangle.Z);
                    }
                    this.FIndices.Add(inds.ToArray());
                }
                this.InvalidateMesh(meshCount);
            }
        }
        public void Evaluate(int SpreadMax)
        {
            this.FInvalidate = false;

            if (this.FPInInCtrlPts.PinIsChanged || this.FPInInRes.PinIsChanged ||
                this.FPinInMeshCount.PinIsChanged || this.FPinInCtrlRes.PinIsChanged)
            {
                this.FVertex.Clear();
                this.FIndices.Clear();

                double dblx, dbly;

                double mc;
                this.FPinInMeshCount.GetValue(0, out mc);

                int patchcnt = (int)mc;


                int ctrlidx = 0;

                for (int pc = 0; pc < patchcnt; pc++)
                {
                    this.FPInInRes.GetValue2D(pc, out dblx, out dbly);

                    int resX = Convert.ToInt32(dblx);
                    int resY = Convert.ToInt32(dbly);


                    this.FPinInCtrlRes.GetValue2D(pc, out dblx, out dbly);
                    int CresX = Convert.ToInt32(dblx);
                    int CresY = Convert.ToInt32(dbly);

                    List <Pos4Norm3Tex2Vertex> verts = new List <Pos4Norm3Tex2Vertex>();

                    float sx = 0.5f;
                    float sy = 0.5f;

                    float ix = (sx / Convert.ToSingle(resX - 1)) * 2.0f;
                    float iy = (sy / Convert.ToSingle(resY - 1)) * 2.0f;


                    float y = -sy;


                    Pos4Norm3Tex2Vertex v = new Pos4Norm3Tex2Vertex();
                    v.Normals = new Vector3(0, 0, -1.0f);

                    List <Vector3> ctrls = new List <Vector3>();

                    double cx, cy, cz;
                    for (int ct = 0; ct < CresX * CresY; ct++)
                    {
                        this.FPInInCtrlPts.GetValue3D(ct + ctrlidx, out cx, out cy, out cz);

                        ctrls.Add(new Vector3((float)cx, (float)cy, (float)cz));
                    }

                    Vector3[] carr = new Vector3[ctrls.Count];

                    for (int i = 0; i < resY; i++)
                    {
                        float x = -sx;
                        for (int j = 0; j < resX; j++)
                        {
                            float tu1 = Convert.ToSingle(VMath.Map(j, 0, resX - 1, 0.0, 1.0, TMapMode.Clamp));
                            float tv1 = Convert.ToSingle(VMath.Map(i, 0, resY - 1, 1.0, 0.0, TMapMode.Clamp));
                            v.TexCoords = new Vector2(tu1, tv1);

                            float[] bu = BernsteinBasis.ComputeBasis(CresX - 1, tu1);
                            float[] bv = BernsteinBasis.ComputeBasis(CresY - 1, tv1);


                            for (int ck = 0; ck < ctrls.Count; ck++)
                            {
                                carr[ck].X = x + ctrls[ck].X;
                                carr[ck].Y = y + ctrls[ck].Y;
                                carr[ck].Z = ctrls[ck].Z;
                            }

                            Vector3 vp = this.EvaluateBezier(carr, bu, bv, CresX, CresY);

                            v.Position = new Vector4(vp.X, vp.Y, vp.Z, 1.0f);
                            x         += ix;


                            //ds.Write<PosNormTexVertex>(v);
                            verts.Add(v);
                        }
                        y += iy;
                    }

                    this.FVertex.Add(verts.ToArray());

                    List <int> indlist = new List <int>();
                    for (int j = 0; j < resY - 1; j++)
                    {
                        int rowlow = (j * resX);
                        int rowup  = ((j + 1) * resX);
                        for (int i = 0; i < resX - 1; i++)
                        {
                            int col = i * (resX - 1);

                            indlist.Add(0 + rowlow + i);
                            indlist.Add(0 + rowup + i);
                            indlist.Add(1 + rowlow + i);

                            indlist.Add(1 + rowup + i);
                            indlist.Add(1 + rowlow + i);
                            indlist.Add(0 + rowup + i);
                        }
                    }

                    this.FIndices.Add(indlist.ToArray());

                    ctrlidx += CresX * CresY;
                }
                this.InvalidateMesh(patchcnt);
            }
        }
        public void Evaluate(int SpreadMax)
        {
            this.FInvalidate = false;

            if (this.FPinInVertices.PinIsChanged || this.FPinInVerticesCount.PinIsChanged)
            {
                this.FVertex.Clear();
                this.FIndices.Clear();
                int cnt = 0;
                for (int i = 0; i < this.FPinInVerticesCount.SliceCount; i++)
                {
                    double dblcount;
                    this.FPinInVerticesCount.GetValue(i, out dblcount);

                    if (dblcount >= 3)
                    {
                        double cx = 0;
                        double cy = 0;
                        double x, y;

                        double minx = double.MaxValue, miny = double.MaxValue;
                        double maxx = double.MinValue, maxy = double.MinValue;

                        Pos4Norm3Tex2Vertex[] verts = new Pos4Norm3Tex2Vertex[Convert.ToInt32(dblcount) + 1];

                        for (int j = 0; j < dblcount; j++)
                        {
                            this.FPinInVertices.GetValue2D(cnt, out x, out y);
                            verts[j + 1].Position  = new Vector4(Convert.ToSingle(x), Convert.ToSingle(y), 0, 1.0f);
                            verts[j + 1].Normals   = new Vector3(0, 0, 1);
                            verts[j + 1].TexCoords = new Vector2(0.0f, 0.0f);
                            cx += x;
                            cy += y;

                            if (x < minx)
                            {
                                minx = x;
                            }
                            if (x > maxx)
                            {
                                maxx = x;
                            }
                            if (y < miny)
                            {
                                miny = y;
                            }
                            if (y > maxy)
                            {
                                maxy = y;
                            }

                            cnt++;
                        }

                        verts[0].Position  = new Vector4(Convert.ToSingle(cx / dblcount), Convert.ToSingle(cy / dblcount), 0, 1.0f);
                        verts[0].Normals   = new Vector3(0, 0, 1);
                        verts[0].TexCoords = new Vector2(0.5f, 0.5f);

                        double w = maxx - minx;
                        double h = maxy - miny;
                        for (int j = 0; j < dblcount; j++)
                        {
                            verts[0].TexCoords = new Vector2(Convert.ToSingle((verts[j + 1].Position.X - minx) / w),
                                                             Convert.ToSingle((verts[j + 1].Position.Y - miny) / h));
                        }

                        this.FVertex.Add(verts);

                        List <int> inds = new List <int>();

                        for (int j = 0; j < dblcount - 1; j++)
                        {
                            inds.Add(0);
                            inds.Add(j + 1);
                            inds.Add(j + 2);
                        }

                        inds.Add(0);
                        inds.Add(verts.Length - 1);
                        inds.Add(1);

                        this.FIndices.Add(inds.ToArray());
                    }
                }
                this.InvalidateMesh(this.FVertex.Count);
            }
        }
Exemple #4
0
        public void Evaluate(int SpreadMax)
        {
            this.FInvalidate = false;

            if (this.FPInInCtrlPts.PinIsChanged || this.FPInInRes.PinIsChanged ||
                this.FPinInMeshCount.PinIsChanged || this.FPinInCtrlRes.PinIsChanged || this.FPinInAbsolute.PinIsChanged)
            {
                this.FVertex.Clear();
                this.FIndices.Clear();

                List <double> hx  = new List <double>();
                List <double> hy  = new List <double>();
                List <int>    pid = new List <int>();

                double dblx, dbly;

                double mc;
                this.FPinInMeshCount.GetValue(0, out mc);

                int patchcnt = (int)mc;

                double dabs;
                this.FPinInAbsolute.GetValue(0, out dabs);

                bool useAbsolute = dabs >= 0.5;

                int ctrlidx = 0;

                for (int pc = 0; pc < patchcnt; pc++)
                {
                    this.FPInInRes.GetValue2D(pc, out dblx, out dbly);

                    int resX = Convert.ToInt32(dblx);
                    int resY = Convert.ToInt32(dbly);


                    this.FPinInCtrlRes.GetValue2D(pc, out dblx, out dbly);
                    int CresX = Convert.ToInt32(dblx);
                    int CresY = Convert.ToInt32(dbly);

                    List <Pos4Norm3Tex2Vertex> verts = new List <Pos4Norm3Tex2Vertex>();

                    float sx = 0.5f;
                    float sy = 0.5f;

                    float ix = (sx / Convert.ToSingle(resX - 1)) * 2.0f;
                    float iy = (sy / Convert.ToSingle(resY - 1)) * 2.0f;


                    float y = -sy;


                    Pos4Norm3Tex2Vertex v = new Pos4Norm3Tex2Vertex();
                    v.Normals = new Vector3(0, 0, -1.0f);

                    List <Vector3> ctrls = new List <Vector3>();

                    float mx = -0.5f;
                    float my = 0.5f;

                    float incx = 1.0f / ((float)CresX - 1.0f);
                    float incy = 1.0f / ((float)CresY - 1.0f);

                    int inch = 0;

                    double cx, cy;
                    for (int ct = 0; ct < CresX * CresY; ct++)
                    {
                        this.FPInInCtrlPts.GetValue2D(ct + ctrlidx, out cx, out cy);

                        ctrls.Add(new Vector3((float)cx, (float)cy, 0.0f));
                    }


                    Matrix4x4 mat;
                    this.FPinInTransform.GetMatrix(pc, out mat);



                    for (int ct = 0; ct < CresX * CresY; ct++)
                    {
                        this.FPInInCtrlPts.GetValue2D(ct + ctrlidx, out cx, out cy);

                        ctrls.Add(new Vector3((float)cx, (float)cy, 0.0f));

                        Vector2D vd = new Vector2D(cx + mx, cy + my);
                        Vector3D v2 = mat * vd;

                        hx.Add(v2.x);
                        hy.Add(v2.y);

                        mx += incx;

                        inch++;
                        if (inch == CresX)
                        {
                            inch = 0;
                            mx   = -0.5f;
                            my  -= incy;
                        }

                        pid.Add(pc);
                    }

                    Vector3[] carr = new Vector3[ctrls.Count];

                    for (int i = 0; i < resY; i++)
                    {
                        float x = -sx;
                        for (int j = 0; j < resX; j++)
                        {
                            //v.Position = new Vector4(x, y, 0.0f, 1.0f);
                            float tu1 = Convert.ToSingle(VMath.Map(j, 0, resX - 1, 0.0, 1.0, TMapMode.Clamp));
                            float tv1 = Convert.ToSingle(VMath.Map(i, 0, resY - 1, 1.0, 0.0, TMapMode.Clamp));
                            v.TexCoords = new Vector2(tu1, tv1);

                            float[] bu = BernsteinBasis.ComputeBasis(CresX - 1, tu1);
                            float[] bv = BernsteinBasis.ComputeBasis(CresY - 1, tv1);

                            if (useAbsolute)
                            {
                                for (int ck = 0; ck < ctrls.Count; ck++)
                                {
                                    carr[ck].X = ctrls[ck].X;
                                    carr[ck].Y = ctrls[ck].Y;
                                }
                            }
                            else
                            {
                                for (int ck = 0; ck < ctrls.Count; ck++)
                                {
                                    carr[ck].X = x + ctrls[ck].X;
                                    carr[ck].Y = y + ctrls[ck].Y;
                                }
                            }


                            Vector3 vp = this.EvaluateBezier(carr, bu, bv, CresX, CresY);

                            v.Position = new Vector4(vp.X, vp.Y, 0.0f, 1.0f);
                            x         += ix;


                            //ds.Write<PosNormTexVertex>(v);
                            verts.Add(v);
                        }
                        y += iy;
                    }

                    this.FVertex.Add(verts.ToArray());

                    List <int> indlist = new List <int>();
                    for (int j = 0; j < resY - 1; j++)
                    {
                        int rowlow = (j * resX);
                        int rowup  = ((j + 1) * resX);
                        for (int i = 0; i < resX - 1; i++)
                        {
                            int col = i * (resX - 1);

                            indlist.Add(0 + rowlow + i);
                            indlist.Add(0 + rowup + i);
                            indlist.Add(1 + rowlow + i);



                            indlist.Add(1 + rowup + i);
                            indlist.Add(1 + rowlow + i);
                            indlist.Add(0 + rowup + i);
                        }
                    }

                    this.FIndices.Add(indlist.ToArray());

                    ctrlidx += CresX * CresY;
                }


                this.FPinOutHelpers.SliceCount = hx.Count;

                for (int i = 0; i < hx.Count; i++)
                {
                    this.FPinOutHelpers.SetValue2D(i, hx[i], hy[i]);
                }

                this.FOutPatchId.SliceCount = pid.Count;
                for (int i = 0; i < pid.Count; i++)
                {
                    this.FOutPatchId.SetValue(i, pid[i]);
                }

                this.InvalidateMesh(patchcnt);
            }
        }