jMonkey Quad с TriangleStrip не может изменить параметр

Я работаю с jMonkey впервые. Мое намерение состояло в том, чтобы создать четырехугольник из одной треугольной полосы с различными подразделениями. Так что я могу сказать Subdivision x == 4; Subdivision y == 4; В этом случае есть 3 ряда треугольников и 3 столбца.

Это работает до сих пор, но как только я меняю подразделения, например x==5, y==5, коды вылетают. Я надеюсь, что кто-то может помочь мне с этим.

P.S.: извините за мой английский, я уже устал ^^

/* * Чтобы изменить этот шаблон, выберите Инструменты | Шаблоны * и откройте шаблон в редакторе. */ пакет jme3.objekte;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.util.BufferUtils;

/**
 *
 * @author Ronny
 */
public class Rechteck2 extends SimpleApplication {

    public static void main(String[] args) {
        Rechteck2 app = new Rechteck2();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        Mesh mesh = new Mesh();
        int x_value = 4; //width_verteces
        int y_value = 4; //heigth_verteces
        int heigth = 3; //heigth
        int width = 3; //width
        float deltaX = width/(x_value-1);
        float deltaY = heigth/(y_value-1);
        int currentVertex = 0;

        Vector3f[] vertices = new Vector3f[x_value*y_value];
          for (int y=0; y<y_value; y++){    //x als nummer des aktuellen vertex
              for (int x=0; x<x_value; x++){
                  vertices[currentVertex] = new Vector3f( x*deltaX, y*deltaY, 0);
                  currentVertex++;
              }
          }
        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);

        final int maxIndex = ((x_value-1)*(y_value-1)*6) + (y_value * 6);
        int[] indexes = new int[maxIndex];         //[(x_value-1)*(y_value-1)*6+(y_value-1)*9];
        int a = 0;
        int b = 1;  
        int c = x_value;       
        boolean direction = true;
        boolean dirchange = false;

        for (int i=0; i<(maxIndex/3); i++){     //((x_value-1)*(y_value-1)*6+((y_value-1)*9)); i++){

            if (direction){

                if (dirchange==true){
                   indexes[i*3] = a;
                   indexes[i*3+1] = a+1;
                   indexes[i*3+2] = c;
                   a = indexes[i*3];
                   b = indexes[i*3+1];
                   c = indexes[i*3+2];
                   dirchange = false;
                }
                else{
                indexes[i*3] = a;
                indexes[i*3+1] = b;
                indexes[i*3+2] = c;
                }
                if(i%2==1){
                    a = b;
                    b = a+1;
                    c = c;
                }
                else{
                    a = c;
                    b = b;
                    c = a+1;
                }
                if (b%x_value==0){
                    i++;
                    indexes[i*3] = a;
                    indexes[i*3+1] = c;
                    indexes[i*3+2] = c;
                    i++;
                    indexes[i*3] = c;
                    indexes[i*3+1] = c;
                    indexes[i*3+2] = c;
                    if ((c+x_value)<= (x_value*y_value-1)){
                        i++;
                        indexes[i*3] = c;
                        indexes[i*3+1] = c;
                        indexes[i*3+2] = c+x_value;
                        a = c;
                        b = c;
                        c = c+x_value;
                    }
                    direction = false;
                    dirchange = true;
                }
            }
            else{
                if(dirchange==true){
                    indexes[i*3] = c;
                    indexes[i*3+1] = c-1;
                    indexes[i*3+2] = a;
                    a = indexes[i*3];
                    b = c-1;
                    c = indexes[i*3+2];
                    dirchange = false;
                }
                else{
                    indexes[i*3] = a;
                    indexes[i*3+1] = b;
                    indexes[i*3+2] = c;
                }
                if(i%2==0){
                    a = b;
                    b = a-1;
                    c = c;
                }
                else{
                    a = c;
                    b = b;
                    c = a-1;
                }
                if (a%x_value==0){
                    i++;
                    indexes[i*3] = c;
                    indexes[i*3+1] = a;
                    indexes[i*3+2] = a;
                    i++;
                    indexes[i*3] = a;
                    indexes[i*3+1] = a;
                    indexes[i*3+2] = a;
                    if ((b+x_value) <= (x_value*y_value-1)){
                        i++;
                        indexes[i*3] = a;
                        indexes[i*3+1] = a;
                        indexes[i*3+2] = a+x_value;
                        a = a;
                        b = a;
                        c = a+x_value;
                    }
                    direction = true;
                    dirchange = true;
                } 
            }
        }
        mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
        mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord)); 
        mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indexes));

        Geometry geo = new Geometry("MyMesh", mesh);
        Material mat1 = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");
        mat1.setColor("Color", ColorRGBA.Green);
        mat1.getAdditionalRenderState().setWireframe(true);
        geo.setMaterial(mat1);

        //mesh.setMode(Mesh.Mode.TriangleStrip);
        mesh.updateBound();
        mesh.setStatic();

        Geometry lines = new Geometry("MyMesh", mesh);
        lines.setMaterial(mat1);

        rootNode.attachChild(lines);
    }

}

person LongRon    schedule 04.06.2013    source источник


Ответы (1)


Я проверил ваш код.

Просто закодируйте этот int x_value = 9; //width_verteces int y_value = 10; //heigth_verteces int heigth = y_value-1; //heigth int width = x_value-1; //width и он отлично работает

person Mir23    schedule 05.06.2013