示例#1
0
    void OnGUI()
    {
        EditorGUILayout.LabelField("输入需要导出的Prefab");
        targetGo = (GameObject)EditorGUILayout.ObjectField(targetGo, typeof(GameObject), true);

        EditorGUILayout.LabelField("选择导出时使用的shader");
        shader = (Shader)EditorGUILayout.ObjectField(shader, typeof(Shader), true);

        EditorGUILayout.LabelField("输入保存路径");
        subPath = EditorGUILayout.TextField(subPath);


        if (GUILayout.Button("Bake"))
        {
            if (null == baker)
            {
                baker = new AnimMapBaker();
            }
            baker.SetAnimData(targetGo);
            List <AnimBakedData> bakedDataList = baker.Bake();
            for (int i = 0; i < bakedDataList.Count; ++i)
            {
                AnimBakedData bakedData = bakedDataList [i];
                SavePrefab(bakedData);
            }
        }
    }
示例#2
0
    void OnGUI()
    {
        targetGo = (GameObject)EditorGUILayout.ObjectField(targetGo, typeof(GameObject), true);
        subPath  = targetGo == null ? subPath : targetGo.name;
        EditorGUILayout.LabelField(string.Format("保存路径output path:{0}", Path.Combine(path, subPath)));
        path    = EditorGUILayout.TextField(path);
        subPath = EditorGUILayout.TextField(subPath);

        if (GUILayout.Button("Bake"))
        {
            if (targetGo == null)
            {
                EditorUtility.DisplayDialog("err", "targetGo is null!", "OK");
                return;
            }

            if (baker == null)
            {
                baker = new AnimMapBaker();
            }

            baker.SetAnimData(targetGo);

            List <BakedData> list = baker.Bake();

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    BakedData data = list[i];
                    Save(ref data);
                }
            }
        }
    }
    public static void ShowWindow()
    {
        EditorWindow.GetWindow(typeof(AnimMapBakerWindow));
        _baker = new AnimMapBaker();
        var shaderName = GraphicsSettings.renderPipelineAsset != null ? URPShader : BuiltInShader;

        _animMapShader = Shader.Find(shaderName);
    }
    private void OnGUI()
    {
        _targetGo = (GameObject)EditorGUILayout.ObjectField(_targetGo, typeof(GameObject), true);
        _subPath  = _targetGo == null ? _subPath : _targetGo.name;
        EditorGUILayout.LabelField(string.Format($"Output Path: {Path.Combine(_path, _subPath)}"));
        _path    = EditorGUILayout.TextField(_path);
        _subPath = EditorGUILayout.TextField(_subPath);

        _strategy = (SaveStrategy)EditorGUILayout.EnumPopup("Output Type:", _strategy);


        _isShadowEnabled = EditorGUILayout.Toggle("Enable Shadow", _isShadowEnabled);

        if (_isShadowEnabled)
        {
            var style = new GUIStyle(EditorStyles.label);
            style.normal.textColor = Color.yellow;

            EditorGUILayout.LabelField("Warning: Enabling shadows will cause additional draw calls to draw shadows.", style);

            _prevAnimMapShader = _animMapShader;
            _animMapShader     = Shader.Find(ShadowShader);
        }
        else if (_prevAnimMapShader != null)
        {
            _animMapShader = _prevAnimMapShader;
        }

        if (!GUILayout.Button("Bake"))
        {
            return;
        }

        if (_targetGo == null)
        {
            EditorUtility.DisplayDialog("err", "targetGo is null!", "OK");
            return;
        }

        if (_baker == null)
        {
            _baker = new AnimMapBaker();
        }

        _baker.SetAnimData(_targetGo);

        var list = _baker.Bake();

        if (list == null)
        {
            return;
        }
        foreach (var t in list)
        {
            var data = t;
            Save(ref data);
        }
    }
示例#5
0
    void OnGUI()
    {
        GUILayout.Label("Target Prefab");
        GameObject oldObj = targetGo;

        targetGo = (GameObject)EditorGUILayout.ObjectField(targetGo, typeof(GameObject), true);
        GUILayout.Label("Target Animation FBX");
        animationFBX = (GameObject)EditorGUILayout.ObjectField(animationFBX, typeof(GameObject), true);
        if (targetGo != oldGameObject)
        {
            oldGameObject = targetGo;
        }

        GUILayout.Label("RootBone GameObject");
        rootBone = (GameObject)EditorGUILayout.ObjectField(rootBone, typeof(GameObject), true);

        Object target = PrefabUtility.GetPrefabParent(targetGo);

        path = AssetDatabase.GetAssetPath(target);
        if (path == "")
        {
            path = AssetDatabase.GetAssetPath(targetGo);
        }
        int index = path.LastIndexOf("/");

        if (index >= 0)
        {
            path = path.Substring(7, index - 7);
        }

        EditorGUILayout.LabelField(string.Format("output path:{0}", path));
        path = EditorGUILayout.TextField(path);

        if (GUILayout.Button("Bake"))
        {
            if (targetGo == null)
            {
                EditorUtility.DisplayDialog("err", "targetGo is null!", "OK");
                return;
            }

            baker = new AnimMapBaker();

            baker.SetAnimData(targetGo, animationFBX, path);
            Dictionary <string, string> dic = new Dictionary <string, string>();
            Mesh             tarMesh        = null;
            List <BakedData> list           = baker.Bake(targetGo, animationFBX, rootBone, path, dic, ref tarMesh);

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    BakedData data = list[i];
                    Save(ref data, i, tarMesh);
                }
            }
        }
    }
    public static void ShowWindow()
    {
        editorWindow = EditorWindow.GetWindow(typeof(AnimMapBakerWindow));
        baker        = new AnimMapBaker();
        if (Selection.objects.Length != 0)
        {
            obj      = Selection.objects;
            objIndex = 0;
        }

        baking = false;
    }
示例#7
0
    private void OnGUI()
    {
        _targetGo = (GameObject)EditorGUILayout.ObjectField(_targetGo, typeof(GameObject), true);
        _subPath  = _targetGo == null ? _subPath : _targetGo.name;
        EditorGUILayout.LabelField(string.Format($"output path:{Path.Combine(_path, _subPath)}"));
        _path    = EditorGUILayout.TextField(_path);
        _subPath = EditorGUILayout.TextField(_subPath);

        _stratege = (SaveStrategy)EditorGUILayout.EnumPopup("output type:", _stratege);


        if (GUILayout.Button("Bake"))
        {
            if (_targetGo == null)
            {
                EditorUtility.DisplayDialog("err", "targetGo is null!", "OK");
                return;
            }

            if (_baker == null)
            {
                _baker = new AnimMapBaker();
            }

            if (_animMapShader == null)
            {
                _animMapShader = Shader.Find("XHH/AnimMapShader");
            }

            _baker.SetAnimData(_targetGo);

            var list = _baker.Bake();

            if (list == null)
            {
                return;
            }
            foreach (var t in list)
            {
                var data = t;
                Save(ref data);
            }
        }
    }
示例#8
0
 public static void ShowWindow()
 {
     EditorWindow.GetWindow(typeof(AnimMapBakerWindow));
     baker         = new AnimMapBaker();
     animMapShader = Shader.Find("chenjd/AnimMapShader");
 }
示例#9
0
    private void OnGUI()
    {
        _targetGo = (GameObject)EditorGUILayout.ObjectField(_targetGo, typeof(GameObject), true);
        if (_oldTargetGo != _targetGo)
        {
            _oldTargetGo = _targetGo;
            ResetAll();
        }
        _subPath = _targetGo == null ? _subPath : _targetGo.name;

        EditorGUILayout.HelpBox(string.Format($"Output Path : {Path.Combine(_path, _subPath)}"), MessageType.Info);
        _path    = EditorGUILayout.TextField(_path);
        _subPath = EditorGUILayout.TextField(_subPath);

        _stratege = (SaveStrategy)EditorGUILayout.EnumPopup("output type:", _stratege);

        _multipleRows = EditorGUILayout.Toggle("Set VAT to multiple rows", _multipleRows);

        showTransform = EditorGUILayout.Foldout(showTransform, "Bake Transform");
        if (showTransform)
        {
            EditorGUI.indentLevel += 2;
            _X = (Direction)EditorGUILayout.EnumPopup("Right", _X);
            _Y = (Direction)EditorGUILayout.EnumPopup("Up", _Y);
            _Z = (Direction)EditorGUILayout.EnumPopup("Forward", _Z);
            EditorGUI.indentLevel -= 2;
        }
        int[] xyz = new int[3];
        SetXYZInfo(xyz, _X, _Y, _Z);

        int         count        = 0;
        int         curClipFrame = 0;
        int         bakedColume  = 0;
        int         bakedRow     = 0;
        MessageType messageType  = MessageType.Warning;

        if (_targetGo)
        {
            SkinnedMeshRenderer smr  = _targetGo.GetComponentInChildren <SkinnedMeshRenderer>();
            Animation           anim = _targetGo.GetComponent <Animation>();

            count = smr ? smr.sharedMesh.vertexCount : 0;
            if (anim != null)
            {
                List <AnimationState> _animClips = new List <AnimationState>(anim.Cast <AnimationState>());
                curClipFrame = (int)(_animClips[0].clip.frameRate * _animClips[0].length);
            }

            bakedColume = Mathf.NextPowerOfTwo(count);
            bakedRow    = Mathf.ClosestPowerOfTwo(curClipFrame);

            if (_multipleRows)
            {
                bakedColume = (int)Mathf.Log(Mathf.NextPowerOfTwo(count), 2);
                bakedRow    = (int)Mathf.Log(Mathf.ClosestPowerOfTwo(curClipFrame), 2);
                int colHighOffset = (bakedColume - bakedRow) / 2;
                if (colHighOffset > 0)
                {
                    bakedColume -= colHighOffset;
                    bakedRow    += colHighOffset;
                }
                bakedColume = (int)Mathf.Pow(2, bakedColume);
                bakedRow    = (int)Mathf.Pow(2, bakedRow);
            }

            if (smr && anim)
            {
                messageType = MessageType.Info;
            }
        }
        bool clickBakeBTN = !GUILayout.Button("Bake");

        string smrS = count != 0 ? $"Vertex Count : {count}" : "SkinnedMeshRenderer Missing";
        string aniS = curClipFrame != 0 ? $"Animation Frame Count : {curClipFrame}" : "Animation Missing";

        EditorGUILayout.HelpBox(string.Format($"{smrS}\n{aniS}" +
                                              $"\nBaked Texture Output Size : {bakedColume} x {bakedRow}"),
                                messageType);

        EditorGUILayout.Space(10);
        showAdvanced = EditorGUILayout.Foldout(showAdvanced, "Advanced");
        if (showAdvanced)
        {
            EditorGUI.indentLevel += 2;
            _shader = EditorGUILayout.TextField("Shader Find", _shader);
            EditorGUI.indentLevel -= 2;
        }


        if (clickBakeBTN)
        {
            return;
        }
        if (_targetGo == null)
        {
            EditorUtility.DisplayDialog("err", "targetGo is null!", "OK");
            return;
        }

        if (_baker == null)
        {
            _baker = new AnimMapBaker();
        }

        _baker.SetAnimData(_targetGo, _multipleRows, xyz);

        EditorUtility.DisplayProgressBar("Bake Animation Texture", "baking...", 0.5f);
        List <BakedData> list = _baker.Bake();

        EditorUtility.DisplayProgressBar("Bake Animation Texture", "saving...", 0.8f);
        if (list == null)
        {
            return;
        }
        foreach (var t in list)
        {
            var data = t;
            Save(ref data);
        }
        EditorUtility.DisplayProgressBar("Bake Animation Texture", "complete...", 0.99f);
        EditorUtility.ClearProgressBar();
    }
示例#10
0
 public static void ResetAll()
 {
     _baker         = new AnimMapBaker();
     _animMapShader = Shader.Find(_shader);
 }
    void OnGUI()
    {
        if (animMapShader == null)
        {
            animMapShader = Shader.Find("chenjd/AnimMapShader");
        }

        if (obj != null && objIndex < obj.Length)
        {
            targetGo = obj[objIndex] as GameObject;
        }
        targetGo = (GameObject)EditorGUILayout.ObjectField(targetGo, typeof(GameObject), true);
        subPath  = targetGo == null ? subPath : targetGo.name;
        EditorGUILayout.LabelField(string.Format("保存路径output path:{0}", Path.Combine(path, subPath)));
        path    = EditorGUILayout.TextField(path);
        subPath = EditorGUILayout.TextField(subPath);

        stratege = (SaveStrategy)EditorGUILayout.EnumPopup("保存策略output type:", stratege);

        if (baking || GUILayout.Button("Bake"))
        {
            if (!AssetDatabase.IsValidFolder("Assets/" + path))
            {
                AssetDatabase.CreateFolder("Assets", path);
            }

            if (obj != null)
            {
                baking = (objIndex < obj.Length);
                if (!baking)
                {
                    obj      = null;
                    targetGo = null;
                    editorWindow.Close();
                    EditorUtility.DisplayDialog("", "批量处理结束", "OK");
                    return;
                }
            }
            if (targetGo == null)
            {
                editorWindow.Close();
                EditorUtility.DisplayDialog("err", "targetGo is null!", "OK");
                return;
            }

            if (baker == null)
            {
                baker = new AnimMapBaker();
            }

            baker.SetAnimData(targetGo);

            List <BakedData> list = baker.Bake();

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    BakedData data = list[i];
                    Save(ref data);
                }
            }

            objIndex += 1;
        }
    }
示例#12
0
 public static void ShowWindow()
 {
     EditorWindow.GetWindow(typeof(AnimMapBakerWindow));
     baker         = new AnimMapBaker();
     animMapShader = Shader.Find("Custom/CharactorShader");
 }