예제 #1
0
파일: Materials.cs 프로젝트: N3X15/VoxelSim
 public void Add(string name, VoxMaterial mat)
 {
     mat.ID = index;
     mMaterials.Add(mat.ID, mat);
     mName2Byte.Add(name, mat.ID);
     index++;
 }
예제 #2
0
 public void Add(string name, VoxMaterial mat)
 {
     mat.ID = index;
     mMaterials.Add(mat.ID, mat);
     mName2Byte.Add(name, mat.ID);
     index++;
 }
예제 #3
0
        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++;
                }
            }
        }
예제 #4
0
        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);
                }
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
 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();
 }
예제 #7
0
파일: Materials.cs 프로젝트: N3X15/VoxelSim
        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++;
                }

            }
        }
예제 #8
0
파일: Materials.cs 프로젝트: N3X15/VoxelSim
        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);
                }
            }
        }
예제 #9
0
파일: Materials.cs 프로젝트: N3X15/VoxelSim
        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);
            }
        }
예제 #10
0
		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";
		}
예제 #11
0
		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());
		}
예제 #12
0
		public void AddMaterial(VoxMaterial butts)
		{
			mMaterials.Add(butts.Name,butts);
		}