Polydata normals

Hello,

I’m currently working on implementing an OBJ writer in vtkjs.

I’m able to read out the vertices and faces via:

    const polys = polyData.getPolys().getData();
    const points = polyData.getPoints().getData();

And write it into an obj file which looks correct.

I was now wondering on how I would go on extracting normals from polyData? I found nothing in the documentation about normals.
I know I could get the normal of a face via: vtkTriangle.computeNormal(v1, v2, v3, n);.
Would this be the best way to go about this?

Or is there a way to extract the normals from the polyData?

Kind regards,
Emil

Hi,

The best my be to store normals on points instead of cells. You can get those with the vtkPolyDataNormals filter. Then you can get the point normals with polyData.getPointData().getNormals().getData()
Should you want normals on cells instead, the best would be to improve vtkPolyDataNormals (PR is welcomed) to conditionally compute the normals on the cells (not just the normals of the points as it is right now).
Then you would then be able to get the normals from polyData.getCellData().getNormals().getData().

Hth, Julien.

FYI there is some work already going towards an OBJ writer here: feat(objwriter): add support for vtkOBJWriter by daker · Pull Request #2405 · Kitware/vtk-js · GitHub

Depending on how far you are, you can look to merge your ideas and changes with that effort.

Alright, thanks for the reply!
Was already thinking of making a PR for mu crude implementation. But I’ll check this one out then!