Hi Lie,

Here is how I create vertex and normal buffers for OpenGL, hope it is
helpful.


def mesh_shape(self,shape):

        if shape.IsNull():

            return



        BRepMesh_Mesh(shape,0.01)

        t = Topo(shape)

        numTriangles = 0

        triangulations = []

        faces = []

        for  aFace in t.faces():

            loc = TopLoc_Location()

            triangulation = BRep_Tool_Triangulation(aFace,loc)

            faces.append(aFace)

            if triangulation.IsNull() == False:

                numTriangles += triangulation.GetObject().NbTriangles()

                triangulations.append(triangulation)



        normals = [0.]*numTriangles*3*3

        triangles = [0.]*numTriangles*3*3



        t = Topo(shape)

        index = 0

        for i in range(len(triangulations)):

            triangulation = triangulations[i]

            tris = triangulation.GetObject().Triangles()

            nodes = triangulation.GetObject().Nodes()

            prop = BRepGProp_Face(faces[i])

            for j in range(1,triangulation.GetObject().NbTriangles()+1):



                N1 = None

                N2 = None

                N3 = None

                #Poly_Triangle

                N1,N2,N3 = tris.Value(j).Get()

                V1 = nodes.Value(N1)

                V2 = nodes.Value(N2)

                V3 = nodes.Value(N3)

                triangles[index*9] = V1.X();

                triangles[index*9+1] = V1.Y();

                triangles[index*9+2] = V1.Z();

                triangles[index*9+3] = V2.X();

                triangles[index*9+4] = V2.Y();

                triangles[index*9+5] = V2.Z();

                triangles[index*9+6] = V3.X();

                triangles[index*9+7] = V3.Y();

                triangles[index*9+8] = V3.Z();



                uv = triangulation.GetObject().UVNodes().Value(N1);

                tmp = gp_Pnt()

                norm = gp_Vec()

                prop.Normal(uv.X(),uv.Y(),tmp,norm);

                norm.Normalize();

                normals[index*9]=norm.X();

                normals[index*9+1]=norm.Y();

                normals[index*9+2]=norm.Z();



                norm.Normalize();

                normals[index*9+3]=norm.X();

                normals[index*9+4]=norm.Y();

                normals[index*9+5]=norm.Z();



                uv = triangulation.GetObject().UVNodes().Value(N3)

                prop.Normal(uv.X(),uv.Y(),tmp,norm)

                norm.Normalize()

                normals[index*9+6]=norm.X()

                normals[index*9+7]=norm.Y()

                normals[index*9+8]=norm.Z()

                index = index+1


On Sat, Sep 3, 2011 at 9:30 PM, Lie Pablo <lie...@gmail.com> wrote:

> István Csanády <istvancsanady@...> writes:
>
> >
> >
> > Hi All!
> >
> > If I give an topological incorrect shape to QuickTriangleMesh, it crashes
> if I
> call compute() (And it does not crash if I call compute_default_precision()
> but
> does not return any data). However the SimpleGUI can display it. Is it
> possible
> somehow to use the SimpleGUI's mesher algorithm (and curve discretizer)?
> I've
> attached the code. (Mac OSX 10.6, python 2.6)
> >
> > István
> >
> > Attachment (main.py): application/octet-stream, 5132 bytes
>
>
> Hi István,
>
> I'm working with QuickTriangleMesh and I found another problem... I get
> about
> half of the normals flipped. But if I save it straight away with
> StlAPI_Writer
> the normals are ok.
>
> All best
> Lie Pablo
>
>
> _______________________________________________
> Pythonocc-users mailing list
> Pythonocc-users@gna.org
> https://mail.gna.org/listinfo/pythonocc-users
>
_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users

Reply via email to