/// <summary> /// Parses the shell information for a 3DReferenceRep out of the xml document into the internal representation. /// the methods opens external 3DReferenceRep files automatically. /// </summary> /// <param name="threeDReferenceRepXmlElement">The 3DReferenceRep xml representation with all attributes and sup nodes</param> /// <param name="nameOfExternalRepFileDiscription"> /// name of the external 3DReferenceRep xml file, is empty if the /// representation is in the same file. /// </param> /// <param name="archive">The unziped file archive of the 3dxml model</param> /// <returns>A Shell of a Mesh, which is holding the trinagular information.</returns> private static Shell GetShell(XElement threeDReferenceRepXmlElement, string nameOfExternalRepFileDiscription, IThreeDXMLArchive archive) { XDocument xmlReferenceRep; IList <Triangle> triangles = new List <Triangle>(); if (nameOfExternalRepFileDiscription != null && nameOfExternalRepFileDiscription.Any()) { xmlReferenceRep = archive.GetNextDocument(ParseUtility.CleanUpFileName(nameOfExternalRepFileDiscription)); } else { xmlReferenceRep = threeDReferenceRepXmlElement.Document; } var bagReps = GetBagRepXmlElements(xmlReferenceRep); foreach (var bagRep in bagReps) { IList <XElement> faces = bagRep.Descendants("{http://www.3ds.com/xsd/3DXML}Faces") .Where(x => x.Parent.Name.LocalName.ToLower() != "polygonallod") .ToList(); var verticies = GetVerticesFromXml(bagRep); foreach (var face in faces.Elements("{http://www.3ds.com/xsd/3DXML}Face")) { triangles = triangles.Concat(GetTrianglesFromXml(face, verticies)).ToList(); triangles = triangles.Concat(GetFansFromXml(face, verticies)).ToList(); triangles = triangles.Concat(GetStripsFromXml(face, verticies)).ToList(); } } return(new Shell(triangles)); }
/// <summary> /// The main entrance point for parsing a 3Dreferencerep. The current supported representation is "Tessellated". /// </summary> /// <param name="xml">the xml manifest of the 3dxml model</param> /// <param name="archive">The unziped file archive of the 3dxml model</param> /// <throw name="FormatNotSupportedException"> /// If the 3DReferenceRep is in a not supported representation this Eception will /// be thrown. /// </throw> /// <throw name="ArgumentException"> /// If the given XDocument does not hold any information about 3DReferenceReps this /// exception will be thrown. /// </throw> /// <returns> /// A list of ReferenceRep objects, with shell informaton, Id, Referencetype and other fields: Name, Version, Usage. /// Note that the other fields can be empty or null. /// </returns> public static IList <ReferenceRep> Parse3DRepresentation(XDocument xml, IThreeDXMLArchive archive) { IList <ReferenceRep> threeDRepresentations = new List <ReferenceRep>(); var xmlReferenceReps = xml.Root.Descendants("{http://www.3ds.com/xsd/3DXML}ReferenceRep"); if ( xmlReferenceReps.All( x => x.Attribute("format").Value.ToLower() == Supported3DRepFormats.Tessellated.ToString().ToLower())) { foreach (var rep in xmlReferenceReps) { threeDRepresentations.Add(Parse3DTessellatedRepresentation(rep, archive)); } } else { var format = xmlReferenceReps.Descendants("ReferenceRep").First().Attribute("format").Value; if (format.Length <= 0) { throw new ArgumentException( "The given file does not hold any information about Reference3DReps, please make sure the file archive is valid."); } throw new FormatNotSupportedException(string.Format( @"The importer cant understand the given 3DReferenceRep format {0}. Try using a representation with a supported format or contact the developers." , format)); } return(threeDRepresentations); }
/// <summary> /// Reads the manifest(the entry point for the 3Dxml parsing) and datamines where to start. /// </summary> /// <param name="archive">The unziped file archive of the 3dxml model</param> /// <returns></returns> public static XDocument ReadManifest(IThreeDXMLArchive archiv) { var manifest = archiv.GetManifest(); //check if the manifest contains the asset information, if the root element is not the manifest then load and return it. var rootElement = manifest.Root.Element("Root"); if (rootElement != null && !rootElement.IsEmpty) { manifest = archiv.GetNextDocument(CleanUpFileName(rootElement.Value)); } return(manifest); }
/// <summary> /// This methods is the main entry point for 3DReferenceReps in the Tessellated format. /// If the Rep has LOD information the most accurate mesh will be parsed the rest will be droped. /// </summary> /// <param name="threeDReferenceRepXmlElement">The 3DReferenceRep xml representation with all attributes and sup nodes</param> /// <param name="archive">The unziped file archive of the 3dxml model</param> /// <returns> /// A ReferenceRep objects, with shell informaton, Id, Referencetype and other fields: Name, Version, Usage. /// Note that the other fields can be empty or null. /// </returns> private static ReferenceRep Parse3DTessellatedRepresentation(XElement threeDReferenceRepXmlElement, IThreeDXMLArchive archive) { var nameOfExternalRepFileDiscription = ""; var referenceRep = new ReferenceRep(); foreach (var attribut in threeDReferenceRepXmlElement.Attributes()) { switch (attribut.Name.LocalName.ToLower()) { case "id": referenceRep.Id = Convert.ToInt32(attribut.Value); break; case "name": referenceRep.Name = attribut.Value; break; case "type": referenceRep.ReferenceType = attribut.Value; break; case "version": referenceRep.Version = attribut.Value; break; case "associatedfile": nameOfExternalRepFileDiscription = attribut.Value; break; default: break; } } referenceRep.Shell = GetShell(threeDReferenceRepXmlElement, nameOfExternalRepFileDiscription, archive); return(referenceRep); }
private XDocument ReadManifest(IThreeDXMLArchive fileArchive) { return ParseUtility.ReadManifest(fileArchive); }
private IList<ReferenceRep> ParseAssetRepresentation(XDocument xml, IThreeDXMLArchive archive) { return ParseReferenceRepUsecase.Parse3DRepresentation(xml, archive); }
private XDocument ReadManifest(IThreeDXMLArchive fileArchive) { return(ParseUtility.ReadManifest(fileArchive)); }
private IList <ReferenceRep> ParseAssetRepresentation(XDocument xml, IThreeDXMLArchive archive) { return(ParseReferenceRepUsecase.Parse3DRepresentation(xml, archive)); }