We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello,
i am experiementing with the delaunay3d example in the he_mesh library. i receive data points for the mesh from the mouse, but the render method in draw() throws a flag "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException." i haven't changed much from the original example, so i don't understand why. i get the expected data from all of my println statements, excpet for the last for loop that controls the render.
thanks in advance,
destro.
here's the original:
import wblut.processing.*;
import wblut.geom.*;
import wblut.core.*;
import wblut.math.*;
import java.util.List;
List <WB_Point> points;
WB_Delaunay triangulation;
WB_Predicates pred = new WB_Predicates();
WB_Render3D render;
void setup() {
size(800, 800, OPENGL);
render = new WB_Render3D(this);
smooth(8);
create();
}
void create() {
points = new ArrayList <WB_Point>();
float x, y, z;
float r = 200;
float[] point = new float[3];
for (int i = 0; i < 400; i ++) {
do {
point[0] = random(-r, r);
point[1] = random(-r, r);
point[2] = random(-r, r);
}
while (noise (10 + 0.006 * point[0], 10 + 0.006 * point[1], 10 + 0.006 * point[2]) < 0.6);
points.add(new WB_Point(point[0], point[1], point[2]));
}
float m = millis();
triangulation = WB_Delaunay.getTriangulation3D(points, 0.001);
println(millis()-m);
}
void draw() {
background(255);
create();
translate(400, 400, 0);
directionalLight(255, 255, 255, 1, 1, -1);
directionalLight(127, 127, 127, -1, -1, 1);
rotateY(mouseX*1.0f/width*TWO_PI);
rotateX(mouseY*1.0f/height*TWO_PI);
noFill();
for (int i = 0; i < triangulation.Tri.length; i ++) {
render.drawTetrahedron(triangulation.Tri[i], points);
}
}
and here is my effort: import wblut.processing.*; import wblut.geom.*; import wblut.core.*; import wblut.math.*; import java.util.List;
FloatList xMouse;
FloatList yMouse;
PVector [] points;
List <WB_Point> meshPoints;
WB_Delaunay triangulation;
// WB_Predicates pred = new WB_Predicates();
WB_Render3D render;
void setup() {
size(800, 800, OPENGL);
render = new WB_Render3D(this);
smooth(8);
xMouse = new FloatList();
yMouse = new FloatList();
// println(xMouse.size());
// println(yMouse.size());
}
void mouseDragged() {
xMouse.append(mouseX);
yMouse.append(mouseY);
// println("x: " + xMouse);
// println("y: " + yMouse);
}
void mouseReleased() {
points = new PVector[xMouse.size()];
for (int i = 0; i < xMouse.size(); i ++) {
points[i] = new PVector(xMouse.get(i), yMouse.get(i));
// println(i);
// printArray(points[i].x + ":" + points[i].y);
// println();
}
create(points);
xMouse.clear();
yMouse.clear();
}
void create(PVector [] points) {
meshPoints = new ArrayList <WB_Point>();
// float x, y, z;
float r = random(200);
float [] point = new float[3];
for (int i = 0; i < points.length; i ++) {
// do {
point[0] = points[i].x;
point[1] = points[i].y;
point[2] = random(-r, r);
// }
// while (noise (10 + 0.006 * point[0], 10 + 0.006 * point[1], 10 + 0.006 * point[2]) < 0.6);
meshPoints.add(new WB_Point(point[0], point[1], point[2]));
}
float m = millis();
triangulation = WB_Delaunay.getTriangulation3D(meshPoints, 0.001);
println (triangulation); //Tri, Vertices, Walk, Edges
//this for loop if fine here and get output, but the same loop in draw() throws a flag
for (int i = 0; i < triangulation.Tri.length; i ++) {
println (triangulation.Tri[i]);
}
// println(millis()-m);
}
void draw() {
background(255);
translate(400, 400, 0);
directionalLight(255, 255, 255, 1, 1, -1);
directionalLight(127, 127, 127, -1, -1, 1);
rotateY(mouseX*1.0f/width*TWO_PI);
rotateX(mouseY*1.0f/height*TWO_PI);
noFill();
//println (triangulation.Tri.length); //throws a flag as well
// for (int i = 0; i < triangulation.Tri.length; i ++) {
// render.drawTetrahedron(triangulation.Tri[i], meshPoints);
// }
}
Answers
it seems that my error was because something was null. i put an if statement in, but i am only able to make the sketch work a couple time before it freezes. any ideas?
i figured out the problem (it freezes if there aren't enough points to render the shape), but if you spend time on this problem and have suggestions, i'm all ears.
cheers,
destro.