我正在使用 HelixToolKit ModelImporter 函数从本地文件加载 STL 文件。加载 Model3D 后,我将它作为具有文件名值的键存储在字典中。我这样做的目的是比较模型以防止加载相同的模型。从相同路径加载相同模型后,它会查找该模型的字典作为键。但它没有找到像那个模型。我哪里错了,请帮忙?
private Model3D currModel = null;
private string modelName = null;
// A record of the 3D models we build.
private Dictionary<Model3D, string> Models= new Dictionary<Model3D, string>();
private Model3D device = null;
private void Button_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog open = new Microsoft.Win32.OpenFileDialog();
if (open.ShowDialog() == true)
{
try
{
string path = open.FileName;
modelName = open.SafeFileName;
currModel = display3D(path);
if (!Models.ContainsKey(currModel))
Models.Add(currModel, modelName);
ModelVisual3D device3D = new ModelVisual3D();
device3D.Content = currModel;
mainViewport.Children.Add(device3D);
mainViewport.ZoomExtents();//modeli ekrana sığdırmak için
}
catch (Exception ex)
{
MessageBox.Show("Error\n" + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
private Model3D display3D(string path)
{
//Import 3D model file
ModelImporter import = new ModelImporter();
//Load the 3D model file
device = import.Load(path);
return device;
}