Пример #1
0
        public static Object Load(String name)
        {
            String directory = Path.GetDirectoryName(name);

            EmxImporter importer = new EmxImporter();
            ModelX      model    = null;

            using (Stream stream = ContentLoader.Current.Open(name + ".emx"))
            {
                model = importer.Import(stream, (fn) =>
                {
                    return(ContentLoader.Current.Open(Path.Combine(directory, fn)));
                });
            }

            foreach (var set in model.MaterialsSets)
            {
                foreach (var material in set)
                {
                    if (!String.IsNullOrWhiteSpace(material.Texture))
                    {
                        Texture2D texture = ContentLoader.Current.Load <Texture2D>(Path.Combine(directory, material.Texture));
                        material.Textures = new MaterialTextures(texture);
                    }
                }
            }

            IGraphicsDeviceService deviceService = ContentLoader.Current.GetService <IGraphicsDeviceService>();

            model.PrepareForRender(deviceService.GraphicsDevice);

            return(model);
        }