"processing stl" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "processing stl" answered properly. Developers are finding an appropriate answer about processing stl related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like processing stl. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on processing stl. 

processing stl

By Thoughtless ThrushThoughtless Thrush on Jan 11, 2021
    ASCII
    PShape s; int p; String sub; Float X,Y,Z;
    float rotX, rotY, camX, camY, camZ;
 
    void setup() 
    { 
      size(640, 360, P3D); 
      background(0); 
      stroke(255);
      fill(130); 
      s=createShape(); 
      s.beginShape(TRIANGLES); 
      String[] lines = loadStrings("test.stl"); //LOAD ASCII STL ONLY!!!
      for (int i = 0 ; i < lines.length; i++) 
      { 
        p=lines[i].indexOf("vertex"); 
        if (p>-1) 
        { 
         sub=lines[i].substring(p+7); 
         String[] list = split(sub, ' ');
         X=float(list[0]); Y=float(list[1]); Z=float(list[2]);
         s.vertex(X, Y, Z);
        } 
      } 
      s.endShape(); 
      camX=width/2;
      camY=height/2;
      rotX=0;
      rotY=0;
    }
 
    void draw() 
    { 
     background(0);
     translate(camX, camY, camZ);
     rotateY(rotY);
     rotateX(rotX);
     shape(s, 0, 0);
    }
 
void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  camZ+=e*5;
}
 
void mouseDragged()
{
  if (mouseButton == LEFT)
  {
    rotY += (pmouseX - mouseX)*0.01;
    rotX += (pmouseY - mouseY)*0.01;
  }
  if (mouseButton == RIGHT)
  {
    camX -= (pmouseX - mouseX);
    camY -= (pmouseY - mouseY);
  }
  if (mouseButton == CENTER)
  {
    camZ += (pmouseY - mouseY);
  }
}

Source: discourse.processing.org

Add Comment

0

processing stl

By Thoughtless ThrushThoughtless Thrush on Jan 11, 2021
Bin
import java.io.FileInputStream;
import java.io.DataInputStream;

    PShape s;  
    float rotX, rotY, camX, camY, camZ;
    boolean shape=false;
    
    java.io.File folder;
    int showfiles=0;
    File[] files;

    void setup() 
    { 
      size(1024, 768, P3D); 
      background(0); 
      stroke(255);
      fill(130); 
      camX=width/2;
      camY=height/2;
      rotX=0;
      rotY=0;
    }

    void draw() 
    { 
     background(0);
     textSize(32);
     if (showfiles>0) {     
      for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) fill(255,0,0); else fill(150);
        text(files[i].getName(),20,32+i*32);
       }
      }
     fill(130);   
     translate(camX, camY, camZ);
     rotateY(rotY);
     rotateX(rotX);
     if (shape) shape(s, 0, 0);
      else text("Click for menu",0,0);
    }
    
void loadSTL(String filename)
{
   float N,X,Y,Z;
   int vertices=0;
   int p; String sub;
      s=createShape(); 
      s.beginShape(TRIANGLES); 
      String[] lines = loadStrings(filename); //LOAD ASCII STL ONLY!!!
      for (int i = 0 ; i < lines.length; i++) 
      { 
        p=lines[i].indexOf("vertex"); 
        if (p>-1) 
        { 
         sub=lines[i].substring(p+7); 
         String[] list = split(sub, ' ');
         X=float(list[0]); Y=float(list[1]); Z=float(list[2]);
         s.vertex(X, Y, Z);
         vertices++;
        } 
      } 
      s.endShape();
   if (vertices==0) //no vertices? it could be binary STL
    {
      println(filename,"is a binary file");
      try{
      FileInputStream fis = new FileInputStream(sketchPath(filename));
      DataInputStream input = new DataInputStream(fis);
      byte[] header = new byte[80];
      byte[] b4=new byte[4];
      byte[] attribute=new byte[2];
      byte[] normal = new byte[12];
      input.read(header);  //read header and throw away
      input.read(b4); vertices=unhex((hex(b4[3])+hex(b4[2])+hex(b4[1])+hex(b4[0]))); //again this endianity
      println("vertices: ",vertices);
      s=createShape(); 
      s.beginShape(TRIANGLES); 
      for (int i = 0 ; i < vertices; i++){
       input.read(normal); //ignore surface normals
       for (int j=0;j<3;j++){
        input.read(b4); X=annoyingEndian(b4);
        input.read(b4); Y=annoyingEndian(b4);
        input.read(b4); Z=annoyingEndian(b4);
        s.vertex(X, Y, Z);}
        input.read(attribute); //ignore attribute
      }
        s.endShape();      
        input.close();
      }
          catch (IOException e)
    {
      System.out.println("IOException : " + e);
    }
    }
   shape=true;   
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  camZ+=e*5;
}

void mouseDragged()
{
  if (mouseButton == LEFT)
  {
    rotY+=(pmouseX-mouseX)*0.01;
    rotX+=(pmouseY-mouseY)*0.01;
  }
  if (mouseButton==RIGHT)
  {
    camX-=(pmouseX-mouseX);
    camY-=(pmouseY-mouseY);
  }
  if (mouseButton==CENTER)
  {
    camZ+=(pmouseY-mouseY);
  }
}

void mouseClicked()
{
 if (showfiles==0) {  
 files = listFiles(sketchPath(""));
 showfiles=1;
 }
 else
 {showfiles=0;
  if (mouseX<500)
   {
    int Choice=mouseY/32;
    if (Choice<files.length)
    {
     showfiles=1;
     String filename;
     filename=files[Choice].getName();
     println(filename);
     if (filename.toLowerCase().indexOf(".stl")>-1) loadSTL(filename);
    }
   }
 }
}

Float annoyingEndian(byte[] b)
{
  return Float.intBitsToFloat(unhex((hex(b[3])+hex(b[2])+hex(b[1])+hex(b[0]))));
}

Source: discourse.processing.org

Add Comment

0

processing stl

By Thoughtless ThrushThoughtless Thrush on Jan 11, 2021
    PShape s; int p; String sub; Float X,Y,Z;
    float rotX, rotY, camX, camY, camZ;
 
    void setup() 
    { 
      size(640, 360, P3D); 
      background(0); 
      stroke(255);
      fill(130); 
      s=createShape(); 
      s.beginShape(TRIANGLES); 
      String[] lines = loadStrings("test.stl"); //LOAD ASCII STL ONLY!!!
      for (int i = 0 ; i < lines.length; i++) 
      { 
        p=lines[i].indexOf("vertex"); 
        if (p>-1) 
        { 
         sub=lines[i].substring(p+7); 
         String[] list = split(sub, ' ');
         X=float(list[0]); Y=float(list[1]); Z=float(list[2]);
         s.vertex(X, Y, Z);
        } 
      } 
      s.endShape(); 
      camX=width/2;
      camY=height/2;
      rotX=0;
      rotY=0;
    }
 
    void draw() 
    { 
     background(0);
     translate(camX, camY, camZ);
     rotateY(rotY);
     rotateX(rotX);
     shape(s, 0, 0);
    }
 
void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  camZ+=e*5;
}
 
void mouseDragged()
{
  if (mouseButton == LEFT)
  {
    rotY += (pmouseX - mouseX)*0.01;
    rotX += (pmouseY - mouseY)*0.01;
  }
  if (mouseButton == RIGHT)
  {
    camX -= (pmouseX - mouseX);
    camY -= (pmouseY - mouseY);
  }
  if (mouseButton == CENTER)
  {
    camZ += (pmouseY - mouseY);
  }
}

Source: discourse.processing.org

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on processing stl can get a collection of related answers to their query. Programmers need to enter their query on processing stl related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about processing stl for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of processing stl while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "processing stl". Visit this developer's friendly online web community, CodeProZone, and get your queries like processing stl resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "processing stl"

View All Whatever queries

Whatever queries related to "processing stl"

Browse Other Code Languages

CodeProZone