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();
}
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);
}
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;
}
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);
}
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();
}
Aggregations