Break the limit!

One day, I wanted to draw the edge lines of a simple box :



import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.scene.Line;
import com.jme.util.geom.BufferUtils;

public class BreakTheLimit extends SimpleGame {
   
   public static void main(String[] args) {
      BreakTheLimit app = new BreakTheLimit();
      app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
      app.start();
   }

   protected void simpleInitGame() {
      Vector3f[] vertices = {
            new Vector3f(-4, 0, -2),
            new Vector3f( 4, 0, -2),
            new Vector3f( 4, 3.5f, -2),
            new Vector3f(-4, 3.5f, -2),
            new Vector3f( 4, 0, 2),
            new Vector3f(-4, 0, 2),
            new Vector3f( 4, 3.5f, 2),
            new Vector3f(-4, 3.5f, 2),
      };
      int[] indices = {
            0, 1,
                                1, 2,
                                2, 3,
                                3, 0,
            5, 4,
                                4, 6,
                                6, 7,
                                7, 5,
            0, 5,
            1, 4,
            2, 6,
            3, 7,
            };
      
      Line line = new Line("line");
      line.getBatch(0).setVertexBuffer(BufferUtils.createFloatBuffer(vertices));
      line.getBatch(0).setIndexBuffer(BufferUtils.createIntBuffer(indices));
      
      rootNode.attachChild(line);
   }
}



It don't work : jME display only 4 of my 12 lines. The problem dones't come from my program, it comes from a strange optimization in com.jme.renderer.lwjgl.LWJGLRenderer class, line 774 :


indices.limit(batch.getVertexCount());



When I comment this line, my program display my box correctly.

I don't know why, but I see that someone limit the vertex buffer and the index buffer in many cases in this file during the geometry batch drawing.
I think that it is not a good idea. In some cases like this, or when you build feature edges http://graphics.cs.brown.edu/games/FeatureEdges/mcguirehughes04edges.pdf, vertex and index buffers could have unconventional sizes.

Could you break this limitation to allow me to draw boxes and feature edges peacefully :) ?

Thanks.

Actually, limit is important, if anything, you are showing a bug in the value applied by limit.  The reason limit is important is because the buffers may be bigger or contain more data than what is being used.  In those case, invalid vertices get referenced by the unintendedly used portion of your buffer and all heck breaks loose.  Drawing lines just hasn't had as much work done on it as triangles.  What we need is a segment count field so we can tell how many segments to draw and thus how to limit the index buffer.

This might be related: I tried to use the GeometryBatch class from the wiki that way:



Thanks renance, but do you plan to do what you say or do you need some help ?  :smiley:

How about the new sound support getting into the repository?  Is that on your list in big fat bold letters with a picture of a frog looking scarily back at you?  :smiley:

Things with a frog next to them mean "ignore" I think…  :wink:

:expressionless:



…moooooo!  :-o



What do you think about "darkcow"?

I've added it to the todo list that I look at every morning.  Can't give you a date though.  :slight_smile:

renanse said:

Things with a frog next to them mean "ignore" I think...  ;)


....I guess you weren't kidding.  :'(

:stuck_out_tongue: