use of org.fxyz.shapes.primitives.helper.LineSegment in project FXyzLib by Birdasaur.
the class Text3DMesh method createLetter.
private void createLetter(String letter) {
Text3DHelper helper = new Text3DHelper(letter, font.get(), fontSize.get());
List<Point3D> origin = helper.getOffset();
final int ind = indSegments.get();
helper.getLineSegment().stream().map(poly -> poly.getPath()).forEach(path -> letterPath = Shape.union(letterPath, path));
helper.getLineSegment().stream().forEach(poly -> {
final List<Point3D> points = poly.getPoints();
List<List<Point3D>> holes = null;
if (poly.getHoles().size() > 0) {
holes = poly.getHoles().stream().map(LineSegment::getPoints).collect(Collectors.toList());
}
List<Point3D> invert = IntStream.range(0, points.size()).mapToObj(i -> points.get(points.size() - 1 - i)).distinct().collect(Collectors.toList());
Bounds bounds = null;
if (joinSegments.get()) {
bounds = letterPath.getBoundsInParent();
}
TriangulatedMesh polyMesh = new TriangulatedMesh(invert, holes, level.get(), height.get(), 0d, bounds);
if (indSegments.get() > ind && joinSegments.get()) {
MeshHelper mh = new MeshHelper((TriangleMesh) meshes.get(meshes.size() - 1).getMesh());
MeshHelper mh1 = new MeshHelper((TriangleMesh) polyMesh.getMesh());
mh1.addMesh(mh);
polyMesh.updateMesh(mh1);
meshes.set(meshes.size() - 1, polyMesh);
} else {
meshes.add(polyMesh);
}
polyMesh.getTransforms().addAll(new Translate(offset.get(ind).x - origin.get(0).x + indLetters.get() * gap.doubleValue(), 0, 0));
polyMesh.setCullFace(CullFace.BACK);
polyMesh.setDrawMode(DrawMode.FILL);
polyMesh.setDepthTest(DepthTest.ENABLE);
polyMesh.setId(poly.getLetter());
System.out.println("l " + poly.getLetter());
indSegments.getAndIncrement();
});
indLetters.getAndIncrement();
}
use of org.fxyz.shapes.primitives.helper.LineSegment in project FXyzLib by Birdasaur.
the class Text3DMesh method updateMesh.
protected final void updateMesh() {
// 1. Full Text to get position of each letter
Text3DHelper helper = new Text3DHelper(text3D.get(), font.get(), fontSize.get());
offset = helper.getOffset();
// 2. Create mesh for each LineSegment
meshes = FXCollections.<TexturedMesh>observableArrayList();
indLetters = new AtomicInteger();
indSegments = new AtomicInteger();
letterPath = new Path();
text3D.get().chars().mapToObj(i -> (char) i).filter(c -> c != SPACE).forEach(letter -> createLetter(letter.toString()));
getChildren().setAll(meshes);
updateTransforms();
}
Aggregations