1
\$\begingroup\$

currently I'm in the works of programming a game - surprise xD I'm using LibGdx for this manner but I've encountered a very unknown bug I guess. I wasn't able to get any further by searching the internet.

If you're interested in the entire source code - it's on Github

here is the code of the Block class

package richbar.com.github.treasurepyramid.block;

public abstract class Block implements EventSubscriber, Loadable {

    public abstract String getId();

    Vector3 pos;
    String name;
    Model model;
    BoundingBox bounds;
    Texture texture;
    Material attributes;

    private boolean loadedData;
    public boolean isLoaded(){return loadedData;}

    public Block(){
        Main.getInstance().addAssetListener(this, "blocks/"+getId()+".json",    Text.class);
    }

    public Block(Block block){
        Main.getInstance().addAssetListener(this, "blocks/"+block.getId()+".json", Text.class);
        pos = block.pos;
        attributes = block.attributes;
        bounds = block.bounds;
    }

    public Model getModel(){
        if(model != null) return model;
        texture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
        Material material = new Material(TextureAttribute.createDiffuse(texture));
        ModelBuilder modelBuilder = new ModelBuilder();
        modelBuilder.begin();
        modelBuilder.node();
        MeshPartBuilder mesh_part_builder = modelBuilder.part("box", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position
            | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates, material);
        BoxShapeBuilder.build(mesh_part_builder, 5, 5, 5);
        return modelBuilder.end();
    }

    boolean stayUpdated = true;
    @Override
    public void eventUpdate(Event e, Object args) {
        AssetManager manager = Main.getInstance().getAssetManager();
        if(e == Event.ASSET_LOADED && manager.isLoaded("blocks/"+getId()+".json")){
            Main.logger.log("loaded blocks/"+getId()+".json");
            stayUpdated = false;
            JsonValue json = new JsonReader().parse((manager.get("blocks/"+getId()+".json")).toString());

            name = json.getString("name");
            texture = new Texture(Gdx.files.internal(json.getString("texture")));
            loadedData = true;
        }
        //generate Cube Model if Absent
        model = getModel();
    }

    @Override
    public boolean stayUpdated() {
        return stayUpdated;
    }
}

Pic of this weird behavior || Changing angles only changes the jaggedness

I'd really appreciate if anyone could help me fix this issue : )

Have a nice evening,

Marco

\$\endgroup\$
  • \$\begingroup\$ Looks a little bit like depth fighting. Are you sure you're not rendering two cubes exactly at the same position, one textured and the other not textured? \$\endgroup\$ – Alexandre Vaillancourt Oct 12 '17 at 10:55
  • \$\begingroup\$ I changed the source code and debugged how many times the getModel() function is called and reduced it so it's called only once - still the same 'effect' though : / \$\endgroup\$ – Mariomarco Oct 12 '17 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.