示例#1
0
        // ------

        public override void  GenBuf(BxCmSeparatePatch_Object patch, BxCmUiParam param)
        {
            fNumSurface = patch.NumSurface;
            TessLevel   = param.NumTess;

            SetVertexBuffer(patch);
            SetIndexBuffer(patch);
            SetVAO();

            Vector3?min = null;
            Vector3?max = null;

            if (param.Min != null)
            {
                min = new Vector3(( float )param.Min.X, ( float )param.Min.Y, ( float )param.Min.Z);
            }
            if (param.Max != null)
            {
                max = new Vector3(( float )param.Max.X, ( float )param.Max.Y, ( float )param.Max.Z);
            }

            if (min != null && max != null)
            {
                Parent.SetObjSize(( Vector3 )min, ( Vector3 )max);
            }

            InitVtf(patch);
        }
示例#2
0
        // ------

        protected override void  SetVertexBuffer(BxCmSeparatePatch_Object patch)
        {
            if (Buf.HasVertexBuffer() == true)
            {
                Buf.ReleaseVertexBuffer();
            }

            Buf.NumVertices = ( int )(patch.NumSurface * 6);

            VertexInfo[] vertexAry = new VertexInfo[Buf.NumVertices];
            for (uint i = 0; i < patch.NumSurface; i++)
            {
                GetPosDiff(patch, i, out BxBezier3Line3F hPosBez0, out BxBezier6Line3F hPosBez1, out BxBezier6Line3F hPosBez2, out BxBezier3Line3F hPosBez3, out BxBezier3Line3F vPosBez0,
                           out BxBezier6Line3F vPosBez1, out BxBezier6Line3F vPosBez2, out BxBezier3Line3F vPosBez3, out BxBezier2Line3F hDiffBez0, out BxBezier5Line3F hDiffBez1,
                           out BxBezier5Line3F hDiffBez2, out BxBezier2Line3F hDiffBez3, out BxBezier2Line3F vDiffBez0, out BxBezier5Line3F vDiffBez1, out BxBezier5Line3F vDiffBez2,
                           out BxBezier2Line3F vDiffBez3);

                int tessDenom = GetTessDenom(patch, i);

                SetVertexBufferOne(hPosBez0, hPosBez1, hPosBez2, hPosBez3, vPosBez0, vPosBez1, vPosBez2, vPosBez3, hDiffBez0, hDiffBez1, hDiffBez2, hDiffBez3, vDiffBez0, vDiffBez1,
                                   vDiffBez2, vDiffBez3, tessDenom, i, vertexAry);
            }

            GL.GenBuffers(1, Buf.VboID);

            GL.BindBuffer(BufferTarget.ArrayBuffer, Buf.VboID[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(Buf.NumVertices * VertexInfo.Length), vertexAry, BufferUsageHint.StaticDraw);

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
        }
示例#3
0
        // -------------------------------------------------------

        public void  Exec(string fileName, out BxVec3F min, out BxVec3F max, out BxCmSeparatePatch_Object patch)
        {
            JsonPatchInfo json;

            ReadPatch(fileName, out json);
            FromJson(json, out min, out max, out patch);
        }
示例#4
0
 private void  GetBezierInner(BxCmSeparatePatch_Object src, uint surfaceNo, byte hvId, byte hvOfs, byte idxPosBez1, BxBezier6Line3F[] /*4*/ tmpBez6)
 {
     for (byte i = 0; i < 7; i++)
     {
         tmpBez6[idxPosBez1][i] = src[surfaceNo].SurfaceEdge[hvId][hvOfs].Inner[i];
     }
 }
示例#5
0
        // ------

        private void  ExecOrgVertexNo(BxCmSeparatePatch_Object src, uint surfaceNo, BxCmSeparatePatch_Object dst)
        {
            for (byte i = 0; i < 4; i++)
            {
                dst[surfaceNo].OrgVertexNo[i] = src[surfaceNo].OrgVertexNo[i];
            }
        }
示例#6
0
        protected override void  SetVertexBuffer(BxCmSeparatePatch_Object patch)
        {
            if (Buf.HasVertexBuffer() == true)
            {
                Buf.ReleaseVertexBuffer();
            }

            Vector3[] vertexAry;
            GenVertexAry(out vertexAry);
            Buf.NumVertices = vertexAry.Length;

            float[] instanceAry = new float[fNumSurface];
            for (uint i = 0; i < fNumSurface; i++)
            {
                instanceAry[i] = ( float )(i + 0.5);
            }

            GL.GenBuffers(2, Buf.VboID);

            int sizeVertexAry = Buf.NumVertices * Vector3.SizeInBytes;

            GL.BindBuffer(BufferTarget.ArrayBuffer, Buf.VboID[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(sizeVertexAry), vertexAry, BufferUsageHint.StaticDraw);

            int sizeInstanceAry = ( int )(fNumSurface * sizeof(float));

            GL.BindBuffer(BufferTarget.ArrayBuffer, Buf.VboID[1]);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(sizeInstanceAry), instanceAry, BufferUsageHint.StaticDraw);

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
        }
示例#7
0
        // -------------------------------------------------------

        public void  GetMinMax(BxCmSeparatePatch_Object patch, out Vector3 min, out Vector3 max)
        {
            min = new Vector3();
            max = new Vector3();

            for (byte i = 0; i < 3; i++)
            {
                min[i] = max[i] = patch[0].Vertex[0].Pos[i];
            }

            for (uint i = 1; i < patch.NumSurface; i++)
            {
                for (byte j = 0; j < 4; j++)
                {
                    for (byte k = 0; k < 3; k++)
                    {
                        if (min[k] > patch[i].Vertex[j].Pos[k])
                        {
                            min[k] = patch[i].Vertex[j].Pos[k];
                        }
                        if (max[k] < patch[i].Vertex[j].Pos[k])
                        {
                            max[k] = patch[i].Vertex[j].Pos[k];
                        }
                    }
                }
            }
        }
示例#8
0
        // -------------------------------------------------------

        private void  GetPosDiff(BxCmSeparatePatch_Object patch, uint surfaceNo, out BxBezier3Line3F hPosBez0, out BxBezier6Line3F hPosBez1, out BxBezier6Line3F hPosBez2, out BxBezier3Line3F hPosBez3,
                                 out BxBezier3Line3F vPosBez0, out BxBezier6Line3F vPosBez1, out BxBezier6Line3F vPosBez2, out BxBezier3Line3F vPosBez3, out BxBezier2Line3F hDiffBez0, out BxBezier5Line3F hDiffBez1,
                                 out BxBezier5Line3F hDiffBez2, out BxBezier2Line3F hDiffBez3, out BxBezier2Line3F vDiffBez0, out BxBezier5Line3F vDiffBez1, out BxBezier5Line3F vDiffBez2, out BxBezier2Line3F vDiffBez3)
        {
            GetPosBezierH(patch, surfaceNo, out hPosBez0, out hPosBez1, out hPosBez2, out hPosBez3);
            GetPosBezierV(patch, surfaceNo, out vPosBez0, out vPosBez1, out vPosBez2, out vPosBez3);
            GetDiffBezierH(patch, surfaceNo, out hDiffBez0, out hDiffBez1, out hDiffBez2, out hDiffBez3);
            GetDiffBezierV(patch, surfaceNo, out vDiffBez0, out vDiffBez1, out vDiffBez2, out vDiffBez3);
        }
示例#9
0
 private void  ExecOrgEdgeNo(BxCmSeparatePatch_Object src, uint surfaceNo, BxCmSeparatePatch_Object dst)
 {
     for (byte hvId = 0; hvId < 2; hvId++)
     {
         for (byte hvOfs = 0; hvOfs < 2; hvOfs++)
         {
             dst[surfaceNo].OrgEdgeNo[hvId][hvOfs] = src[surfaceNo].OrgEdgeNo[hvId][hvOfs];
         }
     }
 }
示例#10
0
        // -------------------------------------------------------

        private int  GetTessDenom(BxCmSeparatePatch_Object src, uint surfaceNo)
        {
            int tessDenom = 1;

            if (src[surfaceNo].PreDivided == true)
            {
                tessDenom = 2;
            }

            return(tessDenom);
        }
示例#11
0
        // -------------------------------------------------------

        private void  ExecMain(BxCmSeparatePatch_Object src, BxCmSeparatePatch_Object dst)
        {
            for (uint i = 0; i < src.NumSurface; i++)
            {
                ExecBezU(src, i, dst);
                ExecBezV(src, i, dst);

                dst[i].OrgSurfaceNo = src[i].OrgSurfaceNo;

                ExecOrgVertexNo(src, i, dst);
                ExecOrgEdgeNo(src, i, dst);
            }
        }
示例#12
0
        private void  GetPosBezierOuter(BxCmSeparatePatch_Object src, uint surfaceNo, byte hvId, byte hvOfs, byte crossIdx, out BxBezier3Line3F posBez)
        {
            byte vNo0, vNo1;

            HVtoVertexNo(hvId, hvOfs, out vNo0, out vNo1);

            byte wingHvId = ( byte )(1 - hvId);

            posBez = new BxBezier3Line3F();
            posBez[0].Set(src[surfaceNo].Vertex[vNo0].Pos);
            posBez[3].Set(src[surfaceNo].Vertex[vNo1].Pos);
            posBez[1].Set(src[surfaceNo].SurfaceEdge[wingHvId][0].Inner[crossIdx]);
            posBez[2].Set(src[surfaceNo].SurfaceEdge[wingHvId][1].Inner[crossIdx]);
        }
示例#13
0
        InitVtf_Pre(BxCmSeparatePatch_Object patch, out int width, out int height, out float[] vtfAry)
        {
            if (HasVtf() == true)
            {
                ReleaseVtf();
            }

            int division = 20;

            width  = 80 * division;
            height = ( int )((patch.NumSurface + division - 1) / division);

            vtfAry = new float[(width * KNumFloatInVector4) * height];
        }
示例#14
0
        // ------

        private void  InitVtf(BxCmSeparatePatch_Object patch)
        {
            InitVtf_Pre(patch, out int width, out int height, out float[] vtfAry);

            uint cnt = 0;

            InitVtf_NonPreDiv(patch, width, height, vtfAry, ref cnt);

            fNumSurface_NonPreDiv = cnt;
            InitVtf_PreDiv(patch, width, height, vtfAry, ref cnt);

            Debug.Assert(cnt == patch.NumSurface);
            InitVtf_Post(width, height, vtfAry);
        }
示例#15
0
        private void  GetDiffBezierMain(BxCmSeparatePatch_Object src, uint surfaceNo, byte hvId, out BxBezier2Line3F diffBez0, out BxBezier5Line3F diffBez1, out BxBezier5Line3F diffBez2, out BxBezier2Line3F diffBez3)
        {
            byte hvOfs, crossIdx;

            hvOfs    = 0;
            crossIdx = 0;
            GetDiffBezierOuter(src, surfaceNo, hvId, hvOfs, crossIdx, out diffBez0);
            GetDiffBezierInner(src, surfaceNo, hvId, hvOfs, out diffBez1);

            hvOfs    = 1;
            crossIdx = 6;
            GetDiffBezierOuter(src, surfaceNo, hvId, hvOfs, crossIdx, out diffBez3);
            GetDiffBezierInner(src, surfaceNo, hvId, hvOfs, out diffBez2);
        }
示例#16
0
        virtual public void  GenBuf(BxCmSeparatePatch_Object patch, BxCmUiParam param)
        {
            TessLevel = param.NumTess;

            SetVertexBuffer(patch);
            SetVAO();

            if (param.Min != null && param.Max != null)
            {
                Vector3 min = new Vector3(( float )param.Min.X, ( float )param.Min.Y, ( float )param.Min.Z);
                Vector3 max = new Vector3(( float )param.Max.X, ( float )param.Max.Y, ( float )param.Max.Z);

                Parent.SetObjSize(min, max);
            }
        }
示例#17
0
        private void  GetBezierOuter(BxCmSeparatePatch_Object src, uint surfaceNo, byte hvId, byte hvOfs, byte crossIdx, byte idxPosBez, BxBezier6Line3F[] /*4*/ tmpBez6)
        {
            byte vNo0, vNo1;

            HVtoVertexNo(hvId, hvOfs, out vNo0, out vNo1);

            byte wingHvId = ( byte )(1 - hvId);

            BxBezier3Line3F bez3 = new BxBezier3Line3F();

            bez3[0].Set(src[surfaceNo].Vertex[vNo0].Pos);
            bez3[3].Set(src[surfaceNo].Vertex[vNo1].Pos);
            bez3[1].Set(src[surfaceNo].SurfaceEdge[wingHvId][0].Inner[crossIdx]);
            bez3[2].Set(src[surfaceNo].SurfaceEdge[wingHvId][1].Inner[crossIdx]);

            tmpBez6[idxPosBez] = bez3.UpperTo6();
        }
示例#18
0
        // ------

        private void  GetBezier(BxCmSeparatePatch_Object src, uint surfaceNo, byte hvId, BxBezier6Line3F[] /*4*/ tmpBez6)
        {
            byte hvOfs, crossIdx, idxPosBez0, idxPosBez1;

            hvOfs      = 0;
            crossIdx   = 0;
            idxPosBez0 = 0;
            idxPosBez1 = 1;
            GetBezierOuter(src, surfaceNo, hvId, hvOfs, crossIdx, idxPosBez0, tmpBez6);
            GetBezierInner(src, surfaceNo, hvId, hvOfs, idxPosBez1, tmpBez6);

            hvOfs      = 1;
            crossIdx   = 6;
            idxPosBez0 = 3;
            idxPosBez1 = 2;
            GetBezierOuter(src, surfaceNo, hvId, hvOfs, crossIdx, idxPosBez0, tmpBez6);
            GetBezierInner(src, surfaceNo, hvId, hvOfs, idxPosBez1, tmpBez6);
        }
示例#19
0
        private void  InitVtf_PreDiv(BxCmSeparatePatch_Object patch, int width, int height, float[] vtfAry, ref uint cnt)
        {
            for (uint i = 0; i < patch.NumSurface; i++)
            {
                if (patch[i].PreDivided == true)
                {
                    GetPosDiff(patch, i, out BxBezier3Line3F hPosBez0, out BxBezier6Line3F hPosBez1, out BxBezier6Line3F hPosBez2, out BxBezier3Line3F hPosBez3, out BxBezier3Line3F vPosBez0,
                               out BxBezier6Line3F vPosBez1, out BxBezier6Line3F vPosBez2, out BxBezier3Line3F vPosBez3, out BxBezier2Line3F hDiffBez0, out BxBezier5Line3F hDiffBez1,
                               out BxBezier5Line3F hDiffBez2, out BxBezier2Line3F hDiffBez3, out BxBezier2Line3F vDiffBez0, out BxBezier5Line3F vDiffBez1, out BxBezier5Line3F vDiffBez2,
                               out BxBezier2Line3F vDiffBez3);

                    ConvVtfInfo(hPosBez0, hPosBez1, hPosBez2, hPosBez3, vPosBez0, vPosBez1, vPosBez2, vPosBez3, hDiffBez0, hDiffBez1, hDiffBez2, hDiffBez3, vDiffBez0, vDiffBez1,
                                vDiffBez2, vDiffBez3, cnt, vtfAry);

                    cnt++;
                }
            }
        }
示例#20
0
        private void  GetDiffBezierOuter(BxCmSeparatePatch_Object src, uint surfaceNo, byte hvId, byte hvOfs, byte crossIdx, out BxBezier2Line3F diffBez)
        {
            byte vNo0, vNo1;

            HVtoVertexNo(hvId, hvOfs, out vNo0, out vNo1);

            byte wingHvId = ( byte )(1 - hvId);

            BxBezier3Line3F posBez = new BxBezier3Line3F();

            posBez[0].Set(src[surfaceNo].Vertex[vNo0].Pos);
            posBez[3].Set(src[surfaceNo].Vertex[vNo1].Pos);
            posBez[1].Set(src[surfaceNo].SurfaceEdge[wingHvId][0].Inner[crossIdx]);
            posBez[2].Set(src[surfaceNo].SurfaceEdge[wingHvId][1].Inner[crossIdx]);

            diffBez = posBez.Diff();

            Debug.Assert(diffBez[0].Length >= (BxMathF.KNearZeroF * 10.0));
            Debug.Assert(diffBez[2].Length >= (BxMathF.KNearZeroF * 10.0));
        }
示例#21
0
        private void  ExecBezV(BxCmSeparatePatch_Object src, uint surfaceNo, BxCmSeparatePatch_Object dst)
        {
            BxBezier6Line3F[] bezV6 = new BxBezier6Line3F[4];
            BxBezier3Line3F[] bezU3 = new BxBezier3Line3F[7];

            for (byte i = 0; i < 4; i++)
            {
                bezV6[i] = new BxBezier6Line3F();
            }
            for (byte i = 0; i < 7; i++)
            {
                bezU3[i] = new BxBezier3Line3F();
            }

            byte hvId = 1;

            GetBezier(src, surfaceNo, hvId, bezV6);
            TransBezier(bezV6, bezU3);
            Correct(bezU3, surfaceNo, hvId, dst);
        }
示例#22
0
        protected void  SetIndexBuffer(BxCmSeparatePatch_Object patch)
        {
            if (Buf.HasIndexBuffer() == true)
            {
                Buf.ReleaseIndexBuffer();
            }

            int[] indexAry;
            GenIndexAry(out indexAry);
            Buf.NumIndices = indexAry.Length;

            int sizeIndexAry = Buf.NumIndices * sizeof(int);

            GL.GenBuffers(1, Buf.EboID);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, Buf.EboID[0]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(sizeIndexAry), indexAry, BufferUsageHint.StaticDraw);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
        }
示例#23
0
        private void  FromJson(JsonPatchInfo json, out BxVec3F min, out BxVec3F max, out BxCmSeparatePatch_Object patch)
        {
            bool success;

            min = null;
            max = null;

            patch = new BxCmSeparatePatch_Object();

            if (json == null || json.surface == null || json.minMax == null)
            {
                patch = null;
                return;
            }

            FromJson_MinMax(json.minMax, out min, out max);

            uint numSurface = 0;

            foreach (JsonPatchInfo_Surface jsonSurface in json.surface)
            {
                numSurface++;
            }

            patch = new BxCmSeparatePatch_Object();
            patch.Alloc(numSurface);

            uint cntSurface = 0;

            foreach (JsonPatchInfo_Surface jsonSurface in json.surface)
            {
                if (jsonSurface.vertex == null || jsonSurface.surfaceEdge == null)
                {
                    patch = null;
                    return;
                }

                patch[cntSurface].Alloc();

                FromJson_Vertex(jsonSurface.vertex, patch[cntSurface]);
                success = FromJson_SurfaceEdge(jsonSurface.surfaceEdge, patch[cntSurface]);
                if (success == false)
                {
                    patch = null;
                    return;
                }
                success = FromJson_TNodeType(jsonSurface.tNodeType, patch[cntSurface]);
                if (success == false)
                {
                    patch = null;
                    return;
                }
                success = FromJson_PreDivided(jsonSurface.preDivided, patch[cntSurface]);
                if (success == false)
                {
                    patch = null;
                    return;
                }

                cntSurface++;
            }
            Debug.Assert(cntSurface == numSurface);
        }
示例#24
0
 public void SetPatch(BxCmSeparatePatch_Object patch)
 {
     SetPatchMain(patch);
 }
示例#25
0
        public void  Exec(BxCmSeparatePatch_Object src, out BxCmSeparatePatch_Object dst)
        {
            dst = new BxCmSeparatePatch_Object(src);

            ExecMain(src, dst);
        }
示例#26
0
 abstract protected void   SetPatchMain(BxCmSeparatePatch_Object patch);
示例#27
0
        private void  Correct(BxBezier3Line3F[] /*7*/ transBez3, uint surfaceNo, byte hvId, BxCmSeparatePatch_Object dst)
        {
            BxVec3F[] handle = new BxVec3F[2];

            for (byte i = 0; i < 7; i++)
            {
                CorrectMain(transBez3[i], handle);

                for (byte j = 0; j < 2; j++)
                {
                    if (handle[j] != null)
                    {
                        byte srcBez6Idx = 0;
                        if (j == 1)
                        {
                            srcBez6Idx = 3;
                        }

                        dst[surfaceNo].SurfaceEdge[hvId][j].Inner[i] = handle[j] + transBez3[i][srcBez6Idx];
                    }
                }
            }
        }
示例#28
0
 public void  SetPatch(BxCmSeparatePatch_Object patch)
 {
     fObjGlMain.SetPatch(patch);
 }
示例#29
0
        // -------------------------------------------------------

        abstract protected void  SetVertexBuffer(BxCmSeparatePatch_Object patch);
示例#30
0
 private void  GetDiffBezierInner(BxCmSeparatePatch_Object src, uint surfaceNo, byte hvId, byte hvOfs, out BxBezier5Line3F diffBezInner)
 {
     diffBezInner = src[surfaceNo].SurfaceEdge[hvId][hvOfs].Inner.Diff();
 }