SuperCad export with texture-coordinates
in
Contributed Library Questions
•
2 years ago
Hi all,
I´m currently working on a simple modification of the superCAD-library so that it is able to export texture-coordinates (and normals in the long run). Theoretically this shouldn´t be a big problem, I got the texture-coordinates and the texture-image from the base class PGraphics / PGraphics3d and thus I got all the information and data I need. Though it doesn´t work, I get the
Exception in thread "Animation Thread" java.lang.RuntimeException: You must first call texture() before using u and v coordinates with vertex()
Exception when I try to export.
Here´s my code:
-
mParent.beginShape(PConstants.TRIANGLES);
-
mParent.texture(null);
-
if(texture != null){
-
mParent.texture(texture.getTexture());
-
mParent.textureMode(PConstants.NORMALIZED);
-
}
-
for(int i = 0; i < triangleIndices.length; i++) {
-
tempVertex = mVertices.get(triangleIndices[i]);
-
if(texture != null) {
-
textureCoords = tempQuad.getTextureCoordsByIndex(triangleIndices[i]);
-
mParent.vertex(tempVertex.getX(), tempVertex.getY(), tempVertex.getZ(), textureCoords.x, textureCoords.y);
-
}
-
} else {
-
mParent.vertex(tempVertex.getX(), tempVertex.getY(), tempVertex.getZ());
- }
(mParent is the PApplet I pass to every object which has to be drawn, it uses OpenGL as Graphics-API)
That´s it, no big deal, I start the recording from another slice of code, as every object in my code draws itself. Though I use the exact calls which Guillaume Labelle uses in his superCAD-examples (which are similar to the DXF-export examples of processing). Just to be complete, here are the initializations:
-
if(mRecordFrame) {
-
SuperCAD.init(mParent);
-
SuperCAD.mode("ObjFile");
-
SuperCAD.fileName("ressource/Export/modelExport");
-
SuperCAD.recordNextFrame();
-
while(componentIter.hasNext()) {
-
current = componentIter.next().draw();
-
}
-
if(mRecordFrame) {
-
mRecordFrame = false;
- }
When I first saw the exception, I thought, that it should be enough to simply overwrite the "texture()"-function (the library does the same with beginShape(), endShape(), fill(), vertex() etc.) though it doesn´t have any effect. I call the texture-function in line 4 of the first code snippet (the texture is definitely set, the if-block is entered, though there´s no effect, the exception remains). I looked at the code of PGraphic and PGraphic3d and there´s nothing remarkable about the functions, so that I don´t have any idea, why it doesn´t work out...
If I don´t use textures the geometry is exported correctly with the same code, so the library generally seems to work, but it doesn´t like my textures...
Does anyone have an idea, why this doesn´t work or even better, how I can make it work?
Thanks in advance!
Patrick
2