Skip to content

Commit 9e5b58a

Browse files
committed
add export ply example
1 parent 5a61989 commit 9e5b58a

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
##Copyright 2021 Thomas Paviot (tpaviot@gmail.com)
2+
##
3+
##This file is part of pythonOCC.
4+
##
5+
##pythonOCC is free software: you can redistribute it and/or modify
6+
##it under the terms of the GNU Lesser General Public License as published by
7+
##the Free Software Foundation, either version 3 of the License, or
8+
##(at your option) any later version.
9+
##
10+
##pythonOCC is distributed in the hope that it will be useful,
11+
##but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
##GNU Lesser General Public License for more details.
14+
##
15+
##You should have received a copy of the GNU Lesser General Public License
16+
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
17+
18+
from OCC.Core.TDocStd import TDocStd_Document
19+
from OCC.Core.TCollection import TCollection_ExtendedString, TCollection_AsciiString
20+
from OCC.Core.XCAFDoc import (
21+
XCAFDoc_DocumentTool_ShapeTool,
22+
XCAFDoc_DocumentTool_LayerTool,
23+
)
24+
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere
25+
from OCC.Core.TColStd import TColStd_IndexedDataMapOfStringString
26+
from OCC.Core.Message import Message_ProgressRange
27+
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
28+
from OCC.Core.BRepTools import breptools_Clean
29+
30+
# GLTF export
31+
from OCC.Core.RWPly import RWPly_CafWriter
32+
33+
# create the shapeto export
34+
shp = BRepPrimAPI_MakeSphere(60.0).Shape()
35+
36+
# create a document
37+
doc = TDocStd_Document(TCollection_ExtendedString("pythonocc-doc"))
38+
shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main())
39+
layer_tool = XCAFDoc_DocumentTool_LayerTool(doc.Main())
40+
41+
# mesh shape
42+
breptools_Clean(shp)
43+
44+
# Triangulate
45+
msh_algo = BRepMesh_IncrementalMesh(shp, True)
46+
msh_algo.Perform()
47+
48+
sub_shape_label = shape_tool.AddShape(shp)
49+
50+
# metadata
51+
a_file_info = TColStd_IndexedDataMapOfStringString()
52+
a_file_info.Add(
53+
TCollection_AsciiString("Authors"), TCollection_AsciiString("pythonocc")
54+
)
55+
56+
rwply_writer = RWPly_CafWriter(TCollection_AsciiString("sphere.ply"))
57+
pr = Message_ProgressRange()
58+
rwply_writer.Perform(doc, a_file_info, pr)

0 commit comments

Comments
 (0)