public bool Save(string file, IVoxelChannel _c) { VoxelChannel c = (VoxelChannel)_c; c.SaveToFile(file); return(true); }
public bool Compare(IVoxelChannel terrainChannel) { if (m_channel != terrainChannel) { return(false); } else { return(false); } }
public VoxelUndoState(IVoxelModule terrainModule, IVoxelChannel terrainChannel) { m_module = terrainModule; m_channel = terrainChannel; }
private void CreateTerrain(WarpRenderer renderer, bool textureTerrain) { IVoxelChannel terrain = m_scene.Voxels; float[] heightmap = terrain.GetFloatsSerialised(); warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2); for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { int v = y * 256 + x; float height = heightmap[v]; warp_Vector pos = ConvertVector(new Vector3(x, y, height)); obj.addVertex(new warp_Vertex(pos, (float)x / 255f, (float)(255 - y) / 255f)); } } for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { if (x < 255 && y < 255) { int v = y * 256 + x; // Normal Vector3 v1 = new Vector3(x, y, heightmap[y * 256 + x]); Vector3 v2 = new Vector3(x + 1, y, heightmap[y * 256 + x + 1]); Vector3 v3 = new Vector3(x, y + 1, heightmap[(y + 1) * 256 + x]); warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); norm = norm.reverse(); obj.vertex(v).n = norm; // Triangle 1 obj.addTriangle( v, v + 1, v + 256); // Triangle 2 obj.addTriangle( v + 256 + 1, v + 256, v + 1); } } } renderer.Scene.addObject("Terrain", obj); UUID[] textureIDs = new UUID[4]; float[] startHeights = new float[4]; float[] heightRanges = new float[4]; RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; textureIDs[0] = regionInfo.TerrainTexture1; textureIDs[1] = regionInfo.TerrainTexture2; textureIDs[2] = regionInfo.TerrainTexture3; textureIDs[3] = regionInfo.TerrainTexture4; startHeights[0] = (float)regionInfo.Elevation1SW; startHeights[1] = (float)regionInfo.Elevation1NW; startHeights[2] = (float)regionInfo.Elevation1SE; startHeights[3] = (float)regionInfo.Elevation1NE; heightRanges[0] = (float)regionInfo.Elevation2SW; heightRanges[1] = (float)regionInfo.Elevation2NW; heightRanges[2] = (float)regionInfo.Elevation2SE; heightRanges[3] = (float)regionInfo.Elevation2NE; uint globalX, globalY; Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); Bitmap image = TerrainSplat.Splat(heightmap, textureIDs, startHeights, heightRanges, new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain); warp_Texture texture = new warp_Texture(image); warp_Material material = new warp_Material(texture); material.setReflectivity(50); renderer.Scene.addMaterial("TerrainColor", material); renderer.SetObjectMaterial("Terrain", "TerrainColor"); }
//#region ITerrainModule Members public void UndoTerrain(IVoxelChannel channel) { m_channel = (VoxelChannel)channel; }
/// <summary> /// From the VoxelSim project /// http://github.com/N3X15/VoxelSim /// </summary> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="chunksize"></param> /// <returns></returns> public void Generate(ref IVoxelChannel _mh, long X, long Y) { VoxelChannel mh = (VoxelChannel)_mh; m_log.InfoFormat("Generating terrain for a <{0},{1},{2}>m area.", mh.XScale, mh.YScale, mh.ZScale); bool PlaceGravel = ((GravelNoise.GetValue((X * mh.XScale), (Y * mh.YScale), 0) + 1) / 2.0) > 0.90d; int ZH = (int)mh.ZScale; byte[, ,] b = new byte[mh.XScale, mh.YScale, mh.ZScale]; m_log.Debug("Stand by, generating terrain..."); Console.WriteLine(); for (int x = 0; x < mh.XScale; x++) { Console.CursorLeft = 0; Console.Write(" * Generating slice {0}/{1}... ({2}% complete)", x, mh.XScale, (int)System.Math.Round(((double)x / (double)mh.XScale) * 100d)); for (int y = 0; y < mh.YScale; y++) { for (int z = 0; z < ZH; z++) { int intensity = z * (255 / ZH); double heightoffset = (ContinentNoise.GetValue(x + (X * mh.XScale), y + (Y * mh.YScale), 0) + 1d) / 2.0; //Console.WriteLine("HeightOffset {0}",heightoffset); //if (z == 0) // b[x, y, z] = 7; ////else if (x == 0 && y == 0) //// b[x, y, z] = 1; //else //{ bool d1 = ((TerrainNoise.GetValue(x + (X * mh.XScale), y + (Y * mh.YScale), z * TerrainDivisor) + 1) / 2.0) > System.Math.Pow((((double)z * (HeightDivisor + (heightoffset))) / (double)ZH), 3d); // 3d double _do = ((CaveNoise.GetValue(x + (X * mh.XScale), y + (Y * mh.YScale), z * CaveDivisor) + 1) / 2.0); bool d3 = _do > CaveThreshold; // XOR? if (d1)//if (!(!d1 || !d2)) { //Console.Write("#"); b[x, y, z] = (d3) ? b[x, y, z] : mMap.Rock.ID; //if (x == 0|| y == 0) // b[x, y, z] = 41; } else if (z == 1) b[x, y, z] = 11; //} } } } Console.WriteLine(); //Console.WriteLine("Done generating chunk. [{0},{1}]",min,max); for (int x = 0; x < mh.XScale; x++) { Console.CursorLeft = 0; Console.Write(" * Applying sediment to slice {0}/{1}... ({2}% complete)", x, mh.XScale, (int)System.Math.Round(((double)x / (double)mh.XScale) * 100d)); //Console.WriteLine(); for (int y = 0; y < mh.YScale; y++) { bool HavePloppedGrass = false; bool HaveTouchedSoil = false; for (int z = (int)mh.ZScale - 1; z > 0; z--) { if (b[x, y, z] == mMap.Rock.ID) { HaveTouchedSoil = true; if (z + DERT_DEPTH >= ZH) continue; byte ddt = b[x, y, z + DERT_DEPTH]; if (ddt == mMap.Air.ID || ddt == mMap.Water.ID) { if (z - DERT_DEPTH <= WaterHeight && GenerateWater) b[x, y, z] = mMap.Sand.ID; // (!PlaceGravel) ? ... else b[x, y, z] = (HavePloppedGrass) ? mMap.Soil.ID : mMap.Grass.ID; if (!HavePloppedGrass) HavePloppedGrass = true; } else { z = 0; } } else if (b[x, y, z] == 0 && z <= WaterHeight && !HaveTouchedSoil && GenerateWater) { b[x, y, z] = mMap.Water.ID; } } } } Console.WriteLine(); /* for (int x = 0; x < mh.XScale; x++) { for (int y = 0; y < mh.YScale; y++) { int z = 1; // TODO Yell at Notch for not making Lava occlude. :| if (b[x, y, z] == 0) b[x, y, z] = mMap.Lava.ID; // Lava for air. else if (b[x, y, z] == mMap.Water.ID) b[x, y, z] = mMap.Obsidian.ID; // Obsidian for underwater shit. } } */ mh.SetTo(b); }
public void SaveStream(Stream a, IVoxelChannel c) { throw new NotSupportedException(); }
public bool Compare(IVoxelChannel terrainChannel) { if (m_channel != terrainChannel) return false; else return false; }
public void Generate(string method, long seed, long X, long Y, object[] args) { if (!Directory.Exists("terrain")) { Directory.CreateDirectory("terrain"); } IVoxelChannel vc = MakeCopy(); if (TerrainGenerators.ContainsKey(method)) { TerrainGenerators[method].Initialize(mMaterials, seed); TerrainGenerators[method].Generate(ref vc, X, Y); Voxels = (vc as VoxelChannel).Voxels; } else { Console.WriteLine("[TERRAGEN] Terrain generation module \"{0}\" not installed.", method); return; } Image image = new Bitmap(XScale, YScale); double[,] hm = GetDoubles(); for (int x = 0; x < XScale; x++) { for (int y = 0; y < YScale; y++) { int c = (int)(255.0d * (hm[x, y] / 256d)); (image as Bitmap).SetPixel(x, 255 - y, Color.FromArgb(c, c, c)); } } image.Save("terrain/GEN.png", System.Drawing.Imaging.ImageFormat.Png); image.Dispose(); AnimatedGifEncoder e = new AnimatedGifEncoder(); e.Start("terrain/SLICE.gif"); e.SetDelay(250); //-1:no repeat,0:always repeat e.SetRepeat(0); for (int x = 0; x < XScale; x++) { image = new Bitmap(YScale, ZScale); for (int y = 0; y < YScale; y++) { //Console.WriteLine(); for (int z = 0; z < ZScale; z++) { if (IsSolid(x, y, z)) { (image as Bitmap).SetPixel(y, ZScale - z - 1, Color.FromArgb(255, 255, 255)); } else { (image as Bitmap).SetPixel(y, ZScale - z - 1, Color.FromArgb(000, 000, 000)); } } } Console.CursorLeft = 0; Console.Write(" * {0}% ({1}/{2}) frames added...", (int)(((float)(x + 1) / ((float)XScale)) * 100f), x + 1, XScale); e.AddFrame((Image)image.Clone()); image.Dispose(); } Console.WriteLine(); e.Finish(); }
public void SaveStream(Stream a,IVoxelChannel c) { throw new NotSupportedException(); }
public bool Save (string file,IVoxelChannel _c) { VoxelChannel c = (VoxelChannel)_c; c.SaveToFile(file); return true; }
/// <summary> /// From the VoxelSim project /// http://github.com/N3X15/VoxelSim /// </summary> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="chunksize"></param> /// <returns></returns> public void Generate(ref IVoxelChannel _mh, long X, long Y) { VoxelChannel mh = (VoxelChannel)_mh; m_log.InfoFormat("Generating terrain for a <{0},{1},{2}>m area.", mh.XScale, mh.YScale, mh.ZScale); bool PlaceGravel = ((GravelNoise.GetValue((X * mh.XScale), (Y * mh.YScale), 0) + 1) / 2.0) > 0.90d; int ZH = (int)mh.ZScale; byte[, ,] b = new byte[mh.XScale, mh.YScale, mh.ZScale]; m_log.Debug("Stand by, generating terrain..."); Console.WriteLine(); for (int x = 0; x < mh.XScale; x++) { Console.CursorLeft = 0; Console.Write(" * Generating slice {0}/{1}... ({2}% complete)", x, mh.XScale, (int)System.Math.Round(((double)x / (double)mh.XScale) * 100d)); for (int y = 0; y < mh.YScale; y++) { for (int z = 0; z < ZH; z++) { int intensity = z * (255 / ZH); double heightoffset = (ContinentNoise.GetValue(x + (X * mh.XScale), y + (Y * mh.YScale), 0) + 1d) / 2.0; //Console.WriteLine("HeightOffset {0}",heightoffset); //if (z == 0) // b[x, y, z] = 7; ////else if (x == 0 && y == 0) //// b[x, y, z] = 1; //else //{ bool d1 = ((TerrainNoise.GetValue(x + (X * mh.XScale), y + (Y * mh.YScale), z * TerrainDivisor) + 1) / 2.0) > System.Math.Pow((((double)z * (HeightDivisor + (heightoffset))) / (double)ZH), 3d); // 3d double _do = ((CaveNoise.GetValue(x + (X * mh.XScale), y + (Y * mh.YScale), z * CaveDivisor) + 1) / 2.0); bool d3 = _do > CaveThreshold; // XOR? if (d1) //if (!(!d1 || !d2)) { //Console.Write("#"); b[x, y, z] = (d3) ? b[x, y, z] : mMap.Rock.ID; //if (x == 0|| y == 0) // b[x, y, z] = 41; } else if (z == 1) { b[x, y, z] = 11; } //} } } } Console.WriteLine(); //Console.WriteLine("Done generating chunk. [{0},{1}]",min,max); for (int x = 0; x < mh.XScale; x++) { Console.CursorLeft = 0; Console.Write(" * Applying sediment to slice {0}/{1}... ({2}% complete)", x, mh.XScale, (int)System.Math.Round(((double)x / (double)mh.XScale) * 100d)); //Console.WriteLine(); for (int y = 0; y < mh.YScale; y++) { bool HavePloppedGrass = false; bool HaveTouchedSoil = false; for (int z = (int)mh.ZScale - 1; z > 0; z--) { if (b[x, y, z] == mMap.Rock.ID) { HaveTouchedSoil = true; if (z + DERT_DEPTH >= ZH) { continue; } byte ddt = b[x, y, z + DERT_DEPTH]; if (ddt == mMap.Air.ID || ddt == mMap.Water.ID) { if (z - DERT_DEPTH <= WaterHeight && GenerateWater) { b[x, y, z] = mMap.Sand.ID; // (!PlaceGravel) ? ... } else { b[x, y, z] = (HavePloppedGrass) ? mMap.Soil.ID : mMap.Grass.ID; } if (!HavePloppedGrass) { HavePloppedGrass = true; } } else { z = 0; } } else if (b[x, y, z] == 0 && z <= WaterHeight && !HaveTouchedSoil && GenerateWater) { b[x, y, z] = mMap.Water.ID; } } } } Console.WriteLine(); /* * for (int x = 0; x < mh.XScale; x++) * { * for (int y = 0; y < mh.YScale; y++) * { * int z = 1; * // TODO Yell at Notch for not making Lava occlude. :| * if (b[x, y, z] == 0) * b[x, y, z] = mMap.Lava.ID; // Lava for air. * else if (b[x, y, z] == mMap.Water.ID) * b[x, y, z] = mMap.Obsidian.ID; // Obsidian for underwater shit. * } * } */ mh.SetTo(b); }