Sharan
Sharan

Reputation: 15

is it possible to convert SVGPath to Mesh in javafx

I am trying to convert .svg file to 3d (.obj file) using javafx.

I can able to convert primitives like Shape - Cylinder, Box etc to Mesh. Is it possible to convert SVGPath to convert to any particular Mesh.

Upvotes: 1

Views: 675

Answers (1)

José Pereda
José Pereda

Reputation: 45486

The open source library FXyz has exactly what you are looking for: a SVG3DMesh class that given a 2D SVGPath (or a string with its content) will return a 3D TriangleMesh, extruding the 2D shape to a certain height.

Later on you can export that mesh to a obj file.

This is a code snippet of how you can use it:

SVG3DMesh svg3DMesh = new SVG3DMesh("M40,60 C42,48 44,30 25,32", 10);

SVG3DMesh

You can show the mesh:

svg3DMesh.setDrawMode(DrawMode.LINE);
svg3DMesh.setCullFace(CullFace.NONE);

or show a solid 3D object with the color you want:

svg3DMesh.setTextureModeNone(Color.RED);

For exporting the mesh to obj:

OBJWriter writer=new OBJWriter((TriangleMesh) ((TexturedMesh) svg3DMesh.getMeshFromLetter("")).getMesh(), "svg");
writer.setMaterialColor(Color.RED);
writer.exportMesh();

it will generate svg.obj and svg.mtl.

Upvotes: 1

Related Questions