Graphic3d_ArrayOfTriangles not using normals

Hi,

I'm using the Graphic3d_ArrayOfTriangles object to draw a mesh with curvature shading.
I instantiate like: Graphic3d_ArrayOfTriangles(n_verts) and use AddVertex( pnt, normal, color ).
However, to my surprise the resulting object is flat shaded, I was expecting gouraud shading.
What am I doing wrong?

Thanks,

-jelle

Roman Lygin's picture

Hi Jelle,

After having briefly looked at Graphic3d_ArrayOfTriangles.cdl and the code in StdPrs I guess you need to specify an explicit Standard_True parameter to the constructor to make it recognize normals. For instance:

Handle(Graphic3d_ArrayOfTriangles) parray = new Graphic3d_ArrayOfTriangles(nbVertices, 3*nbTriangles, Standard_True,Standard_False,Standard_False,Standard_True);

Let us know if this worked. Good luck !
Roman
---
opencascade.blogspot.com - the Open CASCADE blog
www.cadexchanger.com - CAD Exchanger, your 3D data translator

jelle's picture

Hi Roman,

Many thanks for your feedback.
Well, you know, perhaps I'm using the wrong Graphic3d_* primitive.
I've tried with other constructors, but pretty much get a similar result.
Here's a snippet of what I'm trying to do, which is basically reconstructing the mesh, with its vertices colored according to curvature. Perhaps there's a better way to reconstruct the mesh?

Much appreciated,

-jelle

aot = Graphic3d_ArrayOfTriangles(self.triangles.Length()*3, 0, True, True, True, True)
# same result
# aot = Graphic3d_ArrayOfTriangles(self.triangles.Length()*3, 0, True, True,)

for i in xrange( 1, self.triangles.Length()+1):
print 'compute triangle number', i
_tri = self.triangles(i)
p,q,r = self.nodes(_tri(1)), self.nodes(_tri(2)), self.nodes(_tri(3))

def _normal(p,q,r):
a,b,c = p.XYZ(), q.XYZ(), r.XYZ()
v1, v2 = b-a, c-b
d = gp_Dir(v1^v2)
print 'normal', d.Coord()
return d

def do(i,j, normal):
p = self.nodes(_tri(i))
u1, v1 = self.uv_nodes(_tri(i)).XY().Coord()
self.curvature.SetParameters(round(u1, 3), round(v1, 3))
g1 = self.curvatureSampler()
color = self.get_color(span, g1, minVisualizedCurvature)
aot.AddVertex(p, normal, color)
return g1