Advertisement
rsidwell

Hourglass3DFunc.java

Feb 14th, 2023
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.52 KB | None | 0 0
  1. package org.jwildfire.create.tina.variation;
  2. import org.jwildfire.base.Tools;
  3. import org.jwildfire.create.tina.base.Layer;
  4. import org.jwildfire.create.tina.base.XForm;
  5. import org.jwildfire.create.tina.base.XYZPoint;
  6. import static org.jwildfire.base.mathlib.MathLib.*;
  7.  
  8. public class Hourglass3DFunc extends VariationFunc {
  9.   private static final long serialVersionUID = 1L;
  10.  
  11.   private static final String PARAM_KX = "kx";
  12.   private static final String PARAM_KY = "ky";
  13.   private static final String PARAM_KZ = "kz";
  14.   private static final String PARAM_MAXHEIGHT = "maxheight";
  15.   private static final String PARAM_USELIMIT = "uselimit";
  16.   private static final String PARAM_ZERO_EDGES = "zero_edges";
  17.  
  18.   private static final String[] paramNames = {PARAM_KX, PARAM_KY, PARAM_KX, PARAM_MAXHEIGHT, PARAM_USELIMIT, PARAM_ZERO_EDGES};
  19.  
  20.   private double kx = 1.0;
  21.   private double ky = 1.0;
  22.   private double kz = 1.0;
  23.   private double maxheight = 3.0;
  24.   private int limit = 1;
  25.   private int zero = 0;
  26.  
  27.   private double vkx, vky, vkz, h, hb;
  28.  
  29.   @Override
  30.   public void init(FlameTransformationContext pContext, Layer pLayer, XForm pXForm, double pAmount) {
  31.     vkx = pAmount * kx;
  32.     vky = pAmount * ky;
  33.     vkz = pAmount * kz;
  34.     h = sqrt(1 + sqr(maxheight / ky));
  35.     hb = sqrt(sqr(h) - 1);
  36.   }
  37.  
  38.  
  39.   @Override
  40.   public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
  41.     double sn, cn, sh, ch;
  42.     sn = sin(pAffineTP.x);
  43.     cn = cos(pAffineTP.x);
  44.     sh = sinh(pAffineTP.y);
  45.     ch = cosh(pAffineTP.y);
  46.     if (limit == 0) {
  47.         // Function
  48.         pVarTP.x += vkx * ch * sn;
  49.         pVarTP.y += vky * sh;
  50.         pVarTP.z += vkz * ch * cn;
  51.     } else if (zero == 0) {
  52.         // CutBorder
  53.         if (ch < h) {  // cut the surface
  54.           pVarTP.x += vkx * ch * sn;
  55.           pVarTP.y += vky * sh;
  56.           pVarTP.z += vkz * ch * cn;
  57.         } else { // place the point on it's boarder
  58.           pVarTP.x += vkx * h * sn;
  59.           pVarTP.y += vky * sign(sh) * hb;
  60.           pVarTP.z += vkz * h * cn;
  61.         }
  62.     } else {
  63.         // Cut
  64.         if (ch < h) {  // cut the surface
  65.           pVarTP.x += vkx * ch * sn;
  66.           pVarTP.y += vky * sh;
  67.           pVarTP.z += vkz * ch * cn;
  68.         }
  69.     }
  70.   }
  71.  
  72.   @Override
  73.   public String[] getParameterNames() {
  74.     return paramNames;
  75.   }
  76.  
  77.   @Override
  78.   public Object[] getParameterValues() {
  79.     return new Object[]{kx, ky, kz, maxheight, limit, zero};
  80.   }
  81.  
  82.   @Override
  83.   public void setParameter(String pName, double pValue) {
  84.     if (PARAM_KX.equalsIgnoreCase(pName))
  85.       kx = (pValue < 1E-5) ? 1E-5 : pValue;
  86.     else if (PARAM_KY.equalsIgnoreCase(pName))
  87.       ky = (pValue < 1E-5) ? 1E-5 : pValue;
  88.     else if (PARAM_KZ.equalsIgnoreCase(pName))
  89.       kz = (pValue < 1E-5) ? 1E-5 : pValue;
  90.     else if (PARAM_MAXHEIGHT.equalsIgnoreCase(pName))
  91.       maxheight = (pValue < 0.1) ? 0.1 : pValue;
  92.     else if (PARAM_USELIMIT.equalsIgnoreCase(pName))
  93.       limit = limitIntVal(Tools.FTOI(pValue), 0, 1);
  94.     else if (PARAM_ZERO_EDGES.equalsIgnoreCase(pName))
  95.       zero = limitIntVal(Tools.FTOI(pValue), 0, 1);
  96.     else
  97.       throw new IllegalArgumentException(pName);
  98.   }
  99.  
  100.   public String getName() {
  101.     return "hourglass3D";
  102.   }
  103.  
  104.   public VariationFuncType[] getVariationTypes() {
  105. //    return new VariationFuncType[]{VariationFuncType.VARTYPE_3D, VariationFuncType.VARTYPE_SUPPORTS_GPU};
  106.     return new VariationFuncType[]{VariationFuncType.VARTYPE_3D};
  107.   }
  108.  
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement