Esempio n. 1
0
 private static Cb4aLevelMaterial BuildMaterial(BspGeometryFace f)
 {
     BspTexture fTexture = f.Texture;
     var res = new Cb4aLevelMaterial();
     if (fTexture != null) {
         res.Texture = fTexture.Name;
         res.Sky = fTexture.Sky;
         res.Transparent = fTexture.Transparent;
     }
     if (f.Lightmap != null) res.Lightmap = f.Lightmap.Name;
     return res;
 }
Esempio n. 2
0
 private void TessalateFace(IList<BspGeometryFace> faces, BspGeometryFace f)
 {
     var v01 = new BspGeometryVertex() {
         Normal = f.Vertex0.Normal,
         Position = (f.Vertex0.Position + f.Vertex1.Position)*0.5f,
         UV0 = (f.Vertex0.UV0 + f.Vertex1.UV0) * 0.5f,
         UV1 = (f.Vertex0.UV1 + f.Vertex1.UV1) * 0.5f,
         Color = Color.FromArgb(
             (byte)(((int)f.Vertex0.Color.A + (int)f.Vertex1.Color.A) / 2),
             (byte)(((int)f.Vertex0.Color.R + (int)f.Vertex1.Color.R) / 2),
             (byte)(((int)f.Vertex0.Color.G + (int)f.Vertex1.Color.G) / 2),
             (byte)(((int)f.Vertex0.Color.B + (int)f.Vertex1.Color.B) / 2))
     };
     var v02 = new BspGeometryVertex() {
         Normal = f.Vertex0.Normal,
         Position = (f.Vertex0.Position + f.Vertex2.Position)*0.5f,
         UV0 = (f.Vertex0.UV0 + f.Vertex2.UV0) * 0.5f,
         UV1 = (f.Vertex0.UV1 + f.Vertex2.UV1) * 0.5f,
         Color = Color.FromArgb(
             (byte)(((int)f.Vertex0.Color.A + (int)f.Vertex2.Color.A) / 2),
             (byte)(((int)f.Vertex0.Color.R + (int)f.Vertex2.Color.R) / 2),
             (byte)(((int)f.Vertex0.Color.G + (int)f.Vertex2.Color.G) / 2),
             (byte)(((int)f.Vertex0.Color.B + (int)f.Vertex2.Color.B) / 2))
     };
     var v12 = new BspGeometryVertex() {
         Normal = f.Vertex1.Normal,
         Position = (f.Vertex1.Position + f.Vertex2.Position)*0.5f,
         UV0 = (f.Vertex1.UV0 + f.Vertex2.UV0) * 0.5f,
         UV1 = (f.Vertex1.UV1 + f.Vertex2.UV1) * 0.5f,
         Color = Color.FromArgb(
             (byte)(((int)f.Vertex1.Color.A + (int)f.Vertex2.Color.A) / 2),
             (byte)(((int)f.Vertex1.Color.R + (int)f.Vertex2.Color.R) / 2),
             (byte)(((int)f.Vertex1.Color.G + (int)f.Vertex2.Color.G) / 2),
             (byte)(((int)f.Vertex1.Color.B + (int)f.Vertex2.Color.B) / 2))
     };
     faces.Add(new BspGeometryFace()
     {
         Texture = f.Texture, Lightmap = f.Lightmap,
         Vertex0 = f.Vertex0,
         Vertex1 = v01,
         Vertex2 = v02
     });
     faces.Add(new BspGeometryFace()
     {
         Texture = f.Texture,
         Lightmap = f.Lightmap,
         Vertex0 = f.Vertex1,
         Vertex1 = v12,
         Vertex2 = v01
     });
     faces.Add(new BspGeometryFace()
     {
         Texture = f.Texture,
         Lightmap = f.Lightmap,
         Vertex0 = f.Vertex2,
         Vertex1 = v02,
         Vertex2 = v12
     });
     faces.Add(new BspGeometryFace()
     {
         Texture = f.Texture,
         Lightmap = f.Lightmap,
         Vertex0 = v01,
         Vertex1 = v12,
         Vertex2 = v02
     });
 }
Esempio n. 3
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;
             }
         }
     }
 }
Esempio n. 4
0
        private void BuildFace(LevelVBWriter writer, Cb4aLevelVBSubcluster sub, ref CIwVec3 mins, ref CIwVec3 maxs, BspGeometryFace f)
        {
            while (f.Vertex0.UV0.X >= 8 || f.Vertex1.UV0.X >= 8 || f.Vertex2.UV0.X >= 8)
            {
                f.Vertex0.UV0.X -= 1;
                f.Vertex1.UV0.X -= 1;
                f.Vertex2.UV0.X -= 1;
            }
            while (f.Vertex0.UV0.Y >= 8 || f.Vertex1.UV0.Y >= 8 || f.Vertex2.UV0.Y >= 8)
            {
                f.Vertex0.UV0.Y -= 1;
                f.Vertex1.UV0.Y -= 1;
                f.Vertex2.UV0.Y -= 1;
            }
            if (f.Vertex0.UV0.X < -8) f.Vertex0.UV0.X = -8;
            if (f.Vertex1.UV0.X < -8) f.Vertex1.UV0.X = -8;
            if (f.Vertex2.UV0.X < -8) f.Vertex2.UV0.X = -8;
            if (f.Vertex0.UV0.Y < -8) f.Vertex0.UV0.Y = -8;
            if (f.Vertex1.UV0.Y < -8) f.Vertex1.UV0.Y = -8;
            if (f.Vertex2.UV0.Y < -8) f.Vertex2.UV0.Y = -8;

            if (f.Vertex0.Position.X < mins.x) mins.x = (int)f.Vertex0.Position.X;
            if (f.Vertex1.Position.X < mins.x) mins.x = (int)f.Vertex1.Position.X;
            if (f.Vertex2.Position.X < mins.x) mins.x = (int)f.Vertex2.Position.X;
            if (f.Vertex0.Position.Y < mins.y) mins.y = (int)f.Vertex0.Position.Y;
            if (f.Vertex1.Position.Y < mins.y) mins.y = (int)f.Vertex1.Position.Y;
            if (f.Vertex2.Position.Y < mins.y) mins.y = (int)f.Vertex2.Position.Y;
            if (f.Vertex0.Position.Z < mins.z) mins.z = (int)f.Vertex0.Position.Z;
            if (f.Vertex1.Position.Z < mins.z) mins.z = (int)f.Vertex1.Position.Z;
            if (f.Vertex2.Position.Z < mins.z) mins.z = (int)f.Vertex2.Position.Z;

            if (f.Vertex0.Position.X > maxs.x) maxs.x = (int)f.Vertex0.Position.X;
            if (f.Vertex1.Position.X > maxs.x) maxs.x = (int)f.Vertex1.Position.X;
            if (f.Vertex2.Position.X > maxs.x) maxs.x = (int)f.Vertex2.Position.X;
            if (f.Vertex0.Position.Y > maxs.y) maxs.y = (int)f.Vertex0.Position.Y;
            if (f.Vertex1.Position.Y > maxs.y) maxs.y = (int)f.Vertex1.Position.Y;
            if (f.Vertex2.Position.Y > maxs.y) maxs.y = (int)f.Vertex2.Position.Y;
            if (f.Vertex0.Position.Z > maxs.z) maxs.z = (int)f.Vertex0.Position.Z;
            if (f.Vertex1.Position.Z > maxs.z) maxs.z = (int)f.Vertex1.Position.Z;
            if (f.Vertex2.Position.Z > maxs.z) maxs.z = (int)f.Vertex2.Position.Z;

            var index0 = writer.Write(GetLevelVBItem(f.Vertex0));
            var index1 = writer.Write(GetLevelVBItem(f.Vertex1));
            var index2 = writer.Write(GetLevelVBItem(f.Vertex2));
            if ((index0 == index1) || (index0 == index2) || (index2 == index1))
                return;
            sub.Indices.Add(index2);
            sub.Indices.Add(index1);
            sub.Indices.Add(index0);
        }