protected virtual void buildUvs(UVChannelFlags channel) { using (new ProfilerSample("Build Uvs")) { var uvs = MeshCache.GetUvs(_generation.graphic.mesh, channel); var targetList = _generation.uvs[channel.Index()]; targetList.AddRange(uvs); //If we cannot remap this channel, just return if ((_generation.graphic.remappableChannels & channel) == 0) { return; } UnityEngine.Object key; if (_textureFeatures.Count > 0) { key = _textureFeatures[0].featureData[_generation.graphicIndex].texture; } else if (_spriteFeatures.Count > 0) { key = _spriteFeatures[0].featureData[_generation.graphicIndex].sprite; } else { return; } Rect rect = _atlasUvs.GetRect(channel.Index(), key); MeshUtil.RemapUvs(targetList, rect, uvs.Count); } }
private void doPerChannelPack(ProgressBar progress, UVChannelFlags channel, Texture2D[] packedTextures, AtlasUvs channelMapping) { var mainTextureFeature = _features.Query().FirstOrDefault(f => f.channel == channel); if (mainTextureFeature == null) { return; } Texture2D defaultTexture, packedTexture; Texture2D[] rawTextureArray, processedTextureArray; progress.Step("Prepare " + channel); prepareForPacking(mainTextureFeature, out defaultTexture, out packedTexture, out rawTextureArray, out processedTextureArray); progress.Step("Pack " + channel); var packedRects = packedTexture.PackTextures(processedTextureArray, _padding, _maxAtlasSize, makeNoLongerReadable: false); packedTexture.Apply(updateMipmaps: true, makeNoLongerReadable: true); packedTextures[_features.IndexOf(mainTextureFeature)] = packedTexture; packSecondaryTextures(progress, channel, mainTextureFeature, packedTexture, packedRects, packedTextures); //Correct uvs to account for the added border for (int i = 0; i < packedRects.Length; i++) { float dx = 1.0f / packedTexture.width; float dy = 1.0f / packedTexture.height; Rect r = packedRects[i]; if (processedTextureArray[i] != defaultTexture) { dx *= _border; dy *= _border; } r.x += dx; r.y += dy; r.width -= dx * 2; r.height -= dy * 2; packedRects[i] = r; } for (int i = 0; i < rawTextureArray.Length; i++) { channelMapping.SetRect(channel.Index(), rawTextureArray[i], packedRects[i]); } }
public static List <Vector4> GetUvs(Mesh mesh, UVChannelFlags channel) { var key = new UvKey() { mesh = mesh, channel = (int)channel }; List <Vector4> uvs; if (!_uvCache.TryGetValue(key, out uvs)) { uvs = new List <Vector4>(); mesh.GetUVs(channel.Index(), uvs); if (uvs.Count != mesh.vertexCount) { uvs.Fill(mesh.vertexCount, Vector4.zero); } _uvCache[key] = uvs; } return(uvs); }