2016-05-10 23 views
0

我正在制作一个c#应用程序,它在Windows窗体中显示3dmodel.stl。Helix 3d-toolkit显示.STL模型颜色变化

我已经成功地显示它但对模型的默认颜色是蓝色的,我需要将其更改为别的,让说,粉红色/棕色(它应该看起来像皮肤)。

我已经2天找了它,阅读文档和示例,但我还没有找到方法来改变它。

如果有人已经工作过螺旋,并知道如何做(或者即使有办法),我会非常感谢他的信息。

的代码非常简单:

XAML代码:

<UserControl x:Class="Ventana.Visor3D" 
     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:helix="http://helix-toolkit.org/wpf" 
     xmlns:local="clr-namespace:Ventana" 
     mc:Ignorable="d" 
     d:DesignHeight="300" d:DesignWidth="300"> 
<Grid> 
    <helix:HelixViewport3D x:Name="viewPort3d" ZoomExtentsWhenLoaded="true" Grid.RowSpan="2" > 

     <helix:SunLight/> 
    </helix:HelixViewport3D> 
</Grid> 

和C#代码:

public partial class Visor3D : UserControl 
{ 
    private const string MODEL_PATH = "\\Prueba.STL"; 
    ModelVisual3D device3D; 

    public Visor3D(){ } 

    public void Carga() { 

     InitializeComponent(); 
     device3D = new ModelVisual3D(); 
     device3D.Content = Display3d(MODEL_PATH); 

     viewPort3d.Children.Add(device3D);    
} 



    private Model3D Display3d(string model) 
    { 
     Model3D device = null; 
     try 
     { 

      viewPort3d.RotateGesture = new MouseGesture(MouseAction.LeftClick); 


      ModelImporter import = new ModelImporter(); 


      device = import.Load(Environment.CurrentDirectory + model);     
     } 
     catch (Exception e) 
     {    
      MessageBox.Show("Exception Error : " + e.StackTrace); 
     } 
     return device; 
    } 
} 

回答

0

我也发现了同样的问题的obj档案螺旋工具包。我的解决方案是用新的替代对象的Material。我猜不是最好的解决方案,但它适用于我的WPF项目。

// Set your RGB Color on the SolitColorBrush 
System.Windows.Media.Media3D.Material mat = MaterialHelper.CreateMaterial(
      new SolidColorBrush(Color.FromRgb(255, 255, 255)) 

//Replace myModel3DGroup by your Model3DGroup of your view.... 
foreach (System.Windows.Media.Media3D.GeometryModel3D geometryModel in myModel3DGroup.Children) 
{ 
    geometryModel.Material = mat; 
    geometryModel.BackMaterial = mat; 
} 
+0

THX的帮助!问题是.STL没有这个属性。材料,所以我不能改变它 –