Beispiel #1
0
        public static odfTexture CreateTexture(ImportedTexture impTex, ObjectID id, int format, string odfPath)
        {
            odfTexture odfTex = new odfTexture(new ObjectName(impTex.Name, null), id, format);
            odfTex.TextureFile = new ObjectName(impTex.Name, null);

            string destPath = odfPath + @"\" + odfTex.TextureFile;
            DirectoryInfo dir = new DirectoryInfo(odfPath);
            if (!dir.Exists)
            {
                dir.Create();
            }

            if (File.Exists(destPath))
            {
                string backup = Utility.GetDestFile(dir, Path.GetFileNameWithoutExtension(destPath) + ".bak", Path.GetExtension(odfTex.TextureFile));
                File.Move(destPath, backup);
            }

            odf.ImportTexture(impTex, destPath);

            return odfTex;
        }
Beispiel #2
0
            private void Export(string dest, odfMaterial mat, odfTexture tex)
            {
                DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(dest));
                if (!dir.Exists)
                {
                    dir.Create();
                }

                usedTextures = new List<odfTexture>(parser.TextureSection.Count);
                using (StreamWriter writer = new StreamWriter(dest, false))
                {
                    writer.WriteLine("Metasequoia Document");
                    writer.WriteLine("Format Text Ver 1.0");
                    writer.WriteLine();

                    if (mat != null)
                    {
                        writer.WriteLine("Material 1 {");
                        string s = "\t\"" + mat.Name + "\" vcol(1) col(0.800 0.800 0.800 1.000) dif(0.500) amb(0.100) emi(0.500) spc(0.100) power(30.00)";
                        if (tex != null)
                        {
                            s += " tex(\"" + tex.TextureFile + "\")";
                            usedTextures.Add(tex);
                        }
                        writer.WriteLine(s);
                        writer.WriteLine("}");
                    }

                    Random rand = new Random();
                    int vertListIdx = 0;
                    for (int i = 0; i < morphObj.Count; i++)
                    {
                        if (skipUnusedProfiles)
                        {
                            bool skip = true;
                            for (int j = 0; j < morphObj.SelectorList.Count; j++)
                            {
                                if (morphObj.SelectorList[j].ProfileIndex == i)
                                {
                                    skip = false;
                                    break;
                                }
                            }
                            if (skip)
                                continue;
                        }

                        float[] color = new float[3];
                        for (int k = 0; k < color.Length; k++)
                        {
                            color[k] = (float)((rand.NextDouble() / 2) + 0.5);
                        }

                        writer.WriteLine("Object \"" + morphObj[i].Name + "\" {");
                        writer.WriteLine("\tvisible 0");
                        writer.WriteLine("\tshading 1");
                        writer.WriteLine("\tcolor " + color[0].ToFloatString() + " " + color[1].ToFloatString() + " " + color[2].ToFloatString());
                        writer.WriteLine("\tcolor_type 1");
                        SB3Utility.Mqo.ExporterCommon.WriteMeshObject(writer, vertLists[vertListIdx++], faceList, mat != null ? 0 : -1, colorVertex);
                        writer.WriteLine("}");
                    }

                    writer.WriteLine("Eof");
                }
            }
Beispiel #3
0
        public void MergeTexture(odfTexture tex, odfParser srcParser)
        {
            ImportedTexture impTex = new ImportedTexture(Path.GetDirectoryName(srcParser.ODFPath) + @"\" + tex.TextureFile);

            odfTexture newTex = odf.CreateTexture(impTex, null, Parser.TextureSection._FormatType, Path.GetDirectoryName(Parser.ODFPath));
            newTex = tex.Clone(Parser.TextureSection._FormatType);

            bool found = false;
            for (int i = 0; i < Parser.TextureSection.Count; i++)
            {
                var oldTex = Parser.TextureSection[i];
                if (oldTex.Name == newTex.Name)
                {
                    newTex.Id = oldTex.Id;
                    Parser.TextureSection.RemoveChild(i);
                    Parser.TextureSection.InsertChild(i, newTex);
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                Parser.TextureSection.AddChild(newTex);
                if (Parser.IsUsedID(newTex.Id))
                {
                    newTex.Id = Parser.GetNewID(typeof(odfTexture));
                    Report.ReportLog("Warning! Texture " + newTex.Name + " got a new ID : " + newTex.Id);
                }
                else
                    Parser.UsedIDs.Add((int)newTex.Id, typeof(odfTexture));
            }
        }