Example #1
0
 void RegisterTexture(BspTexture t)
 {
     if (t == null)
         return;
     if (textureIndices.ContainsKey(t))
         return;
     textureIndices[t] = 0;
     string subfolder = "../textures/";
     //t.Name = t.Name;
     foreach (var c in Path.GetInvalidFileNameChars())
         t.Name = t.Name.Replace(c, '_');
     Bitmap bmp = null;
     if (t is BspEmbeddedTexture)
     {
         var embeddedTex = (BspEmbeddedTexture)t;
         if (embeddedTex.mipMaps != null && embeddedTex.mipMaps.Length > 0)
             bmp = embeddedTex.mipMaps[0];
     }
     group.AddRes(new CIwTexture() { FilePath = subfolder + t.Name + ".png", Bitmap = bmp });
 }
Example #2
0
 private void UpdateLightmap(BspTexture result, Atlas atlas)
 {
     foreach (var geo in allClusters)
     {
         Size dstSize = new Size(atlas.Bitmap.Width, atlas.Bitmap.Height);
         for (int i = 0; i < geo.Faces.Count; ++i)
         {
             var f = geo.Faces[i];
             if (f.Lightmap != null)
             {
                 if (f.Lightmap.Equals(result))
                     continue;
                 var item = atlas.GetItem(((BspEmbeddedTexture)f.Lightmap).mipMaps[0]);
                 var ff = new BspGeometryFace() { Texture = f.Texture, Lightmap = result };
                 ff.Vertex0 = CorrectLightmapCoords(f.Vertex0, dstSize, item);
                 ff.Vertex1 = CorrectLightmapCoords(f.Vertex1, dstSize, item);
                 ff.Vertex2 = CorrectLightmapCoords(f.Vertex2, dstSize, item);
                 geo.Faces[i] = ff;
             }
         }
     }
 }
Example #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;
            //    }
        }