problems with JoonsRender library when it comes to huge amount of geometries
in
Contributed Library Questions
•
3 years ago
I am using your library for rendering. It works pretty well with basic geometry. However, when I try to instance a huge amount of boxes to cloud of points, it doesn't work. I am wondering which step I went wrong, or it does has something problem with huge amount of geometries.
Here is my code:
- import processing.opengl.*;
import peasy.*;
import joons.*; - PrintWriter output;
ControlP5 controlP5;
PMatrix3D currCameraMatrix;
PGraphics3D g3;
PeasyCam cam;
JoonsRenderer jr; - float strWeight = 1;
float Optdist = 5; - float eyeX = 600;
float eyeY = 620;
float eyeZ = 300;
float centerX = 0;
float centerY = 0;
float centerZ = 0;
float upX = 0;
float upY = 0;
float upZ = -1;
float fov = PI / 3;
float aspect = (float) 1;
float zNear = 5;
float zFar = 10000; - ArrayList points;
boolean rendered = false;
void setup() {
size(800,800,P3D);- jr = new JoonsRenderer(this,width,height); //just declare like this.
jr.setRenderSpeed(0.5); - //smooth();
//background(0);
//strokeWeight(0.7);
controlP5 = new ControlP5(this);
control();
g3 = (PGraphics3D)g;
//cam = new PeasyCam(this,600);
cam = new PeasyCam(this, width-200);
controlP5.setAutoDraw(false); - points = new ArrayList();
- String[] cir_points;
float x,y,z;
float magnatude;
cir_points= loadStrings("trails.txt"); - for(int index = 0; index < cir_points.length; index++) {
String[] pieces = split(cir_points[index], ',');
if (pieces.length == 4) {
x = float(pieces[0]);
y = float(pieces[1]);
z = float(pieces[2]);
magnatude = float(pieces[3]);
points.add(new kPoint(new PVector(x,y,z), magnatude));
}
} - }
void draw() {
//background(0);
//fill(255);- beginRecord("joons.OBJWriter","");
perspective(fov, aspect, zNear, zFar);
camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
for(int i = 0; i < points.size(); i++) {
kPoint p = (kPoint) points.get(i);
p.render();
}
translate(0,0,-400);
box(200);
translate(0,100,0);
sphere(100);
//floor plate - rect(-2000, -2000, 5000, 5000);
noSmooth();
endRecord(); - gui();
if(rendered)
jr.display();
}- void gui() {
currCameraMatrix = new PMatrix3D(g3.camera);
camera();
controlP5.draw();
g3.camera = currCameraMatrix;
} - import controlP5.*;
- void control(){
//strokeWeight
controlP5.addBang("strokeWeight",0,40,80,20).setId(1);
controlP5.controller("strokeWeight").setLabel("strokeWeight");
//strWeight_slider
controlP5.addSlider("strWeight",0,10,1,100,40,100,10).setId(2);
controlP5.controller("strWeight").setLabel("strWeight"); - //optinum
controlP5.addBang("optinum",0,80,80,20).setId(3);
controlP5.controller("optinum").setLabel("optinum");
//strWeight_slider
controlP5.addSlider("dist",0,10,1,100,80,100,10).setId(4);
controlP5.controller("dist").setLabel("dist"); - //tabs
controlP5.tab("default").setLabel("ModelT");
controlP5.controller("strokeWeight").moveTo("agent");
controlP5.controller("strWeight").moveTo("agent");
controlP5.controller("optinum").moveTo("agent");
controlP5.controller("dist").moveTo("agent");
controlP5.tab("agent").setColorForeground(0xffff0000);
controlP5.tab("agent").setColorBackground(0xff330000);
controlP5.trigger();
controlP5.tab("agent").activateEvent(true);
controlP5.tab("agent").setId(1);
}
void controlEvent(ControlEvent theEvent) {
switch(theEvent.controller().id()) {
case(2):
strWeight = (int)(theEvent.controller().value());
break;
case(3):
optinum();
break;
case(4):
Optdist = (int)(theEvent.controller().value());
break;
}
}- void keyPressed() {
- if(key=='f') {
output = createWriter("output" +".txt"); - for(int i = 0; i < points.size(); i++) {
PVector d = (PVector) points.get(i);
output.println(d.x + "," + d.y + "," + d.z);
}
output.flush();
output.close();
}- if (key == 'r' || key == 'R' && !rendered) {
saveFrame("capture.png");
//Glossy
jr.setShader("object1", "Red");
jr.setSC("ambient.sc");
rendered = jr.render("bucket");
// render using render("ipr") to render quick and rough,
// and render("bucket") to render slow and smooth
// if successfully rendered, render() returns true
}
} - class kPoint {
//states
PVector pos;
float magnatude; - //constructor
kPoint(PVector _pos, float _magnatude) {
pos = _pos;
magnatude = _magnatude;
} - void render() {
- pushMatrix();
//strokeWeight(strWeight);
//stroke(magnatude, 0, 0);
translate(pos.x, pos.y, pos.z); - box(10);
//point(0,0,0);
//point(pos.x, pos.y, pos.z);
popMatrix();
}
}
1