We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all,
I extracted a part of this code: http://www.openprocessing.org/sketch/8880 I just want to get the terrain with peasycam. Somehow, I get the following error: "cannot convert from Mesh3D to TriangleMesh". I checked the toxiclibs references and everything seems ok. I don't know what I did wrong.
Thank you for your help,
Roger
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.math.*;
import toxi.processing.*;
//ControlP5
import java.awt.Frame;
import java.awt.BorderLayout;
import controlP5.*;
//PeasyCam
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
PeasyCam cam;
float NOISE_SCALE = 0.08f;
int DIM=80;
Terrain terrain;
ToxiclibsSupport gfx;
TriangleMesh mesh;
void setup() {
size(680,382, P3D);
cam = new PeasyCam(this, 700);
// create terrain & generate elevation data
terrain = new Terrain(DIM,DIM, 50);
float[] el = new float[DIM*DIM];
noiseSeed(23);
for (int z = 0, i = 0; z < DIM; z++) {
for (int x = 0; x < DIM; x++) {
el[i++] = noise(x * NOISE_SCALE, z * NOISE_SCALE) * 400;
}
}
terrain.setElevation(el);
mesh = terrain.toMesh(0);
gfx = new ToxiclibsSupport(this);
}
void draw() {
directionalLight(192, 160, 128, 0, -1000, -0.5f);
directionalLight(255, 64, 0, 0.5f, -0.1f, 0.5f);
fill(255);
noStroke();
// draw mesh & car
gfx.mesh(mesh, false);
}
Answers
Hints (error message, javadocs) were pretty clear. Your object type is a 'TriangleMesh' and you are getting a 'Mesh3D'. These do not match. So either change your object type (line 19 to Mesh3D mesh;) or change what your are getting (line 36 to mesh = (TriangleMesh) terrain.toMesh(0);).
Also, since this question requires a library, it should be in the library questions section. Moved. See: http://forum.processing.org/two/discussion/8043/how-to-choose-a-category-in-this-forum