user3168961 user3168961 - 3 months ago 10
Java Question

Java/Processing - imported objects disappear close to camera

I've imported an object into Processing that I created in Blender.

The code below works and the object appears but seemingly very small (or distant).

If I try to move close to the object with PeasyCamm it disappears completely before it gets close enough to see properly. The only thing I could figure is that the object itself is very close to the camera but is in fact tiny...

I attempted to scale the object but a call to

myshape.getVertexCount()


indicates my object has no vertices and nothing I do seems to change anything. I have a tiny rendered object that disappears at about a quarter of the screen height.

PShape myshape;

import peasy.test.*;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
PeasyCam camera;

void setup(){
size( 640, 480, P3D);
camera = new PeasyCam(this, 0, 0, 0, 50);
frameRate(10);
myshape = loadShape("test.obj");
for (int i = 0; i < myshape.getVertexCount(); i++){
PVector v = myshape.getVertex(i);
println("Inside");
v.x *= 45;
v.y *= 45;
v.z *= 45;
myshape.setVertex(i, v);
}
}

void draw(){
background(0);


shape(myshape);
}

Answer

The getVertexCount() and getVertex() functions only work with shapes that you create in the code, using the vertex() function. More info can be found in the reference.

If all you want to do is scale your shape, then you can simply use the scale() function. Here is some example code that scaled your object by a factor of 20:

PShape myshape;

void setup() {
  size(500, 500, P3D);
  myshape = loadShape("test.obj");
}

void draw() {
  background(0);
  translate(width/2, height/2, 100);
  scale(20);
  shape(myshape);
}

scaled object