Example #1
0
        private void ReadFaces()
        {
            //Length of the Lump
            int FacesLength = Header.DirEntries[13].Length;
            //Number of textures to load
            int nbFaces = FacesLength / (sizeof(int) * 14 + sizeof(float) * 12);


            Faces = new face[nbFaces];
            for (int i = 0; i < nbFaces; i++)
            {
                //texture
                int texture = ReadInt();

                //effect
                int effect = ReadInt();

                //type
                int type = ReadInt();

                //vertex
                int vertex = ReadInt();

                //n_vertices
                int n_vertices = ReadInt();

                //meshvert
                int meshvert = ReadInt();

                //n_meshvert
                int n_meshvert = ReadInt();

                //lm_index
                int lm_index = ReadInt();

                //lm_start
                int[] lm_start = new int[2] {
                    ReadInt(), ReadInt()
                };

                //lm_size
                int[] lm_size = new int[2] {
                    ReadInt(), ReadInt()
                };

                //lm_origin
                float[] lm_origin = new float[3] {
                    ReadFloat(), ReadFloat(), ReadFloat()
                };

                //lm_vecs
                float[,] lm_vecs = new float[2, 3] {
                    { ReadFloat(), ReadFloat(), ReadFloat() }, { ReadFloat(), ReadFloat(), ReadFloat() }
                };

                //normal
                float[] normal = new float[3] {
                    ReadFloat(), ReadFloat(), ReadFloat()
                };

                //size
                int[] size = new int[2] {
                    ReadInt(), ReadInt()
                };

                Faces[i] = new face(texture, effect, type, vertex, n_vertices, meshvert, n_meshvert, lm_index, lm_start, lm_size, lm_origin, lm_vecs, normal, size);
            }
        }
Example #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());
        }