2

我正在使用 Python3.4.2 和 pythonOCC-0.16.0-win32-py34.exe 来绘制组件。每个组件都使用一种定义的颜色正确渲染,但这看起来不像真实世界的组件。

在此处输入图像描述 上图是我的 Python 实现,它从 STEP 文件生成具有一种颜色的 3D 图像。

下图是我的 Windows 软件之一,我使用了 Step 文件。我想渲染组件,如下图所示,使其看起来像一个真实世界的组件。

在此处输入图像描述

有没有办法通过读取 STEP 文件在 Python 中获得正确的彩色输出?我进行了很多搜索,但没有找到实现它的方法。请帮助我前进。

from future import print_function
import sys
#from OCC.STEPCAFControl import STEPCAFControl_Reader
from OCC.STEPControl import STEPControl_Reader
from OCC.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity
from OCC.Display.SimpleGui import init_display
from OCC.Display.WebGl import threejs_renderer

step_reader = STEPControl_Reader()
status = step_reader.ReadFile('./models/test.STEP')

if status == IFSelect_RetDone: # check status
failsonly = False
step_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
step_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)

ok = step_reader.TransferRoot(1)
_nbs = step_reader.NbShapes()
aResShape = step_reader.Shape(1)
else:
print("Error: can't read file.")
sys.exit(0)

#display, start_display, add_menu, add_function_to_menu = init_display()
#display.DisplayShape(aResShape, update=True)
#start_display()

my_renderer = threejs_renderer.ThreejsRenderer(background_color="#123345")
my_renderer.DisplayShape(aResShape)

以上代码用于使用 Python 读取 STEP 文件。

4

0 回答 0