public JSONObject GetAvatarRootNodeJSON(GameObject gameObject, GameObject animatorGameObject, ref int id, ref bool succ, string path = "")
        {
            string avatarPath = Path.GetFullPath(Directory.GetParent(Application.dataPath) + "/" + AssetDatabase.GetAssetPath(avatar.GetInstanceID()));

            if (Path.GetExtension(avatarPath).ToLower() == ".fbx")
            {
                string toolDir = WXConfig.GetModelToolPath();;

                if (toolDir != null)
                {
                    string result = WXUtility.ExecProcess(
                        toolDir,
                        "\"" + avatarPath + "\"",
                        out succ
                        );
                    if (succ)
                    {
                        return(JSONObject.Create(result));
                    }
                }
            }
            else
            {
                EditorUtility.DisplayDialog("Error", "导出的模型格式不支持", "确定");
            }
            succ = false;
            JSONObject rootNode = GetAvatarNodeData(gameObject, animatorGameObject, ref id, path);

            return(rootNode);
        }
Exemplo n.º 2
0
        public JSONObject GetSkinPaths(string name, ref bool succ)
        {
            Transform trans    = renderer.transform;
            Animator  animator = trans.GetComponent(typeof(Animator)) as Animator;

            while (!animator && trans)
            {
                trans = trans.parent;
                if (trans)
                {
                    animator = trans.GetComponent(typeof(Animator)) as Animator;
                }
            }
            JSONObject bonesObject = new JSONObject(JSONObject.Type.ARRAY);

            if (animator)
            {
                string filePath = Path.GetFullPath(Directory.GetParent(Application.dataPath) + "/" + AssetDatabase.GetAssetPath(renderer.sharedMesh.GetInstanceID()));
                if (Path.GetExtension(filePath).ToLower() == ".fbx")
                {
                    string toolDir = WXConfig.GetModelToolPath();
                    if (toolDir != null)
                    {
                        string result = WXUtility.ExecProcess(
                            toolDir,
                            "\"" + filePath + "\" --skin=\"" + name + "\"",
                            out succ
                            );
                        if (succ)
                        {
                            return(JSONObject.Create(result));
                        }
                        else
                        {
                            EditorUtility.DisplayDialog("Error", "导出骨骼模型失败:" + result, "确定");
                        }
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("Error", "模型导出工具缺失", "确定");
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog("Error", "导出的模型格式不支持", "确定");
                }
                succ = false;
                for (int i = 0; i < renderer.bones.Length; i++)
                {
                    Transform     node      = renderer.bones[i];
                    List <string> pathArray = new List <string>();
                    while (node != null && node != trans)
                    {
                        pathArray.Add(node.name);
                        node = node.parent;
                    }
                    if (node != null)
                    {
                        pathArray.Reverse();
                        bonesObject.Add("/" + String.Join("/", pathArray.ToArray()));
                    }
                }
            }
            return(bonesObject);
        }
        public JSONObject GetSkinPaths(string name, ref bool succ)
        {
            Transform trans    = renderer.transform;
            Animator  animator = trans.GetComponent(typeof(Animator)) as Animator;

            while (!animator && trans)
            {
                trans = trans.parent;
                if (trans)
                {
                    animator = trans.GetComponent(typeof(Animator)) as Animator;
                }
            }
            if (animator)
            {
                string filePath = Path.GetFullPath(Directory.GetParent(Application.dataPath) + "/" + AssetDatabase.GetAssetPath(renderer.sharedMesh.GetInstanceID()));
                if (Path.GetExtension(filePath).ToLower() == ".fbx")
                {
                    bool          useFBXSDK = false;
                    AssetImporter importer  = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(renderer.sharedMesh.GetInstanceID()));
                    ModelImporter mImporter = importer as ModelImporter;
                    if (mImporter != null && mImporter.optimizeGameObjects)
                    {
                        useFBXSDK = true;
                    }

                    if (useFBXSDK)
                    {
                        string toolDir = WXConfig.GetModelToolPath();
                        if (toolDir != null)
                        {
                            string result = WXUtility.ExecProcess(
                                toolDir,
                                "\"" + filePath + "\" --skin=\"" + name + "\"",
                                out succ
                                );
                            if (succ)
                            {
                                return(JSONObject.Create(result));
                            }
                            else
                            {
                                ErrorUtil.ExportErrorReporter.create()
                                .setGameObject(trans.gameObject)
                                .setResource(this)
                                .error(ErrorUtil.ErrorCode.SkinnedMesh_FBXToolInvokeFailed, "导出骨骼模型失败:" + result);
                            }
                        }
                        else
                        {
                            ErrorUtil.ExportErrorReporter.create()
                            .setGameObject(trans.gameObject)
                            .setResource(this)
                            .error(ErrorUtil.ErrorCode.SkinnedMesh_FBXToolMissed, "模型导出工具缺失");
                        }
                    }
                    else
                    {
                        return(GetSkinPathsOnScene(trans));
                    }
                }
                else
                {
                    ErrorUtil.ExportErrorReporter.create()
                    .setGameObject(trans.gameObject)
                    .setResource(this)
                    .error(ErrorUtil.ErrorCode.SkinnedMesh_MeshFormatUnsupported, "导出的模型格式不支持");
                }
                succ = false;
                return(GetSkinPathsOnScene(trans));
            }
            else
            {
                ErrorUtil.ExportErrorReporter.create()
                .setGameObject(renderer.gameObject)
                .setResource(this)
                .error(ErrorUtil.ErrorCode.SkinnedMesh_AnimatorNotFound, "MeshRenderer导出的时候没有找到对应Animator");
            }
            return(new JSONObject(JSONObject.Type.OBJECT));
        }