Beispiel #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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public bool LoadFromFile(string mwmFilepath)
        {
            MwmFilepath    = MyMwmUtils.GetFullMwmFilepath(mwmFilepath);
            MwmContentPath = MyMwmUtils.GetFullMwmContentPath(mwmFilepath);
            if (!MyFileSystem.FileExists(MwmFilepath))
            {
                MyRender11.Log.WriteLine(String.Format("Mesh asset {0} missing", MwmFilepath));
                return(false);
            }

            MyModelImporter             modelImporter = GetModelImporter(MwmFilepath);
            Dictionary <string, object> tagData       = modelImporter.GetTagData();

            // Lods
            if (tagData.ContainsKey(MyImporterConstants.TAG_LODS))
            {
                Lods = (MyLODDescriptor[])tagData[MyImporterConstants.TAG_LODS];
            }

            // Parts
            MyRenderProxy.Assert(tagData.ContainsKey(MyImporterConstants.TAG_MESH_PARTS));
            PartInfos = tagData[MyImporterConstants.TAG_MESH_PARTS] as List <MyMeshPartInfo>;
            // Sort parts
            PartInfos.Sort(m_partsComparer);

            // Sections
            if (tagData.ContainsKey(MyImporterConstants.TAG_MESH_SECTIONS))
            {
                SectionInfos = tagData[MyImporterConstants.TAG_MESH_SECTIONS] as List <MyMeshSectionInfo>;
            }

            // Common buffers
            Positions  = (HalfVector4[])tagData[MyImporterConstants.TAG_VERTICES];
            Normals    = (Byte4[])tagData[MyImporterConstants.TAG_NORMALS];
            Tangents   = (Byte4[])tagData[MyImporterConstants.TAG_TANGENTS];
            Bitangents = (Byte4[])tagData[MyImporterConstants.TAG_BINORMALS];
            Texcoords  = (HalfVector2[])tagData[MyImporterConstants.TAG_TEXCOORDS0];

            // Animation
            Bones       = (MyModelBone[])tagData[MyImporterConstants.TAG_BONES];
            BoneIndices = (Vector4I[])tagData[MyImporterConstants.TAG_BLENDINDICES];
            BoneWeights = (Vector4[])tagData[MyImporterConstants.TAG_BLENDWEIGHTS];

            object objectPatternScale;
            float  patternScale = 1f;

            if (tagData.TryGetValue(MyImporterConstants.TAG_PATTERN_SCALE, out objectPatternScale))
            {
                patternScale = (float)objectPatternScale;
            }

            // Data validation
            BoundindBox    = (BoundingBox)tagData[MyImporterConstants.TAG_BOUNDING_BOX];
            BoundingSphere = (BoundingSphere)tagData[MyImporterConstants.TAG_BOUNDING_SPHERE];

            if (patternScale != 1f && Texcoords.Length > 0)
            {
                for (int i = 0; i < Texcoords.Length; ++i)
                {
                    Texcoords[i] = new HalfVector2(Texcoords[i].ToVector2() / patternScale);
                }
            }

            if (Normals.Length > 0 && Tangents.Length > 0 && Bitangents.Length > 0)
            {
                Tangents = CreateAlteredTangents(Normals, Tangents, Bitangents);
            }

            modelImporter.Clear();
            return(true);
        }