Esempio n. 1
0
        public void AddTerrain(R_Landblock landblock)
        {
            foreach (var poly in landblock.Landblock.Polygons)
            {
                var surfnum = (uint)poly.PosSurface;

                var surface  = LandSurf.Instance.GetLandSurface(surfnum);
                var surfInfo = surface.Info;

                for (var i = 0; i < 3; i++)
                {
                    var v = StartVertex(surfInfo);

                    var vertex = poly.Vertices[i];
                    var uvIdx  = poly.PosUVIndices[i];
                    var uv     = LandblockStruct.LandUVs[uvIdx];

                    // pre-transform into world space
                    v.Position = Vector3.Transform(vertex.Origin.ToXna(), landblock.WorldTransform);
                    v.Normal   = vertex.Normal.ToXna();

                    v.TexCoord0 = new Vector3(uv.X, uv.Y, v.TexCoord0.Z);

                    var numTerrains = surfInfo.TerrainRotations.Count;

                    if (numTerrains > 0)
                    {
                        var rot = LandblockStruct.LandUVsRotated[(byte)surfInfo.TerrainRotations[0]][uvIdx];
                        v.TexCoord1 = new Vector4(rot.X, rot.Y, v.TexCoord1.Z, v.TexCoord1.W);
                    }
                    if (numTerrains > 1)
                    {
                        var rot = LandblockStruct.LandUVsRotated[(byte)surfInfo.TerrainRotations[1]][uvIdx];
                        v.TexCoord2 = new Vector4(rot.X, rot.Y, v.TexCoord2.Z, v.TexCoord2.W);
                    }
                    if (numTerrains > 2)
                    {
                        var rot = LandblockStruct.LandUVsRotated[(byte)surfInfo.TerrainRotations[2]][uvIdx];
                        v.TexCoord3 = new Vector4(rot.X, rot.Y, v.TexCoord3.Z, v.TexCoord3.W);
                    }

                    var numRoads = surfInfo.RoadRotations.Count;

                    if (numRoads > 0)
                    {
                        var rot = LandblockStruct.LandUVsRotated[(byte)surfInfo.RoadRotations[0]][uvIdx];
                        v.TexCoord4 = new Vector4(rot.X, rot.Y, v.TexCoord4.Z, v.TexCoord4.W);
                    }
                    if (numRoads > 1)
                    {
                        var rot = LandblockStruct.LandUVsRotated[(byte)surfInfo.RoadRotations[1]][uvIdx];
                        v.TexCoord5 = new Vector4(rot.X, rot.Y, v.TexCoord5.Z, v.TexCoord5.W);
                    }

                    Vertices.Add(v);
                }
            }
        }
Esempio n. 2
0
 public void AddTerrain(R_Landblock landblock)
 {
     if (CurrentBatch == null || !CurrentBatch.CanAdd(landblock))
     {
         CurrentBatch = new TerrainBatchDraw(OverlayAtlasChain, AlphaAtlasChain);
         Batches.Add(CurrentBatch);
     }
     CurrentBatch.AddTerrain(landblock);
 }
Esempio n. 3
0
 public bool CanAdd(R_Landblock landblock)
 {
     return(Vertices.Count + landblock.Landblock.Polygons.Count * 3 <= MaxVertices);
 }