We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to use two libraries in conjunction: the first one, "OBJExport" (http://n-e-r-v-o-u-s.com/tools/obj/), to export 3D models as .obj files. These models will be generated by the "Shapes 3D" library (http://www.lagers.org.uk/s3d4p/index.html), which I need to create an extrusion from my svg path. The export works just fine, but only for one shape. Since I generate multiple extrusions in a recursive manner, I want to export a group of objects rather than one combined model. I'm not sure if this is possible with OBJExport and I could not find anything related on the website of Nervous System, but I think if at all it'll only be possible by having multiple PGraphics (or in this case "OBJExport" which extends PGraphics) objects with all the shapes rendered to them separately. Of course, It'd be nice to have something like ".nextPage()" from the PDF library but for separating objects in the .obj file. My hope was to be able to assign a PGraphics object to the .draw() function of my shape, but I can only initialize it with a different PApplet, which I think is not useful for this situation (or is it?).
Maybe someone else did something like this before and can help me out or there is a different library to export 3D models, otherwise I'd have to separate the objects manually in C4D which will be quite tedious.
Here is my test sketch for the extrusion export based on an example sketch from Shapes 3D (of course it doesn't work, since I need to assign the graphics context to the shape):
import nervoussystem.obj.*;
boolean record = false;
import shapes3d.utils.*;
import shapes3d.animation.*;
import shapes3d.*;
float angleX, angleY, angleZ;
Extrusion e;
Path path;
Contour contour;
ContourScale conScale;
public void setup() {
size(300, 300, P3D);
cursor(CROSS);
path = new P_LinearPath(new PVector(0, 80, 0), new PVector(0, 0, 0));
contour = getBuildingContour();
conScale = new CS_ConstantScale();
// Create the texture coordinates for the end
contour.make_u_Coordinates();
// Create the extrusion
//e = new Extrusion(this, path, 1, contour, conScale);
e = new Extrusion(this, path, 1, contour, conScale);
e.setTexture("wall.png", 1, 1);
e.drawMode(S3D.TEXTURE );
// Extrusion end caps
e.setTexture("grass.jpg", S3D.E_CAP);
e.setTexture("sky.jpg", S3D.S_CAP);
e.drawMode(S3D.TEXTURE, S3D.BOTH_CAP);
}
OBJExport obj;
public void draw() {
background(32, 32, 128);
if (record) {
obj = (OBJExport) createGraphics(width, height, "nervoussystem.obj.OBJExport", "test.obj");
obj.setColor(true);
obj.beginDraw();
obj.noFill();
}
camera(0, 0, 250, 0, 0, 0, 0, 1, 0);
angleX += radians(0.913f);
angleY += radians(0.799f);
angleZ += radians(1.213f);
e.rotateTo(angleX, angleY, angleZ);
e.draw();
//if (record) e.draw(obj); <- this would be needed here!
if (record) {
obj.endDraw();
obj.dispose();
record = false;
}
}
public Contour getBuildingContour() {
PVector[] c = new PVector[] {
new PVector(-30, 30),
new PVector(30, 30),
new PVector(50, 10),
new PVector(10, -30),
new PVector(-10, -30),
new PVector(-50, 10)
};
return new Building(c);
}
// The extrusion contour must be from a class that
// extends the library Contour class.
public class Building extends Contour {
public Building(PVector[] c) {
this.contour = c;
}
}
void keyPressed()
{
if (key == 'r') {
record = true;
}
}
[EDIT] Okay, I saw this thread (https://forum.processing.org/two/discussion/11391/objexport-library#latest) and it seems that my problem is actually that I need to have groups in my .obj files. Something like "g sphere" or "g box" in front of the vertices. But I couldn't find anything related in the OBJExport library source, so I think this is pretty much hopeless. Maybe I can try hacking my way through this, but I'm no Java expert and will probably mess up the code..