Custom Mesh "Problem"

Hi all

i am kinda new to JMonkey so excuse if I misunderstand something.
What I am trying to do:

I am trying to create a custom Mesh by dragging the mouse. This kinda works fine already but I have one strange behaviour.

as you can see, it is basicly the TestCustomMesh example from the JMonkey tests. My problem is the free space between the two triangles.
How it works in my code:

I have two listeners, one actionListener and one analogListener. By clicking the first listener sets my start point and as long as i hold the mouse button the analog listener resets the second point and keeps repainting my mesh.

[java]
public void initKeys() {
inputManager.addMapping(“DragMark”, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(actionListener, “DragMark”);
inputManager.addListener(analogListener, “DragMark”);
}

private AnalogListener analogListener = new AnalogListener(){
    public void onAnalog(String name, float value, float tpf){
        if(name.equals("DragMark")){
            System.out.println("click realeased! ! ");
            if(rootNode.getChild("SelectBox") != null){
                rootNode.detachChildNamed("SelectBox");
            }

            CollisionResults results = new CollisionResults();
            Vector2f clickedStart = inputManager.getCursorPosition();
            Vector3f clickedStart3d = cam.getWorldCoordinates(clickedStart, 0f).clone();
            Vector3f cmDirection = cam.getWorldCoordinates(clickedStart, 1f).subtractLocal(clickedStart3d).normalizeLocal();
            
            Ray ray = new Ray(clickedStart3d, cmDirection);
            floor.collideWith(ray, results);
            if(results.size() > 0){
                Vector3f pt = results.getClosestCollision().getContactPoint();
                System.out.println("click realeased at " + pt.toString());
                //mark2.setLocalTranslation(pt);
                //rootNode.attachChild(mark2);
                end = pt;
                if(start != null && end != null){
                    drawSelect(start, end);
                }
            }
                       
        }
    }
};


private ActionListener actionListener = new ActionListener() {
    public void onAction(String name, boolean keyPressed, float tpf) {
        if (name.equals("DragMark") && keyPressed) {
            System.out.println("KLICK AUSGELĂ–ST! ! ");
            //rootNode.detachChild(mark2);
            CollisionResults results = new CollisionResults();
            Vector2f clickedStart = inputManager.getCursorPosition();
            Vector3f clickedStart3d = cam.getWorldCoordinates(clickedStart, 0f).clone();
            Vector3f cmDirection = cam.getWorldCoordinates(clickedStart, 1f).subtractLocal(clickedStart3d).normalizeLocal();
            
            Ray ray = new Ray(clickedStart3d, cmDirection);
            floor.collideWith(ray, results);
            if(results.size() > 0){
                Vector3f pt = results.getClosestCollision().getContactPoint();
                System.out.println("KLICK AUF " + pt.toString());
                //mark.setLocalTranslation(pt);
                //rootNode.attachChild(mark);
                start = pt;
                
            }
        }
        
    }
    
};

[/java]

my paint funciton:

[java]
public void drawSelect(Vector3f start, Vector3f end){
System.out.println("DRAW AUFGERUFEN: " +start.toString() + " " + end.toString());
Mesh m = new Mesh();

    Vector3f start2 = new Vector3f(start.x, 1.1f, end.z);
    Vector3f end2 = new Vector3f(end.x, 1.1f, start.z);
    
    Vector3f [] vertices = new Vector3f[4];
    vertices[0] = start2;
    vertices[1] = end;
    vertices[2] = start;
    vertices[3] = end2;
    
    Vector2f[] texCoord = new Vector2f[4];
    texCoord[0] = new Vector2f(0,0);
    texCoord[1] = new Vector2f(1,0);
    texCoord[2] = new Vector2f(0,1);
    texCoord[3] = new Vector2f(1,1);
    
    int [] indexes = { 2,0,1, 1,3,2 };
    
    m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
    m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
    m.setBuffer(Type.Index,    1, BufferUtils.createIntBuffer(indexes));
    m.updateBound();
      
    Geometry selectBox = new Geometry("SelectBox", m);
    Material mat = new Material(assetManager, 
                "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    selectBox.setMaterial(mat);
    
    rootNode.attachChild(selectBox);
    
  
    
}

[/java]

for your understanding. This is how my variables match with the points.

start--------end2
| |
| |
| |
start2------end

Any help appreciated.

[java]m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));[/java]

that should be a 3

This guy has done something similar, to what your trying to achieve:
http://hub.jmonkeyengine.org/forum/topic/lines-and-trails/

just changed it to a 3, still the same problem

What are the y values of start and end? Perhaps they are 0 and you are seeing the middle of your “quad” getting clipped as it dips below the surface or something.

I am using the RtsCamera from here http://hub.jmonkeyengine.org/forum/topic/rts-camera-control/ . The Y value of my camera is at 80. In fact that issue gets worse when I scroll out even more.

@mIkEmC said: I am using the RtsCamera from here http://hub.jmonkeyengine.org/forum/topic/rts-camera-control/ . The Y value of my camera is at 80. In fact that issue gets worse when I scroll out even more.

Which further indicates that it might be the problem I stated.

What are the y values of “start” and “end”? Not your camera. But the actual “start” and “end” that you use in your mesh.

You give start2 and end2 1.1f as a value for y. But what is the value of y in “start” and “end”.

“start” and “end” have some y value… what is it? It it is 0 then it will cause your problem. So I’m wondering what it is.

1 Like

…or if that’s still unclear for some reason, maybe you can just show us what the output of this println was:

1 Like

Wow, how could i miss that. Ofc you were right sir. My Y value was not the same for all 4 points, so it kinda clipped into my terrain. The Y values of start and end were always arround 1 eg 0.987… and my mesh wasn’t plane. Thanks a lot. Marked as sloved