c# - 平滑 3D 文件

标签 c# mesh smoothing eyeshot

我正在尝试对 .STL 文件应用平滑算法。

我使用 DevDeptEyeshot 来加载和操作 STL 文件。

Eyeshot 中没有内置方法。

为了应用平滑算法,我尝试将 Eyeshot 实体转换为 Geometry3DSharp 中的实体,因为有内置平滑方法,但是转换不是可能的。但结果并不如预期。

关于如何在 3D 对象上应用平滑算法有什么建议吗?

这是我尝试使用Geometry3DSharp平滑对象的方法:

DMesh3 mesh = load_my_mesh_somehow();
Remesher r = new Remesher(mesh);
r.PreventNormalFlips = true;
r.SetTargetEdgeLength(0.5);
for ( int k = 0; k < 20; ++k )
    r.BasicRemeshPass();

最佳答案

有几种平滑算法。拉普拉斯平滑是最好的解决方案之一。

应用您自己的拉普拉斯平滑算法可能很费力。相反,您可以使用 MeshlabServer 来应用完美的拉普拉斯平滑。

您应该有必要的 meshlab dll。为此,您可以在 PC 上安装 Meshlab。 当您在 PC 上安装 Meshlab 时,安装文件夹中包含所有必需的 dll。但是,如果您只想获取要使用的过滤方法所需的 dll,则可以将它们放在安装文件夹中。在这种情况下,您应该在要调用 MeshlabServer 功能的电脑上安装 Visual C++ Redistribuables (Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.26.2872)。

最后,您应该定义 .mlx 文件来告诉 Meshlab 服务器要应用哪个过滤器。

以下是 6 步拉普拉斯平滑的 .mlx 文件的内容:

 <FilterScript>
  <filter name="Laplacian Smooth">
    <Param name="stepSmoothNum" tooltip="" description="" isxmlparam="0" value="6" 
    type="RichInt"/>
    <Param name="selection" tooltip="" description="" isxmlparam="0" value="false" 
    type="RichBool"/>
    <Param name="boundarySmooth" tooltip="" description="" isxmlparam="0" value="true" 
    type="RichBool"/>
    <Param name="cotangentWeight" tooltip="" description="" isxmlparam="0" value="true" 
    type="RichBool"/>
 </filter>    
</FilterScript>

以及调用过滤函数的C#方法:

    /// <summary>
    /// Applies a laplacian smoothing filter to the given 3D object.
    /// </summary>
    /// <param name="input">The path of the source 3D object</param>
    /// <param name="output">The path to save the smoothed result.</param>
    /// <param name="meshlabRoot">The path of the Meshlab dlls folder</param>
    /// <returns></returns>
    public static bool LaplacianSmoothing(string input, string output, string meshlabRoot)
    {
        bool retVal = true;
        try
        {
            string strCmdText;
            string mlxPath = meshlabRoot + "LaplacianFilter.mlx";
            strCmdText = "/C " + meshlabRoot +
                @"meshlabserver " +
                @"-i " + input + " " +
                @"-o " + output + " -s " +
                mlxPath;

            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = strCmdText;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.StartInfo = startInfo;


            process.Start();


            process.WaitForExit();
        }
        catch (Exception ex)
        {
            UserMethods.ParseError(ex, "SmoothFile");
            retVal = false;
        }

        return retVal;

关于c# - 平滑 3D 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67217371/

相关文章:

c# - 如何获取 DataGridRow 单元格的值?

c# - 使用 XSD 创建 XML 并发布到 URL 的步骤

c# - XOR二进制数c#

c++ - 我正在尝试将 3D 模型查看器集成到我的 GUI 中,但还没有找到一个可以让我轻松完成此操作的库。有什么建议么?

c# - 在 xna 项目中配置模型/纹理位置的最佳方法是什么

javascript - 我应该使用什么脚本来实现平滑的 anchor 滚动?我试过的都不起作用

python - 当我想要基于百分比的值时,我的 MAPE(平均绝对百分比误差)函数返回超过 100 的数字

java.lang.NoClassDefFoundError Android Studio Unity

ios - SceneKit:如何从 3D 模型中识别和访问人脸?

python - 使用 Python NLTK 对 trigrams 进行 Kneser-Ney 平滑