/// <summary> /// Loads a new 3D model file into the ModelViewerControl. /// </summary> void LoadModel(string fileName) { Cursor = Cursors.WaitCursor; // Unload any existing model. modelViewerControl.Model = null; contentManager.Unload(); // Tell the ContentBuilder what to build. contentBuilder.Clear(); contentBuilder.Add(fileName, "Model", null, "ModelProcessor"); // Build this new model data. string buildError = contentBuilder.Build(); if (string.IsNullOrEmpty(buildError)) { // If the build succeeded, use the ContentManager to // load the temporary .xnb file that we just created. modelViewerControl.Model = contentManager.Load <Model>("Model"); } else { // If the build failed, display an error message. MessageBox.Show(buildError, "Error"); } Cursor = Cursors.Arrow; }
/// <summary> /// 新しい 3D モデル ファイルを ModelViewerControl に読み込みます。 /// </summary> void LoadModel(string fileName) { // 砂時計のカーソルにする。 Cursor = Cursors.WaitCursor; // 既存のモデルをすべてアンロードします。 modelViewerControl.Model = null; contentManager.Unload(); // ContentBuilder にビルドする対象を指示します。 contentBuilder.Clear(); // "Model"は名前。"ModelProcessor"は処理するプログラム名。 contentBuilder.Add(fileName, "xxx", null, "ModelProcessor"); // この新しいモデル データをビルドします。 string buildError = contentBuilder.Build(); if (string.IsNullOrEmpty(buildError)) { // ビルドが成功した場合、ContentManager を使用して、 // 作成したばかりの一時 .xnb ファイルを読み込みます。 modelViewerControl.Model = contentManager.Load <Model>("xxx"); } else { // ビルドが失敗した場合、エラー メッセージを表示します。 MessageBox.Show(buildError, "Error"); } // 通常のカーソルにする。 Cursor = Cursors.Arrow; }