I have tried two example code to import CAD model STL binary file. But did not succeed so far. Following are example 1 and example 2.
Example 1:
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("part1Bin.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);
}
}
Result: There is no result on output window screen. STL file size is 20MB. Running processing version 3. windows 10. i waited long but no result.
Example 2:
import toxi.geom.;
import toxi.geom.mesh.;
import toxi.processing.*;
TriangleMesh mesh;
ToxiclibsSupport gfx;
void setup() {
size(600,600,P3D);
mesh=(TriangleMesh)new STLReader().loadBinary(sketchPath(“part1Bin.stl”),STLReader.TRIANGLEMESH);
//mesh=(TriangleMesh)new STLReader().loadBinary(sketchPath(“mesh-flipped.stl”),STLReader.TRIANGLEMESH).flipYAxis();
gfx=new ToxiclibsSupport(this);
}
void draw() {
background(51);
lights();
translate(width/2,height/2,0);
rotateX(mouseY0.01);
rotateY(mouseX0.01);
gfx.origin(new Vec3D(),200);
noStroke();
gfx.mesh(mesh,false,10);
}
Result: Error: Lang . OutOfMemoryError : Java heap space
Solution: I tried to increase the memory in File-> Preferences-> Increase maximum memory size to 5000MB.
also tried to 10000MB.
but the out of memory error persists.
My STL file is in binary format.
Other way round what else can be the possible solution to save the CAD file in a formate which can be easily import in processing can be visuaize ?
Thanks