Search in sources :

Example 1 with Text3DHelper

use of org.fxyz.shapes.primitives.helper.Text3DHelper 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();
}
Also used : IntStream(java.util.stream.IntStream) Path(javafx.scene.shape.Path) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) DoubleProperty(javafx.beans.property.DoubleProperty) Function(java.util.function.Function) IntegerProperty(javafx.beans.property.IntegerProperty) CullFace(javafx.scene.shape.CullFace) TriangleMesh(javafx.scene.shape.TriangleMesh) ArrayList(java.util.ArrayList) LineSegment(org.fxyz.shapes.primitives.helper.LineSegment) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) ColorPalette(org.fxyz.utils.Palette.ColorPalette) Mesh(javafx.scene.shape.Mesh) Patterns(org.fxyz.utils.Patterns) Text3DHelper(org.fxyz.shapes.primitives.helper.Text3DHelper) Color(javafx.scene.paint.Color) Translate(javafx.scene.transform.Translate) TextureMode(org.fxyz.shapes.primitives.helper.TextureMode) Group(javafx.scene.Group) DrawMode(javafx.scene.shape.DrawMode) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) Stream(java.util.stream.Stream) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) DepthTest(javafx.scene.DepthTest) MeshHelper(org.fxyz.shapes.primitives.helper.MeshHelper) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableList(javafx.collections.ObservableList) StringProperty(javafx.beans.property.StringProperty) Shape(javafx.scene.shape.Shape) Point3D(org.fxyz.geometry.Point3D) Bounds(javafx.geometry.Bounds) Point3D(org.fxyz.geometry.Point3D) Bounds(javafx.geometry.Bounds) Text3DHelper(org.fxyz.shapes.primitives.helper.Text3DHelper) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList) Translate(javafx.scene.transform.Translate) MeshHelper(org.fxyz.shapes.primitives.helper.MeshHelper) LineSegment(org.fxyz.shapes.primitives.helper.LineSegment)

Example 2 with Text3DHelper

use of org.fxyz.shapes.primitives.helper.Text3DHelper 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();
}
Also used : Path(javafx.scene.shape.Path) IntStream(java.util.stream.IntStream) Path(javafx.scene.shape.Path) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) DoubleProperty(javafx.beans.property.DoubleProperty) Function(java.util.function.Function) IntegerProperty(javafx.beans.property.IntegerProperty) CullFace(javafx.scene.shape.CullFace) TriangleMesh(javafx.scene.shape.TriangleMesh) ArrayList(java.util.ArrayList) LineSegment(org.fxyz.shapes.primitives.helper.LineSegment) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) ColorPalette(org.fxyz.utils.Palette.ColorPalette) Mesh(javafx.scene.shape.Mesh) Patterns(org.fxyz.utils.Patterns) Text3DHelper(org.fxyz.shapes.primitives.helper.Text3DHelper) Color(javafx.scene.paint.Color) Translate(javafx.scene.transform.Translate) TextureMode(org.fxyz.shapes.primitives.helper.TextureMode) Group(javafx.scene.Group) DrawMode(javafx.scene.shape.DrawMode) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) Stream(java.util.stream.Stream) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) DepthTest(javafx.scene.DepthTest) MeshHelper(org.fxyz.shapes.primitives.helper.MeshHelper) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableList(javafx.collections.ObservableList) StringProperty(javafx.beans.property.StringProperty) Shape(javafx.scene.shape.Shape) Point3D(org.fxyz.geometry.Point3D) Bounds(javafx.geometry.Bounds) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Text3DHelper(org.fxyz.shapes.primitives.helper.Text3DHelper)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects (java.util.Objects)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 Stream (java.util.stream.Stream)2 BooleanProperty (javafx.beans.property.BooleanProperty)2 DoubleProperty (javafx.beans.property.DoubleProperty)2 IntegerProperty (javafx.beans.property.IntegerProperty)2 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)2 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)2 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)2 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)2 StringProperty (javafx.beans.property.StringProperty)2 FXCollections (javafx.collections.FXCollections)2 ObservableList (javafx.collections.ObservableList)2 Bounds (javafx.geometry.Bounds)2 DepthTest (javafx.scene.DepthTest)2