Created
August 26, 2011 16:39
-
-
Save getflourish/1173825 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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