コード例 #1
0
ファイル: Cb4aLeaf.cs プロジェクト: marmalade/bsp4Airplay
 public void SortClusters(Cb4aLevel level)
 {
     if (Clusters.Count == 0) return;
     var ar = Clusters.ToArray();
     Array.Sort(ar, (x, y) => {
         var a = level.subclusters[x];
         var b = level.subclusters[y];
         if (a.VertexBuffer != b.VertexBuffer)
             return a.VertexBuffer - b.VertexBuffer;
         if (a.Material != b.Material)
             return a.Material - b.Material;
         return 0;
     });
     Clusters.Clear();
     Clusters.AddRange(ar);
 }
コード例 #2
0
ファイル: Adapter.cs プロジェクト: marmalade/bsp4Airplay
        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);
        }
コード例 #3
0
ファイル: Adapter.cs プロジェクト: marmalade/bsp4Airplay
 private void AddLeaves(Cb4aLevel level)
 {
     for (int i = 0; i < allLeaves.Count; ++i)
     {
         var bspTreeLeaf = allLeaves[i];
         i = level.Leaves.Count;
         var ll = new Cb4aLeaf() { Index = i, mins = GetVec3(bspTreeLeaf.Mins), maxs = GetVec3(bspTreeLeaf.Maxs) };
         level.Leaves.Add(ll);
         foreach (var g in bspTreeLeaf.Geometries)
         {
             int clusterIndix = clusterIndices[g];
             if (clusterIndix >= 0)
             {
                 foreach (var sub in subclustersInCluster[clusterIndix])
                     ll.Clusters.Add(sub);
             }
         }
         ll.SortClusters(level);
         if (bspTreeLeaf.Colliders != null)
         {
             foreach (var collider in bspTreeLeaf.Colliders)
             {
                 var c = BuildCollider(collider);
                 if (c != null)
                     ll.Colliders.Add(c);
             }
         }
         foreach (var v in bspTreeLeaf.VisibleLeaves)
             ll.VisibleLeaves.Add(leafIndices[v]);
     }
 }
コード例 #4
0
ファイル: Adapter.cs プロジェクト: marmalade/bsp4Airplay
 //private void WriteGeometry(BspGeometry bspGeometry, ModelWriter modelWriter)
 //{
 //    foreach (var face in bspGeometry.Faces)
 //    {
 //        var surface = modelWriter.GetSurfaceIndex(face.Texture.Name);
 //        CIwVec2 v0uv0 = GetVec2Fixed(face.Vertex0.UV0);
 //        CIwVec2 v1uv0 = GetVec2Fixed(face.Vertex1.UV0);
 //        CIwVec2 v2uv0 = GetVec2Fixed(face.Vertex2.UV0);
 //        while (v0uv0.x > 32767 || v1uv0.x > 32767 || v2uv0.x > 32767)
 //        {
 //            v0uv0.x = v0uv0.x-AirplaySDKMath.IW_GEOM_ONE;
 //            v1uv0.x = v1uv0.x-AirplaySDKMath.IW_GEOM_ONE;
 //            v2uv0.x = v2uv0.x-AirplaySDKMath.IW_GEOM_ONE;
 //        }
 //        while (v0uv0.y > 32767 || v1uv0.y > 32767 || v2uv0.y > 32767)
 //        {
 //            v0uv0.y -= AirplaySDKMath.IW_GEOM_ONE;
 //            v1uv0.y -= AirplaySDKMath.IW_GEOM_ONE;
 //            v2uv0.y -= AirplaySDKMath.IW_GEOM_ONE;
 //        }
 //        BspGeometryVertex vertex = face.Vertex0;
 //        var v0 = GetVertex(modelWriter, v0uv0, vertex);
 //        vertex = face.Vertex1;
 //        var v1 = GetVertex(modelWriter, v1uv0, vertex);
 //        vertex = face.Vertex2;
 //        var v2 = GetVertex(modelWriter, v2uv0, vertex);
 //        modelWriter.AddTriangle(surface, v0, v1, v2);
 //    }
 //}
 //private CTrisVertex GetVertex(ModelWriter modelWriter, CIwVec2 v0uv0, BspGeometryVertex vertex)
 //{
 //    return modelWriter.GetVertex(GetVec3(vertex.Position), GetVec3Fixed(vertex.Normal), v0uv0, GetVec2Fixed(vertex.UV1), CIwColour.White);
 //}
 private int AddTreeNode(Cb4aLevel l, BspTreeNode bspTreeNode)
 {
     int i;
     if (!nodeIndices.TryGetValue(bspTreeNode, out i))
     {
         i = l.Nodes.Count;
         var node = new Cb4aNode() { Index = i, mins = GetVec3(bspTreeNode.Mins), maxs = GetVec3(bspTreeNode.Maxs) };
         nodeIndices[bspTreeNode] = i;
         l.Nodes.Add(node);
         node.Plane = writer.WritePlane(new CIwPlane() { v = GetVec3Fixed(bspTreeNode.PlaneNormal), k = (int)(bspTreeNode.PlaneDistance) });
         //node.PlaneDistance = bspTreeNode.PlaneDistance;
         //node.PlaneNormal = GetVec3Fixed(bspTreeNode.PlaneNormal);
         node.IsFrontLeaf = bspTreeNode.Front is BspTreeLeaf;
         node.Front = AddTreeNode(l, bspTreeNode.Front);
         node.IsBackLeaf = bspTreeNode.Back is BspTreeLeaf;
         node.Back = AddTreeNode(l, bspTreeNode.Back);
     }
     return i;
 }
コード例 #5
0
ファイル: Adapter.cs プロジェクト: marmalade/bsp4Airplay
 private int AddTreeNode(Cb4aLevel l, BspTreeElement bspTreeElement)
 {
     if (bspTreeElement is BspTreeNode)
         return AddTreeNode(l, (BspTreeNode)bspTreeElement);
     return AddTreeLeaf(l, (BspTreeLeaf)bspTreeElement);
 }
コード例 #6
0
ファイル: Adapter.cs プロジェクト: marmalade/bsp4Airplay
 private int AddTreeLeaf(Cb4aLevel l, BspTreeLeaf bspTreeLeaf)
 {
     return leafIndices[bspTreeLeaf];
 }