Пример #1
0
        public void Convert(BspDocument bsp, CIwResGroup group)
        {
            this.group = group;
            this.level = new Cb4aLevel();
            level.Name = bsp.Name;
            group.AddRes(new CIwTexture() { FilePath = "../textures/checkers.png" });
            group.AddRes(level);
            writer = new LevelVBWriter(level);

            CollectAllLeaves(bsp.Tree);
            CollectAllClusters();
            BuildLightmapAtlas(bsp);
            BuildClusters();

            //level.Materials.Add(new Cb4aLevelMaterial() { Texture="checkers" });

            foreach (var e in bsp.Entities)
            {
                level.Entities.Add(new Cb4aEntity() { classname = e.ClassName, origin = GetVec3(e.Origin), values = e.Values });
            }
            AddLeaves(level);
            if (bsp.Tree != null)
                AddTreeNode(level, bsp.Tree);
        }
Пример #2
0
 private static BspDocument Load(BinaryReader r)
 {
     var res = new BspDocument();
     var pos = r.BaseStream.Position;
     var magic = r.ReadUInt32();
     IBspReader reader = null;
     if (magic == 0x1D)
         reader = new Quake1Reader();
     else if (magic == 0x1E)
         reader = new HL1Reader();
     else if (magic == 0x50534256)
     {
         magic = r.ReadUInt32();
         if (magic == 17)
             reader = new HL2Reader17();
         else if (magic == 19)
             reader = new HL2Reader19();
         else if (magic == 20)
             reader = new HL2Reader20();
     }
     else if (magic == 0x50534249)
     {
         magic = r.ReadUInt32();
         if (magic == 0x26)
             reader = new Quake2Reader();
         else if (magic == 0x2E)
             reader = new Quake3Reader();
         else if (magic == 0x2F)
             reader = new QuakeLiveReader();
     }
     if (reader == null)
         throw new ApplicationException("Format is not supported");
     r.BaseStream.Seek(pos, SeekOrigin.Begin);
     reader.ReadBsp(r, res);
     return res;
 }
Пример #3
0
        //private Cb4aCollisionMeshSoupFaceEdge BuildBspCollisionFaceSoupFaceEdge(BspCollisionFaceSoupFaceEdge e)
        //{
        //    return new Cb4aCollisionMeshSoupFaceEdge() { Normal = GetVec3Fixed(e.Normal), Distance = (int)e.Distance * AirplaySDKMath.IW_GEOM_ONE };
        //}
        private void BuildLightmapAtlas(BspDocument bsp)
        {
            Dictionary<Bitmap, bool> lightmaps = new Dictionary<Bitmap, bool>();
            CollectAllLightmaps(lightmaps);
            //TODO: Make multiple atlases 128x128 istead one huge atlas. The reason is that there is only 4096 steps in UV coordinate!
            Atlas atlas = new Atlas();
            foreach (var l in lightmaps.Keys)
            {
                atlas.Add(l);
            }

            commonLightmap = new BspEmbeddedTexture() { Name = bsp.Name + "_lightmap", mipMaps = new Bitmap[] { atlas.Bitmap } };
            UpdateLightmap(commonLightmap, atlas);

            //
            //    Bitmap Lightmap = new Bitmap(128,128);
            //    using (var g = Graphics.FromImage(Lightmap))
            //    {
            //        g.Clear(Color.Red);
            //    }
            //    BspEmbeddedTexture lm = new BspEmbeddedTexture() { Name = "lightmap", mipMaps = new Bitmap[1] { Lightmap } };
            //    foreach (var l in leaves)
            //    {
            //        if (l.Geometry != null)
            //            foreach (var f in l.Geometry.Faces)
            //                if (f.Lightmap != null)
            //                    f.Lightmap = lm;
            //    }
        }