KeenSoftwareHouse / SpaceEngineers

2.93k stars 896 forks source link

Fix: DX11 renderer is unable to load LOD models from mods directories. #531

Open theHarven opened 8 years ago

theHarven commented 8 years ago

The change forces LOD model files to be loaded from the same path as main model file. The bug was reported here: http://forums.keenswh.com/threads/1-105-directx-11-renderer-is-unable-to-load-level-of-detail-models.7371600/

harag-on-steam commented 8 years ago

Currently the LOD path is supposed to be relative to a content root (<SE>/Content, <Mod>/). Why change this? This will create a needless mismatch between Dx11 and the legacy Dx9 renderer.

theHarven commented 8 years ago

Hey, It will not create any mismatch, because it's already done this way in Dx9 renderer, look at the code at VRage.Renderer\RendererObjects\MyRendererEntity.cs:

        // This is more hack than correct solution, we have to find lods in same dir as models, because of MODs
        private string GetLodPath(string modelPath, string lodPath)
        {
            return Path.Combine(Path.GetDirectoryName(modelPath), Path.GetFileName(lodPath));
        }

        MyRenderModel AddLODs(string model)
        {
            MyLodModel lodModel = AddLOD(0, model);

            if (lodModel == null)
                return null;

            foreach (var lodDesc in lodModel.Model.LODs)
            {
                string lodModelPath = lodDesc.Model;

                if (String.IsNullOrEmpty(Path.GetExtension(lodModelPath)))
                {
                    //Debug.Fail("Missing LOD file extension: " + lodModelPath);
                    lodModelPath += ".mwm";
                }

                lodModelPath = GetLodPath(model, lodModelPath);

                if (lodDesc.RenderQualityList == null || lodDesc.RenderQualityList.Contains((int)MyRenderConstants.RenderQualityProfile.RenderQuality))
                    AddLOD(lodDesc.Distance, lodModelPath);
            }

            return lodModel.Model;
        }