【问题标题】:How to export mesh in MATLAB to stl or obj?如何将 MATLAB 中的网格导出为 stl 或 obj?
【发布时间】:2017-11-15 05:17:28
【问题描述】:

我已经编写了 MATLAB 代码(如下所示),它制作一条边,然后构建从该边延伸的网格。我可以将图中的 3D 模型视为网格,但无法将此模型导出为 stl 或 obj 等 3d 对象。

我阅读了许多转换为 stl 的示例,其中使用了这样的内容:

% Extract the surface mesh
M=isosurface(x,y,z,F,0);
tr=TriRep(M.faces,M.vertices);
figure('color','w'), h=trimesh(tr); axis equal
% Write to .stl
stlwrite('PillBoxExample.stl',tr.Triangulation,tr.X)

但在我的代码中,我只使用了网格:

figure;
M= surface(-finalLSF); 
hold on;  contour(phi, [0,0], 'r','LineWidth',2);

我尝试了很多次来转换它,但仍然有错误。

代码:

Img = imread('MK2.jpg'); 
Img=double(Img(:,:,1));
%
% ... other code ...
%
figure;
M= mesh(-finalLSF); 
hold on;  contour(phi, [0,0], 'r','LineWidth',2);
str=['Final level set function, ', num2str(iter_outer*iter_inner+iter_refine), ' iterations'];
title(str);
axis on;

【问题讨论】:

  • 我不确定您是否可以,也不确定您是否应该。 mesh 是绘图函数,它实际上并不生成网格对象。

标签: matlab 3d mesh stl-format


【解决方案1】:

要使用 stlwrite,您需要它的源代码。 Matlab 没有这个功能。 https://de.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-filename--varargin- 应该这样做。

【讨论】:

    【解决方案2】:

    您需要download stlwrite from File Exchange,并将其放在您的 Matlab 路径中。您可以通过键入exist('stlwrite') 来检查它是否在您的路径上。如果这返回2,你很好。如果它返回0,那么你需要add it to your path

    您似乎拥有xyz 坐标,在这种情况下您可以调用

    stlwrite('C:\...\filename.stl', x, y, z);
    

    如果你想先使用isosurface,那么就使用

    M = isosurface(x,y,z,F,0);
    stlwrite('C:\...\filename.stl', M);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 2019-04-18
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多