private static H3D LoadMTModel(BinaryReader reader, string modelFile, string mrlSearchPath)
        {
            if (_mtShader != null)
            {
                var mrlData = new MTMaterials();

                foreach (var file in Directory.GetFiles(mrlSearchPath))
                {
                    if (file == modelFile || !file.StartsWith(modelFile.Substring(0, modelFile.LastIndexOf('.'))))
                    {
                        continue;
                    }

                    using (var input = new FileStream(file, FileMode.Open))
                    {
                        if (input.Length < 4)
                        {
                            continue;
                        }

                        var magic = new byte[4];

                        input.Read(magic, 0, magic.Length);

                        if (Encoding.ASCII.GetString(magic) == "MRL\0")
                        {
                            input.Seek(0, SeekOrigin.Begin);

                            mrlData.Materials.AddRange(new MTMaterials(input, _mtShader).Materials);
                        }
                    }
                }

                return(new MTModel(reader, mrlData, _mtShader).ToH3D());
            }
            else
            {
                // A *.lfx shader is necessary to load this format
            }

            return(null);
        }
Esempio n. 2
0
        private static H3D LoadMTModel(BinaryReader Reader, string ModelFile, string MRLSearchPath)
        {
            if (MTShader != null)
            {
                MTMaterials MRLData = new MTMaterials();

                foreach (string File in Directory.GetFiles(MRLSearchPath))
                {
                    if (File == ModelFile || !File.StartsWith(ModelFile.Substring(0, ModelFile.LastIndexOf('.'))))
                    {
                        continue;
                    }

                    using (FileStream Input = new FileStream(File, FileMode.Open))
                    {
                        if (Input.Length < 4)
                        {
                            continue;
                        }

                        byte[] Magic = new byte[4];

                        Input.Read(Magic, 0, Magic.Length);

                        if (Encoding.ASCII.GetString(Magic) == "MRL\0")
                        {
                            Input.Seek(0, SeekOrigin.Begin);

                            MRLData.Materials.AddRange(new MTMaterials(Input, MTShader).Materials);
                        }
                    }
                }

                return(new MTModel(Reader, MRLData, MTShader).ToH3D());
            }
            else
            {
                DialogResult Result = MessageBox.Show(
                    "A *.lfx shader is necessary to load this format." + Environment.NewLine +
                    "Do you want to open the shader file now?",
                    "Shader file missing",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);

                if (Result == DialogResult.Yes)
                {
                    using (OpenFileDialog OpenDlg = new OpenFileDialog())
                    {
                        OpenDlg.Filter = "MT Mobile Shader|*.lfx";

                        if (OpenDlg.ShowDialog() == DialogResult.OK)
                        {
                            LoadMTShader(OpenDlg.FileName);

                            return(LoadMTModel(Reader, ModelFile, MRLSearchPath));
                        }
                    }
                }
            }

            return(null);
        }