public void CalcMatAndUVSamplingRects() { if (allTexturesUseSameMatTiling) { DRect matTiling = new DRect(0f, 0f, 1f, 1f); for (int propIdx = 0; propIdx < ts.Length; propIdx++) { if (!ts[propIdx].isNull) { matTiling = ts[propIdx].matTilingRect; } } for (int matIdx = 0; matIdx < matsAndGOs.mats.Count; matIdx++) { matsAndGOs.mats[matIdx].materialTiling = matTiling; matsAndGOs.mats[matIdx].samplingRectMatAndUVTiling = MB3_UVTransformUtility.CombineTransforms(ref matsAndGOs.mats[matIdx].obUVRectIfTilingSame, ref matTiling); //MB3_TextureCombiner.GetSourceSamplingRect(ts[matIdx], obUVoffset, obUVscale); } } else { // material tiling is different for each texture property // in this case we set the material tiling to 1 here for (int matIdx = 0; matIdx < matsAndGOs.mats.Count; matIdx++) { DRect matTiling = new DRect(0f, 0f, 1f, 1f); matsAndGOs.mats[matIdx].materialTiling = matTiling; matsAndGOs.mats[matIdx].samplingRectMatAndUVTiling = MB3_UVTransformUtility.CombineTransforms(ref matsAndGOs.mats[matIdx].obUVRectIfTilingSame, ref matTiling); //MB3_TextureCombiner.GetSourceSamplingRect(ts[matIdx], obUVoffset, obUVscale); } } }
/* * 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 AssignInitialValuesForMaterialTilingAndSamplingRectMatAndUVTiling(bool allTexturesUseSameMatTiling, DRect matTiling) { if (allTexturesUseSameMatTiling) { materialTiling = matTiling; } else { materialTiling = new DRect(0f, 0f, 1f, 1f); } DRect tmpMatTiling = materialTiling; DRect obUVrect = obUVRectIfTilingSame; samplingRectMatAndUVTiling = MB3_UVTransformUtility.CombineTransforms(ref obUVrect, ref tmpMatTiling); }
//assumes all materials use the same obUVrects. internal void CalcInitialFullSamplingRects(bool fixOutOfBoundsUVs) { DRect validFullSamplingRect = new Core.DRect(0, 0, 1, 1); if (fixOutOfBoundsUVs) { validFullSamplingRect = obUVrect; } for (int propIdx = 0; propIdx < ts.Length; propIdx++) { if (!ts[propIdx].isNull) { DRect matTiling = ts[propIdx].matTilingRect; DRect ruv; if (fixOutOfBoundsUVs) { ruv = obUVrect; } else { ruv = new DRect(0.0, 0.0, 1.0, 1.0); } ts[propIdx].SetEncapsulatingSamplingRect(this, MB3_UVTransformUtility.CombineTransforms(ref ruv, ref matTiling)); validFullSamplingRect = ts[propIdx].GetEncapsulatingSamplingRect(); } } //if some of the textures were null make them match the sampling of one of the other textures for (int propIdx = 0; propIdx < ts.Length; propIdx++) { if (ts[propIdx].isNull) { ts[propIdx].SetEncapsulatingSamplingRect(this, validFullSamplingRect); } } }