Search in sources :

Example 1 with Affine

use of javafx.scene.transform.Affine 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 2 with Affine

use of javafx.scene.transform.Affine in project processing by processing.

the class PGraphicsFX2D method shearY.

@Override
public void shearY(float angle) {
    Affine temp = new Affine();
    temp.appendShear(0, Math.tan(angle));
    context.transform(temp);
}
Also used : Affine(javafx.scene.transform.Affine)

Example 3 with Affine

use of javafx.scene.transform.Affine in project processing by processing.

the class PGraphicsFX2D method getMatrix.

@Override
public PMatrix2D getMatrix(PMatrix2D target) {
    if (target == null) {
        target = new PMatrix2D();
    }
    //double[] transform = new double[6];
    // TODO This is not tested; apparently Affine is a full 3x4
    //.getMatrix(transform);
    Affine t = context.getTransform();
    //    target.set((float) transform[0], (float) transform[2], (float) transform[4],
    //               (float) transform[1], (float) transform[3], (float) transform[5]);
    target.set((float) t.getMxx(), (float) t.getMxy(), (float) t.getTx(), (float) t.getMyx(), (float) t.getMyy(), (float) t.getTy());
    return target;
}
Also used : Affine(javafx.scene.transform.Affine)

Example 4 with Affine

use of javafx.scene.transform.Affine in project processing by processing.

the class PGraphicsFX2D method shearX.

@Override
public void shearX(float angle) {
    Affine temp = new Affine();
    temp.appendShear(Math.tan(angle), 0);
    context.transform(temp);
}
Also used : Affine(javafx.scene.transform.Affine)

Example 5 with Affine

use of javafx.scene.transform.Affine in project processing by processing.

the class PGraphicsFX2D method backgroundImpl.

//  //////////////////////////////////////////////////////////////
//
//  // MATERIAL PROPERTIES
//
//
//  //public void ambient(int rgb)
//  //public void ambient(float gray)
//  //public void ambient(float x, float y, float z)
//  //protected void ambientFromCalc()
//  //public void specular(int rgb)
//  //public void specular(float gray)
//  //public void specular(float x, float y, float z)
//  //protected void specularFromCalc()
//  //public void shininess(float shine)
//  //public void emissive(int rgb)
//  //public void emissive(float gray)
//  //public void emissive(float x, float y, float z )
//  //protected void emissiveFromCalc()
//
//
//
//  //////////////////////////////////////////////////////////////
//
//  // LIGHTS
//
//
//  //public void lights()
//  //public void noLights()
//  //public void ambientLight(float red, float green, float blue)
//  //public void ambientLight(float red, float green, float blue,
//  //                         float x, float y, float z)
//  //public void directionalLight(float red, float green, float blue,
//  //                             float nx, float ny, float nz)
//  //public void pointLight(float red, float green, float blue,
//  //                       float x, float y, float z)
//  //public void spotLight(float red, float green, float blue,
//  //                      float x, float y, float z,
//  //                      float nx, float ny, float nz,
//  //                      float angle, float concentration)
//  //public void lightFalloff(float constant, float linear, float quadratic)
//  //public void lightSpecular(float x, float y, float z)
//  //protected void lightPosition(int num, float x, float y, float z)
//  //protected void lightDirection(int num, float x, float y, float z)
//////////////////////////////////////////////////////////////
// BACKGROUND
@Override
public void backgroundImpl() {
    // if pixels are modified, we don't flush them (just mark them flushed)
    // because they would be immediatelly overwritten by the background anyway
    modified = false;
    loaded = false;
    // Save drawing context (transform, fill, blend mode, etc.)
    context.save();
    // Reset transform to identity
    context.setTransform(new Affine());
    // This only takes into account cases where this is the primary surface.
    // Not sure what we do with offscreen anyway.
    context.setFill(new Color(backgroundR, backgroundG, backgroundB, backgroundA));
    context.setGlobalBlendMode(BlendMode.SRC_OVER);
    context.fillRect(0, 0, width, height);
    // Restore drawing context (transform, fill, blend mode, etc.)
    context.restore();
}
Also used : Affine(javafx.scene.transform.Affine) Color(javafx.scene.paint.Color)

Aggregations

Affine (javafx.scene.transform.Affine)8 Translate (javafx.scene.transform.Translate)4 Face3 (org.fxyz.geometry.Face3)4 Point3D (org.fxyz.geometry.Point3D)4 HashMap (java.util.HashMap)3 List (java.util.List)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Collectors (java.util.stream.Collectors)3 DoubleStream (java.util.stream.DoubleStream)3 IntStream (java.util.stream.IntStream)3 DoubleProperty (javafx.beans.property.DoubleProperty)3 IntegerProperty (javafx.beans.property.IntegerProperty)3 ObjectProperty (javafx.beans.property.ObjectProperty)3 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)3 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)3 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)3 Point2D (javafx.geometry.Point2D)3 DepthTest (javafx.scene.DepthTest)3 CullFace (javafx.scene.shape.CullFace)3 DrawMode (javafx.scene.shape.DrawMode)3