Error loading models
I'm loading some models from "obj" files in Wavefront format, but every time I load a file I get this weird cube on the screen. I've tried a few models with different shapes and I only get this error with 3d models.
I've been trying to solve this for 3 hours now, but I can't see the problem. Here is the shape that I get:
http://i.imgur.com/5vvtPML.png
http://i.imgur.com/knXa1j1.png
I'm parsing the "obj" file myself, here is the code:
String line, tmp[], ftmp[];
ArrayList<Float> vlist = new ArrayList<Float>();
ArrayList<FaceIndex> filist = new ArrayList<FaceIndex>();
float v;
try {
InputStream raw = context.getResources().openRawResource(R.raw.ship__ss_2);
BufferedReader is = new BufferedReader(new InputStreamReader(raw, "UTF8"));
while ((line = is.readLine()) != null) {
tmp = line.split(" ");
/* Parse Vertex */
if (tmp[0].equalsIgnoreCase("v")) {
for (int i = 1; i < 4; i++) {
v = Float.parseFloat(tmp[i]);
vlist.add(v);
}
}
/* Parse Faces index*/
if (tmp[0].equalsIgnoreCase("f")) {
for (int i = 1; i < 4; i++) {
ftmp = tmp[i].split("/");
int chi = Integer.parseInt(ftmp[0]) - 1;
filist.add(new FaceIndex(chi));
}
}
}
vertexBuffer = ByteBuffer.allocateDirect(filist.size() * 3 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
for (int j = 0; j < filist.size(); j++) {
vertexBuffer.put(vlist.get(filist.get(j).Vi * 3));
vertexBuffer.put(vlist.get(filist.get(j).Vi * 3 + 1));
vertexBuffer.put(vlist.get(filist.get(j).Vi * 3 + 2));
}
vertexBuffer.position(0);
I have tested Translations, Rotations,and Scales and loading 2D models without any problem.
Thanks.
I'm loading some models from "obj" files in Wavefront format, but every time I load a file I get this weird cube on the screen. I've tried a few models with different shapes and I only get this error with 3d models.
I've been trying to solve this for 3 hours now, but I can't see the problem. Here is the shape that I get:
http://i.imgur.com/5vvtPML.png
http://i.imgur.com/knXa1j1.png
I'm parsing the "obj" file myself, here is the code:
String line, tmp[], ftmp[];
ArrayList<Float> vlist = new ArrayList<Float>();
ArrayList<FaceIndex> filist = new ArrayList<FaceIndex>();
float v;
try {
InputStream raw = context.getResources().openRawResource(R.raw.ship__ss_2);
BufferedReader is = new BufferedReader(new InputStreamReader(raw, "UTF8"));
while ((line = is.readLine()) != null) {
tmp = line.split(" ");
/* Parse Vertex */
if (tmp[0].equalsIgnoreCase("v")) {
for (int i = 1; i < 4; i++) {
v = Float.parseFloat(tmp[i]);
vlist.add(v);
}
}
/* Parse Faces index*/
if (tmp[0].equalsIgnoreCase("f")) {
for (int i = 1; i < 4; i++) {
ftmp = tmp[i].split("/");
int chi = Integer.parseInt(ftmp[0]) - 1;
filist.add(new FaceIndex(chi));
}
}
}
vertexBuffer = ByteBuffer.allocateDirect(filist.size() * 3 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
for (int j = 0; j < filist.size(); j++) {
vertexBuffer.put(vlist.get(filist.get(j).Vi * 3));
vertexBuffer.put(vlist.get(filist.get(j).Vi * 3 + 1));
vertexBuffer.put(vlist.get(filist.get(j).Vi * 3 + 2));
}
vertexBuffer.position(0);
I have tested Translations, Rotations,and Scales and loading 2D models without any problem.
Thanks.
No comments:
Post a Comment