Esempio n. 1
0
        /// <summary>This will save the current texture state with the specified save name.</summary>
        public void Save(string saveName)
        {
            if (activated == true)
            {
                var readableTexture = P3dHelper.GetReadableCopy(current);

                P3dHelper.SavePngTextureData(readableTexture.EncodeToPNG(), saveName);

                P3dHelper.Destroy(readableTexture);
            }
        }
Esempio n. 2
0
            public void Save()
            {
                var copy = P3dHelper.GetReadableCopy(Current);

                if (copy != null)
                {
                    Pixels = copy.EncodeToPNG();
                    Width  = Current.width;
                    Height = Current.height;

                    DestroyImmediate(copy);
                }
            }
Esempio n. 3
0
        private void Calculate(RenderTexture renderTexture, int scale)
        {
            var threshold32 = (byte)(threshold * 255.0f);
            var width       = renderTexture.width;
            var height      = renderTexture.height;
            var texture2D   = P3dHelper.GetReadableCopy(renderTexture);
            var pixels32    = texture2D.GetPixels32();

            P3dHelper.Destroy(texture2D);

            // Reset totals
            totalR = 0;
            totalG = 0;
            totalB = 0;
            totalA = 0;

            // Calculate totals
            for (var y = 0; y < height; y++)
            {
                var offset = y * width;

                for (var x = 0; x < height; x++)
                {
                    var pixel32 = pixels32[offset + x];

                    if (pixel32.r >= threshold32)
                    {
                        totalR++;
                    }
                    if (pixel32.g >= threshold32)
                    {
                        totalG++;
                    }
                    if (pixel32.b >= threshold32)
                    {
                        totalB++;
                    }
                    if (pixel32.a >= threshold32)
                    {
                        totalA++;
                    }
                }
            }

            // Scale totals to account for downsampling
            totalR *= scale;
            totalG *= scale;
            totalB *= scale;
            totalA *= scale;
        }
Esempio n. 4
0
        private void Calculate(RenderTexture renderTexture, int scale)
        {
            var threshold32 = (int)(threshold * 255.0f);
            var width       = renderTexture.width;
            var height      = renderTexture.height;
            var texture2D   = P3dHelper.GetReadableCopy(renderTexture);
            var pixels32    = texture2D.GetPixels32();

            P3dHelper.Destroy(texture2D);

            PrepareTemp();

            for (var y = 0; y < height; y++)
            {
                var offset = y * width;

                for (var x = 0; x < height; x++)
                {
                    var pixel32      = pixels32[offset + x];
                    var bestIndex    = -1;
                    var bestDistance = threshold32;

                    for (var i = 0; i < P3dTeam.InstanceCount; i++)
                    {
                        var tempTeam = tempTeams[i];
                        var distance = 0;

                        distance += System.Math.Abs(tempTeam.R - pixel32.r);
                        distance += System.Math.Abs(tempTeam.G - pixel32.g);
                        distance += System.Math.Abs(tempTeam.B - pixel32.b);
                        distance += System.Math.Abs(tempTeam.A - pixel32.a);

                        if (distance <= bestDistance)
                        {
                            bestIndex    = i;
                            bestDistance = distance;
                        }
                    }

                    if (bestIndex >= 0)
                    {
                        tempTeams[bestIndex].Count++;
                    }
                }
            }

            // Multiply totals to account for downsampling
            Contribute(scale);
        }
Esempio n. 5
0
        private void HandleExport()
        {
            var basePath = AssetDatabase.GetAssetPath(scene);

            if (string.IsNullOrEmpty(basePath) == true)
            {
                basePath = "Assets/";
            }
            else
            {
                basePath = System.IO.Path.GetDirectoryName(basePath) + "/";
            }

            foreach (var mat in scene.Mats)
            {
                if (mat.Template != null)
                {
                    foreach (var matSlot in mat.Slots)
                    {
                        var sceneSlot = mat.Template.Slots.FirstOrDefault(s => s.Name == matSlot.Name);

                        if (sceneSlot != null && matSlot.Texture != null)
                        {
                            var path    = basePath + settings.ExportFormat.Replace("{SCENE}", scene.name).Replace("{MATERIAL}", mat.Name).Replace("{TEXTURE}", sceneSlot.GetAlias()) + ".png";
                            var texture = P3dHelper.GetReadableCopy(matSlot.Texture);
                            var data    = texture.EncodeToPNG();

                            DestroyImmediate(texture);

                            System.IO.File.WriteAllBytes(path, data);

                            Debug.Log("EXPORT " + path);
                        }
                    }
                }
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Esempio n. 6
0
 /// <summary>If you need to read pixels from this paintable texture then this will return a Texture2D you can read.
 /// NOTE: A new texture is allocated each time you call this, so you must manually delete it when finished.</summary>
 public Texture2D GetReadableCopy()
 {
     return(P3dHelper.GetReadableCopy(current));
 }
        private void BakeOverlap()
        {
            var desc          = new RenderTextureDescriptor(1024, 1024, RenderTextureFormat.ARGB32, 0);
            var renderTexture = P3dHelper.GetRenderTexture(desc);

            if (overlapMaterial == null)
            {
                overlapMaterial = P3dShader.BuildMaterial("Hidden/Paint in 3D/Overlap");
            }

            overlapMaterial.SetVector(P3dShader._Coord, P3dHelper.IndexToVector(coord));

            var oldActive = RenderTexture.active;

            RenderTexture.active = renderTexture;

            GL.Clear(true, true, Color.black);

            overlapMaterial.SetPass(0);

            Graphics.DrawMeshNow(mesh, Matrix4x4.identity, submesh);

            foreach (var obj in Selection.objects)
            {
                var otherMesh = obj as Mesh;

                if (otherMesh != null && otherMesh != mesh)
                {
                    Graphics.DrawMeshNow(otherMesh, Matrix4x4.identity, submesh);
                }
            }

            RenderTexture.active = oldActive;

            overlapTex = P3dHelper.GetReadableCopy(renderTexture);

            P3dHelper.ReleaseRenderTexture(renderTexture);

            var utilizationCount = 0;
            var overlapCount     = 0;

            for (var y = 0; y < overlapTex.height; y++)
            {
                for (var x = 0; x < overlapTex.width; x++)
                {
                    var pixel = overlapTex.GetPixel(x, y);

                    if (pixel.r > 0.0f)
                    {
                        if (pixel.r > 1.5 / 255.0f)
                        {
                            pixel = Color.red;

                            overlapCount += 1;
                        }
                        else
                        {
                            pixel = Color.gray;
                        }

                        utilizationCount += 1;

                        overlapTex.SetPixel(x, y, pixel);
                    }
                }
            }

            var total = overlapTex.width * overlapTex.height * 0.01f;

            utilizationPercent = utilizationCount / total;
            overlapPercent     = overlapCount / total;

            overlapTex.Apply();
        }
        private void Bake(RenderTexture renderTexture, int width, int height, int scale)
        {
            if (bakedPixels == null)
            {
                bakedPixels = new List <bool>();
            }
            else
            {
                bakedPixels.Clear();
            }

            bakedMesh = mesh;
            bakedSize = new Vector2Int(width, height);

            if (cachedMaterial == null)
            {
                cachedMaterial = P3dPaintableManager.BuildMaterial("Hidden/Paint in 3D/White");
            }

            switch (PaintableTexture.Channel)
            {
            case P3dChannel.UV: cachedMaterial.SetVector(P3dShader._Channel, new Vector4(1.0f, 0.0f, 0.0f, 0.0f)); break;

            case P3dChannel.UV2: cachedMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 1.0f, 0.0f, 0.0f)); break;

            case P3dChannel.UV3: cachedMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 0.0f, 1.0f, 0.0f)); break;

            case P3dChannel.UV4: cachedMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); break;
            }

            // Write to temp RenderTexture
            var oldActive = RenderTexture.active;

            RenderTexture.active = renderTexture;

            GL.Clear(true, true, Color.black);

            cachedMaterial.SetPass(0);

            Graphics.DrawMeshNow(mesh, Matrix4x4.identity, PaintableTexture.Slot.Index);

            RenderTexture.active = oldActive;

            // Get readable copy
            var readable = P3dHelper.GetReadableCopy(renderTexture);

            // Run through pixels to count total and build binary mask
            bakedPixels.Capacity = width * height;

            total = 0;

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    if (readable.GetPixel(x, y).r > 0.5f)
                    {
                        bakedPixels.Add(true);

                        total += scale;
                    }
                    else
                    {
                        bakedPixels.Add(false);
                    }
                }
            }

            // Clean up
            P3dHelper.Destroy(readable);
        }
Esempio n. 9
0
        private Texture DrawObject(P3dWindowPaintableTexture paintableTexture, Material material, Texture texture)
        {
            if (texture != null)
            {
                var texture2D = texture as Texture2D;

                if (texture2D != null)
                {
                    EditorGUI.BeginDisabledGroup(paintableTexture.Locked == true);
                    if (material.hideFlags != HideFlags.None)
                    {
                        EditorGUILayout.HelpBox("This may be a shared texture, so you should clone it before modification.", MessageType.Warning);
                    }

                    if (GUILayout.Button("Clone") == true)
                    {
                        texture = texture2D = Instantiate(texture2D);
                    }

                    var textureImporter = P3dHelper.GetAssetImporter <TextureImporter>(texture);

                    if (textureImporter != null)
                    {
                        if (textureImporter.isReadable == false)
                        {
                            EditorGUILayout.HelpBox("This texture's import settings does not have Read/Write Enabled.", MessageType.Error);

                            P3dHelper.BeginColor(Color.green);
                            if (GUILayout.Button("Enable Read/Write") == true)
                            {
                                textureImporter.isReadable = true;

                                textureImporter.SaveAndReimport();
                            }
                            P3dHelper.EndColor();
                        }
                    }
                    else
                    {
                        changeFormat = EditorGUILayout.Foldout(changeFormat, "Change Format");

                        if (changeFormat == true)
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.EnumPopup("Current Format", texture2D.format, EditorStyles.popup);
                            EditorGUI.EndDisabledGroup();

                            changeFormatNew = (TextureFormat)EditorGUILayout.EnumPopup("New Format", changeFormatNew, EditorStyles.popup);

                            P3dHelper.BeginColor(Color.green);
                            if (GUI.Button(P3dHelper.Reserve(), "Change Format") == true)
                            {
                                var newTexture2D = new Texture2D(texture2D.width, texture2D.height, changeFormatNew, texture2D.mipmapCount > 0);

                                changeFormatFailed = true;

                                if (CanReadWrite(newTexture2D) == true)
                                {
                                    var readableTexture = P3dHelper.GetReadableCopy(texture2D);
                                    var pixels          = readableTexture.GetPixels32();

                                    P3dHelper.Destroy(readableTexture);

                                    newTexture2D.name = texture2D.name;
                                    newTexture2D.SetPixels32(pixels);
                                    newTexture2D.Apply();

                                    texture            = texture2D = newTexture2D;
                                    changeFormat       = false;
                                    changeFormatFailed = false;
                                }
                            }
                            P3dHelper.EndColor();

                            if (changeFormatFailed == true)
                            {
                                EditorGUILayout.HelpBox("Failed to change format. This means the format you tried to use is not readable.", MessageType.Error);
                            }
                        }

                        changeSize = EditorGUILayout.Foldout(changeSize, "Change Size");

                        if (changeSize == true)
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.IntField("Current Width", texture2D.width);
                            EditorGUILayout.IntField("Current Height", texture2D.height);
                            EditorGUI.EndDisabledGroup();
                            changeWidth  = EditorGUILayout.IntField("Width", changeWidth);
                            changeHeight = EditorGUILayout.IntField("Height", changeHeight);

                            P3dHelper.BeginColor(Color.green);
                            if (GUILayout.Button("Change Size") == true)
                            {
                                var newTexture2D = new Texture2D(changeWidth, changeHeight, texture2D.format, texture2D.mipmapCount > 0);

                                changeSizeFailed = true;

                                if (CanReadWrite(newTexture2D) == true)
                                {
                                    var readableTexture = P3dHelper.GetReadableCopy(texture2D, TextureFormat.ARGB32, false, changeWidth, changeHeight);
                                    var pixels          = readableTexture.GetPixels32();

                                    P3dHelper.Destroy(readableTexture);

                                    newTexture2D.name = texture2D.name;
                                    newTexture2D.SetPixels32(pixels);
                                    newTexture2D.Apply();

                                    texture          = texture2D = newTexture2D;
                                    changeSize       = false;
                                    changeSizeFailed = false;
                                }
                            }
                            P3dHelper.EndColor();

                            if (changeSizeFailed == true)
                            {
                                EditorGUILayout.HelpBox("Failed to change size. Either the texture format is non-readable, or the texture size you chose is invalid.", MessageType.Error);
                            }
                        }
                    }

                    if (P3dHelper.IsAsset(material) == true && P3dHelper.IsAsset(texture) == false)
                    {
                        EditorGUILayout.HelpBox("This texture is stored in the scene, but it's applied to a material that's stored in an asset. You should save the texture as an asset too, otherwise it won't work properly.", MessageType.Warning);
                    }

                    if (P3dHelper.IsAsset(texture) == false)
                    {
                        if (GUILayout.Button("Save As Texture2D Asset") == true)
                        {
                            var path = P3dHelper.SaveDialog("Save Texture As Asset", "Assets", texture.name, "asset");

                            if (string.IsNullOrEmpty(path) == false)
                            {
                                AssetDatabase.CreateAsset(texture, path);
                            }
                        }

                        if (GUILayout.Button("Save As Png Asset") == true)
                        {
                            var path = P3dHelper.SaveDialog("Export Texture", "Assets", texture.name, "png");

                            if (string.IsNullOrEmpty(path) == false)
                            {
                                P3dHelper.SaveTextureAsset(texture, path, true);

                                var newTexture2D = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D));

                                if (newTexture2D != null)
                                {
                                    //ClearUndo();

                                    var importer = P3dHelper.GetAssetImporter <TextureImporter>(newTexture2D);

                                    importer.isReadable         = true;
                                    importer.textureCompression = TextureImporterCompression.Uncompressed;
                                    importer.filterMode         = FilterMode.Trilinear;
                                    importer.anisoLevel         = 8;
                                    importer.SaveAndReimport();

                                    texture = texture2D = newTexture2D;

                                    P3dHelper.SetDirty(this);
                                }
                            }
                        }
                    }
                    EditorGUI.EndDisabledGroup();

                    if (paintableTexture.Locked == true)
                    {
                        EditorGUILayout.BeginHorizontal();
                        P3dHelper.BeginColor(Color.red);
                        if (GUILayout.Button("Unlock", GUILayout.Width(50.0f)) == true)
                        {
                            paintableTexture.Unlock();
                        }
                        P3dHelper.EndColor();
                        P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), paintableTexture);
                        paintableTexture.Channel = (P3dChannel)EditorGUILayout.EnumPopup(paintableTexture.Channel);
                        if (GUILayout.Button("Paint", GUILayout.Width(45.0f)) == true)
                        {
                            tab = 2;
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        var shared = false;

                        if (TextureAlreadyLocked(texture) == true)
                        {
                            EditorGUILayout.HelpBox("This texture has already been locked in another object, so you don't need to lock it again. Paint will automatically be applied as long as you keep this texture expanded.", MessageType.Info);

                            shared = true;
                        }

                        EditorGUILayout.BeginHorizontal();
                        EditorGUI.BeginDisabledGroup(shared);
                        P3dHelper.BeginColor(Color.green);
                        if (GUILayout.Button("Lock", GUILayout.Width(45.0f)) == true)
                        {
                            Repaint();

                            paintableTexture.Lock(this);
                        }
                        P3dHelper.EndColor();
                        P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), paintableTexture);
                        EditorGUI.EndDisabledGroup();
                        paintableTexture.Channel = (P3dChannel)EditorGUILayout.EnumPopup(paintableTexture.Channel);
                        P3dHelper.BeginColor(Color.green);
                        EditorGUI.BeginDisabledGroup(shared);
                        if (GUILayout.Button("Lock & Paint", GUILayout.Width(85.0f)) == true)
                        {
                            Repaint();

                            if (paintableTexture.Lock(this) == true)
                            {
                                tab = 2;
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                        P3dHelper.EndColor();
                        EditorGUILayout.EndHorizontal();

                        if (paintableTexture.LockFailed == true)
                        {
                            EditorGUILayout.HelpBox("Failed to lock texture.\nThis may be because the texture is not readable, if so, try cloning it.\nThis may be because the texture format is not readable, if so, try changing the format.", MessageType.Error);
                        }
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("This texture isn't a Texture2D, so it cannot be painted.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no texture in this slot. Either drag and drop one in, or create one below.", MessageType.Warning);

                createFormat  = (TextureFormat)EditorGUILayout.EnumPopup("Format", createFormat);
                createMipMaps = EditorGUILayout.Toggle("Mip Maps", createMipMaps);
                createLinear  = EditorGUILayout.Toggle("Linear", createLinear);
                createColor   = EditorGUILayout.ColorField("Color", createColor);
                createWidth   = EditorGUILayout.IntField("Width", createWidth);
                createHeight  = EditorGUILayout.IntField("Height", createHeight);

                P3dHelper.BeginColor(Color.green);
                if (GUILayout.Button("Create") == true)
                {
                    var newTexture2D = new Texture2D(createWidth, createHeight, createFormat, createMipMaps, createLinear);

                    createFailed = true;

                    if (CanReadWrite(newTexture2D) == true)
                    {
                        var pixels32 = new Color32[createWidth * createHeight];
                        var color32  = (Color32)createColor;

                        for (var i = createWidth * createHeight - 1; i >= 0; i--)
                        {
                            pixels32[i] = color32;
                        }

                        newTexture2D.SetPixels32(pixels32);
                        newTexture2D.Apply();

                        texture      = newTexture2D;
                        createFailed = false;
                    }
                }
                P3dHelper.EndColor();

                if (createFailed == true)
                {
                    EditorGUILayout.HelpBox("Failed to create texture. This means the format you tried to use is not readable, or the size is invalid.", MessageType.Error);
                }
            }

            return(texture);
        }
        private void Bake(RenderTexture temporary, int width, int height, RenderTextureFormat format, int scale)
        {
            if (bakedPixels == null)
            {
                bakedPixels = new List <bool>();
            }
            else
            {
                bakedPixels.Clear();
            }

            baked     = true;
            bakedMesh = mesh;
            bakedSize = new Vector2Int(width, height);

            if (cachedMaterial == null)
            {
                cachedMaterial = P3dPaintableManager.BuildMaterial("Hidden/Paint in 3D/White");
            }

            cachedMaterial.SetVector(P3dShader._Channel, P3dHelper.IndexToVector((int)PaintableTexture.Channel));

            // Write to temp RenderTexture
            var oldActive     = RenderTexture.active;
            var renderTexture = temporary;

            if (temporary == null)
            {
                var desc = new RenderTextureDescriptor(width, height, format, 0);

                renderTexture = P3dHelper.GetRenderTexture(desc);
            }

            RenderTexture.active = renderTexture;

            GL.Clear(true, true, Color.black);

            cachedMaterial.SetPass(0);

            Graphics.DrawMeshNow(mesh, Matrix4x4.identity, PaintableTexture.Slot.Index);

            RenderTexture.active = oldActive;

            // Get readable copy
            var readable = P3dHelper.GetReadableCopy(renderTexture);

            if (temporary == null)
            {
                P3dHelper.ReleaseRenderTexture(renderTexture);
            }

            // Run through pixels to count total and build binary mask
            bakedPixels.Capacity = width * height;

            total = 0;

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    if (readable.GetPixel(x, y).r > 0.5f)
                    {
                        bakedPixels.Add(true);

                        total += scale;
                    }
                    else
                    {
                        bakedPixels.Add(false);
                    }
                }
            }

            // Clean up
            P3dHelper.Destroy(readable);
        }
Esempio n. 11
0
        private void DrawNextPaint()
        {
            if (P3dPaintMaterial.CachedInstances.Count > 0)
            {
                if (paintIndex >= P3dPaintMaterial.CachedInstances.Count)
                {
                    paintIndex = 0;
                }

                var paint = P3dPaintMaterial.CachedInstances[paintIndex++];

                DestroyImmediate(paint.Thumbnail);
                paint.Thumbnail = null;

                if (paint != null && paint.Thumbnail == null && paint.Material != null)
                {
                    var tempTextures = new List <RenderTexture>();

                    if (paintProperties == null)
                    {
                        paintProperties = new MaterialPropertyBlock();
                    }
                    else
                    {
                        paintProperties.Clear();
                    }

                    if (paint.Template != null)
                    {
                        foreach (var slot in paint.Template.Slots)
                        {
                            var slotR = paint.GetSlot(slot.WriteR.SourceGroup);
                            var slotG = paint.GetSlot(slot.WriteG.SourceGroup);
                            var slotB = paint.GetSlot(slot.WriteB.SourceGroup);
                            var slotA = paint.GetSlot(slot.WriteA.SourceGroup);

                            if (slotR != null || slotG != null || slotB != null || slotA != null)
                            {
                                var tempTexture = P3dHelper.GetRenderTexture(new RenderTextureDescriptor(1024, 1024, RenderTextureFormat.ARGB32, 0));

                                tempTextures.Add(tempTexture);

                                var textureR = P3dHelper.GetRenderTexture(tempTexture.descriptor);
                                var textureG = P3dHelper.GetRenderTexture(tempTexture.descriptor);
                                var textureB = P3dHelper.GetRenderTexture(tempTexture.descriptor);
                                var textureA = P3dHelper.GetRenderTexture(tempTexture.descriptor);

                                WriteThumbnailTex(textureR, slotR, slot.WriteR);
                                WriteThumbnailTex(textureG, slotG, slot.WriteG);
                                WriteThumbnailTex(textureB, slotB, slot.WriteB);
                                WriteThumbnailTex(textureA, slotA, slot.WriteA);

                                var channelR = P3dHelper.IndexToVector((int)slot.WriteR.SourceChannel);
                                var channelG = P3dHelper.IndexToVector((int)slot.WriteG.SourceChannel);
                                var channelB = P3dHelper.IndexToVector((int)slot.WriteB.SourceChannel);
                                var channelA = P3dHelper.IndexToVector((int)slot.WriteA.SourceChannel);

                                P3dPaintReplaceChannels.Blit(tempTexture, textureR, textureG, textureB, textureA, channelR, channelG, channelB, channelA);

                                P3dHelper.ReleaseRenderTexture(textureR);
                                P3dHelper.ReleaseRenderTexture(textureG);
                                P3dHelper.ReleaseRenderTexture(textureB);
                                P3dHelper.ReleaseRenderTexture(textureA);

                                paintProperties.SetTexture(slot.Name, tempTexture);
                            }
                        }
                    }

                    BeginPreview(thumbnailUtil, new Rect(0, 0, settings.ThumbnailSize, settings.ThumbnailSize));

                    var probeAnchor = default(Transform);
                    var probeExists = false;

                    if (settings.Environment != null)
                    {
                        probeAnchor = settings.Environment.transform;
                        probeExists = true;
                    }

                    switch (paint.Style)
                    {
                    case P3dPaintMaterial.StyleType.Seamless:
                    {
                        thumbnailUtil.DrawMesh(P3dHelper.GetSphereMesh(), Matrix4x4.identity, paint.Material, 0, paintProperties, probeAnchor, probeExists);
                    }
                    break;

                    case P3dPaintMaterial.StyleType.Decal:
                    {
                        thumbnailUtil.DrawMesh(P3dHelper.GetQuadMesh(), Matrix4x4.identity, paint.Material, 0, paintProperties, probeAnchor, probeExists);
                    }
                    break;
                    }

                    paint.Thumbnail = P3dHelper.GetReadableCopy(EndPreview(thumbnailUtil));

                    foreach (var tempTexture in tempTextures)
                    {
                        P3dHelper.ReleaseRenderTexture(tempTexture);
                    }
                }
            }
        }