0

我正在使用以下代码将 Step 文件转换为 Object 文件。

使用下面给出的示例代码 1,转换后输出文件只有顶点(v)和面(f),而 vt 和 vn 不存在。我还需要创建没有发生的相应材料文件。

我是这个编程领域的新手。任何建议或更正将不胜感激。

我正在使用来自 FreeCAD(0.16) 和 python(2.7) 的 Python。

谢谢

示例代码 1 如下。

import FreeCAD
import Part
import Mesh
shape = Part.Shape()
shape.read('my_shape.step')
doc = App.newDocument('Doc')
pf = doc.addObject("Part::Feature","MyShape")
pf.Shape = shape
Mesh.export([pf], 'my_shape.obj')

示例代码 2 如下。在第 5 行(shape = data[0][0].Shape)返回 NULL 会导致错误。

import Mesh
import MeshPart
import Import

data=Import.open("C:/ACE TANK.STEP")
shape = data[0][0].Shape
shape_colors = data[0][1]

mesh = MeshPart.meshFromShape(Shape=shape, LinearDeflection=0.1, Segments=True)

face_colors=[(0,0,0)] * mesh.CountFacets
for i in range(mesh.countSegments()):
    color = shape_colors[i]
    segm = mesh.getSegment(i)
    for j in segm:
        face_colors[j] = color
mesh.write(Filename="C:/test.obj", Material=face_colors, Format="obj")
4

0 回答 0