Exemple #1
0
            private void Export(DirectoryInfo dir)
            {
                try
                {
                    List <MeshRenderer> meshList = new List <MeshRenderer>(1);
                    meshList.Add(morphObj);
                    Mesh mesh = Operations.GetMesh(morphObj);

                    colorLists = new bool[mesh.m_Shapes.shapes.Count][];
                    vertLists  = new List <ImportedVertex> [mesh.m_Shapes.shapes.Count];
                    for (int i = 0; i < mesh.m_Shapes.shapes.Count; i++)
                    {
                        Plugins.UnityConverter conv        = new Plugins.UnityConverter(parser, meshList, false, false);
                        ImportedMesh           meshObjBase = conv.MeshList[0];
                        if (faceList == null)
                        {
                            faceList = meshObjBase.SubmeshList[0].FaceList;
                        }

                        List <ImportedVertex> vertList = conv.MeshList[0].SubmeshList[0].VertexList;
                        vertLists[i]  = vertList;
                        colorLists[i] = new bool[meshObjBase.SubmeshList[0].VertexList.Count];
                        int lastVertIndex = (int)(mesh.m_Shapes.shapes[i].firstVertex + mesh.m_Shapes.shapes[i].vertexCount);
                        for (int j = (int)mesh.m_Shapes.shapes[i].firstVertex; j < lastVertIndex; j++)
                        {
                            BlendShapeVertex srcVert = mesh.m_Shapes.vertices[j];
                            ImportedVertex   vert    = vertList[(int)srcVert.index];
                            vert.Position += srcVert.vertex;
                            colorLists[i][(int)srcVert.index] = true;
                        }
                    }

                    string   dest = Utility.GetDestFile(dir, morphObj.m_GameObject.instance.m_Name + "-" + mesh.m_Name + "-", ".morph.mqo");
                    Material mat  = morphObj.m_Materials[0].instance;
                    Export(dest, mat, mat.m_SavedProperties.m_TexEnvs[0].Value.m_Texture.instance);
                    foreach (Texture2D tex in usedTextures)
                    {
                        try
                        {
                            tex.Export(dir.FullName);
                        }
                        catch (Exception ex)
                        {
                            Utility.ReportException(ex);
                        }
                    }
                    Report.ReportLog("Finished exporting morph to " + dest);
                }
                catch (Exception ex)
                {
                    Report.ReportLog("Error exporting morph: " + ex.Message);
                }
            }
Exemple #2
0
            private static List<Texture2D> Export(string dest, Animator parser, List<MeshRenderer> meshes, bool worldCoords)
            {
                DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(dest));
                if (!dir.Exists)
                {
                    dir.Create();
                }

                Plugins.UnityConverter conv = new Plugins.UnityConverter(parser, meshes, false, false);
                List<Material> materialList = new List<Material>(meshes.Count);
                using (StreamWriter writer = new StreamWriter(dest, false))
                {
                    for (int i = 0; i < meshes.Count; i++)
                    {
                        MeshRenderer meshRenderer = meshes[i];
                        ImportedMesh meshListSome = conv.MeshList[i];
                        for (int j = 0; j < meshListSome.SubmeshList.Count; j++)
                        {
                            Material mat = meshRenderer.m_Materials[j].instance;
                            if (mat != null)
                            {
                                if (!materialList.Contains(mat))
                                {
                                    materialList.Add(mat);
                                }
                            }
                            else
                            {
                                Report.ReportLog("Warning: Mesh " + meshes[i].m_GameObject.instance.m_Name + " Object " + j + " has an invalid material");
                            }
                        }
                    }

                    writer.WriteLine("Metasequoia Document");
                    writer.WriteLine("Format Text Ver 1.0");
                    writer.WriteLine();
                    writer.WriteLine("Material " + materialList.Count + " {");
                    for (int matIdx = 0; matIdx < materialList.Count; matIdx++)
                    {
                        Material mat = materialList[matIdx];
                        string s = "\t\"" + mat.m_Name + "\" col(0.800 0.800 0.800 1.000) dif(0.500) amb(0.100) emi(0.500) spc(0.100) power(30.00)";
                        try
                        {
                            Texture2D tex = mat.m_SavedProperties.m_TexEnvs[0].Value.m_Texture.instance;
                            for (int i = 1; i < mat.m_SavedProperties.m_TexEnvs.Count; i++)
                            {
                                var texProp = mat.m_SavedProperties.m_TexEnvs[i];
                                if (texProp.Key.name == "_MainTex")
                                {
                                    tex = texProp.Value.m_Texture.instance;
                                    break;
                                }
                            }
                            if (tex != null)
                            {
                                string matTexName = tex.m_Name + "-" + tex.m_TextureFormat;
                                string extension = tex.m_TextureFormat == TextureFormat.DXT1 || tex.m_TextureFormat == TextureFormat.DXT5 ? ".dds" : ".tga";
                                s += " tex(\"" + matTexName + extension + "\")";
                            }
                        }
                        catch { }
                        writer.WriteLine(s);
                    }
                    writer.WriteLine("}");

                    Random rand = new Random();
                    for (int i = 0; i < meshes.Count; i++)
                    {
                        MeshRenderer mesh = meshes[i];
                        if (worldCoords)
                        {
                            Transform parent = Operations.FindFrame(meshes[i].m_GameObject.instance.m_Name, parser.RootTransform);
                            conv.WorldCoordinates(i, Transform.WorldTransform(parent));
                        }

                        string meshName = mesh.m_GameObject.instance.m_Name;
                        ImportedMesh meshListSome = conv.MeshList[i];
                        for (int j = 0; j < meshListSome.SubmeshList.Count; j++)
                        {
                            ImportedSubmesh meshObj = meshListSome.SubmeshList[j];
                            Material mat = mesh.m_Materials[j].instance;
                            int mqoMatIdx = -1;
                            if (mat != null)
                            {
                                mqoMatIdx = materialList.IndexOf(mat);
                            }
                            float[] color = new float[3];
                            for (int k = 0; k < color.Length; k++)
                            {
                                color[k] = (float)((rand.NextDouble() / 2) + 0.5);
                            }

                            string mqoName = meshName + "[" + j + "]";
                            if (worldCoords)
                            {
                                mqoName += "[W]";
                            }
                            writer.WriteLine("Object \"" + mqoName + "\" {");
                            writer.WriteLine("\tshading 1");
                            writer.WriteLine("\tcolor " + color[0].ToFloatString() + " " + color[1].ToFloatString() + " " + color[2].ToFloatString());
                            writer.WriteLine("\tcolor_type 1");

                            List<ImportedVertex> vertList = meshObj.VertexList;
                            List<ImportedFace> faceList = meshObj.FaceList;
                            SB3Utility.Mqo.ExporterCommon.WriteMeshObject(writer, vertList, faceList, mqoMatIdx, null);
                            writer.WriteLine("}");
                        }
                    }
                    writer.WriteLine("Eof");
                }

                List<Texture2D> usedTextures = new List<Texture2D>(meshes.Count);
                foreach (Material mat in materialList)
                {
                    try
                    {
                        Texture2D matTex = mat.m_SavedProperties.m_TexEnvs[0].Value.m_Texture.instance;
                        for (int i = 1; i < mat.m_SavedProperties.m_TexEnvs.Count; i++)
                        {
                            var texProp = mat.m_SavedProperties.m_TexEnvs[i];
                            if (texProp.Key.name == "_MainTex")
                            {
                                matTex = texProp.Value.m_Texture.instance;
                                break;
                            }
                        }
                        if (matTex != null && !usedTextures.Contains(matTex))
                        {
                            usedTextures.Add(matTex);
                        }
                    }
                    catch { }
                }
                return usedTextures;
            }
Exemple #3
0
            private void Export(DirectoryInfo dir)
            {
                try
                {
                    List<MeshRenderer> meshList = new List<MeshRenderer>(1);
                    meshList.Add(morphObj);
                    Mesh mesh = Operations.GetMesh(morphObj);

                    colorLists = new bool[mesh.m_Shapes.shapes.Count][];
                    vertLists = new List<ImportedVertex>[mesh.m_Shapes.shapes.Count];
                    for (int i = 0; i < mesh.m_Shapes.shapes.Count; i++)
                    {
                        Plugins.UnityConverter conv = new Plugins.UnityConverter(parser, meshList, false, false);
                        ImportedMesh meshObjBase = conv.MeshList[0];
                        if (faceList == null)
                        {
                            faceList = meshObjBase.SubmeshList[0].FaceList;
                        }

                        List<ImportedVertex> vertList = conv.MeshList[0].SubmeshList[0].VertexList;
                        vertLists[i] = vertList;
                        colorLists[i] = new bool[meshObjBase.SubmeshList[0].VertexList.Count];
                        int lastVertIndex = (int)(mesh.m_Shapes.shapes[i].firstVertex + mesh.m_Shapes.shapes[i].vertexCount);
                        for (int j = (int)mesh.m_Shapes.shapes[i].firstVertex; j < lastVertIndex; j++)
                        {
                            BlendShapeVertex srcVert = mesh.m_Shapes.vertices[j];
                            ImportedVertex vert = vertList[(int)srcVert.index];
                            vert.Position += srcVert.vertex;
                            colorLists[i][(int)srcVert.index] = true;
                        }
                    }

                    string dest = Utility.GetDestFile(dir, morphObj.m_GameObject.instance.m_Name + "-" + mesh.m_Name + "-", ".morph.mqo");
                    Material mat = morphObj.m_Materials[0].instance;
                    Texture2D matTex = mat.m_SavedProperties.m_TexEnvs[0].Value.m_Texture.instance;
                    for (int i = 1; i < mat.m_SavedProperties.m_TexEnvs.Count; i++)
                    {
                        var texProp = mat.m_SavedProperties.m_TexEnvs[i];
                        if (texProp.Key.name == "_MainTex")
                        {
                            matTex = texProp.Value.m_Texture.instance;
                            break;
                        }
                    }
                    Export(dest, mat, matTex);
                    foreach (Texture2D tex in usedTextures)
                    {
                        try
                        {
                            tex.Export(dir.FullName);
                        }
                        catch (Exception ex)
                        {
                            Utility.ReportException(ex);
                        }
                    }
                    Report.ReportLog("Finished exporting morph to " + dest);
                }
                catch (Exception ex)
                {
                    Report.ReportLog("Error exporting morph: " + ex.Message);
                }
            }
Exemple #4
0
            private static List <Texture2D> Export(string dest, Animator parser, List <MeshRenderer> meshes, bool worldCoords)
            {
                DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(dest));

                if (!dir.Exists)
                {
                    dir.Create();
                }

                Plugins.UnityConverter conv         = new Plugins.UnityConverter(parser, meshes, false, false);
                List <Material>        materialList = new List <Material>(meshes.Count);

                using (StreamWriter writer = new StreamWriter(dest, false))
                {
                    for (int i = 0; i < meshes.Count; i++)
                    {
                        MeshRenderer meshRenderer = meshes[i];
                        ImportedMesh meshListSome = conv.MeshList[i];
                        for (int j = 0; j < meshListSome.SubmeshList.Count; j++)
                        {
                            Material mat = meshRenderer.m_Materials[j].instance;
                            if (mat != null)
                            {
                                if (!materialList.Contains(mat))
                                {
                                    materialList.Add(mat);
                                }
                            }
                            else
                            {
                                Report.ReportLog("Warning: Mesh " + meshes[i].m_GameObject.instance.m_Name + " Object " + j + " has an invalid material");
                            }
                        }
                    }

                    writer.WriteLine("Metasequoia Document");
                    writer.WriteLine("Format Text Ver 1.0");
                    writer.WriteLine();
                    writer.WriteLine("Material " + materialList.Count + " {");
                    for (int matIdx = 0; matIdx < materialList.Count; matIdx++)
                    {
                        Material mat = materialList[matIdx];
                        string   s   = "\t\"" + mat.m_Name + "\" col(0.800 0.800 0.800 1.000) dif(0.500) amb(0.100) emi(0.500) spc(0.100) power(30.00)";
                        try
                        {
                            Texture2D tex = mat.m_SavedProperties.m_TexEnvs[0].Value.m_Texture.instance;
                            for (int i = 1; i < mat.m_SavedProperties.m_TexEnvs.Count; i++)
                            {
                                var texProp = mat.m_SavedProperties.m_TexEnvs[i];
                                if (texProp.Key.name == "_MainTex")
                                {
                                    tex = texProp.Value.m_Texture.instance;
                                    break;
                                }
                            }
                            if (tex != null)
                            {
                                string matTexName = tex.m_Name + "-" + tex.m_TextureFormat;
                                string extension  = tex.m_TextureFormat == TextureFormat.DXT1 || tex.m_TextureFormat == TextureFormat.DXT5 ? ".dds" : ".tga";
                                s += " tex(\"" + matTexName + extension + "\")";
                            }
                        }
                        catch { }
                        writer.WriteLine(s);
                    }
                    writer.WriteLine("}");

                    Random rand = new Random();
                    for (int i = 0; i < meshes.Count; i++)
                    {
                        MeshRenderer mesh = meshes[i];
                        if (worldCoords)
                        {
                            Transform parent = Operations.FindFrame(meshes[i].m_GameObject.instance.m_Name, parser.RootTransform);
                            conv.WorldCoordinates(i, Transform.WorldTransform(parent));
                        }

                        string       meshName     = mesh.m_GameObject.instance.m_Name;
                        ImportedMesh meshListSome = conv.MeshList[i];
                        for (int j = 0; j < meshListSome.SubmeshList.Count; j++)
                        {
                            ImportedSubmesh meshObj   = meshListSome.SubmeshList[j];
                            Material        mat       = mesh.m_Materials[j].instance;
                            int             mqoMatIdx = -1;
                            if (mat != null)
                            {
                                mqoMatIdx = materialList.IndexOf(mat);
                            }
                            float[] color = new float[3];
                            for (int k = 0; k < color.Length; k++)
                            {
                                color[k] = (float)((rand.NextDouble() / 2) + 0.5);
                            }

                            string mqoName = meshName + "[" + j + "]";
                            if (worldCoords)
                            {
                                mqoName += "[W]";
                            }
                            writer.WriteLine("Object \"" + mqoName + "\" {");
                            writer.WriteLine("\tshading 1");
                            writer.WriteLine("\tcolor " + color[0].ToFloatString() + " " + color[1].ToFloatString() + " " + color[2].ToFloatString());
                            writer.WriteLine("\tcolor_type 1");

                            List <ImportedVertex> vertList = meshObj.VertexList;
                            List <ImportedFace>   faceList = meshObj.FaceList;
                            SB3Utility.Mqo.ExporterCommon.WriteMeshObject(writer, vertList, faceList, mqoMatIdx, null);
                            writer.WriteLine("}");
                        }
                    }
                    writer.WriteLine("Eof");
                }

                List <Texture2D> usedTextures = new List <Texture2D>(meshes.Count);

                foreach (Material mat in materialList)
                {
                    try
                    {
                        Texture2D matTex = mat.m_SavedProperties.m_TexEnvs[0].Value.m_Texture.instance;
                        for (int i = 1; i < mat.m_SavedProperties.m_TexEnvs.Count; i++)
                        {
                            var texProp = mat.m_SavedProperties.m_TexEnvs[i];
                            if (texProp.Key.name == "_MainTex")
                            {
                                matTex = texProp.Value.m_Texture.instance;
                                break;
                            }
                        }
                        if (matTex != null && !usedTextures.Contains(matTex))
                        {
                            usedTextures.Add(matTex);
                        }
                    }
                    catch { }
                }
                return(usedTextures);
            }