OBJ: Disabling MTL and Applying Custom Colors

I have a similar problem, mtl looks like this:

# Blender MTL File: 'Aa.blend'
# Material Count: 1

newmtl Material.001
Ns 225.000000
Ka 0.680556 0.680556 0.680556
Kd 0.800000 0.046634 0.034524
Ks 0.527778 0.527778 0.527778
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 3

I just want to be the obj red, can I kill the mtl?

I tried renaming the mtl and remove all references to it in the obj file manually.

Then I used this:


PShape letterA;

float angle = 0;

void setup() {
  size(800, 600, P3D);

  letterA = loadShape("Aa.obj");

  letterA.setVisible(true);
  letterA.resetMatrix();
  letterA.disableStyle();
  letterA.setFill(color(255, 0, 0));
  letterA.setFill(true);
  letterA.setFill(255);

  // letterA.fill(color(255, 0, 0));

  println ("End of Setup");
}


void draw() {
  background(240);
  lights();

  translate(width/2, height/2, -30);
  //translate(0, 0, -330);
  rotateX(-0.5);
  rotateY(angle);
  angle += 0.01;

  shape(letterA);
}

It doesn’t display anything

You have a .mtl file, but I think you also need an .obj file containing all the vertices.

1 Like

You are right, but I have an obj file but it doesn’t display.

Therefore I deleted the mtl from the code within the obj and tried to clear the obj but no success.

In the Windows 3D viewer the obj shows.

They are tricky. May not help you but I was able to run the following code of a 3D ‘A’. I found it online as a free .stl file (normally used for 3D printing) and converted it to an .obj file with a free online converter. The conversion included a .mtl file also. I put both files in a ‘data’ folder inside of the sketch folder and then ran the following source code in Processing:
Source code:

PShape a;

void setup() {
  size(400, 400, P3D);
  a = loadShape("A.obj");
//  a.setStroke(0); // Doesn't work
  a.setFill(color(255, 0, 0));
  println ("End of Setup");
}

void draw() {
  background(240);
  lights();
  stroke(0); // Does nothing
  translate(width/2, height/2 - 50, 150);
  scale(2, -2);
  rotateY(radians(30));
  shape(a);
}

This is the .obj file:

#mtllib A.mtl
o ascii
#usemtl DefaultMaterial
v 15.756629943847656 -25.27301025390625 10
v 15.756629943847656 -25.27301025390625 0
v 21.248050689697266 -9.360374450683594 10
v 21.248050689697266 -9.360374450683594 10
v 15.756629943847656 -25.27301025390625 0
v 21.248050689697266 -9.360374450683594 0
v 21.248050689697266 -9.360374450683594 10
v 21.248050689697266 -9.360374450683594 0
v 26.73946762084961 -25.27301025390625 10
v 26.73946762084961 -25.27301025390625 10
v 21.248050689697266 -9.360374450683594 0
v 26.73946762084961 -25.27301025390625 0
v 26.73946762084961 -25.27301025390625 10
v 26.73946762084961 -25.27301025390625 0
v 15.756629943847656 -25.27301025390625 10
v 15.756629943847656 -25.27301025390625 10
v 26.73946762084961 -25.27301025390625 0
v 15.756629943847656 -25.27301025390625 0
v 10.639630317687988 -40 10
v 10.639630317687988 -40 0
v 13.198129653930664 -32.698909759521484 10
v 13.198129653930664 -32.698909759521484 10
v 10.639630317687988 -40 0
v 13.198129653930664 -32.698909759521484 0
v 0.28081122040748596 -40 10
v 0.28081122040748596 -40 0
v 10.639630317687988 -40 10
v 10.639630317687988 -40 10
v 0.28081122040748596 -40 0
v 10.639630317687988 -40 0
v 15.101399421691895 0 10
v 15.101399421691895 0 0
v 0.28081122040748596 -40 10
v 0.28081122040748596 -40 10
v 15.101399421691895 0 0
v 0.28081122040748596 -40 0
v 27.394699096679688 0 10
v 27.394699096679688 0 0
v 15.101399421691895 0 10
v 15.101399421691895 0 10
v 27.394699096679688 0 0
v 15.101399421691895 0 0
v 42.21529006958008 -40 10
v 42.21529006958008 -40 0
v 27.394699096679688 0 10
v 27.394699096679688 0 10
v 42.21529006958008 -40 0
v 27.394699096679688 0 0
v 31.856470108032227 -40 10
v 31.856470108032227 -40 0
v 42.21529006958008 -40 10
v 42.21529006958008 -40 10
v 31.856470108032227 -40 0
v 42.21529006958008 -40 0
v 29.32917022705078 -32.698909759521484 10
v 29.32917022705078 -32.698909759521484 0
v 31.856470108032227 -40 10
v 31.856470108032227 -40 10
v 29.32917022705078 -32.698909759521484 0
v 31.856470108032227 -40 0
v 13.198129653930664 -32.698909759521484 10
v 13.198129653930664 -32.698909759521484 0
v 29.32917022705078 -32.698909759521484 10
v 29.32917022705078 -32.698909759521484 10
v 13.198129653930664 -32.698909759521484 0
v 29.32917022705078 -32.698909759521484 0
v 21.248050689697266 -9.360374450683594 10
v 15.101399421691895 0 10
v 15.756629943847656 -25.27301025390625 10
v 21.248050689697266 -9.360374450683594 10
v 27.394699096679688 0 10
v 15.101399421691895 0 10
v 21.248050689697266 -9.360374450683594 10
v 26.73946762084961 -25.27301025390625 10
v 27.394699096679688 0 10
v 27.394699096679688 0 10
v 26.73946762084961 -25.27301025390625 10
v 42.21529006958008 -40 10
v 42.21529006958008 -40 10
v 26.73946762084961 -25.27301025390625 10
v 29.32917022705078 -32.698909759521484 10
v 31.856470108032227 -40 10
v 42.21529006958008 -40 10
v 29.32917022705078 -32.698909759521484 10
v 29.32917022705078 -32.698909759521484 10
v 26.73946762084961 -25.27301025390625 10
v 13.198129653930664 -32.698909759521484 10
v 13.198129653930664 -32.698909759521484 10
v 26.73946762084961 -25.27301025390625 10
v 15.756629943847656 -25.27301025390625 10
v 0.28081122040748596 -40 10
v 15.756629943847656 -25.27301025390625 10
v 15.101399421691895 0 10
v 0.28081122040748596 -40 10
v 13.198129653930664 -32.698909759521484 10
v 15.756629943847656 -25.27301025390625 10
v 0.28081122040748596 -40 10
v 10.639630317687988 -40 10
v 13.198129653930664 -32.698909759521484 10
v 15.756629943847656 -25.27301025390625 0
v 15.101399421691895 0 0
v 21.248050689697266 -9.360374450683594 0
v 15.756629943847656 -25.27301025390625 0
v 0.28081122040748596 -40 0
v 15.101399421691895 0 0
v 15.756629943847656 -25.27301025390625 0
v 13.198129653930664 -32.698909759521484 0
v 0.28081122040748596 -40 0
v 15.756629943847656 -25.27301025390625 0
v 26.73946762084961 -25.27301025390625 0
v 13.198129653930664 -32.698909759521484 0
v 13.198129653930664 -32.698909759521484 0
v 26.73946762084961 -25.27301025390625 0
v 29.32917022705078 -32.698909759521484 0
v 29.32917022705078 -32.698909759521484 0
v 26.73946762084961 -25.27301025390625 0
v 42.21529006958008 -40 0
v 31.856470108032227 -40 0
v 29.32917022705078 -32.698909759521484 0
v 42.21529006958008 -40 0
v 42.21529006958008 -40 0
v 26.73946762084961 -25.27301025390625 0
v 27.394699096679688 0 0
v 27.394699096679688 0 0
v 26.73946762084961 -25.27301025390625 0
v 21.248050689697266 -9.360374450683594 0
v 15.101399421691895 0 0
v 27.394699096679688 0 0
v 21.248050689697266 -9.360374450683594 0
v 13.198129653930664 -32.698909759521484 0
v 10.639630317687988 -40 0
v 0.28081122040748596 -40 0
vn 0.9452941567987696 -0.3262191857051072 0
vn 0.9452941567987696 -0.3262191857051072 0
vn 0.9452941567987696 -0.3262191857051072 0
vn 0.9452941567987696 -0.3262191857051072 0
vn 0.9452941567987696 -0.3262191857051072 0
vn 0.9452941567987696 -0.3262191857051072 0
vn -0.9452941567987696 -0.3262191857051072 0
vn -0.9452941567987696 -0.3262191857051072 0
vn -0.9452941567987696 -0.3262191857051072 0
vn -0.9452941567987696 -0.3262191857051072 0
vn -0.9452941567987696 -0.3262191857051072 0
vn -0.9452941567987696 -0.3262191857051072 0
vn 0 1 0
vn 0 1 0
vn 0 1 0
vn 0 1 0
vn 0 1 0
vn 0 1 0
vn 0.9437325281505954 -0.3307097145692669 0
vn 0.9437325281505954 -0.3307097145692669 0
vn 0.9437325281505954 -0.3307097145692669 0
vn 0.9437325281505954 -0.3307097145692669 0
vn 0.9437325281505954 -0.3307097145692669 0
vn 0.9437325281505954 -0.3307097145692669 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn -0.937704619475264 0.3474335139487127 0
vn -0.937704619475264 0.3474335139487127 0
vn -0.937704619475264 0.3474335139487127 0
vn -0.937704619475264 0.3474335139487127 0
vn -0.937704619475264 0.3474335139487127 0
vn -0.937704619475264 0.3474335139487127 0
vn 0 1 0
vn 0 1 0
vn 0 1 0
vn 0 1 0
vn 0 1 0
vn 0 1 0
vn 0.937704619475264 0.3474335139487127 0
vn 0.937704619475264 0.3474335139487127 0
vn 0.937704619475264 0.3474335139487127 0
vn 0.937704619475264 0.3474335139487127 0
vn 0.937704619475264 0.3474335139487127 0
vn 0.937704619475264 0.3474335139487127 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn -0.9449860535982872 -0.32711062120440976 0
vn -0.9449860535982872 -0.32711062120440976 0
vn -0.9449860535982872 -0.32711062120440976 0
vn -0.9449860535982872 -0.32711062120440976 0
vn -0.9449860535982872 -0.32711062120440976 0
vn -0.9449860535982872 -0.32711062120440976 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn 0 -1 0
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
vn 0 0 -1
f 1//1 2//2 3//3
f 4//4 5//5 6//6
f 7//7 8//8 9//9
f 10//10 11//11 12//12
f 13//13 14//14 15//15
f 16//16 17//17 18//18
f 19//19 20//20 21//21
f 22//22 23//23 24//24
f 25//25 26//26 27//27
f 28//28 29//29 30//30
f 31//31 32//32 33//33
f 34//34 35//35 36//36
f 37//37 38//38 39//39
f 40//40 41//41 42//42
f 43//43 44//44 45//45
f 46//46 47//47 48//48
f 49//49 50//50 51//51
f 52//52 53//53 54//54
f 55//55 56//56 57//57
f 58//58 59//59 60//60
f 61//61 62//62 63//63
f 64//64 65//65 66//66
f 67//67 68//68 69//69
f 70//70 71//71 72//72
f 73//73 74//74 75//75
f 76//76 77//77 78//78
f 79//79 80//80 81//81
f 82//82 83//83 84//84
f 85//85 86//86 87//87
f 88//88 89//89 90//90
f 91//91 92//92 93//93
f 94//94 95//95 96//96
f 97//97 98//98 99//99
f 100//100 101//101 102//102
f 103//103 104//104 105//105
f 106//106 107//107 108//108
f 109//109 110//110 111//111
f 112//112 113//113 114//114
f 115//115 116//116 117//117
f 118//118 119//119 120//120
f 121//121 122//122 123//123
f 124//124 125//125 126//126
f 127//127 128//128 129//129
f 130//130 131//131 132//132

This is the .mtl file:

# MTL file - created by a modified js OBJExporter

newmtl DefaultMaterial
Tr 0.0000
Tf 1.0000 1.0000 1.0000
illum 1
Pr 1
Pds 1
Pl 1
Ka 1 1 1
Kd 1 1 1
Ke 0 0 0

Output:

I was not able to stroke the outline. I agree that you may not need the .mtl file. The color is controlled by .setFill() but it may not be ‘true’ and exactly as you expect it to be. From previous experience I was able to control the color and pattern by adding a texture with a separate .png file.

I don’t know if you would be willing to post the code that fails or send it to me by Message but I could try running it on my system (macos); no guarantees because I know how fickle objects can be.

2 Likes

thank you so much!

on which internet adress?

Here is it with an outline stroke.
But the obj file seems weird, so that the outline doesn’t look cool…

one issue was that the lights() were rendering the outline invisible (when it was white apparently).

Thanks!

Chrisir



// see https://discourse.processing.org/t/load-a-mlt-and-obj/5222/14

PShape myPShape;
float angle1=90;


void setup() {
  size(1200, 700, P3D);
  myPShape = loadShape("A.obj");

  myPShape.scale(2, -2);

  myPShape.setVisible(true);
  // myPShape.resetMatrix();
  // myPShape.disableStyle();// NOT useful

  myPShape.setFill(color(255, 0, 0));

  myPShape.setStrokeWeight(2);
  myPShape.setStroke(true);
  myPShape.setStroke(color(0)); // works

  println ("End of Setup");
}

void draw() {
  background(240);
  mylights();

  line(width/2, 0,
    width/2, height);

  translate(width/2, height/2 - 50, 315 );

  rotateY(radians(angle1 ));
  translate(0, 0, -5 );

  shape(myPShape, -42.5, 0);

  angle1+=1;
}

void mylights() {

  ambientLight(128, 128, 128);// Color
  directionalLight(128, 128, 128,
    0, 0, -1);
  lightFalloff(1, 0, 0);
  lightSpecular(0, 0, 0);
}


That’s nice; you’ve drawn it with all the triangles used for the vertices. There may be a way to get rid of those lines in py5 using TriMesh; @Villares would likely know. But then you may be back where we started with no lines. We need just the outline only.

2 Likes

in this version I improved the light management

It looks better now (light comes from the front not from the back)



// see https://discourse.processing.org/t/load-a-mlt-and-obj/5222/14

PShape myPShape;
float angle1=90;


void setup() {
  size(1200, 700, P3D);
  myPShape = loadShape("A.obj");

  println(myPShape.getChildCount());
  println(myPShape.getVertexCount());

  println("All children");

  for (PShape ps : myPShape.getChildren()) {
    print (ps.getChildCount());
    print("   ");
    print (ps.getVertexCount());

    println (" ---");
  }//for

  myPShape.scale(2, -2);

  myPShape.setVisible(true);
  // myPShape.resetMatrix();
  // myPShape.disableStyle();// NOT useful

  myPShape.setFill(color(255, 0, 0));

  // myPShape.setStrokeWeight(2);
  myPShape.setStroke(false);
  //  myPShape.setStroke(color(0));

  println ("End of Setup");
}

void draw() {
  background(240);
  mylights();

  line(width/2, 0,
    width/2, height);

  translate(width/2, height/2 - 50, 315 );

  rotateY(radians(angle1 ));
  translate(0, 0, -5 );

  shape(myPShape, -42.5, 0);

  angle1+=1;
}

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
}


1 Like

browse through triangles:



// see https://discourse.processing.org/t/load-a-mlt-and-obj/5222/14

PShape myPShape;
float angle1=90;

int i=0;

void setup() {
  size(1200, 700, P3D);
  myPShape = loadShape("A.obj");

  println(myPShape.getChildCount());
  println(myPShape.getVertexCount());

  println("All children");

  for (PShape ps : myPShape.getChildren()) {
    print (ps.getChildCount());
    print("   ");
    print (ps.getVertexCount());

    println (" ---");
  }//for

  myPShape.scale(2, -2);

  myPShape.setVisible(true);
  // myPShape.resetMatrix();
  // myPShape.disableStyle();// NOT useful

  myPShape.setFill(color(255, 0, 0));

  // myPShape.setStrokeWeight(2);
  myPShape.setStroke(false);
  //  myPShape.setStroke(color(0));


  //myPShape = myPShape.getChild (3);
  println ("End of Setup");
}

void keyPressed() {

  i++;
  if (i>=myPShape.getChildCount ())
    i=0;
}

void draw() {
  background(240);

  fill(0);
  text ("Use Space Bar to scroll to children: Child #"+i, 20, 20);

  mylights();

  line(width/2, 0,
    width/2, height);

  translate(width/2, height/2 - 50, 315 );

  rotateY(radians(angle1 ));
  translate(0, 0, -5 );

  shape(myPShape.getChild (i), -42.5, 0);

  angle1+=1;
}

//--------------------------------------------------------------------

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
}

It would make a cool video if you could add the triangles one by one and have each one ‘stick’ until the ‘A’ was fully reconstructed. However, I have no idea how you would go about doing that.

2 Likes

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());
  }
}
//

3 Likes

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());
  }
}
//

1 Like

I skipped the obj files now.

I made a version now using geomerative library (seems not to be in the download section of the IDE.

see Hair like strokes

With geomerative I read the points from each letter and then extrude it.


keywords: Letter 3D, 3DLetter, Letter3D,Alphabet, Font, Extrude letter. letter outline

2 Likes