Ich habe alten Code in einen neuen konvertiert und hässliche Code-Teile gelöscht, aber es funktioniert nicht mehr. Mögest du mir helfen. Es wäre nett!Habe ich etwas falsch gemacht, während ich alten Code in einen neuen umwandelte
ALTE - Kopf
private ArrayList vertexsets;
private ArrayList vertexsetsnorms;
private ArrayList vertexsetstexs;
private ArrayList faces;
private ArrayList facestexs;
private ArrayList facesnorms;
private ArrayList mattimings;
private MtlLoader materials;
private String mtl_path;
alte Funktion
if (newline.startsWith("f ")) {
facecounter++;
newline = newline.substring(2, newline.length());
StringTokenizer st = new StringTokenizer(newline, " ");
int count = st.countTokens();
int v[] = new int[count];
int vt[] = new int[count];
int vn[] = new int[count];
for (int i = 0; i < count; i++) {
char chars[] = st.nextToken().toCharArray();
StringBuffer sb = new StringBuffer();
char lc = 'x';
for (int k = 0; k < chars.length; k++) {
if (chars[k] == '/' && lc == '/')
sb.append('0');
lc = chars[k];
sb.append(lc);
}
StringTokenizer st2 = new StringTokenizer(sb.toString(), "/");
int num = st2.countTokens();
v[i] = Integer.parseInt(st2.nextToken());
if (num > 1)
vt[i] = Integer.parseInt(st2.nextToken());
else
vt[i] = 0;
if (num > 2)
vn[i] = Integer.parseInt(st2.nextToken());
else
vn[i] = 0;
}
faces.add(v);
facestexs.add(vt);
facesnorms.add(vn);
}
ich eine neue Klasse namens Gesicht hinzugefügt haben, die v hält, vt und vn.
public class Face {
public ArrayList<Float[]> normalIndicies; //vn
public ArrayList<Float[]> textureCoordIndicies; //vt
public ArrayList<Float[]> vertexIndicies; //v
}
NEW ONE - Kopf
protected ArrayList<Vector3f> verticies;
protected ArrayList<Vector3f> normals;
protected ArrayList<Vector3f> textureCoords;
protected LinkedHashMap<String, Integer> material;
protected ArrayList<Face> faces;
protected String mtlLib;
NEW ONE - Funktion
if(line.startsWith("f ")) {
Face face = new Face();
face.vertexIndicies = new ArrayList<Float[]>();
face.textureCoordIndicies = new ArrayList<Float[]>();
face.normalIndicies = new ArrayList<Float[]>();
faceCounter++;
Float[] vertexIndices = new Float[3];
Float[] textureIndex = new Float[3];
Float[] normalIndices = new Float[3];
String[] firstVec = line.split(" ")[1].split("/");
String[] secondVec = line.split(" ")[2].split("/");
String[] thirdVec = line.split(" ")[3].split("/");
for(int i = 0; i < firstVec.length; i++) {
if(i == 0) vertexIndices[0] = Float.valueOf(firstVec[i]);
if(i == 1) textureIndex[0] = Float.valueOf(firstVec[i]);
if(i == 2) normalIndices[0] = Float.valueOf(firstVec[i]);
}
for(int i = 0; i < secondVec.length; i++) {
if(i == 0) vertexIndices[1] = Float.valueOf(secondVec[i]);
if(i == 1) textureIndex[1] = Float.valueOf(secondVec[i]);
if(i == 2) normalIndices[1] = Float.valueOf(secondVec[i]);
}
for(int i = 0; i < thirdVec.length; i++) {
if(i == 0) vertexIndices[2] = Float.valueOf(thirdVec[i]);
if(i == 1) textureIndex[2] = Float.valueOf(thirdVec[i]);
if(i == 2) normalIndices[2] = Float.valueOf(thirdVec[i]);
}
face.vertexIndicies.add(vertexIndices);
face.textureCoordIndicies.add(textureIndex);
face.normalIndicies.add(normalIndices);
this.faces.add(face);
}
vielleicht wurden die hässlichen Teile benötigt? – SaggingRufus