Example #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);
        }
Example #2
0
        public bool CreateGBuffer(MyMwmData mwmData, int lodNum, ref HashSet <string> setMaterialNames)
        {
            UniqueId = MyManagers.IDGenerator.GBufferLods.Generate();
            LodNum   = lodNum;

            IB  = MyManagers.ModelBuffers.GetOrCreateIB(mwmData);
            VB0 = MyManagers.ModelBuffers.GetOrCreateVB0(mwmData);
            VB1 = MyManagers.ModelBuffers.GetOrCreateVB1(mwmData);
            VertexInputComponents = MyManagers.ModelBuffers.CreateStandardVertexInputComponents(mwmData);
            m_instanceMaterialsStrategy.Init();

            BoundingBox = mwmData.BoundindBox;

            HighlightSections = null;
            Parts             = new List <MyPart>();
            GlassParts        = null;

            int offset = 0;

            foreach (var mwmPartInfo in mwmData.PartInfos)
            {
                // Making of parts is connected to the creating index buffer. It will worth to do it much more connected in future
                int    indicesCount = mwmPartInfo.m_indices.Count;
                string materialName = mwmPartInfo.GetMaterialName();
                if (mwmPartInfo.Technique != MyMeshDrawTechnique.GLASS)
                {
                    MyMeshDrawTechnique technique        = mwmPartInfo.Technique;
                    string             cmFilepath        = MyMwmUtils.GetColorMetalTexture(mwmPartInfo, mwmData.MwmContentPath);
                    string             ngFilepath        = MyMwmUtils.GetNormalGlossTexture(mwmPartInfo, mwmData.MwmContentPath);
                    string             extFilepath       = MyMwmUtils.GetExtensionTexture(mwmPartInfo, mwmData.MwmContentPath);
                    string             alphamaskFilepath = MyMwmUtils.GetAlphamaskTexture(mwmPartInfo, mwmData.MwmContentPath);
                    MyStandardMaterial material          = MyManagers.Materials.GetOrCreateStandardMaterial(materialName, technique, cmFilepath, ngFilepath, extFilepath, alphamaskFilepath);

                    MyPart part = new MyPart();
                    part.InitForGBuffer(this, materialName, mwmData.MwmContentPath, mwmPartInfo, material, offset, indicesCount, 0);
                    Parts.Add(part);
                }
                else
                {
                    MyGlassMaterial glassMaterial = MyManagers.Materials.GetGlassMaterial(materialName);

                    MyPart part = new MyPart();
                    part.InitForGlass(this, mwmPartInfo.GetMaterialName(), glassMaterial, mwmPartInfo.Technique, offset, indicesCount, 0);
                    if (GlassParts == null)
                    {
                        GlassParts = new List <MyPart>();
                    }
                    GlassParts.Add(part); // glass parts are rendered by different pipeline than the regular "solid" geometry
                }
                offset += indicesCount;

                setMaterialNames.Add(materialName);
            }

            return(true);
        }
Example #3
0
        public void InitForGBuffer(MyLod parent, string name, string contentPath, MyMeshPartInfo mwmPartInfo, MyStandardMaterial standardMaterial,
                                   int startIndex, int indicesCount, int startVertex)
        {
            MyRenderProxy.Assert(StartIndex == 0 && IndicesCount == 0 && StartVertex == 0, "The part has been initialised before!");
            MyRenderProxy.Assert(indicesCount != 0, "Invalid input");

            bool isCmTexture  = !string.IsNullOrEmpty(MyMwmUtils.GetColorMetalTexture(mwmPartInfo, contentPath));
            bool isNgTexture  = !string.IsNullOrEmpty(MyMwmUtils.GetNormalGlossTexture(mwmPartInfo, contentPath));
            bool isExtTexture = !string.IsNullOrEmpty(MyMwmUtils.GetExtensionTexture(mwmPartInfo, contentPath));

            Technique       = mwmPartInfo.Technique;
            m_shaderBundles = new MyShaderBundle[(int)MyInstanceLodState.StatesCount];
            m_shaderBundles[(int)MyInstanceLodState.Solid] = MyManagers.ShaderBundles.GetShaderBundle(MyRenderPassType.GBuffer,
                                                                                                      Technique,
                                                                                                      MyInstanceLodState.Solid,
                                                                                                      isCmTexture,
                                                                                                      isNgTexture,
                                                                                                      isExtTexture);
            m_shaderBundles[(int)MyInstanceLodState.Transition] = MyManagers.ShaderBundles.GetShaderBundle(MyRenderPassType.GBuffer,
                                                                                                           Technique,
                                                                                                           MyInstanceLodState.Transition,
                                                                                                           isCmTexture,
                                                                                                           isNgTexture,
                                                                                                           isExtTexture);
            m_shaderBundles[(int)MyInstanceLodState.Hologram] = MyManagers.ShaderBundles.GetShaderBundle(MyRenderPassType.GBuffer,
                                                                                                         Technique,
                                                                                                         MyInstanceLodState.Hologram,
                                                                                                         isCmTexture,
                                                                                                         isNgTexture,
                                                                                                         isExtTexture);
            m_shaderBundles[(int)MyInstanceLodState.Dithered] = MyManagers.ShaderBundles.GetShaderBundle(MyRenderPassType.GBuffer,
                                                                                                         Technique,
                                                                                                         MyInstanceLodState.Dithered,
                                                                                                         isCmTexture,
                                                                                                         isNgTexture,
                                                                                                         isExtTexture);
            Parent                      = parent;
            Name                        = name;
            StandardMaterial            = standardMaterial;
            GlassMaterial               = null;
            InstanceMaterialOffsetInLod = -1; // <- not used so far
            StartIndex                  = startIndex;
            IndicesCount                = indicesCount;
            StartVertex                 = startVertex;
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
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);
        }