/* * public class SamplingRectEnclosesComparer : IComparer<MatAndTransformToMerged> * { * public int Compare(MatAndTransformToMerged x, MatAndTransformToMerged y) * { * if (x.samplingRectMatAndUVTiling.Equals(y.samplingRectMatAndUVTiling)) * { * return 0; * } * else if (x.samplingRectMatAndUVTiling.Encloses(y.samplingRectMatAndUVTiling)) * { * return -1; * } * else * { * return 1; * } * } * } */ public static Rect BuildTransformMeshUV2AtlasRectB(bool considerMeshUVs, Rect _atlasRect, //this is uvRect in combined Atlas Rect _obUVRect, Rect _sourceMaterialTiling, Rect _encapsulatingRect) { DRect atlasRect = new DRect(_atlasRect); DRect obUVRect; if (considerMeshUVs) { obUVRect = new DRect(_obUVRect); //this is the uvRect in src mesh } else { obUVRect = new DRect(0.0, 0.0, 1.0, 1.0); } DRect sourceMaterialTiling = new DRect(_sourceMaterialTiling); DRect encapsulatingRectMatAndUVTiling = new DRect(_encapsulatingRect); DRect encapsulatingRectMatAndUVTilingInverse = MB3_UVTransformUtility.InverseTransform(ref encapsulatingRectMatAndUVTiling); DRect toNormalizedUVs = MB3_UVTransformUtility.InverseTransform(ref obUVRect); DRect meshFullSamplingRect = MB3_UVTransformUtility.CombineTransforms(ref obUVRect, ref sourceMaterialTiling); DRect shiftToFitInEncapsulating = MB3_UVTransformUtility.GetShiftTransformToFitBinA(ref encapsulatingRectMatAndUVTiling, ref meshFullSamplingRect); meshFullSamplingRect = MB3_UVTransformUtility.CombineTransforms(ref meshFullSamplingRect, ref shiftToFitInEncapsulating); //transform between full sample rect and encapsulating rect DRect relativeTrans = MB3_UVTransformUtility.CombineTransforms(ref meshFullSamplingRect, ref encapsulatingRectMatAndUVTilingInverse); // [transform] = [toNormalizedUVs][relativeTrans][uvSubRectInAtlas] DRect trans = MB3_UVTransformUtility.CombineTransforms(ref toNormalizedUVs, ref relativeTrans); trans = MB3_UVTransformUtility.CombineTransforms(ref trans, ref atlasRect); Rect rr = trans.GetRect(); return(rr); /* * Debug.Log("toNormalizedUVs " + toNormalizedUVs); * Debug.Log("relativeTrans " + relativeTrans); * Debug.Log("atlasRect " + atlasRect); * Debug.Log("trans " + trans); * Debug.Log("srcMatTiling " + sourceMaterialTiling); * Debug.Log("obUVRect" + obUVRect); * Debug.Log("samplingRectMatAndUVTiling" + encapsulatingRectMatAndUVTiling); */ }
public void DrawRectsToMergeGizmos(Color encC, Color innerC) { DRect r = ts[0].GetEncapsulatingSamplingRect(); r.Expand(.05f); Gizmos.color = encC; Gizmos.DrawWireCube(r.center.GetVector2(), r.size); for (int i = 0; i < matsAndGOs.mats.Count; i++) { DRect rr = matsAndGOs.mats[i].samplingRectMatAndUVTiling; DRect trans = MB3_UVTransformUtility.GetShiftTransformToFitBinA(ref r, ref rr); Vector2 xy = MB3_UVTransformUtility.TransformPoint(ref trans, rr.min); rr.x = xy.x; rr.y = xy.y; //Debug.Log("r " + r + " rr" + rr); Gizmos.color = innerC; Gizmos.DrawWireCube(rr.center.GetVector2(), rr.size); } }