Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace JavaFX text with AWT #63

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

breiler
Copy link

@breiler breiler commented Dec 12, 2024

This PR aims to replace JavaFX font with AWT for extruding texts

@breiler
Copy link
Author

breiler commented Dec 12, 2024

I'll look into why those tests are failing.

Also added unit tests as a part of release script
@madhephaestus
Copy link
Member

One of the external checks that i do is to run the StlExportTest and put TextStl2.stl through PrusaSlicer or Bamboo Slicer. they are very poor quality slicing algorithms and acts as a worst case scenario mesh integrity test.

I use MeshLab to look at TextStl2.stl for any non manifold points or edges, and for any boundary edges. There should be 0 of all of those.

@breiler
Copy link
Author

breiler commented Dec 14, 2024

Thanks

Here is a screenshot from Prusa Slicer, the top is from this branch and the bottom is from the development branch:
image

Here is the new version in meshlab:
image

And here is the development version:
image

My version is obviously worse, but what is the metric I that I should be looking for? Should it look as nice as possible or attempt to count the number of errors?

@madhephaestus
Copy link
Member

madhephaestus commented Dec 14, 2024 via email

@breiler
Copy link
Author

breiler commented Dec 14, 2024

Using the development branch, uncommenting that line will slightly improve the result, but for me there are still missing triangles:
image

Using this code:

package eu.mihosoft.vrl.v3d;

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;

import org.junit.Test;

public class StlExportTest {

	@Test
	public void makeBadSTL() throws IOException {
		Plane.setEPSILON(1.0e-11);
		//Vector3d.setEXPORTEPSILON(10);
		CSG.setUseGPU(false);
		CSG.setPreventNonManifoldTriangles(true);
		CSG badExport2 = CSG.text(" A QUICK BROWN FOX JUMPS OVER THE LAZY DOG", 10,30,"Serif Regular").movey(30);
		System.out.println("First text loaded");
		CSG badExport = CSG.text("THis is some text a quick brown fox jumps over the lazy dog.", 10);
		System.out.println("Second text loaded");
//		badExport2=new Cube(20).toCSG().movey(30);
//		badExport=new Cube(20).toCSG();
		
		badExport=badExport.union(badExport2);
		//String filename ="TextStl.stl";
		FileUtil.write(Paths.get("TextStl.stl"),
				badExport.toStlString());
		System.out.println("Load saved stl");
		File file = new File("TextStl.stl");
		CSG loaded = STL.file(file.toPath());
		System.out.println("Perform difference");
		badExport=loaded.scaleToMeasurmentX(160).scaleToMeasurmentY(30);
		badExport=new Cube(180,40,10).toCSG().toZMin().toXMin().toYMin().movey(-5).difference(badExport).rotx(35).roty(45);
		FileUtil.write(Paths.get("TextStl2.stl"),
				badExport.toStlString());
	}

}

@madhephaestus
Copy link
Member

So I adjusted the 2 epsilon parameters and was able to get down to 4 boundary faces in the development branch. The issue is related to how the CSG stack decides 2 points are coincident vs how other mesh manipulating stacks assume points are coincident. Text seems to be a source of difficult polygons, which is why i use it as the stress test for repairing damaged meshes. I have been addressing this recently in order to support Prusa and Bamboo slicers.

@breiler
Copy link
Author

breiler commented Dec 15, 2024

How are you measuring this? From just looking at it in Prusa with the default settings and in Meshlab I can clearly see polygons missing when uncommenting both those lines in the development branch:

Plane.setEPSILON(1.0e-11);
Vector3d.setEXPORTEPSILON(10);

TextStl2.stl.txt

What OS are you using? For instance I saw a big difference in how fonts are vectorized on Linux/Windows vs MacOSX.

@madhephaestus
Copy link
Member

madhephaestus commented Dec 15, 2024

Plane.setEPSILON(1.0e-10); Vector3d.setEXPORTEPSILON(1.0e-9);
I used these settings and was able to get a lower number of failed polygons on Linux. I have not run these tests on WIndows or Macos, but you are right, OS's process fonts differently and produce very different results, which requires the loader to do some point validation before continuing with the polygon as a source for a 3d shape.

@madhephaestus
Copy link
Member

One other thing to look at is to see if the triangles are missing, or are just backwards, IE wound clockwise instead of Counter-clockwise. The CW wound trinagles come into MeshLab as a dark grey instead of light grey.

When a polygon gets removed from the CSG its because the triangulation algorithm failed to find a convex corner after tracing over the polygon. This could be because of a backtrack, a portion of the polygon that juts out, then backtracks over the same line forming a 0 area section, or it can be 2 points that are coincident, or an edge of the polygon that crosses another edge of the polygon. I have seen all 3 of these types of polygon irregularities when generating shapes using fonts.

@madhephaestus
Copy link
Member

madhephaestus commented Dec 15, 2024

You can also look at TextStl.stl only for the moment, the second one test loading back in the first STL and performing operations on it. If you can make just the text stl with no non-manifold features and no boundary edges, then we can call that a Win and merge this PR.

@breiler
Copy link
Author

breiler commented Dec 16, 2024

Sorry for being a newbie, now that I know what to look for it makes a bit more sense. This is the result when running the tests. Don't merge it just yet, I would like to do some more tests.

My branch
TextStl.stl:
image

TextStl2.stl:
image

Development branch
TextStl.stl:
image

TextStl2.stl
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants