【问题标题】:Helix 3d-toolkit Displayed .STL model color changeHelix 3d-toolkit 显示的 .STL 模型颜色变化
【发布时间】:2017-02-11 18:23:58
【问题描述】:

我正在制作一个以 windows 形式显示 3dmodel.stl 的 c# 应用程序。

我已经设法显示它,但模型的默认颜色是蓝色,我需要将其更改为其他颜色,比如粉红色/棕色(它应该看起来像皮肤)。

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

如果有人使用了 helix 并且知道如何(或者即使有办法)做到这一点,我会非常感谢他提供的信息。

代码很简单:

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;
    }
}

【问题讨论】:

  • 嗨,我也遇到了同样的问题。你有解决方案吗?

标签: helix-3d-toolkit


【解决方案1】:

我发现 .obj 文件与 helix 工具包有同样的问题。我的解决方案是将对象的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;
}

【讨论】:

  • 感谢您的帮助!问题是.STL没有property.Material,所以我不能改变它
猜你喜欢
  • 2016-07-26
  • 1970-01-01
  • 2012-12-27
  • 1970-01-01
  • 2021-01-01
  • 2022-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多