Search in sources :

Example 1 with TriangleMesh

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

the class TetrahedronMesh method createTetrahedron.

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

Example 2 with TriangleMesh

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

the class TexturedMesh method createMesh.

protected TriangleMesh createMesh() {
    TriangleMesh triangleMesh = new TriangleMesh();
    triangleMesh.getPoints().setAll(helper.updateVertices(listVertices));
    switch(textureType.get()) {
        case NONE:
            triangleMesh.getTexCoords().setAll(textureCoords);
            triangleMesh.getFaces().setAll(helper.updateFacesWithTextures(listFaces, listTextures));
            break;
        case PATTERN:
            if (areaMesh.getHeight() > 0 && areaMesh.getWidth() > 0) {
                triangleMesh.getTexCoords().setAll(helper.updateTexCoordsWithPattern((int) rectMesh.getWidth(), (int) rectMesh.getHeight(), patternScale.get(), areaMesh.getHeight() / areaMesh.getWidth()));
            } else {
                triangleMesh.getTexCoords().setAll(helper.updateTexCoordsWithPattern((int) rectMesh.getWidth(), (int) rectMesh.getHeight(), patternScale.get()));
            }
            triangleMesh.getFaces().setAll(helper.updateFacesWithTextures(listFaces, listTextures));
            break;
        case IMAGE:
            triangleMesh.getTexCoords().setAll(textureCoords);
            if (listTextures.size() > 0) {
                triangleMesh.getFaces().setAll(helper.updateFacesWithTextures(listFaces, listTextures));
            } else {
                triangleMesh.getFaces().setAll(helper.updateFacesWithVertices(listFaces));
            }
            break;
        case COLORED_VERTICES_1D:
            triangleMesh.getTexCoords().setAll(helper.getTexturePaletteArray());
            triangleMesh.getFaces().setAll(helper.updateFacesWithFunctionMap(listVertices, listFaces));
            break;
        case COLORED_VERTICES_3D:
            triangleMesh.getTexCoords().setAll(helper.getTexturePaletteArray());
            triangleMesh.getFaces().setAll(helper.updateFacesWithDensityMap(listVertices, listFaces));
            break;
        case COLORED_FACES:
            triangleMesh.getTexCoords().setAll(helper.getTexturePaletteArray());
            triangleMesh.getFaces().setAll(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]);
        // }
        triangleMesh.getFaceSmoothingGroups().addAll(smoothingGroups);
    } else {
        triangleMesh.getFaceSmoothingGroups().addAll(faceSmoothingGroups);
    }
    System.out.println("nodes: " + listVertices.size() + ", faces: " + listFaces.size());
    return triangleMesh;
}
Also used : TriangleMesh(javafx.scene.shape.TriangleMesh)

Example 3 with TriangleMesh

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

the class TetrahedraMesh method createTetrahedra.

private TriangleMesh createTetrahedra(float height, int level) {
    TriangleMesh m0 = null;
    if (level > 0) {
        m0 = createTetrahedra(height, level - 1);
    }
    if (level == 0) {
        a = new Affine();
        float hw = height;
        if (center.get() != null) {
            a = a.createConcatenation(new Translate(center.get().x, center.get().y, center.get().z));
        }
        final float[] baseVertices = new float[] { 0f, 0f, 0.612372f * hw, -0.288675f * hw, -0.5f * hw, -0.204124f * hw, -0.288675f * hw, 0.5f * hw, -0.204124f * hw, 0.57735f * hw, 0f, -0.204124f * hw };
        final float[] baseTexCoords = new float[] { 0f, 0f, 0.5f, 0.866025f, 1f, 0f, 1f, 1.73205f, 1.5f, 0.866025f, 2f, 0f };
        final int[] baseTexture = new int[] { 0, 2, 1, 3, 1, 4, 2, 4, 1, 4, 2, 5 };
        final List<Integer> baseFaces = Arrays.asList(1, 2, 3, 2, 1, 0, 3, 0, 1, 0, 3, 2);
        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 * height);
        areaMesh.setHeight(height * Math.sqrt(3));
        // 1<<j -> bitset, 00100. Otherwise: 000111 will mean they are shared
        smoothingGroups = IntStream.range(0, listFaces.size()).map(i -> 1 << (i / (listFaces.size() / 4))).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 4 with TriangleMesh

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

the class PrismMesh method createCylinder.

private TriangleMesh createCylinder(float radius, float height, int level) {
    TriangleMesh m0 = null;
    if (level > 0) {
        m0 = createCylinder(radius, height, level - 1);
    }
    if (level == 0) {
        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 r = radius;
        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(r * pol * Math.cos(ang), h / 2, r * pol * Math.sin(ang));
            baseVertices[3 * i] = ta.x;
            baseVertices[3 * i + 1] = ta.y;
            baseVertices[3 * i + 2] = ta.z;
        // baseVertices[3*i]=(float)(r*pol*Math.cos(ang));
        // baseVertices[3*i+1]=h/2;
        // baseVertices[3*i+2]=(float)(r*pol*Math.sin(ang));
        }
        // 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(r * pol * Math.cos(ang), -h / 2, r * pol * Math.sin(ang));
            baseVertices[3 * i] = ta.x;
            baseVertices[3 * i + 1] = ta.y;
            baseVertices[3 * i + 2] = ta.z;
        // baseVertices[3*i]=(float)(r*pol*Math.cos(ang));
        // baseVertices[3*i+1]=-h/2;
        // baseVertices[3*i+2]=(float)(r*pol*Math.sin(ang));
        }
        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;
        // baseVertices[6*div]=0f;
        // baseVertices[6*div+1]=h/2f;
        // baseVertices[6*div+2]=0f;
        // baseVertices[6*div+3]=0f;
        // baseVertices[6*div+4]=-h/2f;
        // baseVertices[6*div+5]=0f;
        int nTextCoords = div * 4 + 6;
        float rect = (float) polygonalSize(r);
        float L = (float) (r + 2d * Math.PI * r);
        float H = 4f * r + h;
        final float[] baseTexCoords = new float[nTextCoords * 2];
        // u right ,v up
        for (int i = 0; i <= div; i++) {
            baseTexCoords[2 * i] = (float) (r + i * rect / div) / L;
            baseTexCoords[2 * i + 1] = (float) (2f * r + h) / H;
        }
        for (int i = 0; i <= div; i++) {
            baseTexCoords[2 * div + 2 * i + 2] = (float) (r + i * rect / div) / L;
            baseTexCoords[2 * div + 2 * i + 3] = (float) (2f * r) / 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) (r + r * pol * Math.sin(ang)) / L;
            baseTexCoords[4 * div + 2 * i + 5] = (float) (3f * r + h - r * 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) (r + r * pol * Math.sin(ang)) / L;
            baseTexCoords[6 * div + 2 * i + 7] = (float) (r + r * pol * Math.cos(ang)) / H;
        }
        baseTexCoords[8 * div + 8] = r / L;
        baseTexCoords[8 * div + 9] = (3f * r + h) / H;
        baseTexCoords[8 * div + 10] = r / L;
        baseTexCoords[8 * div + 11] = r / 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());
    // points1.forEach(p->System.out.print(" "+p.f));
    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(radius + 2f * Math.PI * radius);
        areaMesh.setHeight(height + 4f * radius);
        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();
    // listVertices.stream()
    // .sorted((p1,p2)->Double.compare(p1.y,p2.y))
    // .mapToDouble(p->p.f).distinct()
    // .forEach(f->System.out.print(" "+f));
    }
    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) Point2D(javafx.geometry.Point2D) Point3D(org.fxyz.geometry.Point3D) Translate(javafx.scene.transform.Translate) Face3(org.fxyz.geometry.Face3)

Example 5 with TriangleMesh

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

the class CubeMesh method createCube.

private TriangleMesh createCube(float size) {
    TriangleMesh m = new TriangleMesh();
    float hw = size / 2, hh = hw, hd = hh;
    // create points
    m.getPoints().addAll(hw, hh, hd, hw, hh, -hd, hw, -hh, hd, hw, -hh, -hd, -hw, hh, hd, -hw, hh, -hd, -hw, -hh, hd, -hw, -hh, -hd);
    float x0 = 0.0f, x1 = 1.0f / 4.0f, x2 = 2.0f / 4.0f, x3 = 3.0f / 4.0f, x4 = 1.0f;
    float y0 = 0.0f, y1 = 1.0f / 3.0f, y2 = 2.0f / 3.0f, y3 = 1.0f;
    m.getTexCoords().addAll(// 0,1
    (x1 + getImagePadding()), // 0,1
    (y0 + getImagePadding()), // 2,3
    (x2 - getImagePadding()), // 2,3
    (y0 + getImagePadding()), // 4,5
    (x0), // 4,5
    (y1 + getImagePadding()), // 6,7
    (x1 + getImagePadding()), // 6,7
    (y1 + getImagePadding()), // 8,9
    (x2 - getImagePadding()), // 8,9
    (y1 + getImagePadding()), // 10,11
    (x3), // 10,11
    (y1 + getImagePadding()), // 12,13
    (x4), // 12,13
    (y1 + getImagePadding()), // 14,15
    (x0), // 14,15
    (y2 - getImagePadding()), // 16,17
    (x1 + getImagePadding()), // 16,17
    (y2 - getImagePadding()), // 18,19
    (x2 - getImagePadding()), // 18,19
    (y2 - getImagePadding()), // 20,21
    (x3), // 20,21
    (y2 - getImagePadding()), // 22,23
    (x4), // 22,23
    (y2 - getImagePadding()), // 24,25
    (x1 + getImagePadding()), // 24,25
    (y3 - getImagePadding()), // 26,27
    (x2), // 26,27
    (y3 - getImagePadding()));
    m.getFaces().addAll(0, 10, 2, 5, 1, 9, 2, 5, 3, 4, 1, 9, 4, 7, 5, 8, 6, 2, 6, 2, 5, 8, 7, 3, 0, 13, 1, 9, 4, 12, 4, 12, 1, 9, 5, 8, 2, 1, 6, 0, 3, 4, 3, 4, 6, 0, 7, 3, 0, 10, 4, 11, 2, 5, 2, 5, 4, 11, 6, 6, 1, 9, 3, 4, 5, 8, 5, 8, 3, 4, 7, 3);
    return m;
}
Also used : TriangleMesh(javafx.scene.shape.TriangleMesh)

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