首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >平滑3D文件

平滑3D文件
EN

Stack Overflow用户
提问于 2021-04-23 00:35:23
回答 2查看 232关注 0票数 2

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

我使用DevDept中的Eyeshot加载和操作STL文件。

Eyeshot中没有内置的方法。

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

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

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

代码语言:javascript
运行
复制
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();
EN

回答 2

Stack Overflow用户

发布于 2021-05-19 05:58:57

可以检查以确保在网格上使用平滑索引三角形。

代码语言:javascript
运行
复制
Mesh mesh = new Mesh();

Mesh smoothMesh = (Mesh)mesh.Clone();
for (int i = 0; i < smoothMesh.Triangles.Count(); i++)
{
    SmoothTriangle tST = new SmoothTriangle(smoothMesh.Triangles[i].V1, smoothMesh.Triangles[i].V2, smoothMesh.Triangles[i].V3);
    smoothMesh.Triangles[i] = tST;
}

Mesh flatMesh = (Mesh)mesh.Clone();
for (int i = 0; i < flatMesh.Triangles.Count(); i++)
{
    IndexTriangle tIT = new IndexTriangle(flatMesh.Triangles[i].V1, flatMesh.Triangles[i].V2, flatMesh.Triangles[i].V3);
    flatMesh.Triangles[i] = tIT;
}
票数 1
EN

Stack Overflow用户

发布于 2021-04-23 17:22:11

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

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

你应该有必要的meshlab dll。为此,您可以在PC上安装Meshlab。在PC上安装Meshlab时,安装文件夹中有所有必要的dll。但是,如果您只想获取要使用的筛选方法所需的dll,则可以将它们放在安装文件夹中。在这种情况下,您应该在要调用C++服务器功能的pc上安装visual C++可再发行组件(Microsoft Visual MeshlabServer 2015-2019 Redistributable (x64) - 14.26.2872)。

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

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

代码语言:javascript
运行
复制
 <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#方法:

代码语言:javascript
运行
复制
    /// <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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67217371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档