gpt4 book ai didi

java - 带有 TriangleStrip 的 jMonkey Quad 无法更改参数

转载 作者:行者123 更新时间:2023-11-30 11:31:57 25 4
gpt4 key购买 nike

我是第一次使用 jMonkey。我的意图是创建一个由具有不同分割的单个三角形 strip 组成的四边形。所以我可以说 Subdivision x == 4; Subdivision y == 4;在这种情况下,有 3 行三角形和 3 列。

到目前为止这是可行的,但是一旦我更改了分割,例如 x==5y==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);
}

}

最佳答案

我已经测试了你的代码。

只需编写此 int x_value = 9;//width_verteces
int y_value = 10;//heigth_verteces
int heigth = y_value-1;//高度
int width = x_value-1;//宽度
它的工作正常

关于java - 带有 TriangleStrip 的 jMonkey Quad 无法更改参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16925218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com