Exemple #1
0
        // Hook displacements into the bsp tree
        static void DispTreeLeafnum(World world)
        {
            //
            // get the number of displacements per leaf
            //
            List<dDispTri> tris = new List<dDispTri>();
            world.dispCollTrees = new DispCollTree[world.DispIndexToFaceIndex.Length];
            List<dDispVert> verts = new List<dDispVert>();
            int currTri = 0, currVert = 0;
            for (int i = 0; i < world.DispIndexToFaceIndex.Length; i++)
            {
                int j;
                int faceIndex = world.DispIndexToFaceIndex[i];
                int dispId = world.faces_t[faceIndex].dispinfo;
                ddispinfo_t info = world.ddispinfos[dispId];

                int power = info.power;
                int nVerts = (((1 << (power)) + 1) * ((1 << (power)) + 1));
                verts.Clear();
                // fail code
                for (j = 0; j < nVerts; j++)
                {
                    verts.Add(world.dispVerts[j + currVert]);
                }
                currVert += nVerts;

                int nTris = ((1 << (power)) * (1 << (power)) * 2);
                tris.Clear();
                for (j = 0; j < nTris; j++)
                {
                    tris.Add(world.dispTris[j + currTri]);
                }
                currTri += nTris;

                Displacement displace = new Displacement();
                displace.Surface = new DispSurface();
                DispSurface dispSurf = displace.Surface;
                dispSurf.m_PointStart = info.startPosition;
                dispSurf.m_Contents = info.contents;

                displace.InitDispInfo(info.power, info.minTess, info.smoothingAngle, verts, tris);

                dispSurf.m_Index = faceIndex;
                face_t face = world.faces_t[faceIndex];

                if (face.numedges > 4)
                    continue;

                Vector3[] surfPoints = new Vector3[4];
                dispSurf.m_PointCount = face.numedges;

                for (j = 0; j < face.numedges; j++)
                {
                    int eIndex = world.surfEdges[face.firstedge + j];
                    if (eIndex < 0)
                        surfPoints[j] = world.verts[world.edges[-eIndex].v[1]].position;
                    else
                        surfPoints[j] = world.verts[world.edges[eIndex].v[0]].position;
                }

                dispSurf.m_Points = surfPoints;
                dispSurf.FindSurfPointStartIndex();
                dispSurf.AdjustSurfPointData();

                //
                // generate the collision displacement surfaces
                //
                world.dispCollTrees[i] = new DispCollTree();
                DispCollTree dispTree = world.dispCollTrees[i];

                //
                // check for null faces, should have been taken care of in vbsp!!!
                //
                if (dispSurf.m_PointCount != 4)
                    continue;

                displace.Create();

                // new collision
                dispTree.Create(displace);

                DispTreeLeafnum_r(world, faceIndex, i, 0);
            }
        }