# Nervous System OBJ Export

**URL:** <https://discourse.processing.org/t/nervous-system-obj-export/10286>\
**Category:** Libraries\
**Created:** [April 15, 2019, 3:35am UTC](https://discourse.processing.org/t/nervous-system-obj-export/10286 "2019-04-15T03:35:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirstee\_baxt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kirstee_baxt/32/4377_2.png) [@kirstee\_baxt](https://discourse.processing.org/u/kirstee_baxt)\
**Post date:** [April 15, 2019, 3:35am UTC](https://discourse.processing.org/t/nervous-system-obj-export/10286/1 "2019-04-15T03:35:52Z")

</div>

Hello! Wondering if anyone is knowledgeable around using nervoussystem library for obj export from Processing. I used it on one file and it worked - now trying it on a different file and it’s creating the obj, says there are \_\_bites (usually 75-150 bites), but the file seems corrupt and won’t open in other applications. Thinking I’m putting the if (record) lines in incorrect spot, but I tried other places and can’t seem to find one that works.

Here’s my code below – sorry for the messiness as I’m a new coder. 😄

Thanks in advance, kirstee\_baxt

```auto
import nervoussystem.obj.*;
import peasy.*;
Table myTable;
String table_fn="data/data-test.csv";
int numEntries;
float time, radius, day;
boolean diagp = true;
PShape[] myShapes;
PeasyCam cam;

//for export
boolean record = false;
String filename = "Data_TypeA_"+month()+day()+hour()+minute()+".obj";

void setup(){
  size(800, 800, P3D);
  myTable = loadTable(table_fn, "header");
  if (diagp) println("load file: "+table_fn);
  numEntries = myTable.getRowCount();
  make_shapes();
  cam = new PeasyCam(this,1000);
}

void make_shapes(){ 
  noFill();
  int startday = myTable.getRow(0).getInt("Day");
  int endday = myTable.getRow(numEntries-1).getInt("Day");
  int days = endday - startday+1;
  if (diagp) println("start day "+startday+" endday "+endday+" days "+days);
  myShapes = new PShape[days];
  int k = 0;
  for ( int goday = startday; goday <= endday; goday++ ) { // group shapes per day
    myShapes[k] = createShape();
    println("make shape "+k);
    myShapes[k].beginShape();
    for (int i = 0; i < numEntries; i++) {
      time = myTable.getRow(i).getFloat("Time Decimal");
      radius = myTable.getRow(i).getFloat("Productivity Level");
      day = myTable.getRow(i).getFloat("Day");
      //time is x, radius is y, day is z
      
      if ( day == goday ) {
      if (diagp) println("#:i "+i+" x", time+" time decimal ", radius +" productivity ", day +"day");
      float angle = map(time, 0, 1, 0, TWO_PI);
      float xCenter = width/20; 
      float yCenter = height/20;
  
      float xCoord = xCenter + cos(angle-(TWO_PI/4)) * (radius*3);
      float yCoord = yCenter + sin(angle-(TWO_PI/4)) * (radius*3);
      float zCoord = (day * 80); //multiplier is random for separation
      
      myShapes[k].vertex(xCoord, yCoord, zCoord);
      }
    }
      myShapes[k].endShape();
      k++; 
  }
}

void draw() {
//background(135); //removed because creates plane with obj export
if (record) {
    beginRecord("nervoussystem.obj.OBJExport", filename); 
  } 
for ( int k = 0 ; k < myShapes.length; k++ ) {
  shape(myShapes[k]);
  endShape();
}
if (record) {
    endRecord();
    record = false;
  }
}

void keyPressed() {
  if (key == 's') {
    record = true;
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 15, 2019, 3:49am UTC](https://discourse.processing.org/t/nervous-system-obj-export/10286/2 "2019-04-15T03:49:03Z")

</div>

Just a remark : the endshape in draw seems unnecessary

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 17, 2019, 5:56pm UTC](https://discourse.processing.org/t/nervous-system-obj-export/10286/3 "2019-04-17T17:56:32Z")

</div>

> [@kirstee\_baxt](#):
>
> nervoussystem

I’m not familiar with it, no. Yes, endShape is something that you pair with beginShape (not needed when just using `shape()`.

You said one file worked, another didn’t. What file – a csv file? Can you boil them down to simple examples (a few lines) of working and not working? Maybe share them. It may be bad data – or bad error handling (null values, zeros, extra columns etc)

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [April 17, 2019, 8:09pm UTC](https://discourse.processing.org/t/nervous-system-obj-export/10286/4 "2019-04-17T20:09:42Z")

</div>

Two years ago I was having problems with it too so I wrote this (sorry for pasting an image, don’t know where the code is…)

> <https://twitter.com/hamoid/status/816682493793472512>

 ![a](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4fe58ebb028a7e6aca4da194569a40796de29f30.jpeg)

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 17, 2019, 10:03pm UTC](https://discourse.processing.org/t/nervous-system-obj-export/10286/5 "2019-04-17T22:03:35Z")

</div>

Transcript (not checked, may contain OCR errors):

```auto
private void exportMesh(PShape mesh) {
  StringBuilder verts = new StringBuilder();
  StringBuilder faces = new StringBuilder();
  final int vertsNum = mesh.getVertexCount();
  final PVector v = new PVector();
  for (int i=0; i<vertsNum; i+=3) {
    mesh.getVertex(i, v);
    verts.append("v " + v.x + " " + v.y + " " + v.z + "\n");
    mesh.getVertex( i+1, v);
    verts.append("v " + v.x + " " + v.y + " " + v.z + "\n");
    mesh.getVertex( i+2, v);
    verts.append("v " + v.x + " " + v.y + " " + v.z + "\n");
    faces.append("f " + (i+1) + " " + (i+2) + " " + (i+3) + "\n");
  }
  PrintWriter output = createWriter( "thing.obj");
  output.println("o Sphere\n");
  output.println(verts);
  output.println(faces);
  output.flush();
  output.close();
}   

```

What is that syntax “index:” and “filename:” doing…? I don’t think I’ve seen anything like that in Java before.

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [April 18, 2019, 11:28am UTC](https://discourse.processing.org/t/nervous-system-obj-export/10286/6 "2019-04-18T11:28:25Z")

</div>

That’s the OCR in action 🙂 IntelliJ Idea shows you the names of the arguments. It’s not part of the code. Sorry about the confusion.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 18, 2019, 3:38pm UTC](https://discourse.processing.org/t/nervous-system-obj-export/10286/7 "2019-04-18T15:38:17Z")

</div>

ah, got it. Okay, I think I’ve fixed the code above.
