Search in sources :

Example 11 with TriangleMesh

use of javafx.scene.shape.TriangleMesh in project FXyzLib by Birdasaur.

the class ConeMesh method createCone.

/*
    Methods
     */
private TriangleMesh createCone(int divisions, float radius, float height) {
    TriangleMesh mesh = new TriangleMesh();
    // Start with the top of the cone, later we will build our faces from these
    // Point 0: Top of the Cone
    mesh.getPoints().addAll(0, 0, 0);
    // Generate the segments of the bottom circle (Cone Base)
    double segment_angle = 2.0 * Math.PI / divisions;
    float x, z;
    double angle;
    double halfCount = (Math.PI / 2 - Math.PI / (divisions / 2));
    // Reverse loop for speed!! der
    for (int i = divisions + 1; --i >= 0; ) {
        angle = segment_angle * i;
        x = (float) (radius * Math.cos(angle - halfCount));
        z = (float) (radius * Math.sin(angle - halfCount));
        mesh.getPoints().addAll(x, height, z);
    }
    // Point N: Center of the Cone Base
    mesh.getPoints().addAll(0, height, 0);
    // @TODO Birdasaur for now we'll just make an empty texCoordinate group
    // @DUB HELP ME DUBi Wan Kanobi, you are my only hope!
    // I'm not good at determining Texture Coordinates
    mesh.getTexCoords().addAll(0, 0);
    // Must loop through each face, not including first and last points
    for (int i = 1; i <= divisions; i++) {
        // use dummy texCoords, @TODO Upgrade face code to be real
        mesh.getFaces().addAll(// Vertical Faces "wind" counter clockwise
        0, // Vertical Faces "wind" counter clockwise
        0, // Vertical Faces "wind" counter clockwise
        i + 1, // Vertical Faces "wind" counter clockwise
        0, // Vertical Faces "wind" counter clockwise
        i, // Vertical Faces "wind" counter clockwise
        0, // Base Faces "wind" clockwise
        divisions + 2, // Base Faces "wind" clockwise
        0, // Base Faces "wind" clockwise
        i, // Base Faces "wind" clockwise
        0, // Base Faces "wind" clockwise
        i + 1, // Base Faces "wind" clockwise
        0);
    }
    return mesh;
}
Also used : TriangleMesh(javafx.scene.shape.TriangleMesh)

Example 12 with TriangleMesh

use of javafx.scene.shape.TriangleMesh in project FXyzLib by Birdasaur.

the class CuboidMesh method createCube.

private TriangleMesh createCube(float width, float height, float depth, int level) {
    TriangleMesh m0 = null;
    if (level > 0) {
        m0 = createCube(width, height, depth, level - 1);
    }
    if (level == 0) {
        a = new Affine();
        float L = 2f * width + 2f * depth;
        float H = height + 2f * depth;
        float hw = width / 2f, hh = height / 2f, hd = depth / 2f;
        if (center.get() != null) {
            a = a.createConcatenation(new Translate(center.get().x, center.get().y, center.get().z));
        // hw+=center.get().x;
        // hh+=center.get().y;
        // hd+=center.get().z;
        }
        final float[] baseVertices = new float[] { hw, hh, hd, hw, hh, -hd, hw, -hh, hd, hw, -hh, -hd, -hw, hh, hd, -hw, hh, -hd, -hw, -hh, hd, -hw, -hh, -hd };
        final float[] baseTexCoords = new float[] { depth / L, 0f, (depth + width) / L, 0f, 0f, depth / H, depth / L, depth / H, (depth + width) / L, depth / H, (2f * depth + width) / L, depth / H, 1f, depth / H, 0f, (depth + height) / H, depth / L, (depth + height) / H, (depth + width) / L, (depth + height) / H, (2f * depth + width) / L, (depth + height) / H, 1f, (depth + height) / H, depth / L, 1f, (depth + width) / L, 1f };
        final int[] baseTexture = new int[] { 8, 3, 7, 3, 2, 7, 9, 10, 4, 4, 10, 5, 8, 12, 9, 9, 12, 13, 3, 4, 0, 0, 4, 1, 8, 9, 3, 3, 9, 4, 11, 6, 10, 10, 6, 5 };
        final List<Integer> baseFaces = Arrays.asList(0, 2, 1, 2, 3, 1, 4, 5, 6, 6, 5, 7, 0, 1, 4, 4, 1, 5, 2, 6, 3, 3, 6, 7, 0, 4, 2, 2, 4, 6, 1, 3, 5, 5, 3, 7);
        for (int i = 0; i < baseVertices.length / 3; i++) {
            Point3D ta = transform(baseVertices[3 * i], baseVertices[3 * i + 1], baseVertices[3 * i + 2]);
            baseVertices[3 * i] = ta.x;
            baseVertices[3 * i + 1] = ta.y;
            baseVertices[3 * i + 2] = ta.z;
        }
        points0 = baseVertices;
        numVertices = baseVertices.length / 3;
        texCoord0 = baseTexCoords;
        numTexCoords = baseTexCoords.length / 2;
        faces0 = IntStream.range(0, baseFaces.size() / 3).mapToObj(i -> IntStream.of(baseFaces.get(3 * i), baseTexture[3 * i], baseFaces.get(3 * i + 1), baseTexture[3 * i + 1], baseFaces.get(3 * i + 2), baseTexture[3 * i + 2])).flatMapToInt(i -> i).toArray();
        numFaces = baseFaces.size() / 3;
    } else if (m0 != null) {
        points0 = new float[numVertices * m0.getPointElementSize()];
        m0.getPoints().toArray(points0);
    }
    List<Point3D> points1 = IntStream.range(0, numVertices).mapToObj(i -> new Point3D(points0[3 * i], points0[3 * i + 1], points0[3 * i + 2])).collect(Collectors.toList());
    if (level > 0 && m0 != null) {
        texCoord0 = new float[numTexCoords * m0.getTexCoordElementSize()];
        m0.getTexCoords().toArray(texCoord0);
    }
    texCoord1 = IntStream.range(0, numTexCoords).mapToObj(i -> new Point2D(texCoord0[2 * i], texCoord0[2 * i + 1])).collect(Collectors.toList());
    if (level > 0 && m0 != null) {
        faces0 = new int[numFaces * m0.getFaceElementSize()];
        m0.getFaces().toArray(faces0);
    }
    List<Face3> faces1 = IntStream.range(0, numFaces).mapToObj(i -> new Face3(faces0[6 * i], faces0[6 * i + 2], faces0[6 * i + 4])).collect(Collectors.toList());
    index.set(points1.size());
    map.clear();
    listVertices.clear();
    listFaces.clear();
    listVertices.addAll(points1);
    faces1.forEach(face -> {
        int v1 = face.p0;
        int v2 = face.p1;
        int v3 = face.p2;
        if (level > 0) {
            int a = getMiddle(v1, points1.get(v1), v2, points1.get(v2));
            int b = getMiddle(v2, points1.get(v2), v3, points1.get(v3));
            int c = getMiddle(v3, points1.get(v3), v1, points1.get(v1));
            listFaces.add(new Face3(v1, a, c));
            listFaces.add(new Face3(v2, b, a));
            listFaces.add(new Face3(v3, c, b));
            listFaces.add(new Face3(a, b, c));
        } else {
            listFaces.add(new Face3(v1, v2, v3));
        }
    });
    map.clear();
    numVertices = listVertices.size();
    numFaces = listFaces.size();
    List<Face3> textures1;
    if (level == 0) {
        textures1 = IntStream.range(0, faces0.length / 6).mapToObj(i -> new Face3(faces0[6 * i + 1], faces0[6 * i + 3], faces0[6 * i + 5])).collect(Collectors.toList());
    } else {
        textures1 = listTextures.stream().map(t -> t).collect(Collectors.toList());
    }
    index.set(texCoord1.size());
    listTextures.clear();
    textures1.forEach(face -> {
        int v1 = face.p0;
        int v2 = face.p1;
        int v3 = face.p2;
        if (level > 0) {
            int a = getMiddle(v1, texCoord1.get(v1), v2, texCoord1.get(v2));
            int b = getMiddle(v2, texCoord1.get(v2), v3, texCoord1.get(v3));
            int c = getMiddle(v3, texCoord1.get(v3), v1, texCoord1.get(v1));
            listTextures.add(new Face3(v1, a, c));
            listTextures.add(new Face3(v2, b, a));
            listTextures.add(new Face3(v3, c, b));
            listTextures.add(new Face3(a, b, c));
        } else {
            listTextures.add(new Face3(v1, v2, v3));
        }
    });
    map.clear();
    texCoord0 = texCoord1.stream().flatMapToDouble(p -> DoubleStream.of(p.getX(), p.getY())).collect(() -> new FloatCollector(texCoord1.size() * 2), FloatCollector::add, FloatCollector::join).toArray();
    numTexCoords = texCoord0.length / 2;
    textureCoords = texCoord0;
    if (level == getLevel()) {
        areaMesh.setWidth(2f * width + 2f * depth);
        areaMesh.setHeight(height + 2f * depth);
        // 1<<j -> bitset, 00100. Otherwise: 000111 will mean they are shared
        smoothingGroups = IntStream.range(0, listFaces.size()).map(i -> 1 << (i / (listFaces.size() / 6))).toArray();
    // smoothing groups based on 3DViewer -> same result
    // float[] normals=new float[]{1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1};
    // int[] newFaces = IntStream.range(0, listFaces.size())
    // .mapToObj(i->IntStream.of((int)listFaces.get(i).x, (int)listFaces.get(i).x,
    // (int)listFaces.get(i).y, (int)listFaces.get(i).y,
    // (int)listFaces.get(i).z, (int)listFaces.get(i).z))
    // .flatMapToInt(i->i).toArray();
    // int[] newFaceNormals = IntStream.range(0,listFaces.size()).mapToObj(i->{
    // int j=(i/(listFaces.size()/6));
    // return IntStream.of(j,j,j);
    // }).flatMapToInt(i->i).toArray();
    // smoothingGroups=SmoothingGroups.calcSmoothGroups(new TriangleMesh(), newFaces, newFaceNormals, normals);
    }
    return createMesh();
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) Affine(javafx.scene.transform.Affine) HashMap(java.util.HashMap) DoubleProperty(javafx.beans.property.DoubleProperty) IntegerProperty(javafx.beans.property.IntegerProperty) CullFace(javafx.scene.shape.CullFace) TriangleMesh(javafx.scene.shape.TriangleMesh) NonInvertibleTransformException(javafx.scene.transform.NonInvertibleTransformException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Point2D(javafx.geometry.Point2D) Transform(javafx.scene.transform.Transform) ObjectProperty(javafx.beans.property.ObjectProperty) FloatCollector(org.fxyz.utils.FloatCollector) Translate(javafx.scene.transform.Translate) DrawMode(javafx.scene.shape.DrawMode) Collectors(java.util.stream.Collectors) DoubleStream(java.util.stream.DoubleStream) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) DepthTest(javafx.scene.DepthTest) Face3(org.fxyz.geometry.Face3) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Point3D(org.fxyz.geometry.Point3D) TriangleMesh(javafx.scene.shape.TriangleMesh) FloatCollector(org.fxyz.utils.FloatCollector) Affine(javafx.scene.transform.Affine) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Point2D(javafx.geometry.Point2D) Point3D(org.fxyz.geometry.Point3D) Translate(javafx.scene.transform.Translate) Face3(org.fxyz.geometry.Face3)

Example 13 with TriangleMesh

use of javafx.scene.shape.TriangleMesh in project FXyzLib by Birdasaur.

the class FrustumMesh method createFrustum.

private TriangleMesh createFrustum(float majorRadius, float minorRadius, float height, int level) {
    TriangleMesh m0 = null;
    if (level > 0) {
        m0 = createFrustum(majorRadius, minorRadius, height, level - 1);
    }
    if (level == 0) {
        a = new Affine();
        int div = DEFAULT_DIVISIONS > 3 ? DEFAULT_DIVISIONS : 3;
        if (getSectionType() != TriangleMeshHelper.SectionType.CIRCLE) {
            div = getSectionType().getSides() * ((int) (div / getSectionType().getSides()) + 1);
        }
        if (getAxisOrigin() != null && getAxisEnd() != null) {
            Point3D dir = getAxisEnd().substract(getAxisOrigin()).crossProduct(new Point3D(0, -1, 0));
            double angle = Math.acos(getAxisEnd().substract(getAxisOrigin()).normalize().dotProduct(new Point3D(0, -1, 0)));
            a = a.createConcatenation(new Translate(getAxisOrigin().x, getAxisOrigin().y - height / 2d, getAxisOrigin().z)).createConcatenation(new Rotate(-Math.toDegrees(angle), 0d, height / 2d, 0d, new javafx.geometry.Point3D(dir.x, -dir.y, dir.z)));
        }
        int nPoints = 2 * div + 2;
        float rBase = majorRadius;
        float rTop = minorRadius;
        float h = height;
        final float[] baseVertices = new float[nPoints * 3];
        // base at y=h/2
        for (int i = 0; i < div; i++) {
            double ang = i * 2d * Math.PI / div;
            double pol = polygonalSection(ang);
            Point3D ta = transform(rBase * pol * Math.cos(ang), h / 2, rBase * pol * Math.sin(ang));
            baseVertices[3 * i] = ta.x;
            baseVertices[3 * i + 1] = ta.y;
            baseVertices[3 * i + 2] = ta.z;
        }
        // top at y=-h/2
        for (int i = div; i < 2 * div; i++) {
            double ang = i * 2d * Math.PI / div;
            double pol = polygonalSection(ang);
            Point3D ta = transform(rTop * pol * Math.cos(ang), -h / 2, rTop * pol * Math.sin(ang));
            baseVertices[3 * i] = ta.x;
            baseVertices[3 * i + 1] = ta.y;
            baseVertices[3 * i + 2] = ta.z;
        }
        Point3D ta = transform(0, h / 2, 0);
        baseVertices[6 * div] = ta.x;
        baseVertices[6 * div + 1] = ta.y;
        baseVertices[6 * div + 2] = ta.z;
        ta = transform(0, -h / 2, 0);
        baseVertices[6 * div + 3] = ta.x;
        baseVertices[6 * div + 4] = ta.y;
        baseVertices[6 * div + 5] = ta.z;
        int nTextCoords = div * 4 + 6;
        float rectBase = (float) polygonalSize(rBase);
        float rectTop = (float) polygonalSize(rTop);
        float L = (float) (rBase + 2d * Math.PI * rBase);
        float H = 2f * (rBase + rTop) + h;
        final float[] baseTexCoords = new float[nTextCoords * 2];
        // u right ,v up
        for (int i = 0; i <= div; i++) {
            baseTexCoords[2 * i] = (float) (rBase + i * rectBase / div) / L;
            baseTexCoords[2 * i + 1] = (float) (2f * rTop + h) / H;
        }
        for (int i = 0; i <= div; i++) {
            baseTexCoords[2 * div + 2 * i + 2] = (float) (rBase + i * rectTop / div) / L;
            baseTexCoords[2 * div + 2 * i + 3] = (float) (2f * rTop) / H;
        }
        for (int i = 0; i <= div; i++) {
            double ang = i * 2d * Math.PI / div;
            double pol = polygonalSection(ang);
            baseTexCoords[4 * div + 2 * i + 4] = (float) (rBase + rBase * pol * Math.sin(ang)) / L;
            baseTexCoords[4 * div + 2 * i + 5] = (float) (2f * rTop + rBase + h - rBase * pol * Math.cos(ang)) / H;
        }
        for (int i = 0; i <= div; i++) {
            double ang = i * 2d * Math.PI / div;
            double pol = polygonalSection(ang);
            baseTexCoords[6 * div + 2 * i + 6] = (float) (rBase + rTop * pol * Math.sin(ang)) / L;
            baseTexCoords[6 * div + 2 * i + 7] = (float) (rTop + rTop * pol * Math.cos(ang)) / H;
        }
        baseTexCoords[8 * div + 8] = rBase / L;
        baseTexCoords[8 * div + 9] = (2f * rTop + rBase + h) / H;
        baseTexCoords[8 * div + 10] = rBase / L;
        baseTexCoords[8 * div + 11] = rTop / H;
        int nFaces = div * 4;
        final int[] baseTexture = new int[nFaces * 3];
        final int[] baseFaces = new int[nFaces * 3];
        for (int i = 0; i < div; i++) {
            int p1 = i + 1;
            int p2 = i + div;
            int p3 = i + div + 1;
            baseFaces[6 * i] = i;
            baseFaces[6 * i + 1] = p1 == div ? 0 : p1;
            baseFaces[6 * i + 2] = p2;
            baseFaces[6 * i + 3] = p3 % div == 0 ? p3 - div : p3;
            baseFaces[6 * i + 4] = p2;
            baseFaces[6 * i + 5] = p1 == div ? 0 : p1;
            baseTexture[6 * i] = i;
            baseTexture[6 * i + 1] = p1;
            baseTexture[6 * i + 2] = p2 + 1;
            baseTexture[6 * i + 3] = p3 + 1;
            baseTexture[6 * i + 4] = p2 + 1;
            baseTexture[6 * i + 5] = p1;
        }
        for (int i = 0; i < div; i++) {
            int p1 = div * 2;
            int p2 = i + 1;
            baseFaces[6 * div + 3 * i] = i;
            baseFaces[6 * div + 3 * i + 1] = p1;
            baseFaces[6 * div + 3 * i + 2] = p2 == div ? 0 : p2;
            baseTexture[6 * div + 3 * i] = (div + 1) * 2 + i;
            baseTexture[6 * div + 3 * i + 1] = (div + 1) * 4;
            baseTexture[6 * div + 3 * i + 2] = (div + 1) * 2 + i + 1;
        }
        for (int i = 0; i < div; i++) {
            int p1 = div * 2 + 1;
            int p2 = i + 1 + div;
            baseFaces[9 * div + 3 * i] = i + div;
            baseFaces[9 * div + 3 * i + 1] = p2 % div == 0 ? p2 - div : p2;
            baseFaces[9 * div + 3 * i + 2] = p1;
            baseTexture[9 * div + 3 * i] = (div + 1) * 3 + i;
            baseTexture[9 * div + 3 * i + 1] = (div + 1) * 3 + i + 1;
            baseTexture[9 * div + 3 * i + 2] = (div + 1) * 4 + 1;
        }
        points0 = baseVertices;
        numVertices = baseVertices.length / 3;
        texCoord0 = baseTexCoords;
        numTexCoords = baseTexCoords.length / 2;
        faces0 = IntStream.range(0, baseFaces.length / 3).mapToObj(i -> IntStream.of(baseFaces[3 * i], baseTexture[3 * i], baseFaces[3 * i + 1], baseTexture[3 * i + 1], baseFaces[3 * i + 2], baseTexture[3 * i + 2])).flatMapToInt(i -> i).toArray();
        numFaces = baseFaces.length / 3;
    } else if (m0 != null) {
        points0 = new float[numVertices * m0.getPointElementSize()];
        m0.getPoints().toArray(points0);
    }
    final float h = height;
    List<Point3D> points1 = IntStream.range(0, numVertices).mapToObj(i -> {
        Point3D p = new Point3D(points0[3 * i], points0[3 * i + 1], points0[3 * i + 2]);
        // f = h of local cylinder from 0 on top (ini) to 1 on bottom (end)
        p.f = (h / 2 - unTransform(p).y) / h;
        return p;
    }).collect(Collectors.toList());
    if (level > 0 && m0 != null) {
        texCoord0 = new float[numTexCoords * m0.getTexCoordElementSize()];
        m0.getTexCoords().toArray(texCoord0);
    }
    texCoord1 = IntStream.range(0, numTexCoords).mapToObj(i -> new Point2D(texCoord0[2 * i], texCoord0[2 * i + 1])).collect(Collectors.toList());
    if (level > 0 && m0 != null) {
        faces0 = new int[numFaces * m0.getFaceElementSize()];
        m0.getFaces().toArray(faces0);
    }
    List<Face3> faces1 = IntStream.range(0, numFaces).mapToObj(i -> new Face3(faces0[6 * i], faces0[6 * i + 2], faces0[6 * i + 4])).collect(Collectors.toList());
    index.set(points1.size());
    map.clear();
    listVertices.clear();
    listFaces.clear();
    listVertices.addAll(points1);
    faces1.forEach(face -> {
        int v1 = face.p0;
        int v2 = face.p1;
        int v3 = face.p2;
        if (level > 0) {
            int a = getMiddle(v1, points1.get(v1), v2, points1.get(v2));
            int b = getMiddle(v2, points1.get(v2), v3, points1.get(v3));
            int c = getMiddle(v3, points1.get(v3), v1, points1.get(v1));
            listFaces.add(new Face3(v1, a, c));
            listFaces.add(new Face3(v2, b, a));
            listFaces.add(new Face3(v3, c, b));
            listFaces.add(new Face3(a, b, c));
        } else {
            listFaces.add(new Face3(v1, v2, v3));
        }
    });
    map.clear();
    numVertices = listVertices.size();
    numFaces = listFaces.size();
    List<Face3> textures1;
    if (level == 0) {
        textures1 = IntStream.range(0, faces0.length / 6).mapToObj(i -> new Face3(faces0[6 * i + 1], faces0[6 * i + 3], faces0[6 * i + 5])).collect(Collectors.toList());
    } else {
        textures1 = listTextures.stream().map(t -> t).collect(Collectors.toList());
    }
    index.set(texCoord1.size());
    listTextures.clear();
    AtomicInteger kk = new AtomicInteger();
    textures1.forEach(face -> {
        int v1 = face.p0;
        int v2 = face.p1;
        int v3 = face.p2;
        if (level > 0) {
            int a = getMiddle(v1, texCoord1.get(v1), v2, texCoord1.get(v2));
            int b = getMiddle(v2, texCoord1.get(v2), v3, texCoord1.get(v3));
            int c = getMiddle(v3, texCoord1.get(v3), v1, texCoord1.get(v1));
            listTextures.add(new Face3(v1, a, c));
            listTextures.add(new Face3(v2, b, a));
            listTextures.add(new Face3(v3, c, b));
            listTextures.add(new Face3(a, b, c));
        } else {
            listTextures.add(new Face3(v1, v2, v3));
        }
    });
    map.clear();
    texCoord0 = texCoord1.stream().flatMapToDouble(p -> DoubleStream.of(p.getX(), p.getY())).collect(() -> new FloatCollector(texCoord1.size() * 2), FloatCollector::add, FloatCollector::join).toArray();
    numTexCoords = texCoord0.length / 2;
    textureCoords = texCoord0;
    if (level == getLevel()) {
        areaMesh.setWidth(majorRadius + 2f * Math.PI * majorRadius);
        areaMesh.setHeight(height + 2f * (minorRadius + majorRadius));
        smoothingGroups = IntStream.range(0, listFaces.size()).map(i -> {
            if (getSectionType() != TriangleMeshHelper.SectionType.CIRCLE) {
                return 0;
            }
            if (i < listFaces.size() / 2) {
                return 1;
            } else if (i < 3 * listFaces.size() / 4) {
                return 2;
            }
            return 4;
        }).toArray();
    }
    return createMesh();
}
Also used : IntStream(java.util.stream.IntStream) Affine(javafx.scene.transform.Affine) Rotate(javafx.scene.transform.Rotate) HashMap(java.util.HashMap) DoubleProperty(javafx.beans.property.DoubleProperty) IntegerProperty(javafx.beans.property.IntegerProperty) CullFace(javafx.scene.shape.CullFace) TriangleMesh(javafx.scene.shape.TriangleMesh) NonInvertibleTransformException(javafx.scene.transform.NonInvertibleTransformException) SectionType(org.fxyz.shapes.primitives.helper.TriangleMeshHelper.SectionType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Point2D(javafx.geometry.Point2D) Transform(javafx.scene.transform.Transform) TriangleMeshHelper(org.fxyz.shapes.primitives.helper.TriangleMeshHelper) ObjectProperty(javafx.beans.property.ObjectProperty) FloatCollector(org.fxyz.utils.FloatCollector) Translate(javafx.scene.transform.Translate) DrawMode(javafx.scene.shape.DrawMode) Collectors(java.util.stream.Collectors) DoubleStream(java.util.stream.DoubleStream) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) DepthTest(javafx.scene.DepthTest) Face3(org.fxyz.geometry.Face3) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Point3D(org.fxyz.geometry.Point3D) TriangleMesh(javafx.scene.shape.TriangleMesh) Rotate(javafx.scene.transform.Rotate) FloatCollector(org.fxyz.utils.FloatCollector) Affine(javafx.scene.transform.Affine) Point2D(javafx.geometry.Point2D) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Point3D(org.fxyz.geometry.Point3D) Translate(javafx.scene.transform.Translate) Face3(org.fxyz.geometry.Face3)

Example 14 with TriangleMesh

use of javafx.scene.shape.TriangleMesh in project FXyzLib by Birdasaur.

the class PyramidMesh method createPyramid.

private TriangleMesh createPyramid(double hypotenuse, double height) {
    TriangleMesh mesh = new TriangleMesh();
    float hy = (float) hypotenuse;
    float he = (float) height;
    mesh.getPoints().addAll(// point O
    0, // point O
    0, // point O
    0, // point A
    0, // point A
    he, // point A
    -hy / 2, // point B
    -hy / 2, // point B
    he, // point B
    0, // point C
    hy / 2, // point C
    he, // point C
    0, // point D
    0, // point D
    he, // point D
    hy / 2);
    mesh.getTexCoords().addAll(0, 0);
    mesh.getFaces().addAll(// O-B-A
    0, // O-B-A
    0, // O-B-A
    2, // O-B-A
    0, // O-B-A
    1, // O-B-A
    0, // O-A-C
    0, // O-A-C
    0, // O-A-C
    1, // O-A-C
    0, // O-A-C
    3, // O-A-C
    0, // O-C-D
    0, // O-C-D
    0, // O-C-D
    3, // O-C-D
    0, // O-C-D
    4, // O-C-D
    0, // O-D-B
    0, // O-D-B
    0, // O-D-B
    4, // O-D-B
    0, // O-D-B
    2, // O-D-B
    0, // D-A-B
    4, // D-A-B
    0, // D-A-B
    1, // D-A-B
    0, // D-A-B
    2, // D-A-B
    0, // D-C-A
    4, // D-C-A
    0, // D-C-A
    3, // D-C-A
    0, // D-C-A
    1, // D-C-A
    0);
    return mesh;
}
Also used : TriangleMesh(javafx.scene.shape.TriangleMesh)

Example 15 with TriangleMesh

use of javafx.scene.shape.TriangleMesh 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()) {
            /*
                Combine new polyMesh with previous polyMesh into one single polyMesh
                */
            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

TriangleMesh (javafx.scene.shape.TriangleMesh)22 Point3D (org.fxyz.geometry.Point3D)9 List (java.util.List)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 IntStream (java.util.stream.IntStream)8 DrawMode (javafx.scene.shape.DrawMode)8 Collectors (java.util.stream.Collectors)7 IntegerProperty (javafx.beans.property.IntegerProperty)7 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)7 DepthTest (javafx.scene.DepthTest)7 CullFace (javafx.scene.shape.CullFace)7 HashMap (java.util.HashMap)6 DoubleStream (java.util.stream.DoubleStream)6 DoubleProperty (javafx.beans.property.DoubleProperty)6 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)6 Point2D (javafx.geometry.Point2D)6 Face3 (org.fxyz.geometry.Face3)6 FloatCollector (org.fxyz.utils.FloatCollector)6 ArrayList (java.util.ArrayList)5 ObjectProperty (javafx.beans.property.ObjectProperty)5