Update 2:This is where I get so far…
function generateVtkPolyData(vertices, faces) {
const vtkPolyData = vtk.Common.DataModel.vtkPolyData;
const vtkPoints = vtk.Common.Core.vtkPoints;
const vtkCellArray = vtk.Common.Core.vtkCellArray;
const polyData = vtkPolyData.newInstance();
const points = vtkPoints.newInstance();
points.setNumberOfPoints(vertices.length);
vertices.forEach((vertex, index) => {
points.setPoint(index, vertex);
});
const polys = vtkCellArray.newInstance();
faces.forEach((face) => {
polys.insertNextCell([face.length, ...face]);
});
polyData.setPoints(points);
polyData.setPolys(polys);
return polyData;
}
initOpenCascade().then(openCascade => {
document.getElementById("step-file").addEventListener('input', async (event) => {
const shape = await loadSTEPorIGES(openCascade, event.srcElement.files[0]);
const fullScreenRenderer = vtk.Rendering.Misc.vtkFullScreenRenderWindow.newInstance();
const actor = vtk.Rendering.Core.vtkActor.newInstance();
const mapper = vtk.Rendering.Core.vtkMapper.newInstance();
const vtkTriangleFilter = vtk.Filters.General.vtkTriangleFilter;
/* shape vertices and faces for simple box 10x10x10:
shape.vertices = [
[-5, -5, -5],
[-5, -5, 5],
[-5, 5, -5],
[-5, 5, 5],
[5, -5, -5],
[5, -5, 5],
[5, 5, -5],
[5, 5, 5],
]
shape.faces = [
[0, 1, 2, 3],
[4, 5, 6, 7],
[0, 1, 4, 5],
[2, 3, 6, 7],
[0, 2, 4, 6],
[1, 3, 5, 7],
]
*/
const polyData = generateVtkPolyData(shape.vertices, shape.faces)
const triangleFilter = vtkTriangleFilter.newInstance();
triangleFilter.setInputData(polyData);
triangleFilter.update();
actor.setMapper(mapper);
mapper.setInputData(triangleFilter.getOutputData());
const renderer = fullScreenRenderer.getRenderer();
renderer.addActor(actor);
renderer.resetCamera();
const renderWindow = fullScreenRenderer.getRenderWindow();
renderWindow.render();
});
});
The problem that I have now is with vtkTriangleFilter:
Triangulation failed at cellOffset 0
Triangulation failed at cellOffset 6
Triangulation failed at cellOffset 12
Triangulation failed at cellOffset 18
Triangulation failed at cellOffset 24
Triangulation failed at cellOffset 30
What is wrong here?