private static int CalCurIndex(int i, int j, TexAreaCalWithBounder bounderCal) { int calPiexlIndexX = 0; int calPiexlIndexY = 0; //左侧贴边,从右侧开始算 if (bounderCal.IsBounder[0]) { calPiexlIndexX = bounderCal.OriWidth - (i + bounderCal.OffStartX) - 1; } else { calPiexlIndexX = (i + bounderCal.OffStartX); } if (bounderCal.IsBounder[1]) { calPiexlIndexY = (bounderCal.OriHeight - (j + bounderCal.OffStartY) - 1) * bounderCal.CalWidth; } else { calPiexlIndexY = (j + bounderCal.OffStartY) * bounderCal.CalWidth; } return(calPiexlIndexX + calPiexlIndexY); }
public static Color[] TransferToColorArray(List <MRBPixelModel> targetList, TexAreaCalWithBounder bounderCal, bool isBlend) { //基本算是冗余的判断 int count = bounderCal.OriWidth * bounderCal.OriHeight; if (count <= 0) { return(null); } Color[] colorArray = new Color[count]; int arrayIndex, listIndex; int offX = bounderCal.OffStartX; int offY = bounderCal.OffStartY; for (int i = 0; i < bounderCal.OriWidth; i++) { for (int j = 0; j < bounderCal.OriHeight; j++) { arrayIndex = j * bounderCal.OriWidth + i; listIndex = (j + offY) * bounderCal.CalWidth + (i + offX); if (arrayIndex >= colorArray.Length || arrayIndex >= targetList.Count) { Debug.LogError($"i : {i}, j : {j}, arrayIndex : {arrayIndex}"); } if (isBlend) { colorArray[arrayIndex] = targetList[listIndex].SelfPixelBlend; } else { colorArray[arrayIndex] = targetList[listIndex].SelfPixelIndex; } } } return(colorArray); }
private static void CalCurNearIndex(List <MRBPixelModel> targetList, int curIndex, TexAreaCalWithBounder bounderCal) { mNearIndexList.Clear(); int calIndex = 0; //四个边 if (!bounderCal.IsBounder[0]) { calIndex = curIndex - 1; AddCurNearIndexToList(calIndex, targetList[calIndex]); } if (!bounderCal.IsBounder[1]) { calIndex = curIndex - bounderCal.CalWidth; AddCurNearIndexToList(calIndex, targetList[calIndex]); } if (!bounderCal.IsBounder[2]) { calIndex = curIndex + 1; AddCurNearIndexToList(calIndex, targetList[calIndex]); } if (!bounderCal.IsBounder[3]) { calIndex = curIndex + bounderCal.CalWidth; AddCurNearIndexToList(calIndex, targetList[calIndex]); } /*//4个边感觉数量不够,再+4个角试试看 * //左下 * if (!bounderCal.IsBounder[0] && !bounderCal.IsBounder[1]) * { * calIndex = curIndex - 1 - bounderCal.CalWidth; * AddCurNearIndexToList(calIndex, targetList[calIndex]); * } * //左上 * if (!bounderCal.IsBounder[0] && !bounderCal.IsBounder[3]) * { * calIndex = curIndex - 1 + bounderCal.CalWidth; * AddCurNearIndexToList(calIndex, targetList[calIndex]); * } * //右下 * if (!bounderCal.IsBounder[2] && !bounderCal.IsBounder[1]) * { * calIndex = curIndex + 1 - bounderCal.CalWidth; * AddCurNearIndexToList(calIndex, targetList[calIndex]); * } * //右上 * if (!bounderCal.IsBounder[2] && !bounderCal.IsBounder[3]) * { * calIndex = curIndex + 1 + bounderCal.CalWidth; * AddCurNearIndexToList(calIndex, targetList[calIndex]); * }*/ }
/// <summary> /// 这里不考虑,刷一下的范围,触碰>=3条边的深井冰情况 /// </summary> /// <param name="targetList"></param> /// <param name="bounderCal"></param> public static void ResortListAccordingToIndex(List <MRBPixelModel> targetList, TexAreaCalWithBounder bounderCal) { int count = 0; int calCount = bounderCal.CalWidth * bounderCal.CalHeight; for (int i = 0; i < calCount; i++) { if (targetList[i].IsDirty) { count++; } } int curIndex = 0; //理论上,都会在一轮循环以后处理完毕 //当然得配合上边角的优化计算。对index做个处理应该就好了 //然后还得考虑边角的非dirty //考虑过使用List记录Index的情况,但是考虑到比较极限的情况循环次数(计算周边是否Dirty的次数)可能会非常大。 //索性通过算法来尽量一次循环。 //说好的不考虑消耗呢! int loopCount = 0; while (count > 0 && loopCount < 5) { for (int i = 0; i < bounderCal.OriWidth; i++) { if (count == 0) { break; } for (int j = 0; j < bounderCal.OriHeight; j++) { if (count == 0) { break; } curIndex = CalCurIndex(i, j, bounderCal); if (!targetList[curIndex].IsDirty) { continue; } //考虑把bounderCal用static代替,但是他在另一个脚本里面,有点不放心 //先只计算4个相邻的格子,看效果,有必要再+4个斜对角格子,加权计算 CalCurNearIndex(targetList, curIndex, bounderCal); //周边只有0-1个干净的像素,先不计算(理论上不可能出现这种情况) if (mNearIndexList.Count < 2) { continue; } ResetCurIndexWithRecommendIndex(targetList, curIndex); //大致思路 //1.脏像素一定是排好序的,所以以Index的r,g的顺序来确定权重(b最后放剩下的) //2.关于权重存储,预定是给个int[3],来分别处理干净像素的r,g,b对应的权重值 //3.关于权重值,如果有相同,且数值>0.01f,则+1,如果不相同且weight<0.01f,则+0.5(暂时,看情况优化) //4.然后根据权重值sort //TODO:如果这么计算权重中,3个值都为0,还可以把4个对角的格子加入权重计算,暂时不添加 CalIndexWeight(targetList, curIndex); //计算完毕,用mIndexResultArray开始调整位置吧 targetList[curIndex].ResortByIndexResult(mIndexResultArray); targetList[curIndex].IsDirty = false; count--; } } loopCount++; } for (int i = 0; i < calCount; i++) { //Debug.LogError($"{i}\n{targetList[i].ToString()}"); } if (count > 0) { Debug.LogError("出现意外错误,请先确认刷新范围是否触碰>=3条边,否则去找程序处理"); } }