Graphic issue with showing Cubes on Grid

Sorry polinc! Ishould habe been more specific. I know that I need to translate everything in the y direction for the geometries to be on on the grid. I just wanted to express that in one of the pictures it looks like they are underneath the coordinate system. Which is not right.

Also also I already dreaded that the camera could be an issue. This happens with my old camera too though…

    flyCam.setEnabled(false);

    ChaseCamera cam1 = new ChaseCamera(cam, rootNode.rotate(0, 8, 0), inputManager);
    cam1.setHideCursorOnRotate(false);
    cam1.setDefaultDistance(2000);

    cam.setFrustumPerspective(45f, (float) cam.getWidth() / cam.getHeight(), 0.01f, 1000f);

    cam1.setMaxDistance(20000);
    cam1.setRotationSpeed(3);
    cam1.setZoomSensitivity(17); 

    cam.setFrustumFar(200000);
    cam.update();

Maybe this is of help?

Hey Murph9!
It is seriousy not a z fighting problem (probably…). I disabled the grid, I put an offset to the geometries, I used a different camera… But at some point they just start to melt as if the material was not solid… I just don’t know what else the issue could be…

When doing test project keep in mind that this means minimal code that it takes to reproduce the problem.

Maybe you should cut it down to two boxes and remove anything that is not needed to reproduce the issue, like the grid and chaseCam and start from there.

Hey mitm!

You are right! I’m sorry about that. First time for me to actually write in a Forum to ask questions. I’m still learning :slight_smile:

But even if I remove everything this issue still occures. (Even when I put a space between the geometries) And I’m still not sure why…

We need a test case we can run. Your previous test case was not runnable.

In the menu on the left there is the link for transparency.

Transparency for Dummies

import com.jme3.app.SimpleApplication;
import com.jme3.bounding.BoundingBox;
import com.jme3.input.ChaseCamera;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.debug.Grid;
import com.jme3.scene.debug.WireBox;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Line;
import com.jme3.system.AppSettings;

public class Testprojekt extends SimpleApplication {

public static void main(final String[] args) {

    Testprojekt app = new Testprojekt();
    AppSettings settings = new AppSettings(true);
    settings.setTitle("3D Visualization"); //$NON-NLS-1$
    app.setSettings(settings);
    app.setShowSettings(false);
    settings.setResolution(1280, 720);
    app.start();
}

private Line x_axis_line;

private Line y_axis_line;

private Line z_axis_line;

private Geometry g_x;

private Geometry g_y;

private Geometry g_z;

private Material m_x;

private Material m_y;

private Material m_z;

private Node cs_node;

private Node pivotNode;

@SuppressWarnings("deprecation")
@Override
public void simpleInitApp() {

    // Background
    getViewPort().setBackgroundColor(ColorRGBA.LightGray);

    // Mousesetting
    inputManager.setCursorVisible(true);

    // Grid
    int min = 500;
    int max = 500;
    Grid g = new Grid(min, max, 500);
    Geometry grid = new Geometry("Ground", g);//$NON-NLS-1$
    grid.setLocalTranslation(new Vector3f(-min * 250, 0, -max * 250));
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");//$NON-NLS-1$
    mat.setColor("Color", ColorRGBA.Black);//$NON-NLS-1$
    grid.setMaterial(mat);

    // Coordinate system
    cs_node = new Node("coordinate_system");//$NON-NLS-1$

    x_axis_line = new Line(new Vector3f(-1000, 0, 0), new Vector3f(+1000, 0, 0));
    x_axis_line.setLineWidth(3f);
    y_axis_line = new Line(new Vector3f(0, -1000, 0), new Vector3f(0, +1000, 0));
    y_axis_line.setLineWidth(3f);
    z_axis_line = new Line(new Vector3f(0, 0, -1000), new Vector3f(0, 0, +1000));
    z_axis_line.setLineWidth(3f);

    g_x = new Geometry("x_axis", x_axis_line);//$NON-NLS-1$
    g_y = new Geometry("y_axis", y_axis_line);//$NON-NLS-1$
    g_z = new Geometry("z_axis", z_axis_line);//$NON-NLS-1$

    m_x = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");//$NON-NLS-1$
    m_x.setColor("Color", ColorRGBA.Black);//$NON-NLS-1$
    m_y = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");//$NON-NLS-1$
    m_y.setColor("Color", ColorRGBA.Black);//$NON-NLS-1$
    m_z = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");//$NON-NLS-1$
    m_z.setColor("Color", ColorRGBA.Blue);//$NON-NLS-1$

    g_x.setMaterial(m_x);
    g_y.setMaterial(m_y);
    g_z.setMaterial(m_z);

    cs_node.attachChild(g_x);
    cs_node.attachChild(g_y);
    cs_node.attachChild(g_z);

    // Geometries

    Box Ruby = new Box(2000, 500, 700);
    Geometry red = new Geometry("Box", Ruby); //$NON-NLS-1$
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); //$NON-NLS-1$
    mat1.setColor("Color", ColorRGBA.Red); //$NON-NLS-1$
    red.setMaterial(mat1);
    red.setLocalTranslation(0, 0, 700f);

    Box Sapphire = new Box(2000, 500, 700);
    Geometry blue = new Geometry("Box", Sapphire); //$NON-NLS-1$
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); //$NON-NLS-1$
    mat2.setColor("Color", ColorRGBA.Blue); //$NON-NLS-1$
    blue.setMaterial(mat2);
    blue.setLocalTranslation(0, 0, 2100f);

    // BoundingBox
    Material boundingMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); //$NON-NLS-1$
    boundingMaterial.setColor("Color", ColorRGBA.Black); //$NON-NLS-1$

    Geometry boundingVolume = WireBox.makeGeometry((BoundingBox) red.getWorldBound());
    boundingVolume.setMaterial(boundingMaterial);
    boundingVolume.setLocalTranslation(red.getLocalTranslation());
    boundingVolume.setLocalRotation(red.getLocalRotation());
    boundingVolume.setLocalScale(red.getLocalScale());

    Geometry boundingVolume2 = WireBox.makeGeometry((BoundingBox) blue.getWorldBound());
    boundingVolume2.setMaterial(boundingMaterial);
    boundingVolume2.setLocalTranslation(blue.getLocalTranslation());
    boundingVolume2.setLocalRotation(blue.getLocalRotation());
    boundingVolume2.setLocalScale(blue.getLocalScale());

    // Nodes
    rootNode.attachChild(cs_node);

    pivotNode = new Node("pivot");//$NON-NLS-1$
    rootNode.attachChild(pivotNode);
    pivotNode.attachChild(red);
    pivotNode.attachChild(blue);

    pivotNode.attachChild(boundingVolume);
    pivotNode.attachChild(boundingVolume2);

    // Disabeling flyCam
    flyCam.setEnabled(false);

    //FocusCam
    ChaseCamera cam1 = new ChaseCamera(cam, rootNode.rotate(0, 8, 0), inputManager);
    cam1.setHideCursorOnRotate(false);

    cam1.setDefaultDistance(2000);

    cam.setFrustumPerspective(45f, (float) cam.getWidth() / cam.getHeight(), 0.01f, 1000f);

    cam1.setMaxDistance(20000);
    cam1.setRotationSpeed(3);
    cam1.setZoomSensitivity(17);

    cam.setFrustumFar(200000);
    cam.update();

}

Hope this will work then…

Yup found it. IMO this is the problem. Units. I dont know why you are using such enormous numbers. The initial box example is 1,1,1 afair and it fine. I divided everything by 100 in the test and it works. It is a GL problem not the engine. I guess with such a big distance AA doesn’t work as expected.

Tips for future tests:

  1. Always provide working flycam
  2. Remove anything which isnt a problem
  3. Dont disable splash screen settings.

Yeah, the numbers are quite big… The problem is that I have not much to say about the sizes of the geometries. This project reads in files from an external source and is supposed to show whats written in the file accordingly. One of the worst case examples are these big boxes.

Thanks for helping me out! I think I can work with all the advices you gave me :wink:

you can always scale everything.

he could also subdivide this boxes, so GL would not have issues.

I indeed subdevided the boxes and it works! Now if I have like “normal” boxes though (Box(20, 5, 10)) it’s a mess… But easy enough problem to fix! Thanks again, everyone! :smiley:

you dont need create new boxes for subdivide, you just need to have subdivided box mesh (you can do it yourself via code, or via Blender or in any other tool)

its just about “too big faces”, so you need make box of “smaller faces” instead of “very big faces”

or like others said, simply scale everything that might help too.

1 Like

This is your issue.

The Z-buffer does not have the resolution necessary to prevent z-fighting in the sub-20 pixel range. It has to somehow fit 2 million resolution in 16 bits.

Set this smaller and your z-fighting issue will go away.

1 Like

wow, i did not noticed it, i just seen scale solutions dont even looking at code :joy:

@Joutaro why you use for everything so big values? ;p i belive you thought frustrumFar is something different. you wanted to make it see much distant geoms? or why?

when now i think for your box scales its not that big, but belive me, overall scale would be good.

for example 100 of your units = 1 game unit.

so just make rootNode.scale(0.01f); (if its allowed for rootNode, if not then do subnode)

I…Actually I don’t know :joy: I did this like… 3 months ago when I started to use JME for the first time and was still learning stuff! :upside_down_face: Never thought that this could be the issue though! But I understand now! :laughing:

Well, generally should not be issues.

but there are… :grinning:

if you want make it proper. make 1 meter = 1 game unit. then most things should be fine, even when you will add physics or other things. (with default world params of gravity)

so just stick to 1 meter = 1 unit(0.1 meter = 0.1f unit) and all should be fine. If you dont know what is meter in your models, then just scale it down to make it proper.

well, too low values also might cause issue like “accuracy issue” because float can have certain amount of numbers after comma too. (but i never had issues like this, even when i had character 1.8 meters height, so hand finger like 0.0something, no issues, i just mean, do not try overscale it too ;p)

I also find setting the near plane less that 0.1 causes shadow issues.

are you sure?

    float scale = 0.01f;
    app.getCamera().setFrustumNear(1f*scale);

and i have no shadow issues

I scaled everything down! Different example (more like it is supposed to look like), but no eye-killing flickering anymore!!!


Thanks so much again! Now I have time for the other 2 big issues I need to fix… :rofl: