MB2_TextureBakeResults.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. using UnityEngine;
  2. using System;
  3. using System.Text;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using DigitalOpus.MB.Core;
  7. using UnityEngine.Serialization;
  8. /// <summary>
  9. /// Used internally during the material baking process
  10. /// </summary>
  11. [Serializable]
  12. public class MB_AtlasesAndRects{
  13. /// <summary>
  14. /// One atlas per texture property.
  15. /// </summary>
  16. public Texture2D[] atlases;
  17. [NonSerialized]
  18. public List<MB_MaterialAndUVRect> mat2rect_map;
  19. public string[] texPropertyNames;
  20. }
  21. public class MB_TextureArrayResultMaterial
  22. {
  23. public MB_AtlasesAndRects[] slices;
  24. }
  25. [System.Serializable]
  26. public class MB_MultiMaterial{
  27. public Material combinedMaterial;
  28. public bool considerMeshUVs;
  29. public List<Material> sourceMaterials = new List<Material>();
  30. }
  31. [System.Serializable]
  32. public class MB_TexArraySliceRendererMatPair
  33. {
  34. public Material sourceMaterial;
  35. public GameObject renderer;
  36. }
  37. [System.Serializable]
  38. public class MB_TexArraySlice
  39. {
  40. public bool considerMeshUVs;
  41. public List<MB_TexArraySliceRendererMatPair> sourceMaterials = new List<MB_TexArraySliceRendererMatPair>();
  42. public bool ContainsMaterial(Material mat)
  43. {
  44. for (int i = 0; i < sourceMaterials.Count; i++)
  45. {
  46. if (sourceMaterials[i].sourceMaterial == mat) return true;
  47. }
  48. return false;
  49. }
  50. public HashSet<Material> GetDistinctMaterials()
  51. {
  52. HashSet<Material> distinctMats = new HashSet<Material>();
  53. if (sourceMaterials == null) return distinctMats;
  54. for (int i = 0; i < sourceMaterials.Count; i++)
  55. {
  56. distinctMats.Add(sourceMaterials[i].sourceMaterial);
  57. }
  58. return distinctMats;
  59. }
  60. public bool ContainsMaterialAndMesh(Material mat, Mesh mesh)
  61. {
  62. for (int i = 0; i < sourceMaterials.Count; i++)
  63. {
  64. if (sourceMaterials[i].sourceMaterial == mat &&
  65. MB_Utility.GetMesh(sourceMaterials[i].renderer) == mesh) return true;
  66. }
  67. return false;
  68. }
  69. public List<Material> GetAllUsedMaterials(List<Material> usedMats)
  70. {
  71. usedMats.Clear();
  72. for (int i = 0; i < sourceMaterials.Count; i++)
  73. {
  74. usedMats.Add(sourceMaterials[i].sourceMaterial);
  75. }
  76. return usedMats;
  77. }
  78. public List<GameObject> GetAllUsedRenderers(List<GameObject> allObjsFromTextureBaker)
  79. {
  80. if (considerMeshUVs)
  81. {
  82. List<GameObject> usedRendererGOs = new List<GameObject>();
  83. for (int i = 0; i < sourceMaterials.Count; i++)
  84. {
  85. usedRendererGOs.Add(sourceMaterials[i].renderer);
  86. }
  87. return usedRendererGOs;
  88. }
  89. else
  90. {
  91. return allObjsFromTextureBaker;
  92. }
  93. }
  94. }
  95. [System.Serializable]
  96. public class MB_TextureArrayReference
  97. {
  98. public string texFromatSetName;
  99. public Texture2DArray texArray;
  100. public MB_TextureArrayReference(string formatSetName, Texture2DArray ta)
  101. {
  102. texFromatSetName = formatSetName;
  103. texArray = ta;
  104. }
  105. }
  106. [System.Serializable]
  107. public class MB_TexArrayForProperty
  108. {
  109. public string texPropertyName;
  110. public MB_TextureArrayReference[] formats = new MB_TextureArrayReference[0];
  111. public MB_TexArrayForProperty(string name, MB_TextureArrayReference[] texRefs)
  112. {
  113. texPropertyName = name;
  114. formats = texRefs;
  115. }
  116. }
  117. [System.Serializable]
  118. public class MB_MultiMaterialTexArray
  119. {
  120. public Material combinedMaterial;
  121. public List<MB_TexArraySlice> slices = new List<MB_TexArraySlice>();
  122. public List<MB_TexArrayForProperty> textureProperties = new List<MB_TexArrayForProperty>();
  123. }
  124. [System.Serializable]
  125. public class MB_TextureArrayFormat
  126. {
  127. public string propertyName;
  128. public TextureFormat format;
  129. }
  130. [System.Serializable]
  131. public class MB_TextureArrayFormatSet
  132. {
  133. public string name;
  134. public TextureFormat defaultFormat;
  135. public MB_TextureArrayFormat[] formatOverrides;
  136. public bool ValidateTextureImporterFormatsExistsForTextureFormats(MB2_EditorMethodsInterface editorMethods, int idx)
  137. {
  138. if (editorMethods == null) return true;
  139. if (!editorMethods.TextureImporterFormatExistsForTextureFormat(defaultFormat))
  140. {
  141. Debug.LogError("TextureImporter format does not exist for Texture Array Output Formats: " + idx + " Defaut Format " + defaultFormat);
  142. return false;
  143. }
  144. for (int i = 0; i < formatOverrides.Length; i++)
  145. {
  146. if (!editorMethods.TextureImporterFormatExistsForTextureFormat(formatOverrides[i].format))
  147. {
  148. Debug.LogError("TextureImporter format does not exist for Texture Array Output Formats: " + idx + " Format Overrides: " + i + " (" + formatOverrides[i].format + ")");
  149. return false;
  150. }
  151. }
  152. return true;
  153. }
  154. public TextureFormat GetFormatForProperty(string propName)
  155. {
  156. for (int i = 0; i < formatOverrides.Length; i++)
  157. {
  158. if (formatOverrides.Equals(formatOverrides[i].propertyName))
  159. {
  160. return formatOverrides[i].format;
  161. }
  162. }
  163. return defaultFormat;
  164. }
  165. }
  166. [System.Serializable]
  167. public class MB_MaterialAndUVRect
  168. {
  169. /// <summary>
  170. /// The source material that was baked into the atlas.
  171. /// </summary>
  172. public Material material;
  173. /// <summary>
  174. /// The rectangle in the atlas where the texture (including all tiling) was copied to.
  175. /// </summary>
  176. public Rect atlasRect;
  177. /// <summary>
  178. /// For debugging. The name of the first srcObj that uses this MaterialAndUVRect.
  179. /// </summary>
  180. public string srcObjName;
  181. public int textureArraySliceIdx = -1;
  182. public bool allPropsUseSameTiling = true;
  183. /// <summary>
  184. /// Only valid if allPropsUseSameTiling = true. Else should be 0,0,0,0
  185. /// The material tiling on the source material
  186. /// </summary>
  187. [FormerlySerializedAs("sourceMaterialTiling")]
  188. public Rect allPropsUseSameTiling_sourceMaterialTiling;
  189. /// <summary>
  190. /// Only valid if allPropsUseSameTiling = true. Else should be 0,0,0,0
  191. /// The encapsulating sampling rect that was used to sample for the atlas. Note that the case
  192. /// of dont-considerMeshUVs is the same as do-considerMeshUVs where the uv rect is 0,0,1,1
  193. /// </summary>
  194. [FormerlySerializedAs("samplingEncapsulatinRect")]
  195. public Rect allPropsUseSameTiling_samplingEncapsulatinRect;
  196. /// <summary>
  197. /// Only valid if allPropsUseSameTiling = false.
  198. /// The UVrect of the source mesh that was baked. We are using a trick here.
  199. /// Instead of storing the material tiling for each
  200. /// texture property here, we instead bake all those tilings into the atlases and here we pretend
  201. /// that all those tilings were 0,0,1,1. Then all we need is to store is the
  202. /// srcUVsamplingRect
  203. /// </summary>
  204. public Rect propsUseDifferntTiling_srcUVsamplingRect;
  205. [NonSerialized]
  206. public List<GameObject> objectsThatUse;
  207. /// <summary>
  208. /// The tilling type for this rectangle in the atlas.
  209. /// </summary>
  210. public MB_TextureTilingTreatment tilingTreatment = MB_TextureTilingTreatment.unknown;
  211. /// <param name="mat">The Material</param>
  212. /// <param name="destRect">The rect in the atlas this material maps to</param>
  213. /// <param name="allPropsUseSameTiling">If true then use sourceMaterialTiling and samplingEncapsulatingRect.
  214. /// if false then use srcUVsamplingRect. None used values should be 0,0,0,0.</param>
  215. /// <param name="sourceMaterialTiling">allPropsUseSameTiling_sourceMaterialTiling</param>
  216. /// <param name="samplingEncapsulatingRect">allPropsUseSameTiling_samplingEncapsulatinRect</param>
  217. /// <param name="srcUVsamplingRect">propsUseDifferntTiling_srcUVsamplingRect</param>
  218. public MB_MaterialAndUVRect(Material mat,
  219. Rect destRect,
  220. bool allPropsUseSameTiling,
  221. Rect sourceMaterialTiling,
  222. Rect samplingEncapsulatingRect,
  223. Rect srcUVsamplingRect,
  224. MB_TextureTilingTreatment treatment,
  225. string objName)
  226. {
  227. if (allPropsUseSameTiling)
  228. {
  229. Debug.Assert(srcUVsamplingRect == new Rect(0, 0, 0, 0));
  230. }
  231. if (!allPropsUseSameTiling) {
  232. Debug.Assert(samplingEncapsulatingRect == new Rect(0, 0, 0, 0));
  233. Debug.Assert(sourceMaterialTiling == new Rect(0, 0, 0, 0));
  234. }
  235. material = mat;
  236. atlasRect = destRect;
  237. tilingTreatment = treatment;
  238. this.allPropsUseSameTiling = allPropsUseSameTiling;
  239. allPropsUseSameTiling_sourceMaterialTiling = sourceMaterialTiling;
  240. allPropsUseSameTiling_samplingEncapsulatinRect = samplingEncapsulatingRect;
  241. propsUseDifferntTiling_srcUVsamplingRect = srcUVsamplingRect;
  242. srcObjName = objName;
  243. }
  244. public override int GetHashCode()
  245. {
  246. return material.GetInstanceID() ^ allPropsUseSameTiling_samplingEncapsulatinRect.GetHashCode() ^ propsUseDifferntTiling_srcUVsamplingRect.GetHashCode();
  247. }
  248. public override bool Equals(object obj)
  249. {
  250. if (!(obj is MB_MaterialAndUVRect)) return false;
  251. MB_MaterialAndUVRect b = (MB_MaterialAndUVRect)obj;
  252. return material == b.material &&
  253. allPropsUseSameTiling_samplingEncapsulatinRect == b.allPropsUseSameTiling_samplingEncapsulatinRect &&
  254. allPropsUseSameTiling_sourceMaterialTiling == b.allPropsUseSameTiling_sourceMaterialTiling &&
  255. allPropsUseSameTiling == b.allPropsUseSameTiling &&
  256. propsUseDifferntTiling_srcUVsamplingRect == b.propsUseDifferntTiling_srcUVsamplingRect;
  257. }
  258. public Rect GetEncapsulatingRect()
  259. {
  260. if (allPropsUseSameTiling)
  261. {
  262. return allPropsUseSameTiling_samplingEncapsulatinRect;
  263. }
  264. else
  265. {
  266. return propsUseDifferntTiling_srcUVsamplingRect;
  267. }
  268. }
  269. public Rect GetMaterialTilingRect()
  270. {
  271. if (allPropsUseSameTiling)
  272. {
  273. return allPropsUseSameTiling_sourceMaterialTiling;
  274. }
  275. else
  276. {
  277. return new Rect(0, 0, 1, 1);
  278. }
  279. }
  280. }
  281. /// <summary>
  282. /// This class stores the results from an MB2_TextureBaker when materials are combined into atlases. It stores
  283. /// a list of materials and the corresponding UV rectangles in the atlases. It also stores the configuration
  284. /// options that were used to generate the combined material.
  285. ///
  286. /// It can be saved as an asset in the project so that textures can be baked in one scene and used in another.
  287. /// </summary>
  288. public class MB2_TextureBakeResults : ScriptableObject {
  289. public enum ResultType
  290. {
  291. atlas,
  292. textureArray,
  293. }
  294. public static int VERSION { get { return 3252; } }
  295. public int version;
  296. public ResultType resultType = ResultType.atlas;
  297. /// <summary>
  298. /// Information about the atlas UV rects.
  299. /// IMPORTANT a source material can appear more than once in this list. If we are using considerUVs,
  300. /// then different parts of a source texture could be extracted to different atlas rects.
  301. /// </summary>
  302. public MB_MaterialAndUVRect[] materialsAndUVRects;
  303. /// <summary>
  304. /// This is like the combinedMeshRenderer.sharedMaterials. Some materials may be omitted if they have zero submesh triangles.
  305. /// There is one of these per MultiMaterial mapping.
  306. /// Lists source materials that were combined into each result material, and whether considerUVs was used.
  307. /// This is the result materials if building for atlases.
  308. /// </summary>
  309. public MB_MultiMaterial[] resultMaterials;
  310. /// <summary>
  311. /// This is like combinedMeshRenderer.sharedMaterials. Each result mat likely uses a different shader.
  312. /// There is one of these per MultiMaterialTexArray mapping.
  313. /// Each of these lists the slices and each slice has list of source mats that are in that slice.
  314. /// This is the result materials if building for texArrays.
  315. /// </summary>
  316. public MB_MultiMaterialTexArray[] resultMaterialsTexArray;
  317. public bool doMultiMaterial;
  318. public MB2_TextureBakeResults()
  319. {
  320. version = VERSION;
  321. }
  322. private void OnEnable()
  323. {
  324. // backward compatibility copy depricated fixOutOfBounds values to resultMaterials
  325. if (version < 3251)
  326. {
  327. for (int i = 0; i < materialsAndUVRects.Length; i++)
  328. {
  329. materialsAndUVRects[i].allPropsUseSameTiling = true;
  330. }
  331. }
  332. version = VERSION;
  333. }
  334. public int NumResultMaterials()
  335. {
  336. if (resultType == ResultType.atlas) return resultMaterials.Length;
  337. else return resultMaterialsTexArray.Length;
  338. }
  339. public Material GetCombinedMaterialForSubmesh(int idx)
  340. {
  341. if (resultType == ResultType.atlas)
  342. {
  343. return resultMaterials[idx].combinedMaterial;
  344. } else
  345. {
  346. return resultMaterialsTexArray[idx].combinedMaterial;
  347. }
  348. }
  349. public bool GetConsiderMeshUVs(int idxInSrcMats, Material srcMaterial)
  350. {
  351. if (resultType == ResultType.atlas)
  352. {
  353. return resultMaterials[idxInSrcMats].considerMeshUVs;
  354. }
  355. else
  356. {
  357. // TODO do this once and cache.
  358. List<MB_TexArraySlice> slices = resultMaterialsTexArray[idxInSrcMats].slices;
  359. for (int i = 0; i < slices.Count; i++)
  360. {
  361. if (slices[i].ContainsMaterial(srcMaterial)) return slices[i].considerMeshUVs;
  362. }
  363. Debug.LogError("There were no source materials for any slice in this result material.");
  364. return false;
  365. }
  366. }
  367. public List<Material> GetSourceMaterialsUsedByResultMaterial(int resultMatIdx)
  368. {
  369. if (resultType == ResultType.atlas)
  370. {
  371. return resultMaterials[resultMatIdx].sourceMaterials;
  372. } else
  373. {
  374. // TODO do this once and cache.
  375. HashSet<Material> output = new HashSet<Material>();
  376. List<MB_TexArraySlice> slices = resultMaterialsTexArray[resultMatIdx].slices;
  377. for (int i = 0; i < slices.Count; i++)
  378. {
  379. List<Material> usedMaterials = new List<Material>();
  380. slices[i].GetAllUsedMaterials(usedMaterials);
  381. for (int j = 0; j < usedMaterials.Count; j++)
  382. {
  383. output.Add(usedMaterials[j]);
  384. }
  385. }
  386. List<Material> outMats = new List<Material>(output);
  387. return outMats;
  388. }
  389. }
  390. /// <summary>
  391. /// Creates for materials on renderer.
  392. /// </summary>
  393. /// <returns>Generates an MB2_TextureBakeResult that can be used if all objects to be combined use the same material.
  394. /// Returns a MB2_TextureBakeResults that will map all materials used by renderer r to
  395. /// the rectangle 0,0..1,1 in the atlas.</returns>
  396. public static MB2_TextureBakeResults CreateForMaterialsOnRenderer(GameObject[] gos, List<Material> matsOnTargetRenderer)
  397. {
  398. HashSet<Material> fullMaterialList = new HashSet<Material>(matsOnTargetRenderer);
  399. for (int i = 0; i < gos.Length; i++)
  400. {
  401. if (gos[i] == null)
  402. {
  403. Debug.LogError(string.Format("Game object {0} in list of objects to add was null", i));
  404. return null;
  405. }
  406. Material[] oMats = MB_Utility.GetGOMaterials(gos[i]);
  407. if (oMats.Length == 0)
  408. {
  409. Debug.LogError(string.Format("Game object {0} in list of objects to add no renderer", i));
  410. return null;
  411. }
  412. for (int j = 0; j < oMats.Length; j++)
  413. {
  414. if (!fullMaterialList.Contains(oMats[j])) { fullMaterialList.Add(oMats[j]); }
  415. }
  416. }
  417. Material[] rms = new Material[fullMaterialList.Count];
  418. fullMaterialList.CopyTo(rms);
  419. MB2_TextureBakeResults tbr = (MB2_TextureBakeResults) ScriptableObject.CreateInstance( typeof(MB2_TextureBakeResults) );
  420. List<MB_MaterialAndUVRect> mss = new List<MB_MaterialAndUVRect>();
  421. for (int i = 0; i < rms.Length; i++)
  422. {
  423. if (rms[i] != null)
  424. {
  425. MB_MaterialAndUVRect matAndUVRect = new MB_MaterialAndUVRect(rms[i], new Rect(0f, 0f, 1f, 1f), true, new Rect(0f,0f,1f,1f), new Rect(0f,0f,1f,1f), new Rect(0,0,0,0), MB_TextureTilingTreatment.none, "");
  426. if (!mss.Contains(matAndUVRect))
  427. {
  428. mss.Add(matAndUVRect);
  429. }
  430. }
  431. }
  432. tbr.resultMaterials = new MB_MultiMaterial[mss.Count];
  433. for (int i = 0; i < mss.Count; i++){
  434. tbr.resultMaterials[i] = new MB_MultiMaterial();
  435. List<Material> sourceMats = new List<Material>();
  436. sourceMats.Add (mss[i].material);
  437. tbr.resultMaterials[i].sourceMaterials = sourceMats;
  438. tbr.resultMaterials[i].combinedMaterial = mss[i].material;
  439. tbr.resultMaterials[i].considerMeshUVs = false;
  440. }
  441. if (rms.Length == 1)
  442. {
  443. tbr.doMultiMaterial = false;
  444. } else
  445. {
  446. tbr.doMultiMaterial = true;
  447. }
  448. tbr.materialsAndUVRects = mss.ToArray();
  449. return tbr;
  450. }
  451. public bool DoAnyResultMatsUseConsiderMeshUVs()
  452. {
  453. if (resultType == ResultType.atlas)
  454. {
  455. if (resultMaterials == null) return false;
  456. for (int i = 0; i < resultMaterials.Length; i++)
  457. {
  458. if (resultMaterials[i].considerMeshUVs) return true;
  459. }
  460. return false;
  461. }
  462. else
  463. {
  464. if (resultMaterialsTexArray == null) return false;
  465. for (int i = 0; i < resultMaterialsTexArray.Length; i++)
  466. {
  467. MB_MultiMaterialTexArray resMat = resultMaterialsTexArray[i];
  468. for (int j = 0; j < resMat.slices.Count; j++)
  469. {
  470. if (resMat.slices[j].considerMeshUVs) return true;
  471. }
  472. }
  473. return false;
  474. }
  475. }
  476. public bool ContainsMaterial(Material m)
  477. {
  478. for (int i = 0; i < materialsAndUVRects.Length; i++)
  479. {
  480. if (materialsAndUVRects[i].material == m){
  481. return true;
  482. }
  483. }
  484. return false;
  485. }
  486. public string GetDescription(){
  487. StringBuilder sb = new StringBuilder();
  488. sb.Append("Shaders:\n");
  489. HashSet<Shader> shaders = new HashSet<Shader>();
  490. if (materialsAndUVRects != null){
  491. for (int i = 0; i < materialsAndUVRects.Length; i++){
  492. if (materialsAndUVRects[i].material != null)
  493. {
  494. shaders.Add(materialsAndUVRects[i].material.shader);
  495. }
  496. }
  497. }
  498. foreach(Shader m in shaders){
  499. sb.Append(" ").Append(m.name).AppendLine();
  500. }
  501. sb.Append("Materials:\n");
  502. if (materialsAndUVRects != null){
  503. for (int i = 0; i < materialsAndUVRects.Length; i++){
  504. if (materialsAndUVRects[i].material != null)
  505. {
  506. sb.Append(" ").Append(materialsAndUVRects[i].material.name).AppendLine();
  507. }
  508. }
  509. }
  510. return sb.ToString();
  511. }
  512. public void UpgradeToCurrentVersion(MB2_TextureBakeResults tbr)
  513. {
  514. if (tbr.version < 3252)
  515. {
  516. for (int i = 0; i < tbr.materialsAndUVRects.Length; i++)
  517. {
  518. tbr.materialsAndUVRects[i].allPropsUseSameTiling = true;
  519. }
  520. }
  521. }
  522. public static bool IsMeshAndMaterialRectEnclosedByAtlasRect(MB_TextureTilingTreatment tilingTreatment, Rect uvR, Rect sourceMaterialTiling, Rect samplingEncapsulatinRect, MB2_LogLevel logLevel)
  523. {
  524. Rect potentialRect = new Rect();
  525. // test to see if this would fit in what was baked in the atlas
  526. potentialRect = MB3_UVTransformUtility.CombineTransforms(ref uvR, ref sourceMaterialTiling);
  527. if (logLevel >= MB2_LogLevel.trace)
  528. {
  529. if (logLevel >= MB2_LogLevel.trace) Debug.Log("IsMeshAndMaterialRectEnclosedByAtlasRect Rect in atlas uvR=" + uvR.ToString("f5") + " sourceMaterialTiling=" + sourceMaterialTiling.ToString("f5") + "Potential Rect (must fit in encapsulating) " + potentialRect.ToString("f5") + " encapsulating=" + samplingEncapsulatinRect.ToString("f5") + " tilingTreatment=" + tilingTreatment);
  530. }
  531. if (tilingTreatment == MB_TextureTilingTreatment.edgeToEdgeX)
  532. {
  533. if (MB3_UVTransformUtility.LineSegmentContainsShifted(samplingEncapsulatinRect.y, samplingEncapsulatinRect.height, potentialRect.y, potentialRect.height))
  534. {
  535. return true;
  536. }
  537. }
  538. else if (tilingTreatment == MB_TextureTilingTreatment.edgeToEdgeY)
  539. {
  540. if (MB3_UVTransformUtility.LineSegmentContainsShifted(samplingEncapsulatinRect.x, samplingEncapsulatinRect.width, potentialRect.x, potentialRect.width))
  541. {
  542. return true;
  543. }
  544. }
  545. else if (tilingTreatment == MB_TextureTilingTreatment.edgeToEdgeXY)
  546. {
  547. //only one rect in atlas and is edge to edge in both X and Y directions.
  548. return true;
  549. }
  550. else
  551. {
  552. if (MB3_UVTransformUtility.RectContainsShifted(ref samplingEncapsulatinRect, ref potentialRect))
  553. {
  554. return true;
  555. }
  556. }
  557. return false;
  558. }
  559. }