Пример #1
0
        /// <summary>
        /// Loads all the points / edges, builds the polygon and loads the polygon data.
        /// </summary>
        private void LoadMeta()
        {
            bspMeta = map.SelectedMeta;
            map.OpenMap(MapTypes.Internal);

            // Load the collision planes into the BSP Collision as they are not laoded by default
            for (int i = 0; i < coll.PlaneReflexiveCount; i++)
            {
                map.BR.BaseStream.Position = map.SelectedMeta.offset + coll.PlaneReflexiveTranslation + i * 16;
                Vector4 temp = new Vector4();
                temp.X = map.BR.ReadSingle();
                temp.Y = map.BR.ReadSingle();
                temp.Z = map.BR.ReadSingle();
                temp.W = map.BR.ReadSingle();
                coll.Planes[i].Add(temp);
            }

            // This will build our solid surfaces from the point / edge lists
            for (int i = 0; i < coll.SurfaceReflexiveCount; i++)
            {
                // Creates a new empty polygon (* Collision surfaces are not necessarily triangles)
                polygonInfo pi = new polygonInfo();

                // Collision BSP / 3D Nodes (Offset 36 / 0) [each entry is 8 bytes long]
                map.BR.BaseStream.Position = map.SelectedMeta.offset + coll.SurfaceReflexiveTranslation + i * 8;
                pi.plane = map.BR.ReadInt16();
                int startEdge = map.BR.ReadInt16();
                pi.flags        = map.BR.ReadByte();
                pi.breakSurface = map.BR.ReadByte();
                pi.material     = map.BR.ReadInt16();

                // The edges are listed in a circular order, we know the first edge, so cycle through until we get back home
                List <short> indices     = new List <short>();
                int          currentEdge = startEdge;
                do
                {
                    // Collision BSP / Edges (Offset 36 / 48) [each entry is 12 bytes long]
                    map.BR.BaseStream.Position = map.SelectedMeta.offset + coll.FaceReflexiveTranslation + currentEdge * 12;
                    short startVertex = map.BR.ReadInt16();
                    short endVertex   = map.BR.ReadInt16();
                    short edge1       = map.BR.ReadInt16();
                    short edge2       = map.BR.ReadInt16();
                    short surfL       = map.BR.ReadInt16();
                    short surfR       = map.BR.ReadInt16();

                    // The edges are used by two surface that can be listed either left or right
                    // We know what surface we are working with, so we use the edge that relates to our surface #
                    // edge1 for Surface Left, edge2 for Surface Right
                    if (surfL == i)
                    {
                        currentEdge = edge1;
                        indices.Add(endVertex);
                    }
                    else if (surfR == i)
                    {
                        currentEdge = edge2;
                        indices.Add(startVertex);
                    }
                } while (currentEdge != startEdge);

                // The last vertices added is actually the first, so move it to the front
                indices.Insert(0, indices[indices.Count - 1]);
                indices.RemoveAt(indices.Count - 1);
                pi.indices = indices.ToArray();
                polygons.Add(pi);
            }
            map.CloseMap();
        }
Пример #2
0
        /// <summary>
        /// Loads all the points / edges, builds the polygon and loads the polygon data.
        /// </summary>
        private void LoadMeta()
        {
            bspMeta = map.SelectedMeta;
            map.OpenMap(MapTypes.Internal);

            // Load the collision planes into the BSP Collision as they are not laoded by default
            for (int i = 0; i < coll.PlaneReflexiveCount; i++)
            {
                map.BR.BaseStream.Position = map.SelectedMeta.offset + coll.PlaneReflexiveTranslation + i * 16;
                Vector4 temp = new Vector4();
                temp.X = map.BR.ReadSingle();
                temp.Y = map.BR.ReadSingle();
                temp.Z = map.BR.ReadSingle();
                temp.W = map.BR.ReadSingle();
                coll.Planes[i].Add(temp);
            }

            // This will build our solid surfaces from the point / edge lists
            for (int i = 0; i < coll.SurfaceReflexiveCount; i++)
            {
                // Creates a new empty polygon (* Collision surfaces are not necessarily triangles)
                polygonInfo pi = new polygonInfo();

                // Collision BSP / 3D Nodes (Offset 36 / 0) [each entry is 8 bytes long]
                map.BR.BaseStream.Position = map.SelectedMeta.offset + coll.SurfaceReflexiveTranslation + i * 8;
                pi.plane = map.BR.ReadInt16();
                int startEdge = map.BR.ReadInt16();
                pi.flags = map.BR.ReadByte();
                pi.breakSurface = map.BR.ReadByte();
                pi.material = map.BR.ReadInt16();

                // The edges are listed in a circular order, we know the first edge, so cycle through until we get back home
                List<short> indices = new List<short>();
                int currentEdge = startEdge;
                do
                {
                    // Collision BSP / Edges (Offset 36 / 48) [each entry is 12 bytes long]
                    map.BR.BaseStream.Position = map.SelectedMeta.offset + coll.FaceReflexiveTranslation + currentEdge * 12;
                    short startVertex = map.BR.ReadInt16();
                    short endVertex = map.BR.ReadInt16();
                    short edge1 = map.BR.ReadInt16();
                    short edge2 = map.BR.ReadInt16();
                    short surfL = map.BR.ReadInt16();
                    short surfR = map.BR.ReadInt16();

                    // The edges are used by two surface that can be listed either left or right
                    // We know what surface we are working with, so we use the edge that relates to our surface #
                    // edge1 for Surface Left, edge2 for Surface Right
                    if (surfL == i)
                    {
                        currentEdge = edge1;
                        indices.Add(endVertex);
                    }
                    else if (surfR == i)
                    {
                        currentEdge = edge2;
                        indices.Add(startVertex);
                    }

                } while (currentEdge != startEdge);

                // The last vertices added is actually the first, so move it to the front
                indices.Insert(0, indices[indices.Count - 1]);
                indices.RemoveAt(indices.Count - 1);
                pi.indices = indices.ToArray();
                polygons.Add(pi);
            }
            map.CloseMap();
        }