Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        public static InstanceRep FromXDocument(XElement xElement)
        {
            var id       = int.Parse(xElement.Attribute(XName.Get("id")).Value);
            var name     = xElement.Attribute(XName.Get("name")).Value;
            var instance = new InstanceRep(id, name)
            {
                AggregatedBy = ParseUtility.ValueOfDescendant(xElement, "IsAggregatedBy", Convert.ToInt32, 0),
                InstanceOf   = ParseUtility.ValueOfDescendant(xElement, "IsInstanceOf", Convert.ToInt32, 0)
            };

            return(instance);
        }
        public static Instance3D FromXDocument(XElement xElement)
        {
            var id       = int.Parse(xElement.Attribute(XName.Get("id")).Value);
            var name     = xElement.Attribute(XName.Get("name")).Value;
            var instance = new Instance3D(id, name)
            {
                AggregatedBy   = ParseUtility.ValueOfDescendant(xElement, "IsAggregatedBy", Convert.ToInt32, 0),
                InstanceOf     = ParseUtility.ValueOfDescendant(xElement, "IsInstanceOf", Convert.ToInt32, 0),
                RelativeMatrix =
                    ParseUtility.ValueOfDescendant <IList <double> >(xElement, "RelativeMatrix",
                                                                     ParseList, new List <double>())
            };

            return(instance);
        }
Ejemplo n.º 4
0
        public IModel Parse(Stream stream)
        {
            var fileArchive = ThreeDXMLFile.Create(stream);
            var xmlManifest = ReadManifest(fileArchive);
            // create 3dxml model and fill it with data
            var internalModel = new ThreeDXMLImplementation(ParseUtility.GetHeader(xmlManifest))
            {
                ReferenceReps    = ParseAssetRepresentation(xmlManifest, fileArchive),
                ThreeDReferences = ParseReference3D(xmlManifest),
                ThreeDInstances  = ParseInstance3D(xmlManifest),
                InstanceReps     = ParseInstanceRep(xmlManifest)
            };

            // return the model definition
            return(internalModel.ToModel());
        }
Ejemplo n.º 5
0
 private XDocument ReadManifest(IThreeDXMLArchive fileArchive)
 {
     return(ParseUtility.ReadManifest(fileArchive));
 }
Ejemplo n.º 6
0
 private IList <InstanceRep> ParseInstanceRep(XDocument document)
 {
     return(ParseUtility.RootDescendants(document, "InstanceRep").Select(ParseInstanceRepUsecase.FromXDocument).ToList());
 }
Ejemplo n.º 7
0
 private IList <Reference3D> ParseReference3D(XDocument document)
 {
     return(ParseUtility.RootDescendants(document, "Reference3D").Select(ParseReference3DUsecase.FromXDocument).ToList());
 }