예제 #1
0
        private void calcExtends(BoundsItem[] items, int imin, int imax, float[] bmin, float[] bmax)
        {
            bmin[0] = items[imin].bmin[0];
            bmin[1] = items[imin].bmin[1];

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

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

                if (it.bmax[0] > bmax[0])
                {
                    bmax[0] = it.bmax[0];
                }
                if (it.bmax[1] > bmax[1])
                {
                    bmax[1] = it.bmax[1];
                }
            }
        }
예제 #2
0
        public ChunkyTriMesh(float[] verts, int[] tris, int ntris, int trisPerChunk)
        {
            int nchunks = (ntris + trisPerChunk - 1) / trisPerChunk;

            nodes      = new List <ChunkyTriMeshNode>(nchunks);
            this.ntris = ntris;

            // Build tree
            BoundsItem[] items = new BoundsItem[ntris];

            for (int i = 0; i < ntris; i++)
            {
                int        t  = i * 3;
                BoundsItem it = items[i] = new BoundsItem();
                it.i = i;
                // Calc triangle XZ bounds.
                it.bmin[0] = it.bmax[0] = verts[tris[t] * 3 + 0];
                it.bmin[1] = it.bmax[1] = verts[tris[t] * 3 + 2];
                for (int j = 1; j < 3; ++j)
                {
                    int v = tris[t + j] * 3;
                    if (verts[v] < it.bmin[0])
                    {
                        it.bmin[0] = verts[v];
                    }
                    if (verts[v + 2] < it.bmin[1])
                    {
                        it.bmin[1] = verts[v + 2];
                    }

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

            subdivide(items, 0, ntris, trisPerChunk, nodes, tris);

            // Calc max tris per node.
            maxTrisPerChunk = 0;
            foreach (ChunkyTriMeshNode node in nodes)
            {
                bool isLeaf = node.i >= 0;
                if (!isLeaf)
                {
                    continue;
                }
                if (node.tris.Length / 3 > maxTrisPerChunk)
                {
                    maxTrisPerChunk = node.tris.Length / 3;
                }
            }
        }