2017-04-30 8 views
0

HelixViewport3D에서 다른 유형의 3D 개체를 추가했습니다. 내 질문은 일반적인 CAD 응용 프로그램처럼 파일에 3D 개체/모델을 저장하고 늦게 열어 보는 방법입니다.뷰포트의 3D 객체를 파일로 저장하고 늦게 열려면 어떻게해야합니까?

HelixViewport3D는 UserControl.xaml 컨트롤에서 정의 된 사용자입니다.

UserControl을 다음과 같이 defiend입니다 :

<UserControl x:Class="SubWindows.UserControl1" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:HelixToolkit="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf" 
     Height="350" Width="525" MouseRightButtonDown="OnMouseRightButtonDown" TabIndex="0" MouseMove="UserControl_MouseMove" Opacity="1"> 
<Grid> 
<HelixToolkit:HelixViewport3D x:Name="ViewPort" ZoomExtentsWhenLoaded="True" ItemsSource="{Binding}"> 
     <HelixToolkit:SunLight Brightness="0.4" Ambient="0.1" /> 
     <ModelVisual3D Content="{Binding Model}"/> 
     <ModelVisual3D x:Name="SolidModels"/> 
     <ModelVisual3D x:Name="ScreenLineModels"/> 
     <ModelVisual3D x:Name="DimLinesModels"/> 
     <ModelVisual3D x:Name="TagsModels"/> 
    </HelixToolkit:HelixViewport3D> 
    <Canvas Name="TagsOverlay" IsHitTestVisible="False" ClipToBounds="False"/> 
    <Canvas Name="DimsOverlay" IsHitTestVisible="False" ClipToBounds="False" /> 
</Grid> 

다음과 같이 저장 파일 이벤트는 다음과 같습니다

private void saveToolStripMenuItem_Click(object sender, EventArgs e) 
    { 
     SaveFileDialog saveFileDialog = new SaveFileDialog(); 
     saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); 
     saveFileDialog.Filter = "pvp Files (*.pvp)|*.pvp|Text Files (*.xaml)|*.xaml|All Files (*.*)|*.*"; 

     if (saveFileDialog.ShowDialog(this) == DialogResult.OK) 
     { 
      string FileName = saveFileDialog.FileName; 
      string fileNameExtention = System.IO.Path.GetExtension(FileName); 
      fileNameExtention = fileNameExtention.ToLower(); 
      if (fileNameExtention == ".xaml") 
      { 
       uc.ViewPort.Export(FileName); 
      } 
     } 
    } 

"우리가"UserControl1을의 인스턴스 UserControl1을 UC로 정의 = 새로운 UserControl1(); SaveToolStripMenuItem_Click을 사용하여 파일을 저장하면 아래 스냅 샷과 같은 오류가 발생합니다.

enter image description here

그러나 뷰포트의 부분은 XAML 형식으로 저장되었습니다.

문제를 해결하기위한 모든 의견을 환영합니다.

답변

0

첫 번째로 Export() [[예]를 사용하여 viewport3D를 내 보내야합니다. 키 값, 을 사용하여 XAML 파일 (모델을 .xaml로 내보낼 경우)을 제공 할 Helix Vieport3D의 viewport.Export (/sample.xaml) 메소드 나중에 내 보낸 XAML 파일을 프로젝트 디렉토리에 추가하고 아래에서 사용하십시오 암호. UserConrol.xaml의

코드는 XAML 파일

HelixViewport3D viewport; //Extra viewport to store the childrens 
     viewport= (HelixViewport3D)FindResource("Model"); 
     // "Model" is the key value of my exported XAML file 

     List<Visual3D> items = new List<Visual3D>(); // List is use to store the childrens of ResourceDirectories xaml. 

     //Adds the children inside List 
     for (int i=(viewport.Children.Count - 1);i>=0;i--) 
     { 
      items.Add(viewport.Children[i]); 
      viewport.Children.RemoveAt(i); 
     } 

     //viewport3D.Children.Clear(); 

     foreach(Visual3D item in items) 
     { 
      viewport3D.Children.Add(item); 
     } 
을 가져 오기위한

<UserControl.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="<Path towards your exported xaml file>\sample.xaml"/> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 

</UserControl.Resources> 

코드 파일