Beispiel #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();
        }
Beispiel #2
0
        public GfxObj(DatLoader.FileTypes.GfxObj gfxObj)
        {
            if (gfxObj == null)
            {
                return;
            }

            ID                 = gfxObj.Id;
            SurfaceIDs         = gfxObj.Surfaces;
            NumSurfaces        = SurfaceIDs != null ? SurfaceIDs.Count : 0;
            VertexArray        = CreateMutable(gfxObj.VertexArray);
            NumPhysicsPolygons = gfxObj.PhysicsPolygons.Count;
            PhysicsPolygons    = new Dictionary <ushort, Polygon>();
            foreach (var kvp in gfxObj.PhysicsPolygons)
            {
                PhysicsPolygons.Add(kvp.Key, new Polygon(kvp.Value, gfxObj.VertexArray));
            }
            PhysicsBSP    = new BSP.BSPTree(gfxObj.PhysicsBSP, gfxObj.PhysicsPolygons, gfxObj.VertexArray);
            PhysicsSphere = PhysicsBSP.GetSphere();
            SortCenter    = gfxObj.SortCenter;
            NumPolygons   = gfxObj.Polygons.Count;
            Polygons      = new Dictionary <ushort, Polygon>();
            foreach (var kvp in gfxObj.Polygons)
            {
                Polygons.Add(kvp.Key, new Polygon(kvp.Value, gfxObj.VertexArray));
            }
            // usebuiltmesh
            DrawingBSP    = new BSP.BSPTree(gfxObj.DrawingBSP, gfxObj.Polygons, gfxObj.VertexArray);
            DrawingSphere = DrawingBSP.GetSphere();
        }
Beispiel #3
0
        public GfxObj(DatLoader.FileTypes.GfxObj gfxObj)
        {
            if (gfxObj == null)
            {
                return;
            }

            ID                 = gfxObj.Id;
            SurfaceIDs         = gfxObj.Surfaces;
            NumSurfaces        = SurfaceIDs != null ? SurfaceIDs.Count : 0;
            VertexArray        = CreateMutable(gfxObj.VertexArray);
            NumPhysicsPolygons = gfxObj.PhysicsPolygons.Count;
            PhysicsPolygons    = new Dictionary <ushort, Polygon>();
            foreach (var kvp in gfxObj.PhysicsPolygons)
            {
                PhysicsPolygons.Add(kvp.Key, CreateMutable(kvp.Value));
            }
            // usebuiltmesh
            // physicssphere
            PhysicsBSP = CreateMutable(gfxObj.PhysicsBSP);  // not mutable,
            // but still has non-unpack methods associated with it
            SortCenter  = gfxObj.SortCenter;
            NumPolygons = gfxObj.Polygons.Count;
            Polygons    = new Dictionary <ushort, Polygon>();
            foreach (var kvp in gfxObj.Polygons)
            {
                Polygons.Add(kvp.Key, CreateMutable(kvp.Value));
            }
            // drawing sphere/bsp
        }
Beispiel #4
0
        /// <summary>
        /// Loads the vertices for a polygon
        /// </summary>
        public void LoadVertices(CVertexArray vertexArray)
        {
            Vertices = new List <SWVertex>();

            foreach (var id in Polygon.VertexIds)
            {
                Vertices.Add(vertexArray.Vertices[(ushort)id]);
            }
        }
        public static List <VertexPositionColor> ToWireframeXna(this CVertexArray vertexArray)
        {
            var verts = new List <VertexPositionColor>();

            foreach (var v in vertexArray.Vertices)
            {
                verts.AddRange(v.Value.ToWireframeXna());
            }

            return(verts);
        }
        public static List <VertexPositionNormalTexture> ToXna(this CVertexArray vertexArray)
        {
            var verts = new List <VertexPositionNormalTexture>();

            foreach (var v in vertexArray.Vertices)
            {
                verts.AddRange(v.Value.ToXna());
            }

            return(verts);
        }
Beispiel #7
0
        public static Polygon Get(DatLoader.Entity.Polygon p, CVertexArray v)
        {
            var polygon = new Polygon(p, v);

            if (!Enabled)
            {
                return(polygon);
            }

            return(Get(polygon));
        }
Beispiel #8
0
        public static CVertexArray CreateMutable(DatLoader.Entity.CVertexArray _vertexArray)
        {
            var vertexArray = new CVertexArray();

            vertexArray.VertexType = _vertexArray.VertexType;
            vertexArray.Vertices   = new Dictionary <ushort, SWVertex>();
            foreach (var kvp in _vertexArray.Vertices)
            {
                vertexArray.Vertices.Add(kvp.Key, CreateMutable(kvp.Value));
            }
            return(vertexArray);
        }
 public static bool HasWrappingUVs(this CVertexArray vertexArray)
 {
     foreach (var v in vertexArray.Vertices.Values)
     {
         foreach (var uv in v.UVs)
         {
             if (uv.U < 0 || uv.U > 1 || uv.V < 0 || uv.V > 1)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        public static bool Verify(this CVertexArray vertexArray)
        {
            var keys = vertexArray.Vertices.Keys.ToList();

            keys.Sort();

            for (var i = 0; i < keys.Count; i++)
            {
                var key = keys[i];
                if (key != i)
                {
                    return(false);
                }
            }
            return(true);
        }
        public static Dictionary <Tuple <ushort, ushort>, ushort> BuildUVLookup(this CVertexArray vertexArray)
        {
            var uvLookupTable = new Dictionary <Tuple <ushort, ushort>, ushort>();

            ushort i = 0;

            foreach (var v in vertexArray.Vertices)
            {
                if (v.Value.UVs == null || v.Value.UVs.Count == 0)
                {
                    uvLookupTable.Add(new Tuple <ushort, ushort>(v.Key, 0), i++);
                    continue;
                }

                for (ushort uvIdx = 0; uvIdx < v.Value.UVs.Count; uvIdx++)
                {
                    uvLookupTable.Add(new Tuple <ushort, ushort>(v.Key, uvIdx), i++);
                }
            }
            return(uvLookupTable);
        }
Beispiel #12
0
 /// <summary>
 /// Constructs a new polygon
 /// </summary>
 public ModelPolygon(DatLoader.Entity.Polygon polygon, CVertexArray vertexArray)
 {
     Polygon = polygon;
     LoadVertices(vertexArray);
 }
Beispiel #13
0
        public static GfxObj ReadFromDat(uint fileId)
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(fileId))
            {
                return((GfxObj)DatManager.PortalDat.FileCache[fileId]);
            }
            else
            {
                DatReader datReader = DatManager.PortalDat.GetReaderForFile(fileId);
                GfxObj    obj       = new GfxObj();

                obj.Id    = datReader.ReadUInt32();
                obj.Flags = datReader.ReadUInt32();

                short num_surfaces = datReader.ReadPackedByte();
                for (short i = 0; i < num_surfaces; i++)
                {
                    obj.Surfaces.Add(datReader.ReadUInt32());
                }

                obj.VertexArray = CVertexArray.Read(datReader);

                // Has Physics
                if ((obj.Flags & 1) > 0)
                {
                    short num_physics_polygons = datReader.ReadPackedByte();
                    for (ushort i = 0; i < num_physics_polygons; i++)
                    {
                        ushort poly_id = datReader.ReadUInt16();
                        obj.PhysicsPolygons.Add(poly_id, Polygon.Read(datReader));
                    }

                    obj.PhysicsBSP = BSPTree.Read(datReader, BSPType.Physics);
                }

                obj.SortCenter = PositionExtensions.ReadPositionFrame(datReader);

                // Has Drawing
                if ((obj.Flags & 2) > 0)
                {
                    short num_polygons = datReader.ReadPackedByte();
                    for (ushort i = 0; i < num_polygons; i++)
                    {
                        ushort poly_id = datReader.ReadUInt16();
                        obj.Polygons.Add(poly_id, Polygon.Read(datReader));
                    }

                    obj.DrawingBSP = BSPTree.Read(datReader, BSPType.Drawing);
                }

                if ((obj.Flags & 8) > 0)
                {
                    obj.DIDDegrade = datReader.ReadUInt32();
                }

                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[fileId] = obj;

                return(obj);
            }
        }
Beispiel #14
0
 public static Polygon Get(DatLoader.Entity.Polygon p, CVertexArray v)
 {
     return(Get(new Polygon(p, v)));
 }