How to create a more accuracy triangles?

Hi Dears.
I'm beginner of OpenCC.
I saw a meshing animation in showroom section
: creating a sphere, creating a mesh, and "creating more and more accuracy mesh"

I am looking for a sample.
I found a sample , 02_7_TopologyTriangulation.
That show how to make some shape and create triangles from the shape.
(I cannot understand whole code.)

How can I create more accuracy triangles, adding some code
: just call some functins? calculate the first mesh result?

Please, show me a key point,
or very kindly a sample. ^^

Thank you for reading my poor English.
I'm waiting for your reply.

Have a nice day.

Thomas Paviot's picture


I guess you talk about the Mesh() method of the BRepMesh class. This method takes two parameters: the TopoDS_Shape to mesh and a Standard_Real float number (named d). The more d is small, the more precise is the mesh.

Here is a part of a pythonOCC sample that shows howto mesh a TopoDS_Shape (a sphere actually) with this basic algorithm:

shape = BRepPrimAPI_MakeSphere(gp_Pnt(100,20,20),80).Shape()
MESH_QUALITY = 0.8 # test with 0.5, 0.1, 0.05 etc.
# Mesh the shape
builder = BRep_Builder()
Comp = TopoDS_Compound()

ex = TopExp_Explorer(shape,TopAbs_FACE)
while ex.More():
F = TopoDS().Face(ex.Current())
L = TopLoc_Location()
facing = (BRep_Tool().Triangulation(F,L)).GetObject()
tab = facing.Nodes()
tri = facing.Triangles()
for i in range(1,facing.NbTriangles()+1):
trian = tri.Value(i)
index1, index2, index3 = trian.Get()
for j in range(1,4):
if j==1:
M = index1
N = index2
elif j==2:
N = index3
elif j==3:
M = index2
ME = BRepBuilderAPI_MakeEdge(tab.Value(M),tab.Value(N))
if ME.IsDone():

# Display

Complete source code of this sample is available here:



iphds's picture

I'm very thank you for your answer.