// The two texture sets are equal if they are using the same // textures/color properties for each map and have the same // tiling for each of those color properties internal bool IsEqual(object obj, bool fixOutOfBoundsUVs, bool considerNonTextureProperties, MB3_TextureCombinerNonTextureProperties resultMaterialTextureBlender) { if (!(obj is MB_TexSet)) { return(false); } MB_TexSet other = (MB_TexSet)obj; if (other.ts.Length != ts.Length) { return(false); } else { for (int i = 0; i < ts.Length; i++) { if (ts[i].matTilingRect != other.ts[i].matTilingRect) { return(false); } if (!ts[i].AreTexturesEqual(other.ts[i])) { return(false); } if (considerNonTextureProperties) { if (resultMaterialTextureBlender != null) { if (!resultMaterialTextureBlender.NonTexturePropertiesAreEqual(matsAndGOs.mats[0].mat, other.matsAndGOs.mats[0].mat)) { return(false); } } } } //IMPORTANT don't use Vector2 != Vector2 because it is only acurate to about 5 decimal places //this can lead to tiled rectangles that can't accept rectangles. if (fixOutOfBoundsUVs && (obUVoffset.x != other.obUVoffset.x || obUVoffset.y != other.obUVoffset.y)) { return(false); } if (fixOutOfBoundsUVs && (obUVscale.x != other.obUVscale.x || obUVscale.y != other.obUVscale.y)) { return(false); } return(true); } }
public bool AllTexturesAreSameForMerge(MB_TexSet other, bool considerNonTextureProperties, MB3_TextureCombinerNonTextureProperties resultMaterialTextureBlender) { if (other.ts.Length != ts.Length) { return(false); } else { if (!other.allTexturesUseSameMatTiling || !allTexturesUseSameMatTiling) { return(false); } // must use same set of textures int idxOfFirstNoneNull = -1; for (int i = 0; i < ts.Length; i++) { if (!ts[i].AreTexturesEqual(other.ts[i])) { return(false); } if (idxOfFirstNoneNull == -1 && !ts[i].isNull) { idxOfFirstNoneNull = i; } if (considerNonTextureProperties) { if (!resultMaterialTextureBlender.NonTexturePropertiesAreEqual(matsAndGOs.mats[0].mat, other.matsAndGOs.mats[0].mat)) { return(false); } } } if (idxOfFirstNoneNull != -1) { //check that all textures are the same. Have already checked all tiling is same for (int i = 0; i < ts.Length; i++) { if (!ts[i].AreTexturesEqual(other.ts[i])) { return(false); } } } return(true); } }
public bool AllTexturesAreSameForMerge(MB_TexSet other, /*bool considerTintColor*/ bool considerNonTextureProperties, MB3_TextureCombinerNonTextureProperties resultMaterialTextureBlender) { if (other.ts.Length != ts.Length) { return(false); } else { if (!other.allTexturesUseSameMatTiling || !allTexturesUseSameMatTiling) { return(false); } // must use same set of textures int idxOfFirstNoneNull = -1; for (int i = 0; i < ts.Length; i++) { if (!ts[i].AreTexturesEqual(other.ts[i])) { return(false); } if (idxOfFirstNoneNull == -1 && !ts[i].isNull) { idxOfFirstNoneNull = i; } if (considerNonTextureProperties) { if (resultMaterialTextureBlender != null) { if (!resultMaterialTextureBlender.NonTexturePropertiesAreEqual(matsAndGOs.mats[0].mat, other.matsAndGOs.mats[0].mat)) { return(false); } } } } if (idxOfFirstNoneNull != -1) { //check that all textures are the same. Have already checked all tiling is same for (int i = 0; i < ts.Length; i++) { if (!ts[i].AreTexturesEqual(other.ts[i])) { return(false); } } //========================================================= // OLD check less strict //When comparting two sets of textures (main, bump, spec ...) A and B that have different scales & offsets.They can share if: // - the scales of each texPropertyName (main, bump ...) are the same ratio: ASmain / BSmain = ASbump / BSbump = ASspec / BSspec // - the offset of A to B in uv space is the same for each texPropertyName: // offset = final - initial = OA / SB - OB must be the same /* * MeshBakerMaterialTexture ma = ts[idxOfFirstNoneNull]; * MeshBakerMaterialTexture mb = other.ts[idxOfFirstNoneNull]; * //construct a rect that will ratio and offset * DRect r1 = new DRect( (ma.matTilingRect.x / mb.matTilingRect.width - mb.matTilingRect.x), * (ma.matTilingRect.y / mb.matTilingRect.height - mb.matTilingRect.y), * (mb.matTilingRect.width / ma.matTilingRect.width), * (mb.matTilingRect.height / ma.matTilingRect.height)); * for (int i = 0; i < ts.Length; i++) * { * if (ts[i].t != null) * { * ma = ts[i]; * mb = other.ts[i]; * DRect r2 = new DRect( (ma.matTilingRect.x / mb.matTilingRect.width - mb.matTilingRect.x), * (ma.matTilingRect.y / mb.matTilingRect.height - mb.matTilingRect.y), * (mb.matTilingRect.width / ma.matTilingRect.width), * (mb.matTilingRect.height / ma.matTilingRect.height)); * if (Math.Abs(r2.x - r1.x) > 10e-10f) return false; * if (Math.Abs(r2.y - r1.y) > 10e-10f) return false; * if (Math.Abs(r2.width - r1.width) > 10e-10f) return false; * if (Math.Abs(r2.height - r1.height) > 10e-10f) return false; * } * } */ } return(true); } }