We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi to all!! :) i've a little problem with this code...It basicly read the vertex points from an obj file and save it in a PVetor matrix...but it doesn't work and i don't know why!! thanks to all!! here the code:
PShape s;
ObjClass obj;
void setup() {
size(1000, 1000, P3D);
// The file "bot.obj" must be in the data folder
// of the current sketch to load successfully
s = loadShape("FinalBaseMesh.obj");
obj=new ObjClass(s);
obj.createShapes();
}
void draw() {
background(0);
obj.render();
}
class ObjClass {
PShape shape, finals;
PVector[][] pos;
ObjClass(PShape shape) {
this.shape=shape;
readChild();
}
void readChild() {
for (int i=0; i<shape.getChildCount()/8; i++) {
PShape mom=shape.getChild(i);
pos=new PVector[shape.getChildCount()/8][mom.getVertexCount()];
for (int j=0; j<mom.getVertexCount(); j++) {
pos[i][j]=mom.getVertex(j);
}
}
println("file read");
}
void createShapes() {
finals=createShape();
finals.beginShape(POINTS);
finals.stroke(255);
finals.fill(255);
for (int i=0; i<pos.length; i++) {
for (int j=0; j<pos[0].length; j++) {
<del>finals.vertex(pos[i][j].x, pos[i][j].y, pos[i][j].z);</del>
}
}
finals.endShape(CLOSE);
}
void render(){
shape(finals);
}
}
problem is a nullPointerExpection on the deleted line!!
Answers
solved!!!
if anyone is interested the problem was that i initialize pos in readChild method!
Given I was already refactoring your class in order to spot the NPE from the 2D PVector[][], I'm gonna post it below even though you've fixed it by yourself already: =D>