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 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 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); }