use of org.jwildfire.create.tina.base.solidrender.MaterialSettings in project JWildfire by thargor6.
the class FlameControlsDelegate method solidRenderingMaterialReflectionMappingCmb_changed.
public void solidRenderingMaterialReflectionMappingCmb_changed() {
if (!isNoRefresh()) {
MaterialSettings material = getSolidRenderingSelectedMaterial();
if (material != null) {
owner.saveUndoPoint();
material.setReflectionMapping((ReflectionMapping) data.tinaSolidRenderingMaterialReflectionMappingCmb.getSelectedItem());
owner.refreshFlameImage(true, false, 1, true, true);
}
}
}
use of org.jwildfire.create.tina.base.solidrender.MaterialSettings in project JWildfire by thargor6.
the class JWFScriptController method convertFlameToScript.
private String convertFlameToScript(Flame pFlame) {
StringBuilder sb = new StringBuilder();
sb.append("import org.jwildfire.create.tina.base.Flame;\n");
sb.append("import org.jwildfire.create.tina.base.XForm;\n");
sb.append("import org.jwildfire.create.tina.palette.RGBPalette;\n");
sb.append("import org.jwildfire.create.tina.script.ScriptRunnerEnvironment;\n");
sb.append("import org.jwildfire.create.tina.transform.XFormTransformService;\n");
sb.append("import org.jwildfire.create.tina.base.Layer;\n");
sb.append("import org.jwildfire.create.tina.variation.Variation;\n");
sb.append("import org.jwildfire.create.tina.variation.VariationFunc;\n");
sb.append("import org.jwildfire.create.tina.variation.VariationFuncList;\n");
sb.append("import org.jwildfire.create.tina.mutagen.RandomGradientMutation;\n");
sb.append("import org.jwildfire.create.tina.transform.XFormTransformService;\n");
sb.append("import org.jwildfire.create.tina.base.EditPlane;\n");
sb.append("\n");
sb.append("");
sb.append("public void run(ScriptRunnerEnvironment pEnv) throws Exception {\n");
sb.append(" // create a new flame\n");
sb.append(" Flame flame=new Flame();\n");
sb.append(" flame.getLayers().clear(); // get rid of the default layer because we create all layers by ourselves\n");
sb.append(" // set the flame main attributes\n");
sb.append(" flame.setCamRoll(" + Tools.doubleToString(pFlame.getCamRoll()) + ");\n");
sb.append(" flame.setCamPitch(" + Tools.doubleToString(pFlame.getCamPitch()) + ");\n");
sb.append(" flame.setCamYaw(" + Tools.doubleToString(pFlame.getCamYaw()) + ");\n");
sb.append(" flame.setCamPerspective(" + Tools.doubleToString(pFlame.getCamPerspective()) + ");\n");
sb.append(" flame.setWidth(" + pFlame.getWidth() + ");\n");
sb.append(" flame.setHeight(" + pFlame.getHeight() + ");\n");
sb.append(" flame.setPixelsPerUnit(" + Tools.doubleToString(pFlame.getPixelsPerUnit()) + ");\n");
sb.append(" flame.setCamZoom(" + Tools.doubleToString(pFlame.getCamZoom()) + ");\n");
sb.append(" flame.setBGTransparency(" + pFlame.isBGTransparency() + ");\n");
switch(pFlame.getPostSymmetryType()) {
case POINT:
sb.append(" flame.setPostSymmetryType(org.jwildfire.create.tina.base.PostSymmetryType." + pFlame.getPostSymmetryType().toString() + ");\n");
sb.append(" flame.setPostSymmetryOrder(" + pFlame.getPostSymmetryOrder() + ");\n");
sb.append(" flame.setPostSymmetryCentreX(" + Tools.doubleToString(pFlame.getPostSymmetryCentreX()) + ");\n");
sb.append(" flame.setPostSymmetryCentreY(" + Tools.doubleToString(pFlame.getPostSymmetryCentreY()) + ");\n");
break;
case X_AXIS:
case Y_AXIS:
sb.append(" flame.setPostSymmetryType(org.jwildfire.create.tina.base.PostSymmetryType." + pFlame.getPostSymmetryType().toString() + ");\n");
sb.append(" flame.setPostSymmetryDistance(" + Tools.doubleToString(pFlame.getPostSymmetryDistance()) + ");\n");
sb.append(" flame.setPostSymmetryRotation(" + Tools.doubleToString(pFlame.getPostSymmetryRotation()) + ");\n");
sb.append(" flame.setPostSymmetryCentreX(" + Tools.doubleToString(pFlame.getPostSymmetryCentreX()) + ");\n");
sb.append(" flame.setPostSymmetryCentreY(" + Tools.doubleToString(pFlame.getPostSymmetryCentreY()) + ");\n");
break;
default:
// nothing to do
break;
}
if (pFlame.getSolidRenderSettings().isSolidRenderingEnabled()) {
sb.append(" //// Begin of solid-rendering-settings\n");
sb.append(" flame.getSolidRenderSettings().setSolidRenderingEnabled(true);\n");
sb.append(" // Ambient shadows\n");
sb.append(" flame.getSolidRenderSettings().setAoEnabled(" + (pFlame.getSolidRenderSettings().isAoEnabled() ? "true" : "false") + ");\n");
if (pFlame.getSolidRenderSettings().isAoEnabled()) {
sb.append(" flame.getSolidRenderSettings().setAoIntensity(" + Tools.doubleToString(pFlame.getSolidRenderSettings().getAoIntensity()) + ");\n");
sb.append(" flame.getSolidRenderSettings().setAoSearchRadius(" + Tools.doubleToString(pFlame.getSolidRenderSettings().getAoSearchRadius()) + ");\n");
sb.append(" flame.getSolidRenderSettings().setAoBlurRadius(" + Tools.doubleToString(pFlame.getSolidRenderSettings().getAoBlurRadius()) + ");\n");
sb.append(" flame.getSolidRenderSettings().setAoRadiusSamples(" + pFlame.getSolidRenderSettings().getAoRadiusSamples() + ");\n");
sb.append(" flame.getSolidRenderSettings().setAoAzimuthSamples(" + pFlame.getSolidRenderSettings().getAoAzimuthSamples() + ");\n");
sb.append(" flame.getSolidRenderSettings().setAoFalloff(" + Tools.doubleToString(pFlame.getSolidRenderSettings().getAoFalloff()) + ");\n");
sb.append(" flame.getSolidRenderSettings().setAoAffectDiffuse(" + Tools.doubleToString(pFlame.getSolidRenderSettings().getAoAffectDiffuse()) + ");\n");
}
sb.append(" // Hard shadows\n");
sb.append(" flame.getSolidRenderSettings().setShadowType(" + pFlame.getSolidRenderSettings().getShadowType().getClass().getName() + "." + pFlame.getSolidRenderSettings().getShadowType().toString() + ");\n");
if (!ShadowType.OFF.equals(pFlame.getSolidRenderSettings().getShadowType())) {
sb.append(" flame.getSolidRenderSettings().setShadowmapBias(" + Tools.doubleToString(pFlame.getSolidRenderSettings().getShadowmapBias()) + ");\n");
sb.append(" flame.getSolidRenderSettings().setShadowmapSize(" + pFlame.getSolidRenderSettings().getShadowmapSize() + ");\n");
if (ShadowType.SMOOTH.equals(pFlame.getSolidRenderSettings().getShadowType())) {
sb.append(" flame.getSolidRenderSettings().setShadowSmoothRadius(" + Tools.doubleToString(pFlame.getSolidRenderSettings().getShadowSmoothRadius()) + ");\n");
}
}
sb.append(" // Post bokeh\n");
sb.append(" flame.getSolidRenderSettings().setPostBokehFilterKernel(" + pFlame.getSolidRenderSettings().getPostBokehFilterKernel().getDeclaringClass().getName() + "." + pFlame.getSolidRenderSettings().getPostBokehFilterKernel().toString() + ");\n");
sb.append(" flame.getSolidRenderSettings().setPostBokehIntensity(" + Tools.doubleToString(pFlame.getSolidRenderSettings().getPostBokehIntensity()) + ");\n");
sb.append(" flame.getSolidRenderSettings().setPostBokehBrightness(" + Tools.doubleToString(pFlame.getSolidRenderSettings().getPostBokehBrightness()) + ");\n");
sb.append(" flame.getSolidRenderSettings().setPostBokehSize(" + Tools.doubleToString(pFlame.getSolidRenderSettings().getPostBokehSize()) + ");\n");
sb.append(" flame.getSolidRenderSettings().setPostBokehActivation(" + Tools.doubleToString(pFlame.getSolidRenderSettings().getPostBokehActivation()) + ");\n");
sb.append(" // Materials\n");
sb.append(" flame.getSolidRenderSettings().getMaterials().clear();\n");
for (MaterialSettings material : pFlame.getSolidRenderSettings().getMaterials()) {
sb.append(" {\n");
sb.append(" org.jwildfire.create.tina.base.solidrender.MaterialSettings material = new org.jwildfire.create.tina.base.solidrender.MaterialSettings();\n");
sb.append(" flame.getSolidRenderSettings().getMaterials().add(material);\n");
sb.append(" material.setDiffuse(" + Tools.doubleToString(material.getDiffuse()) + ");\n");
sb.append(" material.setAmbient(" + Tools.doubleToString(material.getAmbient()) + ");\n");
sb.append(" material.setPhong(" + Tools.doubleToString(material.getPhong()) + ");\n");
sb.append(" material.setPhongSize(" + Tools.doubleToString(material.getPhongSize()) + ");\n");
sb.append(" material.setPhongRed(" + Tools.doubleToString(material.getPhongRed()) + ");\n");
sb.append(" material.setPhongGreen(" + Tools.doubleToString(material.getPhongGreen()) + ");\n");
sb.append(" material.setPhongBlue(" + Tools.doubleToString(material.getPhongBlue()) + ");\n");
sb.append(" material.setLightDiffFunc(" + ((LightDiffFuncPreset) material.getLightDiffFunc()).getDeclaringClass().getName() + "." + material.getLightDiffFunc().toString() + ");\n");
if (material.getReflMapFilename() != null && material.getReflMapFilename().length() > 0) {
sb.append(" material.setReflMapFilename(\"" + material.getReflMapFilename() + "\");\n");
sb.append(" material.setReflMapIntensity(" + Tools.doubleToString(material.getReflMapIntensity()) + ");\n");
sb.append(" material.setReflectionMapping(" + material.getReflectionMapping().getDeclaringClass().getName() + "." + material.getReflectionMapping().toString() + ");\n");
}
sb.append(" }\n");
}
sb.append(" // Lights\n");
sb.append(" flame.getSolidRenderSettings().getLights().clear();\n");
for (DistantLight light : pFlame.getSolidRenderSettings().getLights()) {
sb.append(" {\n");
sb.append(" org.jwildfire.create.tina.base.solidrender.DistantLight light = new org.jwildfire.create.tina.base.solidrender.DistantLight();\n");
sb.append(" flame.getSolidRenderSettings().getLights().add(light);\n");
sb.append(" light.setRed(" + Tools.doubleToString(light.getRed()) + ");\n");
sb.append(" light.setGreen(" + Tools.doubleToString(light.getGreen()) + ");\n");
sb.append(" light.setBlue(" + Tools.doubleToString(light.getBlue()) + ");\n");
sb.append(" light.setIntensity(" + Tools.doubleToString(light.getIntensity()) + ");\n");
sb.append(" light.setCastShadows(" + (light.isCastShadows() ? "true" : "false") + ");\n");
sb.append(" light.setAltitude(" + Tools.doubleToString(light.getAltitude()) + ");\n");
sb.append(" light.setAzimuth(" + Tools.doubleToString(light.getAzimuth()) + ");\n");
sb.append(" light.setShadowIntensity(" + Tools.doubleToString(light.getShadowIntensity()) + ");\n");
sb.append(" // randomize light positions (uncomment to play around)\n");
sb.append(" // light.setAltitude(180.0 - 360.0 * Math.random());\n");
sb.append(" // light.setAzimuth(360.0 - 720.0 * Math.random());\n");
sb.append(" }\n");
}
sb.append(" //// End of solid-rendering-settings\n");
}
for (int i = 0; i < pFlame.getLayers().size(); i++) {
Layer layer = pFlame.getLayers().get(i);
addLayer(sb, layer, i);
}
sb.append(" // Either update the currently selected flame (to not need to create a new thumbnail\n");
sb.append(" // in the thumbnail ribbon after each run of the script...\n");
sb.append(" Flame selFlame = pEnv.getCurrFlame();\n");
sb.append(" if(selFlame!=null) {\n");
sb.append(" selFlame.assign(flame);\n");
sb.append(" pEnv.refreshUI();\n");
sb.append(" }\n");
sb.append(" // ...or load the flame in the editor and refresh the UI\n");
sb.append(" else {\n");
sb.append(" pEnv.setCurrFlame(flame);\n");
sb.append(" }\n");
sb.append("}\n");
return sb.toString();
}
Aggregations