예제 #1
0
        private void CalcExtends(BoundsItem[] items, int nitems, int imin, int imax, ref ChunkyTriMeshNode node)
        {
            node.bmin[0] = items[imin].bmin[0];
            node.bmin[1] = items[imin].bmin[1];

            node.bmax[0] = items[imin].bmax[0];
            node.bmax[1] = items[imin].bmax[1];

            for (int i = imin + 1; i < imax; i++)
            {
                BoundsItem it = items[i];
                if (it.bmin[0] < node.bmin[0])
                {
                    node.bmin[0] = it.bmin[0];
                }
                if (it.bmin[1] < node.bmin[1])
                {
                    node.bmin[1] = it.bmin[1];
                }

                if (it.bmax[0] > node.bmax[0])
                {
                    node.bmax[0] = it.bmax[0];
                }
                if (it.bmax[1] > node.bmax[1])
                {
                    node.bmax[1] = it.bmax[1];
                }
            }
        }
예제 #2
0
        int IComparer.Compare(object va, object vb)
        {
            BoundsItem a = va as BoundsItem;
            BoundsItem b = vb as BoundsItem;

            if (a != null && b != null)
            {
                if (a.bmin[1] < b.bmin[1])
                {
                    return(-1);
                }
                if (a.bmin[1] > b.bmin[1])
                {
                    return(1);
                }
            }
            return(0);
        }
예제 #3
0
        public ChunkyTriMesh(RecastVertex[] verts, int[] tris, int ntris, int trisPerChunk)
        {
            int nchunks = (ntris + trisPerChunk - 1) / trisPerChunk;

            Nodes = new ChunkyTriMeshNode[nchunks * 4];
            Tris  = new int[ntris * 3];

            NTris = ntris;

            BoundsItem[] items = new BoundsItem[ntris];

            for (int i = 0; i < ntris; i++)
            {
                int t = i * 3;
                items[i] = new BoundsItem();
                BoundsItem it = items[i];
                it.i       = i;
                it.bmin[0] = it.bmax[0] = verts[tris[t]].X;
                it.bmin[1] = it.bmax[1] = verts[tris[t]].Z;
                for (int j = 1; j < 3; j++)
                {
                    int v = tris[t + j];
                    if (verts[v].X < it.bmin[0])
                    {
                        it.bmin[0] = verts[v].X;
                    }
                    if (verts[v].Z < it.bmin[1])
                    {
                        it.bmin[1] = verts[v].Z;
                    }

                    if (verts[v].X > it.bmax[0])
                    {
                        it.bmax[0] = verts[v].X;
                    }
                    if (verts[v].Z > it.bmax[1])
                    {
                        it.bmax[1] = verts[v].Z;
                    }
                }
            }

            int curTri  = 0;
            int curNode = 0;

            Subdivide(ref items, ntris, 0, ntris, trisPerChunk, ref curNode, nchunks * 4, ref curTri, tris);

            NNodes = curNode;

            MaxTrisPerChunk = 0;
            for (int i = 0; i < NNodes; i++)
            {
                bool isLeaf = Nodes[i].i >= 0;
                if (!isLeaf)
                {
                    continue;
                }
                if (Nodes[i].n > MaxTrisPerChunk)
                {
                    MaxTrisPerChunk = Nodes[i].n;
                }
            }
        }