Skip to content

Instantly share code, notes, and snippets.

@getflourish
Created August 26, 2011 16:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getflourish/1173825 to your computer and use it in GitHub Desktop.
Save getflourish/1173825 to your computer and use it in GitHub Desktop.
GLModel getGLModelForOBJModel (OBJModel model) {
GLModel model = model;
model.enableDebug();
glmodel = new GLModel(this, model.getFaceCount() * 3, TRIANGLES, GLModel.DYNAMIC);
// copy vertices from OBJModel to GLModel
glmodel.beginUpdateVertices();
int index = 0;
float maxX = 0;
for (int f = 0; f < model.getFaceCount(); f++) {
PVector[] fverts = model.getFaceVertices(f);
for (int v = 0; v < fverts.length; v++) {
glmodel.updateVertex(index++, fverts[v].x, fverts[v].y, fverts[v].z);
if (fverts[v].x > maxX) maxX = fverts[v].x;
}
}
glmodel.endUpdateVertices();
// copy normals from OBJModel to GLModel
glmodel.initNormals();
glmodel.beginUpdateNormals();
index = 0;
for (int s = 0; s < model.getSegmentCount(); s++) {
Segment segment = model.getSegment(s);
Face[] faces = segment.getFaces();
for (int i = 0; i < faces.length; i++) {
PVector[] vs = faces[i].getVertices();
PVector[] ns = faces[i].getNormals();
for (int k = 0; k < vs.length; k++) {
glmodel.updateNormal(index++, ns[k].x, ns[k].y, ns[k].z);
}
}
}
glmodel.endUpdateNormals();
return glmodel;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment