Example #1
0
        public GfxObj(DatLoader.FileTypes.GfxObj gfxObj)
        {
            if (gfxObj == null)
            {
                return;
            }

            ID          = gfxObj.Id;
            VertexArray = gfxObj.VertexArray;

            Polygons = new Dictionary <ushort, Polygon>();
            foreach (var kvp in gfxObj.Polygons)
            {
                Polygons.Add(kvp.Key, PolygonCache.Get(new Polygon(kvp.Value, gfxObj.VertexArray)));
            }

            if (gfxObj.PhysicsPolygons.Count > 0)
            {
                PhysicsPolygons = new Dictionary <ushort, Polygon>();
                foreach (var kvp in gfxObj.PhysicsPolygons)
                {
                    PhysicsPolygons.Add(kvp.Key, PolygonCache.Get(new Polygon(kvp.Value, gfxObj.VertexArray)));
                }

                PhysicsBSP    = BSPCache.Get(gfxObj.PhysicsBSP, gfxObj.PhysicsPolygons, gfxObj.VertexArray);
                PhysicsSphere = PhysicsBSP.GetSphere();
            }

            SortCenter    = gfxObj.SortCenter;
            DrawingBSP    = BSPCache.Get(gfxObj.DrawingBSP, gfxObj.Polygons, gfxObj.VertexArray);
            DrawingSphere = DrawingBSP.GetSphere();

            Init();
        }
Example #2
0
        public CellStruct(DatLoader.Entity.CellStruct cellStruct)
        {
            Polygons = new Dictionary <ushort, Polygon>();
            foreach (var poly in cellStruct.Polygons)
            {
                Polygons.Add(poly.Key, PolygonCache.Get(poly.Value, cellStruct.VertexArray));
            }

            Portals = new List <Polygon>();
            foreach (var portal in cellStruct.Portals)
            {
                Portals.Add(Polygons[portal]);
            }

            PhysicsPolygons = new Dictionary <ushort, Polygon>();
            foreach (var poly in cellStruct.PhysicsPolygons)
            {
                PhysicsPolygons.Add(poly.Key, PolygonCache.Get(poly.Value, cellStruct.VertexArray));
            }

            if (cellStruct.CellBSP != null)
            {
                CellBSP = BSPCache.Get(cellStruct.CellBSP, cellStruct.PhysicsPolygons, cellStruct.VertexArray);
            }

            if (cellStruct.DrawingBSP != null)
            {
                DrawingBSP = BSPCache.Get(cellStruct.DrawingBSP, cellStruct.Polygons, cellStruct.VertexArray);
            }
            if (cellStruct.PhysicsBSP != null)
            {
                PhysicsBSP = BSPCache.Get(cellStruct.PhysicsBSP, cellStruct.PhysicsPolygons, cellStruct.VertexArray);
            }
        }
Example #3
0
        /// <summary>
        /// Finalize arrays for vertices and polygons
        /// by linking to cached versions
        /// </summary>
        public void FinalizePVArrays()
        {
            for (var i = 0; i < VertexArray.Vertices.Count; i++)
            {
                VertexArray.Vertices[i] = VertexCache.Get(VertexArray.Vertices[i]);
            }

            for (var i = 0; i < Polygons.Count; i++)
            {
                Polygons[i] = PolygonCache.Get(Polygons[i]);
            }
        }
Example #4
0
 public BSPNode(DatLoader.Entity.BSPNode node, Dictionary <ushort, DatLoader.Entity.Polygon> polys, DatLoader.Entity.CVertexArray vertexArray)
 {
     if (node.Sphere != null)
     {
         Sphere = new Sphere(node.Sphere);
     }
     if (node.SplittingPlane != null)
     {
         SplittingPlane = node.SplittingPlane.ToNumerics();
     }
     Typename = node.Type;
     //Typename
     if (node.InPolys != null)
     {
         NumPolys = node.InPolys.Count;
         PolyIDs  = node.InPolys;
         Polygons = new List <Polygon>(node.InPolys.Count);
         foreach (var poly in node.InPolys)
         {
             Polygons.Add(PolygonCache.Get(polys[poly], vertexArray));
         }
     }
     if (node.PosNode != null)
     {
         if (!(node.PosNode is DatLoader.Entity.BSPLeaf))
         {
             PosNode = new BSPNode(node.PosNode, polys, vertexArray);
         }
         else // portal?
         {
             PosNode = new BSPLeaf((DatLoader.Entity.BSPLeaf)node.PosNode, polys, vertexArray);
         }
     }
     if (node.NegNode != null)
     {
         if (!(node.NegNode is DatLoader.Entity.BSPLeaf))
         {
             NegNode = new BSPNode(node.NegNode, polys, vertexArray);
         }
         else // portal?
         {
             NegNode = new BSPLeaf((DatLoader.Entity.BSPLeaf)node.NegNode, polys, vertexArray);
         }
     }
 }