aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs43
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs89
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs5
3 files changed, 135 insertions, 2 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs
new file mode 100644
index 0000000..d0f5d07
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs
@@ -0,0 +1,43 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using OpenSim.Region.Environment.Modules.Terrain;
6using OpenSim.Region.Environment.Interfaces;
7
8namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
9{
10 public class RAW32 : ITerrainLoader
11 {
12 #region ITerrainLoader Members
13
14 public ITerrainChannel LoadFile(string filename)
15 {
16 TerrainChannel retval = new TerrainChannel();
17
18 FileInfo file = new FileInfo(filename);
19 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
20 BinaryReader bs = new BinaryReader(s);
21 int x, y;
22 for (y = 0; y < retval.Height; y++)
23 {
24 for (x = 0; x < retval.Width; x++)
25 {
26 retval[x, y] = bs.ReadSingle();
27 }
28 }
29
30 bs.Close();
31 s.Close();
32
33 return retval;
34 }
35
36 public void SaveFile(string filename)
37 {
38 throw new NotImplementedException();
39 }
40
41 #endregion
42 }
43}
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs
new file mode 100644
index 0000000..2443173
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs
@@ -0,0 +1,89 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using OpenSim.Region.Environment.Modules.Terrain;
6using OpenSim.Region.Environment.Interfaces;
7
8namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
9{
10 /// <summary>
11 /// Terragen File Format Loader
12 /// Built from specification at
13 /// http://www.planetside.co.uk/terragen/dev/tgterrain.html
14 /// </summary>
15 class Terragen : ITerrainLoader
16 {
17 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
18
19 #region ITerrainLoader Members
20
21 public ITerrainChannel LoadFile(string filename)
22 {
23 TerrainChannel retval = new TerrainChannel();
24
25 FileInfo file = new FileInfo(filename);
26 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
27 BinaryReader bs = new BinaryReader(s);
28
29 bool eof = false;
30
31 if (ASCIIEncoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN")
32 {
33 // Terragen file
34 while (eof == false)
35 {
36 int w = 256;
37 int h = 256;
38 string tmp = ASCIIEncoding.ASCII.GetString(bs.ReadBytes(4));
39 switch (tmp)
40 {
41 case "SIZE":
42 int sztmp = bs.ReadInt16() + 1;
43 w = sztmp;
44 h = sztmp;
45 bs.ReadInt16();
46 break;
47 case "XPTS":
48 w = bs.ReadInt16();
49 bs.ReadInt16();
50 break;
51 case "YPTS":
52 h = bs.ReadInt16();
53 bs.ReadInt16();
54 break;
55 case "ALTW":
56 eof = true;
57 Int16 heightScale = bs.ReadInt16();
58 Int16 baseHeight = bs.ReadInt16();
59 retval = new TerrainChannel(w, h);
60 int x, y;
61 for (x = 0; x < w; x++)
62 {
63 for (y = 0; y < h; y++)
64 {
65 retval[x, y] = (double)baseHeight + (double)bs.ReadInt16() * (double)heightScale / 65536.0;
66 }
67 }
68 break;
69 default:
70 bs.ReadInt32();
71 break;
72 }
73 }
74 }
75
76 bs.Close();
77 s.Close();
78
79 return retval;
80 }
81
82 public void SaveFile(string filename)
83 {
84 throw new NotImplementedException();
85 }
86
87 #endregion
88 }
89}
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
index d9fc2f4..22b5fd9 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
@@ -143,8 +143,9 @@ namespace OpenSim.Region.Environment.Modules.Terrain
143 m_floodeffects[StandardTerrainEffects.Raise] = new FloodBrushes.RaiseArea(); 143 m_floodeffects[StandardTerrainEffects.Raise] = new FloodBrushes.RaiseArea();
144 144
145 // Float[256,256] array format (RAW32) 145 // Float[256,256] array format (RAW32)
146 // m_loaders[".r32"] = new FileLoaders.RAW32(); 146 m_loaders[".r32"] = new FileLoaders.RAW32();
147 // m_loaders[".f32"] = m_loaders[".r32"]; 147 m_loaders[".f32"] = m_loaders[".r32"];
148 m_loaders[".ter"] = new FileLoaders.Terragen();
148 } 149 }
149 150
150 public void LoadFromFile(string filename) 151 public void LoadFromFile(string filename)