public static odfMaterial CreateMaterial(ImportedMaterial impMat, ObjectID id) { odfMaterial odfMat = new odfMaterial(new ObjectName(impMat.Name, null), id); odfMat.Diffuse = impMat.Diffuse; odfMat.Ambient = impMat.Ambient; odfMat.Specular = impMat.Specular; odfMat.Emissive = impMat.Emissive; odfMat.SpecularPower = impMat.Power; return odfMat; }
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"); } }
public void MergeMaterial(odfMaterial srcMat, odfParser srcParser) { odfMaterial newMat = srcMat.Clone(); bool found = false; for (int i = 0; i < Parser.MaterialSection.Count; i++) { odfMaterial oldMat = Parser.MaterialSection[i]; if (oldMat.Name == newMat.Name) { newMat.Id = oldMat.Id; Parser.MaterialSection.RemoveChild(i); Parser.MaterialSection.InsertChild(i, newMat); found = true; break; } } if (!found) { Parser.MaterialSection.AddChild(newMat); if (Parser.IsUsedID(newMat.Id)) { newMat.Id = Parser.GetNewID(typeof(odfMaterial)); Report.ReportLog("Warning! Material " + newMat.Name + " got a new ID : " + newMat.Id); } else Parser.UsedIDs.Add((int)newMat.Id, typeof(odfMaterial)); } if (Parser.MataSection != null && srcParser.MataSection != null) { odfMaterialList newMatList = odf.FindMaterialList(newMat.Id, srcParser.MataSection); if (newMatList != null) { odfMaterialList matList = odf.FindMaterialList(newMat.Id, Parser.MataSection); if (matList != null) { int originalIdx = Parser.MataSection.IndexOf(matList); Parser.MataSection.RemoveChild(originalIdx); Parser.MataSection.InsertChild(originalIdx, newMatList); } else Parser.MataSection.AddChild(newMatList); } } }