I just stripped the corners from the obj and connected them myself
Now the A looks as intended
with PeasyCam
// see https://discourse.processing.org/t/load-a-mlt-and-obj/5222/14
//
//-----------------------------------------------------------------
// imports
import peasy.*;
//-----------------------------------------------------------------
// 3D camera
PeasyCam cam;
// Make a PShape
PShape myPShape;
PShape myPShapeFront;
PShape myPShapeBack;
PShape myPShapeSide;
PShape myPShapeGroup;
float angle1=90;
// int i=0;
String allOldPVs = "";
ArrayList<PVector>listPV=new ArrayList();
//-------------------------------------------------------------------------
void setup() {
size(1200, 700, P3D);
// fullScreen(P3D);
avoidClipping();
cam = new PeasyCam(this, 1000);
cam.setMinimumDistance(0);
cam.setMaximumDistance(100000);
cam.setActive(true);
myPShape = loadShape("A.obj");
inits();
println ("End of Setup");
}
void draw() {
background(240);
output();
// angle1=0;
angle1+=1;
}
//-------------------------------------------------------------------------
// Inits
void inits() {
// myPShapeGROUP=createShape();
println(myPShape.getChildCount());
println(myPShape.getVertexCount());
println("All children");
makeListPV();
printListPV();
//myPShapeGROUP.scale(2, -2);
// myPShape.setVisible(true);
// myPShape.resetMatrix();
// myPShape.disableStyle();// NOT useful
// myPShapeGROUP.setFill(color(255, 0, 0));
// myPShape.setStrokeWeight(2);
// myPShape.setStroke(false);
// myPShape.setStroke(color(0));
// myPShapeGROUP.setStrokeWeight(2);
// myPShapeGROUP.setStroke(true);
//myPShapeGROUP.setStroke(color(0));
//myPShape = myPShape.getChild (3);
// -------------------------------------------------------------
// make Front
myPShapeFront=createShape();
myPShapeFront.beginShape();
int i=0;
// clockwise
int[] listIntOutlineIndices = {
5, 6, 7, 8, 9,
10, 4,
3, 5
};
for ( int i3 : listIntOutlineIndices) {
PVector pv=listPV.get(i3);
// push();
// translate(pv.x, 100-pv.y, pv.z );
myPShapeFront.vertex(pv.x, 100-pv.y, pv.z );
// fill(255, 0, 0);
// noStroke();
//sphere(4);
// text (i, 0, 0);
// pop();
i++;
}
// anti clockwise
int[] listIntContourIndices = {
0, 2, 1, 0
};
// Interior part of shape
myPShapeFront.beginContour();
for (int i4 : listIntContourIndices) {
PVector pv=listPV.get(i4);
myPShapeFront.vertex(pv.x, 100-pv.y, pv.z);
}
myPShapeFront.endContour();
myPShapeFront.endShape();
// ------------------------------------------------------------------------------
// make BACKSIDE
myPShapeBack=createShape();
myPShapeBack.beginShape();
float distZ = -10;
for (int i3 : listIntOutlineIndices) {
PVector pv=listPV.get(i3);
// push();
// translate(pv.x, 100-pv.y, pv.z );
myPShapeBack.vertex(pv.x, 100-pv.y, pv.z+distZ );
// fill(255, 0, 0);
// noStroke();
//sphere(4);
// text (i, 0, 0);
// pop();
i++;
}//for
// Interior part of shape -----
myPShapeBack.beginContour();
for (int i4 : listIntContourIndices) {
PVector pv=listPV.get(i4);
myPShapeBack.vertex( pv.x, 100-pv.y, pv.z +distZ );
}
myPShapeBack.endContour();
myPShapeBack.endShape();
// -----------------------------------------------
// NOW PShape Side 1
// MIDDLE SECTION (left Side, 3 Top Roofs,right side, bottoms)
// First create the shape
myPShapeSide = createShape();
myPShapeSide.setFill(color(255, 0, 0)); // 112 RED
// myPShapeSide.beginShape();
myPShapeSide.beginShape(QUADS);
// You can set fill and stroke
myPShapeSide.stroke(255);
// myPShapeSide.strokeWeight(2);
makeSide(listIntOutlineIndices, distZ); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
makeSide(listIntContourIndices, distZ); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
myPShapeSide.endShape();
//----
// -----------------------------------------------
// Make the parent shape
myPShapeGroup=createShape(GROUP);
// Add the 3 "child" shapes to the parent group
myPShapeGroup.addChild(myPShapeFront);
myPShapeGroup.addChild(myPShapeBack);
myPShapeGroup.addChild(myPShapeSide);
// -----------------------------------------------
myPShapeGroup.setFill(color(255, 0, 0));
myPShapeGroup.setStrokeWeight(3);
myPShapeGroup.setStroke(color(111, 111, 111));
}
//--------------------------------------------------------------------------
void makeSide(int[] listInt, float distZ) {
// Side = connecting back and front with tiles
for (int i=0; i<listInt.length-1; i++) {
// for (int i3 : listInt) {
//if (i>=listInt.length-2) // ???
// break;
if (myPShapeSide==null)
println("null");
PVector pv=listPV.get(listInt[i]);
myPShapeSide.vertex(pv.x, 100-pv.y, pv.z+distZ); // back 1
pv=listPV.get(listInt[i+1]);
myPShapeSide.vertex(pv.x, 100-pv.y, pv.z+distZ); // back 2
pv=listPV.get(listInt[i+1]);
myPShapeSide.vertex(pv.x, 100-pv.y, pv.z); // front 1
pv=listPV.get(listInt[i]);
myPShapeSide.vertex(pv.x, 100-pv.y, pv.z); // front 2
//vertex(bottomRadius*cos(angle), 0, bottomRadius*sin(angle));
//vertex(topRadius*cos(angle), -cHeight, topRadius*sin(angle));
//??? i++;
}//for
// CLOSE
/*
PVector pv=listPV.get(listInt.length-1);
myPShapeSide.vertex(pv.x, 100-pv.y, pv.z+distZ);
pv=listPV.get(listInt[0]);
myPShapeSide.vertex(pv.x, 100-pv.y, pv.z+distZ);
pv=listPV.get(listInt[0]);
myPShapeSide.vertex(pv.x, 100-pv.y, pv.z);
pv=listPV.get(listInt.length-1);
myPShapeSide.vertex(pv.x, 100-pv.y, pv.z);
*/
}
//
//-------------------------------------------------------------------------
// Outputs
void output() {
cam.beginHUD();
message();
verticalLine();
cam.endHUD();
mylights();
// translate(width/2, height/2 - 50, 315 );
rotateY(radians(angle1 ));
// translate(0, 0, -5 );
// shape(myPShape.getChild (i), -42.5, 0);
// shape(myPShape, -42.5, 0);
// stroke(255);
shape(myPShapeGroup, 0, 0); // THE CORE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// outputListPV();// ALSO THE CORE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}//func
//
void message () {
fill(0);
text ("Made an ArrayList and display it - success", 20, 20);
}
void verticalLine() {
stroke(0);
line(width/2, 0,
width/2, height);
}
//--------------------------------------------------------------------
// Tools
void mylights() {
ambientLight(128, 128, 128); // Color
directionalLight(128, 128, 128, // color and axis
0, -1, 1); // default is 0,0,-1 BUT 0,0,1 looks much better
lightFalloff(1, 0, 0);// something else
lightSpecular(0, 0, 0);// colors
int concentration = 600; // Try 1 -> 10000
spotLight(51, 102, 126, // color
0, 200, 1600, // POS
0, 0, -1, // DIR
PI/16, // angle cone
concentration); // exponent determining the center bias of the cone
}
boolean isNew(PVector pv) {
// println(pv.toString());
return
allOldPVs.indexOf(pv.toString()) < 0;
}
void avoidClipping() {
// avoid clipping (at camera):
// https : //
// forum.processing.org/two/discussion/4128/quick-q-how-close-is-too-close-why-when-do-3d-objects-disappear
perspective(PI/3.0, (float) width/height, 1, 1000000);
}//func
//--------------------------------------------------------------------------------------------
// ListPV
void outputListPV() {
int i=0;
for (PVector pv : listPV) {
push();
translate(pv.x, 100-pv.y, pv.z );
fill(255, 0, 0);
noStroke();
//sphere(4);
text (i, 0, 0);
pop();
i++;
}
}
void makeListPV () {
float prevZ=-10000;
boolean firstTime=true;
for (PShape ps : myPShape.getChildren()) {
//print (ps.getChildCount());
//print(" ");
//print (ps.getVertexCount());
for (int i2=0; i2 < ps.getVertexCount(); i2++) {
// PVector getVertex(int index, PVector vec)
PVector pv = ps.getVertex(i2);
if (isNew(pv)) {
// NEW
if (firstTime) {
// firstTime
prevZ=pv.z;
firstTime=false;
}//if
else {
// NOT firstTime
if (abs (pv.z - prevZ) > 9 )
continue;
}
// prevZ=pv.z;
listPV.add (pv);
allOldPVs+="#"+pv.toString()+"#";
}//if
}//for II
println (" ---");
// myPShapeGROUP.addChild(ps); // Add as children
}//for I
}//
void printListPV() {
for (PVector pv : listPV) {
println(pv.toString());
}
}
//