Beispiel #1
0
 public void Load(Stream stream)
 {
     using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
     {
         var magic = io.ReadCString(4);
         if (magic != "NBHm")
         {
             throw new Exception("Not a valid neighbourhood model!");
         }
         Version = io.ReadInt32();
         var houseC = io.ReadInt32();
         for (int i = 0; i < houseC; i++)
         {
             var house = new NBHmHouse()
             {
                 HouseNum = io.ReadInt16(),
                 Position = new Vector3()
                 {
                     X = io.ReadFloat(),
                     Y = io.ReadFloat(),
                     Z = io.ReadFloat()
                 }
             };
             Houses[house.HouseNum] = house;
         }
         io.ReadByte(); //has model. right now there is no model.
     }
 }
Beispiel #2
0
        public NBHm(OBJ obj)
        {
            foreach (var group in obj.FacesByObjgroup)
            {
                if (group.Key[0] == 'p')
                {
                    //lot group
                    var split = group.Key.Split('_');
                    if (split.Length > 1 && split[1] == "floor")
                    {
                        Vector2 minLocation = new Vector2(999999999, 999999999);
                        var     candidates  = new List <Vector3>();
                        foreach (var inds in group.Value)
                        {
                            var vtx = obj.Vertices[inds[0] - 1];
                            if (vtx.X < minLocation.X)
                            {
                                minLocation.X = vtx.X; candidates.Clear();
                            }
                            if (vtx.Z < minLocation.Y)
                            {
                                minLocation.Y = vtx.Z; candidates.Clear();
                            }
                            if ((int)vtx.Z == (int)minLocation.Y && (int)vtx.X == (int)minLocation.X)
                            {
                                candidates.Add(vtx);
                            }
                        }

                        var minLocation3 = new Vector3(minLocation.X, candidates.Min(x => x.Y), minLocation.Y);

                        //add this house
                        var house = new NBHmHouse()
                        {
                            HouseNum = short.Parse(split[0].Substring(1)),
                            Position = minLocation3
                        };
                        Houses[house.HouseNum] = house;
                    }
                }
            }
        }