public static Rect BuildTransformMeshUV2AtlasRect( bool considerMeshUVs, Rect _atlasRect, 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); //封装材质, UV 参数 DRect encapsulatingRectMatAndUVTiling = new DRect(_encapsulatingRect); DRect encapsulatingRectMatAndUVTilingInverse = UVRectUtility.InverseTransform(ref encapsulatingRectMatAndUVTiling); DRect toNormalizedUVs = UVRectUtility.InverseTransform(ref obUVRect); DRect meshFullSamplingRect = UVRectUtility.CombineTransforms(ref obUVRect, ref sourceMaterialTiling); DRect shiftToFitInEncapsulating = UVRectUtility.GetShiftTransformToFitBinA(ref encapsulatingRectMatAndUVTiling, ref meshFullSamplingRect); meshFullSamplingRect = UVRectUtility.CombineTransforms(ref meshFullSamplingRect, ref shiftToFitInEncapsulating); //transform between full sample rect and encapsulating rect DRect relativeTrans = UVRectUtility.CombineTransforms(ref meshFullSamplingRect, ref encapsulatingRectMatAndUVTilingInverse); DRect trans = UVRectUtility.CombineTransforms(ref toNormalizedUVs, ref relativeTrans); trans = UVRectUtility.CombineTransforms(ref trans, ref atlasRect); Rect rr = trans.GetRect(); return(rr); }
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 = UVRectUtility.GetShiftTransformToFitBinA(ref r, ref rr); Vector2 xy = UVRectUtility.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); } }