コード例 #1
0
        private void ReadLeafFaces()
        {
            //Length of the Lump
            int LeafFacesLength = Header.DirEntries[5].Length;
            //Number of textures to load
            int nbLeafFaces = LeafFacesLength / (sizeof(int));

            LeafFaces = new leafface[nbLeafFaces];
            for (int i = 0; i < nbLeafFaces; i++)
            {
                //face
                int face = ReadInt();

                LeafFaces[i] = new leafface(face);
            }
        }
コード例 #2
0
        private void DetermineVisibleFaces()
        {
            int leafIndex    = findLeaf();
            int clusterIndex = file.Leaves[leafIndex].Cluster;

            //Visible leaves
            List <leaf> visibleLeaves = new List <leaf>();

            foreach (leaf l in file.Leaves)
            {
                //if(isLeafVisible(clusterIndex,l.Cluster))
                visibleLeaves.Add(l);
            }

            //visible faces
            HashSet <int>   usedIndices  = new HashSet <int>();
            List <leafface> leafFaces    = new List <leafface>();
            List <face>     visibleFaces = new List <face>();

            foreach (leaf l in visibleLeaves)
            {
                for (int i = l.LeafFace; i < l.LeafFace + l.N_LeafFaces; i++)
                {
                    if (!usedIndices.Contains(i))
                    {
                        leafface f = file.LeafFaces[i];
                        leafFaces.Add(f);
                        usedIndices.Add(i);
                    }
                }
            }

            //face

            foreach (leafface l in leafFaces)
            {
                face f = file.Faces[l.Face];
                visibleFaces.Add(f);
            }



            List <int>[] Texturearrays = new List <int> [file.Textures.Count()];
            for (int i = 0; i < file.Textures.Count(); i++)
            {
                Texturearrays[i] = new List <int>();
            }

            //arrays
            foreach (face f in visibleFaces)
            {
                if (f.Type == 1 || f.Type == 3)
                {
                    //Meshes and faces
                    for (int i = f.Meshvert; i < f.Meshvert + f.N_Meshverts; i++)
                    {
                        //index
                        int index = f.Vertex + file.MeshVerts[i].Offset;
                        Texturearrays[f.Texture].Add(index);
                    }
                }
            }

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

            textureLengths = new int[file.Textures.Count()];
            int cpt = 0;

            for (int i = 0; i < Texturearrays.Length; i++)
            {
                realList.AddRange(Texturearrays[i]);
                cpt += Texturearrays[i].Count;
                textureLengths[i] = cpt;
            }

            IBuffer = new IndexBuffer(Game.GraphicsDevice, IndexElementSize.ThirtyTwoBits, realList.Count, BufferUsage.WriteOnly);
            IBuffer.SetData(realList.ToArray());
        }