use of org.jwildfire.transform.Mesh3D in project JWildfire by thargor6.
the class ScriptProcessor method executeTransformer.
public TransformResult executeTransformer(String pInputName, boolean pStoreMesh3D, String pOutputName, String pOutput3DName, boolean pRecordAction) {
Buffer inBuffer = bufferList.bufferByName(pInputName);
if (inBuffer == null) {
dumpBuffers();
throw new RuntimeException("Input buffer <" + pInputName + "> not found");
}
SimpleImage newImg = null;
SimpleHDRImage newHDRImg = null;
if (inBuffer.getBufferType() == BufferType.IMAGE) {
transformer.setStoreMesh3D(pStoreMesh3D);
newImg = inBuffer.getImage().clone();
transformer.transformImage(newImg);
} else if (inBuffer.getBufferType() == BufferType.HDR_IMAGE) {
transformer.setStoreMesh3D(pStoreMesh3D);
newHDRImg = inBuffer.getHDRImage().clone();
transformer.transformImage(newHDRImg);
} else if (inBuffer.getBufferType() == BufferType.MESH3D) {
transformer.setStoreMesh3D(pStoreMesh3D);
Mesh3D mesh3D = inBuffer.getMesh3D();
newImg = new SimpleImage(mesh3D.getImageWidth(), mesh3D.getImageHeight());
transformer.setInputMesh3D(mesh3D);
transformer.transformImage(newImg);
}
Buffer outBuffer = null;
if (newImg != null) {
outBuffer = bufferList.addImageBuffer(addBuffersToDesktop ? desktop : null, transformer.getName(), newImg);
if ((pOutputName != null) && (pOutputName.length() > 0))
outBuffer.setName(pOutputName);
}
Buffer outHDRBuffer = null;
if (newHDRImg != null) {
outHDRBuffer = bufferList.addHDRImageBuffer(addBuffersToDesktop ? desktop : null, transformer.getName(), newHDRImg);
if ((pOutputName != null) && (pOutputName.length() > 0))
outHDRBuffer.setName(pOutputName);
}
Buffer outBuffer3D = null;
if (pStoreMesh3D) {
ScaleTransformer scaleT = new ScaleTransformer();
scaleT.setAspect(ScaleAspect.KEEP_WIDTH);
scaleT.setUnit(ScaleTransformer.Unit.PIXELS);
scaleT.setScaleWidth(120);
SimpleImage scaledImg = newImg.clone();
scaleT.transformImage(scaledImg);
outBuffer3D = bufferList.addMesh3DBuffer(addBuffersToDesktop ? desktop : null, pInputName, transformer.getOutputMesh3D(true), scaledImg);
if ((pOutput3DName != null) && (pOutput3DName.length() > 0))
outBuffer3D.setName(pOutput3DName);
}
return new TransformResult(inBuffer, outBuffer, outHDRBuffer, outBuffer3D);
}
use of org.jwildfire.transform.Mesh3D in project JWildfire by thargor6.
the class MeshPreviewRenderer method renderMesh.
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 (Point3f 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));
trans.setCentreY(trans.getCentreY() * (1.0 - pPositionY));
trans.setZoom(pSize * 0.5);
trans.setLight(Light.NORMAL);
trans.setDoRotate(Rotate.YZ);
trans.setSmoothing(0);
trans.setAmbient(0.4);
trans.setDoCam(false);
trans.setAlpha(pRotateAlpha);
trans.setBeta(pRotateBeta);
trans.setLight1Color(new Color(255, 245, 180));
SimpleImage out = new SimpleImage(pWidth, pHeight);
trans.transformImage(out);
return out;
}
Aggregations