Ejemplo n.º 1
0
 public static void Initialize()
 {
     if (_instance != null)
     {
         return;
     }
     _instance = new ExtraModelProvider();
     ExtraModels.Register(_instance);
 }
Ejemplo n.º 2
0
        public static async Task StartLiteAsync(string kn5, string skinId = null)
        {
            if (_starting)
            {
                return;
            }
            _starting = true;

            _last?.Stop();
            _last = null;

            ForwardKn5ObjectRenderer renderer = null;

            Logging.Write("Custom Showroom: Magick.NET IsSupported=" + ImageUtils.IsMagickSupported);
            RenderLogging.Initialize(Logging.Filename, true);

            try {
                var carDirectory = Path.GetDirectoryName(kn5);
                if (Path.GetFileName(Path.GetDirectoryName(carDirectory)) == @"..")
                {
                    carDirectory = Path.GetDirectoryName(Path.GetDirectoryName(carDirectory));
                }

                var carObject   = CarsManager.Instance.GetById(Path.GetFileName(carDirectory) ?? "");
                var toolboxMode = IsSameDirectories(carObject?.Location, carDirectory);

                LiteShowroomWrapper wrapper;
                using (var waiting = new WaitingDialog()) {
                    waiting.Report(ControlsStrings.CustomShowroom_Loading);

                    var description = new CarDescription(kn5, carDirectory, carObject?.AcdData);
                    if (toolboxMode)
                    {
                        ExtraModelProvider.Initialize();

                        var toolsRenderer = await Task.Run(() => SettingsHolder.CustomShowroom.UseOldLiteShowroom?
                                                           new ToolsKn5ObjectRenderer(description) {
                            VisibleUi = false,
                            UseSprite = false,
                            UseMsaa   = SettingsHolder.CustomShowroom.LiteUseMsaa,
                            UseFxaa   = SettingsHolder.CustomShowroom.LiteUseFxaa,
                            UseBloom  = SettingsHolder.CustomShowroom.LiteUseBloom
                        } :
                                                           new DarkKn5ObjectRenderer(description)
                        {
                            VisibleUi = false,
                            UseSprite = false
                        });

                        wrapper  = new LiteShowroomWrapperWithTools(toolsRenderer, carObject, skinId);
                        renderer = toolsRenderer;
                    }
                    else
                    {
                        Logging.Warning($"Can’t find CarObject for “{carDirectory}”");
                        Logging.Warning($"Found location: “{carObject?.Location ?? @"NULL"}”");

                        renderer = await Task.Run(() => SettingsHolder.CustomShowroom.UseOldLiteShowroom?
                                                  new ForwardKn5ObjectRenderer(description) {
                            UseMsaa  = SettingsHolder.CustomShowroom.LiteUseMsaa,
                            UseFxaa  = SettingsHolder.CustomShowroom.LiteUseFxaa,
                            UseBloom = SettingsHolder.CustomShowroom.LiteUseBloom
                        } :
                                                  new DarkKn5ObjectRenderer(description)
                        {
                            FlatMirror = true,
                            VisibleUi  = true,
                            UseSprite  = true
                        });

                        wrapper = new LiteShowroomWrapper(renderer);

                        if (skinId != null)
                        {
                            renderer.SelectSkin(skinId);
                        }
                    }

                    _last = wrapper;
                    SetProperties(wrapper, renderer);

                    wrapper.Form.Icon = AppIconService.GetAppIcon();
                }

                wrapper.Run(() => _starting = false);
                GC.Collect();
            } catch (Exception e) {
                NonfatalError.Notify(ControlsStrings.CustomShowroom_CannotStart, e);
            } finally {
                renderer?.Dispose();
                _last     = null;
                _starting = false;
            }
        }