public static SimpleImage renderMesh(Mesh pMesh, int pWidth, int pHeight, double pPositionX, double pPositionY,
double pSize, double pScaleZ, double pRotateAlpha, double pRotateBeta) {
if (pMesh.getFaces().size() == 0)
return new SimpleImage(pWidth, pHeight);
Mesh3D mesh3d = new Mesh3D();
mesh3d.setImageWidth(pWidth);
mesh3d.setImageHeight(pHeight);
int pCount = pMesh.getVertices().size();
mesh3d.setPCount(pCount);
double[] x = new double[pCount];
double[] y = new double[pCount];
double[] z = new double[pCount];
double cx = pWidth / 2;
double cy = pHeight / 2;
int idx = 0;
double xmin = pMesh.getPMin().x;
double ymin = pMesh.getPMin().y;
double zmin = pMesh.getPMin().z;
double xmax = pMesh.getPMax().x;
double ymax = pMesh.getPMax().y;
double zmax = pMesh.getPMax().z;
double size = (xmax - xmin + ymax - ymin + zmax - zmin) / 3.0;
for (Point point : pMesh.getVertices()) {
double currX = (point.x - xmin) / size * pWidth - cx;
double currY = (point.y - ymin) / size * pHeight - cy;
double currZ = pScaleZ * (point.z - zmin) / size * pHeight;
x[idx] = currX;
y[idx] = currY;
z[idx] = currZ;
idx++;
}
mesh3d.setX(x);
mesh3d.setY(y);
mesh3d.setZ(z);
int fCount = pMesh.getFaces().size();
mesh3d.setFCount(fCount);
mesh3d.setU(null);
mesh3d.setV(null);
mesh3d.setTexture(null);
int[] pp1 = new int[fCount];
int[] pp2 = new int[fCount];
int[] pp3 = new int[fCount];
idx = 0;
for (Face face : pMesh.getFaces()) {
pp1[idx] = face.a;
pp2[idx] = face.b;
pp3[idx] = face.c;
idx++;
}
mesh3d.setPP1(pp1);
mesh3d.setPP2(pp2);
mesh3d.setPP3(pp3);
int color[] = new int[fCount];
Pixel toolPixel = new Pixel();
toolPixel.setRGB(225, 185, 160);
int argb = toolPixel.getARGBValue();
for (int c = 0; c < fCount; c++) {
color[c] = argb;
}
mesh3d.setColor(color);
PerspectiveTransformer trans = new PerspectiveTransformer();
trans.setInputMesh3D(mesh3d);
trans.setDoCam(true);
trans.setCentreX(trans.getCentreX() * (1.0 + pPositionX));