Search in sources :

Example 1 with MeshHelper

use of org.fxyz.shapes.primitives.helper.MeshHelper in project FXyzLib by Birdasaur.

the class TexturedMesh method precreateMesh.

protected MeshHelper precreateMesh() {
    MeshHelper mh = new MeshHelper();
    mh.setPoints(helper.updateVertices(listVertices));
    switch(textureType.get()) {
        case NONE:
            mh.setTexCoords(textureCoords);
            mh.setFaces(helper.updateFacesWithTextures(listFaces, listTextures));
            break;
        case PATTERN:
            if (areaMesh.getHeight() > 0 && areaMesh.getWidth() > 0) {
                mh.setTexCoords(helper.updateTexCoordsWithPattern((int) rectMesh.getWidth(), (int) rectMesh.getHeight(), patternScale.get(), areaMesh.getHeight() / areaMesh.getWidth()));
            } else {
                mh.setTexCoords(helper.updateTexCoordsWithPattern((int) rectMesh.getWidth(), (int) rectMesh.getHeight(), patternScale.get()));
            }
            mh.setFaces(helper.updateFacesWithTextures(listFaces, listTextures));
            break;
        case IMAGE:
            mh.setTexCoords(textureCoords);
            if (listTextures.size() > 0) {
                mh.setFaces(helper.updateFacesWithTextures(listFaces, listTextures));
            } else {
                mh.setFaces(helper.updateFacesWithVertices(listFaces));
            }
            break;
        case COLORED_VERTICES_1D:
            mh.setTexCoords(helper.getTexturePaletteArray());
            mh.setFaces(helper.updateFacesWithFunctionMap(listVertices, listFaces));
            break;
        case COLORED_VERTICES_3D:
            mh.setTexCoords(helper.getTexturePaletteArray());
            mh.setFaces(helper.updateFacesWithDensityMap(listVertices, listFaces));
            break;
        case COLORED_FACES:
            mh.setTexCoords(helper.getTexturePaletteArray());
            mh.setFaces(helper.updateFacesWithFaces(listFaces));
            break;
    }
    // 0 == hard edges
    int[] faceSmoothingGroups = new int[listFaces.size()];
    // 1: soft edges, all the faces in same surface
    Arrays.fill(faceSmoothingGroups, 1);
    if (smoothingGroups != null) {
        //            for(int i=0; i<smoothingGroups.length; i++){
        //                System.out.println("i: "+smoothingGroups[i]);
        //            }
        mh.setFaceSmoothingGroups(smoothingGroups);
    } else {
        mh.setFaceSmoothingGroups(faceSmoothingGroups);
    }
    return mh;
}
Also used : TriangleMeshHelper(org.fxyz.shapes.primitives.helper.TriangleMeshHelper) MeshHelper(org.fxyz.shapes.primitives.helper.MeshHelper)

Example 2 with MeshHelper

use of org.fxyz.shapes.primitives.helper.MeshHelper in project FXyzLib by Birdasaur.

the class ScatterMesh method createDots.

private void createDots() {
    if (!joinSegments.get()) {
        List<TexturedMesh> dots = new ArrayList<>();
        index = new AtomicInteger();
        scatterData.get().forEach(point3d -> {
            TexturedMesh dot = new TetrahedraMesh(height.get(), level.get(), point3d);
            dot.setCullFace(CullFace.BACK);
            dot.setDrawMode(DrawMode.FILL);
            dot.setDepthTest(DepthTest.ENABLE);
            dot.setId("" + index.getAndIncrement());
            dots.add(dot);
        });
        meshes.addAll(dots);
    } else {
        //            TexturedMesh dot = new CuboidMesh(height.get(), height.get(), height.get(), level.get(), scatterData.get().get(0));
        TexturedMesh dot = new TetrahedraMesh(height.get(), level.get(), scatterData.get().get(0));
        dot.setCullFace(CullFace.BACK);
        dot.setDrawMode(DrawMode.FILL);
        dot.setDepthTest(DepthTest.ENABLE);
        dot.setId("0");
        /*
            Combine new polyMesh with previous polyMesh into one single polyMesh
            */
        MeshHelper mh = new MeshHelper((TriangleMesh) dot.getMesh());
        //            TexturedMesh dot1 = new CuboidMesh(height.get(), height.get(), height.get(), level.get(), null);
        TexturedMesh dot1 = new TetrahedraMesh(height.get(), level.get(), null);
        MeshHelper mh1 = new MeshHelper((TriangleMesh) dot1.getMesh());
        mh.addMesh(mh1, scatterData.get().stream().skip(1).collect(Collectors.toList()));
        dot.updateMesh(mh);
        meshes.add(dot);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) MeshHelper(org.fxyz.shapes.primitives.helper.MeshHelper)

Example 3 with MeshHelper

use of org.fxyz.shapes.primitives.helper.MeshHelper 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)

Aggregations

MeshHelper (org.fxyz.shapes.primitives.helper.MeshHelper)3 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 List (java.util.List)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 BooleanProperty (javafx.beans.property.BooleanProperty)1 DoubleProperty (javafx.beans.property.DoubleProperty)1 IntegerProperty (javafx.beans.property.IntegerProperty)1 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)1 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)1 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 StringProperty (javafx.beans.property.StringProperty)1 FXCollections (javafx.collections.FXCollections)1 ObservableList (javafx.collections.ObservableList)1 Bounds (javafx.geometry.Bounds)1