public void Add(string name, VoxMaterial mat) { mat.ID = index; mMaterials.Add(mat.ID, mat); mName2Byte.Add(name, mat.ID); index++; }
internal void FromNbt(NbtCompound c) { foreach (NbtTag tag in c.Tags) { VoxMaterial m = new VoxMaterial(); m.Name = tag.Name; foreach (NbtTag t in (tag as NbtCompound).Tags) { switch (t.Name) { case "ID": m.ID = (t as NbtByte).Value; break; case "Type": m.Type = (MaterialType)(t as NbtInt).Value; break; case "Density": m.Density = (t as NbtFloat).Value; break; case "Deposit": m.Deposit = (DepositType)(t as NbtInt).Value; break; case "Texture": m.Texture = new UUID((t as NbtString).Value); break; case "Flags": m.Flags = (MatFlags)(t as NbtByte).Value; break; } } mMaterials.Add(m.ID, m); mName2Byte.Add(m.Name, m.ID); if (m.ID > index) { index = m.ID; index++; } } }
internal void Deserialize(XmlTextReader reader) { bool keepreading = true; while (keepreading) { reader.Read(); if (reader.Name.Equals("material") && reader.NodeType.Equals(XmlNodeType.Element)) { VoxMaterial mat = new VoxMaterial(); mat.ID = (byte)reader.ReadContentAsInt(); mat.Name = reader.ReadContentAsString(); mat.Flags = (MatFlags)Enum.Parse(typeof(MatFlags), reader.ReadContentAsString()); mat.Density = reader.ReadContentAsFloat(); mat.Deposit = (DepositType)Enum.Parse(typeof(DepositType), reader.ReadContentAsString()); mat.Texture = UUID.Parse(reader.ReadContentAsString()); mat.Type = (MaterialType)Enum.Parse(typeof(MaterialType), reader.ReadContentAsString()); if (mat.ID > index) { index = mat.ID; index++; } mMaterials.Add(mat.ID, mat); mName2Byte.Add(mat.Name, mat.ID); } } }
internal void Deserialize(ref XmlElement doc) { int version = 0; if (!int.TryParse(doc.GetAttribute("version"), out version)) { return; } if (version > 1) { return; } foreach (XmlElement material in doc) { VoxMaterial mat = new VoxMaterial(); mat.ID = byte.Parse(material.GetAttribute("id")); mat.Name = material.GetAttribute("name"); mat.Flags = (MatFlags)Enum.Parse(typeof(MatFlags), material.GetAttribute("flags")); mat.Density = float.Parse(material.GetAttribute("density")); mat.Deposit = (DepositType)Enum.Parse(typeof(DepositType), material.GetAttribute("deposit")); mat.Texture = UUID.Parse(material.GetAttribute("texture")); mat.Type = (MaterialType)Enum.Parse(typeof(MaterialType), material.GetAttribute("type")); if (mat.ID > index) { index = mat.ID; index++; } mMaterials.Add(mat.ID, mat); mName2Byte.Add(mat.Name, mat.ID); } }
internal void Serialize(ref XmlWriter w) { w.WriteStartElement("materials"); w.WriteAttributeString("version", "1"); foreach (KeyValuePair <byte, VoxMaterial> kvp in mMaterials) { w.WriteStartElement("material"); VoxMaterial mat = kvp.Value; w.WriteAttributeString("id", mat.ID.ToString()); w.WriteAttributeString("name", mat.Name.ToString()); w.WriteAttributeString("flags", mat.Flags.ToString()); w.WriteAttributeString("density", mat.Density.ToString()); w.WriteAttributeString("deposit", mat.Deposit.ToString()); w.WriteAttributeString("texture", mat.Texture.ToString()); w.WriteAttributeString("type", mat.Type.ToString()); w.WriteEndElement(); } w.WriteEndElement(); }
internal void Deserialize(ref XmlElement doc) { int version = 0; if (!int.TryParse(doc.GetAttribute("version"), out version)) return; if (version > 1) return; foreach (XmlElement material in doc) { VoxMaterial mat = new VoxMaterial(); mat.ID = byte.Parse(material.GetAttribute("id")); mat.Name = material.GetAttribute("name"); mat.Flags = (MatFlags)Enum.Parse(typeof(MatFlags), material.GetAttribute("flags")); mat.Density = float.Parse(material.GetAttribute("density")); mat.Deposit = (DepositType)Enum.Parse(typeof(DepositType), material.GetAttribute("deposit")); mat.Texture = UUID.Parse(material.GetAttribute("texture")); mat.Type = (MaterialType)Enum.Parse(typeof(MaterialType), material.GetAttribute("type")); if (mat.ID > index) { index = mat.ID; index++; } mMaterials.Add(mat.ID, mat); mName2Byte.Add(mat.Name, mat.ID); } }
string HandleSetMatTableReq(string request, string path, string param, OSHttpRequest req, OSHttpResponse res) { OSDMap input = (OSDMap)OSDParser.DeserializeLLSDXml(request); VoxMaterial mat = new VoxMaterial(); mat.Name = input["name"].AsString(); mat.Deposit = (DepositType)input["deposit"].AsInteger(); mat.Density = (float)input["density"].AsReal(); mat.Flags = (MatFlags)input["flags"].AsBinary()[0]; mat.Texture = input["texture"].AsUUID(); mat.Type = (MaterialType)input["type"].AsBinary()[0]; if(input["id"].AsBinary()[0]==0x00) // 0x00=AIR_VOXEL, so we cannot set it. (m_scene.Voxels as VoxelChannel).AddMaterial(mat); else { byte id = input["id"].AsBinary()[0]; (m_scene.Voxels as VoxelChannel).mMaterials[id]=mat; } return "OK"; }
public VoxelChannel(uint x,uint y,uint z) { Voxels = new byte[x*y*z]; XScale=(int)x; YScale=(int)y; ZScale=(int)z; VoxMaterial m = new VoxMaterial(); m.Flags=MatFlags.Solid; AddMaterial(m); FillVoxels(new Vector3(0, 0, 0), new Vector3((int)x, (int)y, (int)z), AIR_VOXEL); TerrainGenerators.Add("default", new HillGenerator()); }
public void AddMaterial(VoxMaterial butts) { mMaterials.Add(butts.Name,butts); }