Ejemplo n.º 1
0
        public bool GetOrCreateModels(string filepath, out MyModels models)
        {
            filepath = MyMwmUtils.GetFullMwmFilepath(filepath);
            if (m_models.TryGetValue(filepath, out models))
            {
                return(true);
            }

            // Load mwm as first lod
            MyMwmData firstLodMwmData = new MyMwmData();

            if (!firstLodMwmData.LoadFromFile(filepath))
            {
                MyRender11.Log.WriteLine(string.Format("Mwm '{0}' cannot be loaded from file", filepath));
                return(false);
            }

            if (!IsModelSuitable(firstLodMwmData))
            {
                return(false);
            }

            MyRenderProxy.Assert(!m_models.ContainsKey(firstLodMwmData.MwmFilepath));
            models = CreateModels(firstLodMwmData);
            m_models.Add(firstLodMwmData.MwmFilepath, models);

            return(true);
        }
Ejemplo n.º 2
0
        // The mwmData will be loaded and if there are link to another files with lods, they will be loaded
        bool LoadFromMwmData(MyMwmData firstLodMwmData, ICreateLodStrategy strategy)
        {
            m_tmpAllMaterialNames.Clear();
            MyLod firstLods = new MyLod();

            if (!strategy.CreateLod(firstLods, firstLodMwmData, 0, ref m_tmpAllMaterialNames))
            {
                MyRender11.Log.WriteLine(string.Format("Mwm '{0}' cannot be loaded as the 1st lod", firstLodMwmData.MwmFilepath));
                return(false);
            }

            // if no lods are specified inside of the mwm, models with the single lod will be created:
            if (firstLodMwmData.Lods.Length == 0)
            {
                CreateFromSingleLod(firstLods);
            }
            else // otherwise all lods will be loaded and initilised:
            {
                m_lodStrategyInfo.Init(firstLodMwmData.Lods);
                List <MyLod> multipleLods = new List <MyLod>();
                multipleLods.Add(firstLods);
                for (int i = 0; i < firstLodMwmData.Lods.Length; i++)
                {
                    string lodFilepath = firstLodMwmData.Lods[i].GetModelAbsoluteFilePath(firstLodMwmData.MwmFilepath);

                    MyLod     lod     = new MyLod();
                    MyMwmData mwmData = new MyMwmData();
                    if (!mwmData.LoadFromFile(lodFilepath))
                    {
                        MyRender11.Log.WriteLine(string.Format("Mwm '{0}' cannot be loaded as the other lod", lodFilepath));
                        continue;
                    }
                    strategy.CreateLod(lod, mwmData, i + 1, ref m_tmpAllMaterialNames);
                    multipleLods.Add(lod);
                }
                CreateFromMultipleLods(multipleLods);

                m_lodStrategyInfo.ReduceLodsCount(m_lods.Count);
            }

            m_instanceMaterialStrategy.Init(m_tmpAllMaterialNames);

            return(true);
        }
Ejemplo n.º 3
0
        // This function will open the file, read it and close it again. Use it only for debug!
        public bool IsModelSuitable(string filepath)
        {
            filepath = MyMwmUtils.GetFullMwmFilepath(filepath);
            if (m_resultsForIsModelSuitable.ContainsKey(filepath)) // if the results have been resolved before, reuse them!
            {
                return(m_resultsForIsModelSuitable[filepath]);
            }

            // The file has not been analyzed before, the file will be opened and analyzed:
            MyMwmData mwmData = new MyMwmData();

            if (!mwmData.LoadFromFile(filepath))
            {
                m_resultsForIsModelSuitable.Add(filepath, false);
                return(false);
            }
            bool result = IsModelSuitable(mwmData);

            m_resultsForIsModelSuitable.Add(filepath, result);
            return(result);
        }
Ejemplo n.º 4
0
        public bool GetOrCreateModels(string filepath, out MyModels models)
        {
            filepath = MyMwmUtils.GetFullMwmFilepath(filepath);
            if (m_models.TryGetValue(filepath, out models)) // if the model is loaded, return true
            {
                return(true);
            }

            // if the model has been loaded, but it did not been suitable, return false:
            if (m_resultsForIsModelSuitable.ContainsKey(filepath))
            {
                if (m_resultsForIsModelSuitable[filepath] == false)
                {
                    return(false);
                }
            }

            // Load mwm as first lod
            MyMwmData firstLodMwmData = new MyMwmData();

            if (!firstLodMwmData.LoadFromFile(filepath))
            {
                MyRender11.Log.WriteLine(string.Format("Mwm '{0}' cannot be loaded from file", filepath));
                return(false);
            }

            if (!IsModelSuitable(firstLodMwmData))
            {
                m_resultsForIsModelSuitable.Add(filepath, false);
                return(false);
            }

            MyRenderProxy.Assert(!m_models.ContainsKey(firstLodMwmData.MwmFilepath));
            models = CreateModels(firstLodMwmData);
            m_models.Add(firstLodMwmData.MwmFilepath, models);

            return(true);
        }
Ejemplo n.º 5
0
        bool IsModelSuitable(MyMwmData mwmData)
        {
            if (mwmData.HasBones)
            {
                return(false);
            }
            if (!mwmData.IsValid2ndStream)
            {
                return(false);
            }
            foreach (var partInfo in mwmData.PartInfos)
            {
                if (partInfo.m_MaterialDesc == null)
                {
                    continue;
                }
                string materialName = partInfo.m_MaterialDesc.MaterialName;
                if (m_blackListMaterials.Contains(materialName))
                {
                    return(false);
                }

                switch (partInfo.m_MaterialDesc.Facing)
                {
                case MyFacingEnum.None:
                    break;

                default:
                    return(false);
                }

                switch (partInfo.Technique)
                {
                case MyMeshDrawTechnique.MESH:
                case MyMeshDrawTechnique.ALPHA_MASKED:
                case MyMeshDrawTechnique.DECAL:
                case MyMeshDrawTechnique.DECAL_CUTOUT:
                case MyMeshDrawTechnique.DECAL_NOPREMULT:
                    break;

                default:
                    return(false);
                }
            }

            // The current model is fine, let's check the lods
            foreach (var lod in mwmData.Lods)
            {
                string filepath = lod.GetModelAbsoluteFilePath(mwmData.MwmFilepath);
                if (filepath == null)
                {
                    string errMsg = string.Format("The table for lods is specified, but it is invalid (filepath for lod is missing). File: '{0}'", mwmData.MwmFilepath);
                    MyRenderProxy.Fail(errMsg);
                    MyRenderProxy.Log.WriteLine(errMsg);
                    return(false);
                }

                MyMwmData lodMwmData = new MyMwmData();
                if (lodMwmData.LoadFromFile(filepath))
                {
                    bool isSuitable = IsModelSuitable(lodMwmData);
                    if (!isSuitable)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }