Git Product home page Git Product logo

quiche-pantie-patch-unity-editor's Introduction

キッシュちゃんパンツパッチUnityEditor

キッシュちゃんパンツパッチをUnityエディタ上から利用できるようにするエディタ拡張です

Unityエディタ上からキッシュちゃんパンツパッチに関する以下の機能が利用できるようになります

  • パンツ変換元テクスチャデータの一括取得
  • パンツ変換元テクスチャから、キッシュちゃんパンツパッチに対応したアバターへのパンツテクスチャ(透過PNG)の作成

使用方法

こちらのwikiに掲載しています

動作確認環境

  • Unity 2017.4.28f1

quiche-pantie-patch-unity-editor's People

Contributors

ramtype0 avatar sansuke05 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

quiche-pantie-patch-unity-editor's Issues

テクスチャの重ね合わせ処理が正常に機能しない

概要

テクスチャを重ね合わせる処理が実行段階でテクスチャ保存時にエラーを吐く

Consoleのエラー内容

Unsupported texture format - Texture2D::EncodeTo functions do not support compressed texture formats.
UnityEngine.ImageConversion:EncodeToPNG(Texture2D)
TextureCombinator:SaveTexture(String, Texture2D) (at Assets/AliceLaboratory/Test/Editor/TextureCombinator.cs:93)
TextureCombinator:OnGUI() (at Assets/AliceLaboratory/Test/Editor/TextureCombinator.cs:83)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
NullReferenceException: Object reference not set to an instance of an object
System.IO.File.WriteAllBytes (System.String path, System.Byte[] bytes) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:595)
TextureCombinator.SaveTexture (System.String filePath, UnityEngine.Texture2D texture) (at Assets/AliceLaboratory/Test/Editor/TextureCombinator.cs:94)
TextureCombinator.OnGUI () (at Assets/AliceLaboratory/Test/Editor/TextureCombinator.cs:83)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:295)
UnityEditor.HostView.Invoke (System.String methodName) (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:288)
UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:255)

該当するエラー箇所と重ね合わせ処理

        /// <summary>
        /// テクスチャの重ね合わせ処理
        /// </summary>
        public static Texture2D Overlap(Texture2D overTex, Texture2D baseTex) {
            var output = new Texture2D(baseTex.width, baseTex.height);
            var dest = output.GetPixels();
            var renderTexture = RenderTexture.GetTemporary(baseTex.width, baseTex.height);

            Graphics.Blit(baseTex, renderTexture);
            dest = GetPixelsFromRT(renderTexture);
            Graphics.Blit(overTex, renderTexture);
            var pixels = GetPixelsFromRT(renderTexture);
            for (int i = 0; i < pixels.Length; i++) {
                // RTのアルファ値が1ならば上書き
                if(pixels[i].a == 1) {
                    dest[i] = pixels[i];
                }
            }
            RenderTexture.ReleaseTemporary(renderTexture);
            output.SetPixels(dest);
            output.Apply();
            return baseTex;
        }

       /// <summary>
        /// RenderTextureからピクセル情報を取得する
        /// </summary>
        private static Color[] GetPixelsFromRT(RenderTexture target) {
            var preRT = RenderTexture.active;
            RenderTexture.active = target;

            // ReadPixels()でレンダーターゲットからテクスチャ情報を生成する
            var texture = new Texture2D(target.width, target.height);
            texture.ReadPixels(new Rect(0, 0, target.width, target.height), 0, 0);
            texture.Apply();

            RenderTexture.active = preRT;
            return texture.GetPixels();
        }
        var output = Utilities.Overlap(overTex:_textures[0], baseTex:_textures[1]);

        // 出来たテクスチャを保存する
        var filePath = EditorUtility.SaveFilePanel("Save Texture", "Assets", "name", "png");
        if (!string.IsNullOrEmpty(filePath)) {
            SaveTexture(filePath, output);
        }
    /// <summary>
    /// テクスチャを保存する
    /// </summary>
    private void SaveTexture(string filePath, Texture2D texture)
    {
        var bytes = texture.EncodeToPNG();
        System.IO.File.WriteAllBytes(filePath, bytes);
        AssetDatabase.Refresh();
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.