예제 #1
0
        private int WriteVB(BspGeometry geometry, LevelVBWriter writer)
        {
            if (geometry == null)
                return -1;
            if (geometry.Faces.Count == 0)
                return -1;

            TessalateFaces(geometry);

            var clusterIndex = subclustersInCluster.Count;
            var cluster = new List<int>();
            subclustersInCluster.Add(cluster);

            writer.PrepareVertexBuffer(geometry.Faces.Count * 3);
            //cluster.VertexBuffer = level.VertexBuffers.Count - 1;
            Dictionary<int, bool> materialMap = new Dictionary<int, bool>();
            List<int> materialInices = new List<int>(geometry.Faces.Count);
            foreach (var f in geometry.Faces)
            {
                RegisterTexture(f.Texture);
                if (f.Lightmap != null && commonLightmap != f.Lightmap)
                    throw new ApplicationException("not atlased lightmap");
                RegisterTexture(f.Lightmap);
                int matIndex = writer.WriteMaterial(BuildMaterial(f));
                materialInices.Add(matIndex);
                materialMap[matIndex] = true;
            }
            foreach (int t in materialMap.Keys)
            {
                var sub = new Cb4aLevelVBSubcluster();
                sub.Material = t;
                sub.VertexBuffer = level.VertexBuffers.Count - 1;
                CIwVec3 mins = new CIwVec3(int.MaxValue, int.MaxValue, int.MaxValue);
                CIwVec3 maxs = new CIwVec3(int.MinValue, int.MinValue, int.MinValue);
                for (int i = 0; i < materialInices.Count; ++i)
                {
                    if (materialInices[i] == t)
                    {
                        var f = geometry.Faces[i];

                        //TODO: slice face into more faces
                        BuildFace(writer, sub, ref mins, ref maxs, f);
                    }
                }
                if (mins.x > maxs.x)
                {
                    mins = CIwVec3.g_Zero;
                    maxs = CIwVec3.g_Zero;
                }
                sub.Mins = mins;
                sub.Maxs = maxs;
                if (sub.Indices.Count > 0)
                {
                    cluster.Add(level.subclusters.Count);
                    level.subclusters.Add(sub);
                }
            }

            return clusterIndex;
        }
예제 #2
0
 public void AddModel(BspGeometry bspGeometry)
 {
     models.Add(bspGeometry);
 }
예제 #3
0
 private void TessalateFaces(BspGeometry bspGeometry)
 {
     for (int i = 0; i < bspGeometry.Faces.Count; )
     {
         var f = bspGeometry.Faces[i];
         if (f.MaxUV0Distance > 15.5f)
         {
             bspGeometry.Faces.RemoveAt(i);
             TessalateFace(bspGeometry.Faces, f);
             continue;
         }
         ++i;
     }
 }