Example #1
0
        internal Model(Include include, IReadOnlyDictionary <string, string> modelPaths)
        {
            System.Uri uri = include.Uri.ToUri();

            if (!modelPaths.TryGetValue(uri.Host.ToUpperInvariant(), out string path))
            {
                Console.Error.WriteLine("Model: Failed to find path '" + uri.Host + "'");

                IsInvalid = true;
                Includes  = new List <Include>().AsReadOnly();
                Models    = new List <Model>().AsReadOnly();
                Frames    = new List <Frame>().AsReadOnly();
                Links     = new List <Link>().AsReadOnly();
                return;
            }

            string sdfPath = path + "/model.sdf";

            if (!File.Exists(sdfPath))
            {
                throw new FileNotFoundException(sdfPath);
            }

            SdfFile sdfFile = SdfFile.CreateFromFile(sdfPath);

            if (sdfFile.Models.Count == 0)
            {
                Console.WriteLine("Warning: Included model file " + sdfPath + " with no models!");
                IsInvalid = true;
                Includes  = new List <Include>().AsReadOnly();
                Models    = new List <Model>().AsReadOnly();
                Frames    = new List <Frame>().AsReadOnly();
                Links     = new List <Link>().AsReadOnly();
                return;
            }

            Model source = sdfFile.Models[0].ResolveIncludes(modelPaths);

            Name             = include.Name ?? source.Name;
            CanonicalLink    = source.CanonicalLink;
            Static           = include.Static ?? source.Static;
            SelfCollide      = source.SelfCollide;
            AllowAutoDisable = source.AllowAutoDisable;
            EnableWind       = source.EnableWind;
            Frames           = source.Frames;
            Pose             = source.Pose;
            IncludePose      = include.Pose;
            Links            = Name is null ?
                               source.Links :
                               source.Links.Select(link => new Link(link, Name + "::" + link.Name)).ToList().AsReadOnly();
            Models   = source.Models;
            Includes = source.Includes; // should be empty
        }
Example #2
0
 SdfFile(SdfFile source, IReadOnlyDictionary <string, string> modelPaths)
 {
     Worlds = source.Worlds.Select(world => world.ResolveIncludes(modelPaths)).ToList().AsReadOnly();
     Models = source.Models.Select(model => model.ResolveIncludes(modelPaths)).ToList().AsReadOnly();
     Lights = source.Lights;
 }