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