public void AddEnvironment(BaseChunk chunk) { const int safeBorder = 2; var count = random.Next(maxTreeCountInChunk); for (var treeCount = 0; treeCount < count; treeCount++) { var x = random.Next(safeBorder, BaseChunk.Width - safeBorder); var z = random.Next(safeBorder, BaseChunk.Length - safeBorder); var top = BaseChunk.Height; for (; top > 0; top--) { if (chunk.Map[x, top - 1, z] != 0) { break; } } if (chunk.Map[x, top - 1, z] != Grass) { continue; } var position = new Vector3(x, top, z); var tree = GetTree(); TryPlaceEnvironment(tree, chunk, position); } }
public void AddEnvironment(BaseChunk chunk) { var count = random.Next(MaxCountInChunk); for (int treeCount = 0; treeCount < count; treeCount++) { var x = random.Next(BaseChunk.Width); var z = random.Next(BaseChunk.Length); var top = BaseChunk.Height; for (; top > 0; top--) { if (chunk.Map[x, top - 1, z] != 0) { break; } } if (chunk.Map[x, top - 1, z] != (int)BlockType.Sand) { continue; } var length = random.Next(MaxLength); for (var i = 0; i < length; i++) { chunk.Map[x, top + i, z] = (int)BlockType.Cactus; } } }
public ChunkModel(BaseChunk chunk, ITextureStorage storage) { this.chunk = chunk; this.storage = storage; UpdateModel(); }
public override bool Read(BinaryReader br) { attributes1 = br.ReadUInt32(); attributes2 = br.ReadUInt32(); guid = br.ReadUInt32(); nextChunk = SetNextChunk(br, attributes1); if (nextChunk == null) { return(true); } return(nextChunk.Read(br)); }
/// <summary> /// Loads Mesh from File /// </summary> /// <param name="path">The path.</param> /// <returns></returns> /// <exception cref="ArgumentException">Path given is not valid</exception> /// <exception cref="EndOfDataException">Unexpected end of Data</exception> /// <exception cref="FileNotFoundException">File could not be found</exception> /// <exception cref="InsufficientPermissionsException">Insufficient Permissions</exception> /// <exception cref="IOException">Read / Write Error</exception> public static MSH LoadFromFile(string path) { MSH msh = new MSH(); Log.Add("Open File " + path, LogType.Info); ChunkStream stream = null; try { stream = new ChunkStream(path, FileMode.Open, FileAccess.Read); msh.header = new HEDR(BaseChunk.FromData(stream, msh)); Log.Add("Flushing raw Data", LogType.Info); msh.header.FlushData(); } catch (ArgumentException ex) { Log.Add("Path given is not valid!", LogType.Error); throw new ArgumentException("Path given is not valid!", ex); } catch (NotSupportedException ex) { Log.Add("Path given is not valid!", LogType.Error); throw new ArgumentException("Path given is not valid!", ex); } catch (PathTooLongException ex) { Log.Add("Path given is not valid!", LogType.Error); throw new ArgumentException("Path given is not valid!", ex); } catch (UnauthorizedAccessException ex) { Log.Add("Insufficient Permissions!", LogType.Error); throw new InsufficientPermissionsException("Insufficient Permissions!", ex); } catch (SecurityException ex) { Log.Add("Insufficient Permissions!", LogType.Error); throw new InsufficientPermissionsException("Insufficient Permissions!", ex); } finally { if (stream != null) { stream.Close(); } } //Apply Parent Reference AFTER we loaded all Models Log.Add("Apply References", LogType.Info); foreach (MODL mdl in msh.Models) { mdl.ApplyReferences(); } Log.Add("DONE!", LogType.Info); return(msh); }
private static bool TryPlaceEnvironment(EnvironmentObject obj, BaseChunk chunk, Vector3 anchor) { const bool noExcess = true; foreach (var(offset, blockId) in obj.Parts) { var x = (int)(offset.X + anchor.X); var y = (int)(offset.Y + anchor.Y); var z = (int)(offset.Z + anchor.Z); var chunkPositionOffset = (x / BaseChunk.Width, z / BaseChunk.Length); if (chunkPositionOffset == (0, 0)) { chunk.Map[x, y, z] = blockId; } } return(noExcess); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (mshView.SelectedNode == null) { return; } removeMaterialMenuItem.Enabled = false; removeModelMenuItem.Enabled = false; removeSegmentMenuItem.Enabled = false; switch (mshView.SelectedNode.Name) { case "SINF": selectedChunk = msh.SelectionInformation; break; case "FRAM": selectedChunk = msh.SelectionInformation.FrameInformation; break; case "BBOX": selectedChunk = msh.SelectionInformation.BoundingBox; break; case "CAMR": selectedChunk = msh.Camera; break; /*case "MATL": * selectedChunk = msh.Materials; * break; * case "MODL": * selectedChunk = msh.Models; * break;*/ default: selectedChunk = null; break; } //Material Selection Match match = Regex.Match(mshView.SelectedNode.Name, "MAT[0-9]+"); if (match.Success) { int index = Convert.ToInt32(match.Value.Replace("MAT", "")); selectedChunk = msh.Materials[index]; removeMaterialMenuItem.Enabled = true; } //Model Selection match = Regex.Match(mshView.SelectedNode.Name, "MOD[0-9]+"); if (match.Success) { int index = Convert.ToInt32(match.Value.Replace("MOD", "")); selectedChunk = msh.Models[index]; removeModelMenuItem.Enabled = true; } //Geometry Bounding Box Selection match = Regex.Match(mshView.SelectedNode.Name, "GBOX[0-9]+"); if (match.Success) { int index = Convert.ToInt32(match.Value.Replace("GBOX", "")); selectedChunk = msh.Models[index].Geometry.BoundingBox; } //Segment Selection match = Regex.Match(mshView.SelectedNode.Name, "SEG[0-9]+.[0-9]+"); if (match.Success) { string txt = match.Value.Replace("SEG", ""); int[] indices = Array.ConvertAll(txt.Split(new char[] { '.' }), int.Parse); selectedChunk = msh.Models[indices[0]].Geometry.Segments[indices[1]]; removeSegmentMenuItem.Enabled = true; } inspector.SelectedObject = selectedChunk; glDraw.SegmentsToRender = GetSegmentsFromSelection(); }
public void AddChunk(BaseChunk chunk) { if (!_chunkList.ContainsKey(chunk.GetType())) { _chunkList.Add(chunk.GetType(), new List<BaseChunk>()); } _chunkList[chunk.GetType()].Add(chunk); }