public static Vector3 GetCenter(BoctModel model) { if (model.Regions == null) { return(Vector3.zero); } if (model.Regions.Count == 0) { return(Vector3.zero); } var sum = Vector3.zero; int count = 0; foreach (var r in model.Regions) { var solidList = BoctTools.GetSolidBoctArray(r.Value.Head); for (int i = 0; i < solidList.Length; i++) { var boct = solidList[i]; sum += BoctAddressTools.GetCoordinate(boct.Address); count++; } } return(sum / count); }
public void AddRegion(RegionData data) { var headAddress = BoctAddressTools.FromString(data.HeadAddress); var head = Find(headAddress, true); if (head == null) { throw new BoctException("Could not found the boct."); } if (head.RegionId != BoctRegion.EmptyId) { throw new BoctException("RegionId is not empty: " + head.RegionId); } head.ClearChildren(); if (data.HeadMaterialId == BoctMaterial.EmptyId) { for (int i = 0; i < data.AddressList.Count; i++) { var byteAddress = BoctAddressTools.FromString(data.HeadAddress + data.AddressList[i]); BoctTools.InsertBoct(byteAddress, _head, data.MaterialIdList[i]); } } else { head.MaterialId = data.HeadMaterialId; } head.ExtensionId = data.HeadExtensionId; AddRegion(head, data.GUID, data.LUID); }
/// <summary> /// Get the flood boct list. /// </summary> public static List <Boct> GetFloodBoctList(Boct target, Boct head) { // Debug.Log("[GetFloodBoctList]"); var sameDepthBoctList = new List <Boct>(); BoctTools.FindSameDepthBoct(target.Depth, head, sameDepthBoctList); // Debug.Log("SameDepthBoct: " + sameDepthBoctList.Count); var sameMaterialBoctList = sameDepthBoctList.Where(b => b.MaterialId == target.MaterialId).ToList <Boct>(); // Debug.Log("SameMaterialBoct: " + sameMaterialBoctList.Count); // Debug.Log("Dictionary"); var dic = BoctTools.ToDictionary(sameMaterialBoctList); //foreach (var kv in dic) //{ // Debug.Log(kv.Key + " " + kv.Value.ToString()); //} // Remove target. dic.Remove(target.AddressString); var output = new List <Boct>(); output.Add(target); var searchList = new List <Boct>(); searchList.Add(target); while (searchList.Count > 0) { var b = searchList[0]; searchList.RemoveAt(0); for (int i = 0; i < 6; i++) { var address = BoctAddressTools.GetAdjoiningBoctAddress(b.Address, i); if (address == null) { continue; } var addressString = BoctAddressTools.ToString(address); // Debug.Log("Address" + i + ": " + addressString); if (dic.ContainsKey(addressString)) { output.Add(dic[addressString]); searchList.Add(dic[addressString]); dic.Remove(addressString); } } } return(output); }
public static Boct GetAdjoiningBoct(Boct b, int face, BoctModel model) { var adjoiningAddress = BoctAddressTools.GetAdjoiningBoctAddress(b.Address, face); if (adjoiningAddress == null) { return(null); } else { return(model.Find(adjoiningAddress)); } }
public override string ToString() { return("[B] " + BoctAddressTools.ToString(Address, true)); }
public static Bounds GetBounds(BoctModel model, bool scanBoct = true) { var bounds = new Bounds(); if (model.Regions == null) { return(bounds); } if (model.Regions.Count == 0) { return(bounds); } var xRange = new Vector2(float.MaxValue, float.MinValue); var yRange = new Vector2(float.MaxValue, float.MinValue); var zRange = new Vector2(float.MaxValue, float.MinValue); if (scanBoct) { foreach (var r in model.Regions) { var solidList = BoctTools.GetSolidBoctArray(r.Value.Head); for (int j = 0; j < solidList.Length; j++) { var boct = solidList[j]; var boctBounds = BoctAddressTools.GetBounds(boct.Address); //Debug.Log("Bound: " + boctBounds.ToString("F4")); if (xRange.x > boctBounds.x - boctBounds.w) { xRange.x = boctBounds.x - boctBounds.w; } if (xRange.y < boctBounds.x + boctBounds.w) { xRange.y = boctBounds.x + boctBounds.w; } if (yRange.x > boctBounds.y - boctBounds.w) { yRange.x = boctBounds.y - boctBounds.w; } if (yRange.y < boctBounds.y + boctBounds.w) { yRange.y = boctBounds.y + boctBounds.w; } if (zRange.x > boctBounds.z - boctBounds.w) { zRange.x = boctBounds.z - boctBounds.w; } if (zRange.y < boctBounds.z + boctBounds.w) { zRange.y = boctBounds.z + boctBounds.w; } } } } else { foreach (var r in model.Regions) { var boct = r.Value.Head; var boctBounds = BoctAddressTools.GetBounds(boct.Address); //Debug.Log("Bound: " + boctBounds.ToString("F4")); if (xRange.x > boctBounds.x - boctBounds.w) { xRange.x = boctBounds.x - boctBounds.w; } if (xRange.y < boctBounds.x + boctBounds.w) { xRange.y = boctBounds.x + boctBounds.w; } if (yRange.x > boctBounds.y - boctBounds.w) { yRange.x = boctBounds.y - boctBounds.w; } if (yRange.y < boctBounds.y + boctBounds.w) { yRange.y = boctBounds.y + boctBounds.w; } if (zRange.x > boctBounds.z - boctBounds.w) { zRange.x = boctBounds.z - boctBounds.w; } if (zRange.y < boctBounds.z + boctBounds.w) { zRange.y = boctBounds.z + boctBounds.w; } } } var center = new Vector3( (xRange.x + xRange.y) * 0.5f, (yRange.x + yRange.y) * 0.5f, (zRange.x + zRange.y) * 0.5f ); var extents = new Vector3( (xRange.y - xRange.x) * 0.5f, (yRange.y - yRange.x) * 0.5f, (zRange.y - zRange.x) * 0.5f ); bounds.center = center; bounds.extents = extents; return(bounds); }
public BoctData(Boct b) { address = BoctAddressTools.ToString(b.Address); mid = b.MaterialId; }