내가하려는 것의 Wavefront OBJ 파일을로드하려고합니다. 나는 그것을 가지고있다. 렌더링 될 때 얼굴 중 일부가 누락되거나 잘못된 꼭지점 위치가 있습니다. 내가 그들을 로딩하는 방식은 아마 너무 최적화되어 있지 않다. 나는 LWJGL을 사용하고 있으며 OpenGL 바인딩 (제 바인딩이라고 생각합니다)을 사용하여 제 모델을 렌더링합니다. 여기 http://i1291.photobucket.com/albums/b560/DandDMC/javaw2014-07-0415-52-54-99_zpsdf14fb6c.pngWavefront OBJ로드 오류 : 누락 및 부정확 한 얼굴
가 로딩 방식의 : 여기 http://i1291.photobucket.com/albums/b560/DandDMC/blender2014-07-0415-28-40-23_zps0fbfcebb.png
그것이 게임 내 모습이다 : 여기
public static Model loadModel(String fileLocation)
{
File file = new File(fileLocation);
if(!file.exists())
{
try
{
throw new FileNotFoundException("The file named: " + fileLocation + " doesn't exist!");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
return null;
}
ArrayList<Vertex> vertices = new ArrayList<Vertex>();
ArrayList<Vertex> texVertices = new ArrayList<Vertex>();
ArrayList<Face> faces = new ArrayList<Face>();
try
{
BufferedReader r = new BufferedReader(new FileReader(file));
String s = "";
int refIndex = 1;
int vertIndex = 1;
int texVertIndex = 1;
while((s = r.readLine()) != null)
{
String[] split = s.split(" ");
if(split[0].equals("v"))
{
vertices.add(new Vertex(Double.parseDouble(split[1]), Double.parseDouble(split[2]), Double.parseDouble(split[3]), vertIndex));
vertIndex ++;
}
else if(split[0].equals("vt"))
{
texVertices.add(new Vertex(Double.parseDouble(split[1]), Double.parseDouble(split[2]), 0.0, texVertIndex));
texVertIndex ++;
}
else if(split[0].equals("f"))
{
ArrayList<Integer> vert = new ArrayList<Integer>();
ArrayList<Integer> texVert = new ArrayList<Integer>();
for(int i = 1; i < split.length; i ++)
{
String[] fSplit = split[i].split("/");
vert.add(Integer.parseInt(fSplit[0]));
texVert.add(Integer.parseInt(fSplit[1]));
}
faces.add(new Face(vert, texVert));
}
else if(split[0].equals("#") || split[0].equals("o") || split[0].equals("mtllib") || split[0].equals("usemtl") || split[0].equals("s"))
{
// Don't have a use for as of now
}
else
{
throw new Exception("The syntax at line: " + refIndex + " is incorrect.");
}
refIndex ++;
}
r.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return new Model(vertices, texVertices, faces);
}
얼굴 클래스의 다음
는 모델과 같이하도록되어 무엇 (매우 간단합니다) :}
정점 클래스도 간단 :
package com.glh.model;
public class Vertex
{
public double x;
public double y;
public double z;
public int index;
public Vertex(double x, double y, double z, int index)
{
this.x = x;
this.y = y;
this.z = z;
this.index = index;
}
public Vertex()
{
this(0.0, 0.0, 0.0, 0);
}
}
그리고 렌더링하는 방법은 모델 클래스는 단지 모든 정점과 얼굴의 목록을 보유하고
public void renderModel_tri(Model m)
{
// The model is much smaller in Blender
glScalef(0.3F, 0.3F, 0.3F);
glBegin(GL_QUADS);
for(Face f : m.faces)
{
ArrayList<Vertex> vertices = f.getVertexPositions(m);
ArrayList<Vertex> texVertices = f.getTextureVertexPositions(m);
for(int i = 0; i < vertices.size(); i ++)
{
Vertex vert = vertices.get(i);
Vertex texVert = texVertices.get(i);
glTexCoord2d(texVert.x, texVert.y);
glVertex3d(vert.x, vert.y, vert.z);
}
}
glEnd();
}
.
package com.glh.model;
import java.util.*;
public class Model
{
public ArrayList<Vertex> vertices;
public ArrayList<Vertex> texVertices;
public ArrayList<Face> faces;
public Model(ArrayList<Vertex> vertices, ArrayList<Vertex> texVertices, ArrayList<Face> faces)
{
this.vertices = vertices;
this.texVertices = texVertices;
this.faces = faces;
}
}
가장 최근의 질문을 삭제 한 이유는 무엇입니까? 당신이 관심이 있다면 나는 적절한 대답을 가지고있다. – chqrlie
Woops, 가장 최근의 논평은 나의 의심을 확인 했으므로 삭제하지 않을 것이라고 생각 했으므로 어디에서든 삭제 취소 버튼을 볼 수는 없으므로 아마 내가 오후 PM 일 수있다. xH – David
undelete로 투표를했지만, 나는 그것을 지원할 14 명의 다른 회원이 있을지 의심 스럽다. 나는 너에게 PM도하는 법을 모른다. – chqrlie