我有一个 Django 应用程序,我在其中使用了 pythonOCC 包。我必须在我的模板中显示 3D .stl、.stp、.igs 文件。我尝试使用包中 x3dom_renderer.py 文件中的 render() 函数。
这是我的看法:
from OCC.Extend.DataExchange import read_step_file
from OCC.Display.WebGl import x3dom_renderer
from OCC.Core.BRep import BRep_Builder
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.BRepTools import breptools_Read
def index(request):
shape = read_step_file('test.stp')
my_renderer = x3dom_renderer.X3DomRenderer()
my_renderer.DisplayShape(shape)
my_renderer.render()
return render(request, 'index.html')
当我调用该render()
函数时,我的 vscode 控制台上会出现以下输出,并且由于由 pythonocc 而不是 django 创建的烧瓶应用程序开始在 localhost 中运行,因此我index.html
永远不会呈现。
调用渲染函数时的输出:
** Model Complete Check List **
Check:1 -- Entity (n0:id) 5:#14 Type:CURVE_STYLE
Parameter n0.2 (curve_font) not an Entity
Check:2 -- Entity (n0:id) 6:#15 Type:CURVE_STYLE
Parameter n0.2 (curve_font) not an Entity
Check:3 -- Entity (n0:id) 7:#16 Type:CURVE_STYLE
Parameter n0.2 (curve_font) not an Entity
Check:4 -- Entity (n0:id) 8:#17 Type:CURVE_STYLE
Parameter n0.2 (curve_font) not an Entity
Check:5 -- Entity (n0:id) 9:#18 Type:CURVE_STYLE
Parameter n0.2 (curve_font) not an Entity
Check:6 -- Entity (n0:id) 10:#19 Type:CURVE_STYLE
Parameter n0.2 (curve_font) not an Entity
## x3dom webgl renderer - render axes/planes : True - axes/plane zoom factor : 1
| meshing shapes... 100%
## Serving C:\Users\imgea\AppData\Local\Temp\tmppopa5opx
## using Flask
## Open your webbrowser at the URL: http://localhost:8080
正如您在此x3dom_renderer.py
https://github.com/tpaviot/pythonocc-core/blob/master/src/Display/WebGl/x3dom_renderer.py中看到的,html 文件是在此 python 文件中创建的,并根据以下图像进行成形我发了。如何在我的 Django 模板中使用这个渲染器?你能给点建议吗?