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
Community Proposals
Community Proposals
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

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

66%
+2 −0
Q&A How would I avoid textures being blurred when mapped to a TriangleMesh?

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 m...

0 answers  ·  posted 1y ago by cuzzo‭  ·  edited 1y ago by Alexei‭

Question java 3d javafx fxyz3d
#5: Post edited by user avatar Alexei‭ · 2022-11-29T09:11:28Z (over 1 year ago)
added relevant tags
#4: Post edited by user avatar cuzzo‭ · 2022-11-29T05:03:51Z (over 1 year ago)
  • 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 low quality 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](https://software.codidact.com/uploads/22je5rbw94ez85jwrx5svbxm3zqd)
  • 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](https://software.codidact.com/uploads/22je5rbw94ez85jwrx5svbxm3zqd)
#3: Post edited by user avatar cuzzo‭ · 2022-11-29T04:41:44Z (over 1 year ago)
  • How would I avoid these blurry textures mapped to this TriangleMesh?
  • How would I avoid textures being blurred when mapped to a TriangleMesh?
#2: Post edited by user avatar cuzzo‭ · 2022-11-29T04:11:15Z (over 1 year ago)
  • 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 low quality and they have transparent gaps in between the faces if you look closely, is there any way to improve this?:![Image showing blurry texture](https://software.codidact.com/uploads/22je5rbw94ez85jwrx5svbxm3zqd)
  • 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 low quality 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](https://software.codidact.com/uploads/22je5rbw94ez85jwrx5svbxm3zqd)
#1: Initial revision by user avatar cuzzo‭ · 2022-11-29T04:07:28Z (over 1 year ago)
How would I avoid these blurry textures mapped to this TriangleMesh?
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 low quality and they have transparent gaps in between the faces if you look closely, is there any way to improve this?:![Image showing blurry texture](https://software.codidact.com/uploads/22je5rbw94ez85jwrx5svbxm3zqd)