private void prepareForPacking(LeapTextureFeature feature, out Texture2D defaultTexture, out Texture2D packedTexture, out Texture2D[] rawTextureArray, out Texture2D[] processedTextureArray) { if (_extraTextures == null) { _extraTextures = new TextureReference[0]; } rawTextureArray = feature.featureData.Query(). Select(dataObj => dataObj.texture). Concat(_extraTextures.Query(). Where(p => p.channel == feature.channel). Select(p => p.texture)). ToArray(); processedTextureArray = rawTextureArray.Query(). Select(t => processTexture(t)). ToArray(); defaultTexture = getDefaultTexture(Color.white); //TODO, pull color from feature data for (int i = 0; i < processedTextureArray.Length; i++) { if (processedTextureArray[i] == null) { processedTextureArray[i] = defaultTexture; } } packedTexture = new Texture2D(1, 1, TextureFormat.ARGB32, mipmap: false, linear: true); packedTexture.filterMode = _filterMode; }
private void packSecondaryTextures(ProgressBar progress, UVChannelFlags channel, LeapTextureFeature mainFeature, Texture2D packedTexture, Rect[] packedRects, Texture2D[] packedTextures) { //All texture features that are NOT the main texture do not get their own atlas step //They are simply copied into a new texture var nonMainFeatures = _features.Query().Where(f => f.channel == channel).Skip(1).ToList(); progress.Begin(nonMainFeatures.Count, "", "Copying secondary textures: ", () => { foreach (var secondaryFeature in nonMainFeatures) { RenderTexture secondaryRT = new RenderTexture(packedTexture.width, packedTexture.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); RenderTexture.active = secondaryRT; GL.Clear(clearDepth: false, clearColor: true, backgroundColor: Color.black); GL.LoadPixelMatrix(0, 1, 0, 1); progress.Begin(secondaryFeature.featureData.Count, "", secondaryFeature.propertyName, () => { for (int i = 0; i < secondaryFeature.featureData.Count; i++) { var mainTexture = mainFeature.featureData[i].texture; if (mainTexture == null) { progress.Step(); continue; } var secondaryTexture = secondaryFeature.featureData[i].texture; if (secondaryTexture == null) { progress.Step(); continue; } progress.Step(secondaryTexture.name); Rect rect = packedRects[i]; //Use mainTexture instead of secondaryTexture here to calculate correct border to line up with main texture float borderDX = _border / (float)mainTexture.width; float borderDY = _border / (float)mainTexture.height; drawTexture(secondaryTexture, secondaryRT, rect, borderDX, borderDY); } }); packedTextures[_features.IndexOf(secondaryFeature)] = convertToTexture2D(secondaryRT, mipmap: false); } }); }