public GameObject(string MeshName) { Position = new DVector3(); MMC = ContentManager.LoadMultiMesh(MeshName); LocalAABBMin = Conversion.ToDoubleVector(MMC.LocalAABBMin); LocalAABBMax = Conversion.ToDoubleVector(MMC.LocalAABBMax); Transformation = DMatrix.CreateScale(1d)*DMatrix.CreateTranslation(Position) * DMatrix.CreateFromYawPitchRoll(0, 0, 0); RecalcAABB(); InitObj(); Lens = ContentManager.LoadTexture2D("Content/Textures/Lens"); }
/// <summary> /// Получить мультимеш мэш /// </summary> /// <param name="FileName"></param> /// <returns></returns> public static MultiMeshContainer LoadMultiMesh(string FileName) { string Origin = FileName; if (MultiMesh.ContainsKey(Origin) && MultiMesh[Origin].IsAlive) { //Уже есть return (MultiMeshContainer)MultiMesh[Origin].Target; } else { //нужно загрузить MultiMeshContainer _MConteints = null; if (File.Exists(FileName + ".material")) { FileName += ".material"; } else if (File.Exists(FileName + ".model")) { FileName += ".model"; } string extension = System.IO.Path.GetExtension(FileName); if (extension.ToLower() == ".model") { try { System.IO.FileStream fs = new System.IO.FileStream(FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); Serialize.MeshesContainer MC = Serializer.Deserialize<Serialize.MeshesContainer>(fs); fs.Close(); if (MC != null) _MConteints = new MultiMeshContainer(MC); else return null; } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show("Error! Ошибкак чтения модели: " + FileName); new FileNotFoundException("Файл", FileName); } } else if (extension.ToLower() == ".material") { #if !DEBUG try #endif { Serialize.MeshesContainer MC = new Serialize.MeshesContainer(); XmlSerializer dsr = new XmlSerializer(MC.GetType()); FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read); MC = (Serialize.MeshesContainer)dsr.Deserialize(fs); fs.Close(); fs = new System.IO.FileStream(Path.ChangeExtension(FileName, ".geometry"), System.IO.FileMode.Open, System.IO.FileAccess.Read); Serialize.GeometryData GD = Serializer.Deserialize<Serialize.GeometryData>(fs); fs.Close(); if (MC != null && GD != null) { MC.Geometry = GD; _MConteints = new MultiMeshContainer(MC); } else return null; } //TODO Debug #if !DEBUG catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show("Error! Ошибкак чтения модели: " + FileName); new FileNotFoundException("Файл", FileName); } #endif } else { System.Windows.Forms.MessageBox.Show("Error! Неверный тип файла: " + FileName); new FileNotFoundException("Неверный тип файла", FileName); } WeakReference wr = new WeakReference(_MConteints, false); MultiMesh.Add(Origin, wr); _MConteints.Name = Origin; return _MConteints; //TODO проверка на валидность загрузки } }