简体   繁体   English

将多个Stl文件合并为一个

[英]Combine multiple stl files into one

I am working with asp.NET MVC 5, I have found ac# code to display a stl file on my browser, now I would like to combine it with another stl file. 我正在使用asp.NET MVC 5,我发现ac#代码在浏览器中显示一个stl文件,现在我想将其与另一个stl文件结合在一起。 I found that VTK allows you to do this : http://www.vtk.org/Wiki/VTK/Examples/Cxx/Filtering/CombinePolyData . 我发现VTK允许您执行此操作: http : //www.vtk.org/Wiki/VTK/Examples/Cxx/Filtering/CombinePolyData But the code is in .cxx, I suppose that I can't use it on a Web application ? 但是代码在.cxx中,我想不能在Web应用程序上使用它吗?

The STL-format is just a triangle soup, that is, a collection of triangles without any connectivity information. STL格式只是一个三角形的汤,即没有任何连接信息的三角形的集合。 Analogously to mixing two soups in one pot in real life, nothing prevents you from putting all the triangles from both your files into one before displaying them. 类似于现实生活中在一个锅中混合两种汤,没有什么可以阻止您在显示它们之前将两个文件中的所有三角形都放入一个。

More precisely, suppose that file1.stl looks like 更准确地说,假设file1.stl看起来像

solid model1
  facet normal 0.0 0.0 -1.0
    outer loop
      vertex 20.0 0.0 0.0
      vertex 0.0 -20.0 0.0
      vertex 0.0 0.0 0.0
    endloop
  endfacet
.
.
.
  facet normal 0.0 0.0 -1.0
    outer loop
      vertex 0.0 -20.0 0.0
      vertex 20.0 0.0 0.0
      vertex 20.0 -20.0 0.0
    endloop
  endfacet
endsolid

(the dots suggest further triangles and would not be present in the actual file) and file2.stl as (点表示其他三角形,并且在实际文件中将不存在)和file2.stl

solid model2
  facet normal -0.0 1.0 0.0
    outer loop
      vertex 0.0 0.0 20.0
      vertex 20.0 0.0 0.0
      vertex 0.0 0.0 0.0
    endloop
  endfacet
.
.
.
  facet normal -0.0 1.0 0.0
    outer loop
      vertex 20.0 0.0 0.0
      vertex 0.0 0.0 20.0
      vertex 20.0 0.0 20.0
    endloop
  endfacet
endsolid

I am not an expert in C# but it should be a fairly easy exercise on string manipulation to put both of these models into one file result.stl : 我不是C#方面的专家,但是在字符串操作上将这两个模型放到一个文件result.stl应该是一个相当容易的练习:

solid bothModelsInOne
  facet normal 0.0 0.0 -1.0
    outer loop
      vertex 20.0 0.0 0.0
      vertex 0.0 -20.0 0.0
      vertex 0.0 0.0 0.0
    endloop
  endfacet
.
.
.
  facet normal 0.0 0.0 -1.0
    outer loop
      vertex 0.0 -20.0 0.0
      vertex 20.0 0.0 0.0
      vertex 20.0 -20.0 0.0
    endloop
  endfacet
  facet normal -0.0 1.0 0.0
    outer loop
      vertex 0.0 0.0 20.0
      vertex 20.0 0.0 0.0
      vertex 0.0 0.0 0.0
    endloop
  endfacet
.
.
.
  facet normal -0.0 1.0 0.0
    outer loop
      vertex 20.0 0.0 0.0
      vertex 0.0 0.0 20.0
      vertex 20.0 0.0 20.0
    endloop
  endfacet
endsolid

Notice that all the facets (triangles) are in one file but there is only one solid / endsolid pair enclosing the model. 请注意,所有构面(三角形)都在一个文件中,但是只有一对solid / endsolid对封闭了模型。

Now you can pass this file to your renderer as you did before. 现在,您可以像以前一样将此文件传递到渲染器。

This quite certainly does the job when the two bodies are disjoint. 当两个物体不相交时,这肯定可以完成工作。 Whether it does what you want in case of an intersection would require you to provide a more precise definition of "combine". 在相交的情况下,它是否满足您的要求,将要求您提供“组合”的更精确定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM