コンポーネントを描画するために Python3.4.2 と pythonOCC-0.16.0-win32-py34.exe を使用しています。すべてのコンポーネントは 1 つの定義された色で適切にレンダリングされますが、実際のコンポーネントのようには見えません。
上の画像は、STEPファイルから1色で3D画像を生成する私のPython実装です。
以下の画像は、私の Windows ソフトウェアの 1 つをレンダリングしたもので、そこで 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 ファイルを読み込むために使用されます。