예제 #1
0
        public static bool Export(GameObject go, string path, Settings settings)
        {
            if (path == null || path.Length == 0 || go == null)
            {
                return(false);
            }

            var inst = new ObjExporter();

            inst.DoExport(go, path, settings);
            return(true);
        }
예제 #2
0
        void DrawInExportPanel()
        {
            var settings = m_target.settings;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical(GUILayout.Width(indentSize));
            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GUILayout.Width(c1Width));
            settings.inexportIndex = GUILayout.SelectionGrid(settings.inexportIndex, strInExport, 1);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GUILayout.Width(spaceSize));
            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();

            if (settings.inexportIndex == 0)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Convert To Vertex Color"))
                {
                    m_target.BakeToVertexColor(true);
                }
                if (GUILayout.Button("Convert From Vertex Color"))
                {
                    m_target.LoadVertexColor(true);
                }
                GUILayout.EndHorizontal();
            }
            else if (settings.inexportIndex == 1)
            {
                settings.bakeFormat            = (ImageFormat)EditorGUILayout.EnumPopup("Format", settings.bakeFormat);
                settings.bakeWidth             = EditorGUILayout.IntField("Width", settings.bakeWidth);
                settings.bakeHeight            = EditorGUILayout.IntField("Height", settings.bakeHeight);
                settings.bakeSeparateSubmeshes = EditorGUILayout.Toggle("Separate Submeshes", settings.bakeSeparateSubmeshes);

                if (GUILayout.Button("Bake"))
                {
                    string path = settings.bakeFormat == ImageFormat.PNG ?
                                  EditorUtility.SaveFilePanel("Export .png file", "", SanitizeForFileName(m_target.name) + "_normal", "png") :
                                  EditorUtility.SaveFilePanel("Export .exr file", "", SanitizeForFileName(m_target.name) + "_normal", "exr");
                    m_target.BakeToTexture(settings.bakeWidth, settings.bakeHeight, path, settings.bakeFormat, settings.bakeSeparateSubmeshes);
                }
            }
            else if (settings.inexportIndex == 2)
            {
                settings.bakeSource = EditorGUILayout.ObjectField("Source Texture", settings.bakeSource, typeof(Texture), true) as Texture;

                if (GUILayout.Button("Load"))
                {
                    m_target.LoadTexture(settings.bakeSource, true);
                }
            }
            else if (settings.inexportIndex == 3)
            {
                if (GUILayout.Button("Export .asset file"))
                {
                    string path = EditorUtility.SaveFilePanel("Export .asset file", "Assets", SanitizeForFileName(m_target.name), "asset");
                    if (path.Length > 0)
                    {
                        var dataPath = Application.dataPath;
                        if (!path.StartsWith(dataPath))
                        {
                            Debug.LogError("Invalid path: Path must be under " + dataPath);
                        }
                        else
                        {
                            path = path.Replace(dataPath, "Assets");
                            AssetDatabase.CreateAsset(Instantiate(m_target.mesh), path);
                            Debug.Log("Asset exported: " + path);
                        }
                    }
                }
            }
            else if (settings.inexportIndex == 4)
            {
                settings.objFlipHandedness  = EditorGUILayout.Toggle("Flip Handedness", settings.objFlipHandedness);
                settings.objFlipFaces       = EditorGUILayout.Toggle("Flip Faces", settings.objFlipFaces);
                settings.objMakeSubmeshes   = EditorGUILayout.Toggle("Make Submeshes", settings.objMakeSubmeshes);
                settings.objApplyTransform  = EditorGUILayout.Toggle("Apply Transform", settings.objApplyTransform);
                settings.objIncludeChildren = EditorGUILayout.Toggle("Include Children", settings.objIncludeChildren);

                if (GUILayout.Button("Export .obj file"))
                {
                    string path = EditorUtility.SaveFilePanel("Export .obj file", "", SanitizeForFileName(m_target.name), "obj");
                    ObjExporter.Export(m_target.gameObject, path, new ObjExporter.Settings
                    {
                        flipFaces       = settings.objFlipFaces,
                        flipHandedness  = settings.objFlipHandedness,
                        includeChildren = settings.objIncludeChildren,
                        makeSubmeshes   = settings.objMakeSubmeshes,
                        applyTransform  = settings.objApplyTransform,
                    });
                }
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        }