Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

How would I avoid textures being blurred when mapped to a TriangleMesh?

+2
−0

I am making a game using JavaFX and the Fxyz library. I have chunks which are made of Point3D's, these points are then passed to a ScatterMesh and that is used to generate a TriangleMesh so I can map textures to it. Which is what the below code does:

    //Cube object extends Point3D
    private final List<Cube> chunk = new ArrayList<>();
    private TriangleMesh mesh;
/**
     * Iterates through a chunks points and creates a chunk mesh based on which points are active.
     */
    public void updateMesh() {
        //Retrieving active vertices that should be rendered
        List<Cube> cubes = new ArrayList<>();
        for (Cube value : chunk) {
            if (value.isActive()) {
                cubes.add(value);
            }
        }

        //Mesh creation
        if (cubes.size() > 0) {
            List<Point3D> pCubes = new ArrayList<>(cubes);

            //Defining block texture atlas
            PhongMaterial mat = new PhongMaterial();
            mat.setDiffuseMap(new Image("file:src/main/resources/textures.png"));

            //Scatter mesh to be converted to triangle mesh
            ScatterMesh scatter = new ScatterMesh(pCubes, 1);
            scatter.setMarker(MarkerFactory.Marker.CUBE);

            //Triangle mesh creation
            mesh = (TriangleMesh) scatter.getMeshFromId("scatter").getMesh();
            mesh.setVertexFormat(VertexFormat.POINT_TEXCOORD);
            float[] newTex = { //512x512 image file with a 16x16 texture
                    0f, 0f, //upper left corner
                    0f, 0.03125f,
                    0.03125f, 0.03125f, //lower right corner
                    0.03125f, 0f,
            };


            //sets texture coords for faces. Every 12 face elements = 2 triangular
            //faces = 1 square of a cube, see trianglemesh docs
            for (int i = 1; i < mesh.getFaces().size(); i += 12) {
                for (int j = 0; j < cubes.size(); j++) {

                    //every other element in face array is a texture coordinate.
                    if (cubes.get(j).getType().equals(BlockType.DEFAULT)) {
                        //triangle1
                        mesh.getFaces().set(i, 0);
                        mesh.getFaces().set(i + 2, 1);
                        mesh.getFaces().set(i + 4, 3);

                        //triangle2
                        mesh.getFaces().set(i + 6, 3);
                        mesh.getFaces().set(i + 8, 1);
                        mesh.getFaces().set(i + 10, 2);

                    } else {
                        mesh.getFaces().set(i, 0);
                        mesh.getFaces().set(i + 2, 0);
                        mesh.getFaces().set(i + 4, 0);

                        mesh.getFaces().set(i + 6, 0);
                        mesh.getFaces().set(i + 8, 0);
                        mesh.getFaces().set(i + 10, 0);
                    }
                }
            }
            mesh.getTexCoords().setAll(newTex);
            scatter.setId("scatter");
            setCache(true);
            setDrawMode(DrawMode.FILL);
            setCullFace(CullFace.BACK);
            setMesh(mesh);
            setMaterial(mat);

        }
    }

The resulting mesh view looks very blurry and the square faces have transparent gaps in between them if you look closely, is there any way to improve this?:Image showing blurry texture

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

Interpolation (1 comment)
Extra information that might be useful to receive an answer (2 comments)

0 answers

Sign up to answer this question »