Search in sources :

Example 56 with XYZPoint

use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.

the class DLA3DWFFunc method getRawSampleFromNodeMesh.

private Sample getRawSampleFromNodeMesh(double scale, double defaultColor, Matrix3D rotation) {
    Sample sample = new Sample();
    Face f = nodeMesh.getFace(_randGen.random(nodeMesh.getFaceCount()));
    Vertex rawP1 = nodeMesh.getVertex(f.v1);
    Vertex rawP2 = nodeMesh.getVertex(f.v2);
    Vertex rawP3 = nodeMesh.getVertex(f.v3);
    if (nodeColorMapHolder.isActive() && rawP1 instanceof VertexWithUV) {
        VertexWithUV p1 = nodeTransform((VertexWithUV) rawP1, node_mesh_scale, scale, nodeMesh.getBoundingBox(), rotation);
        VertexWithUV p2 = nodeTransform((VertexWithUV) rawP2, node_mesh_scale, scale, nodeMesh.getBoundingBox(), rotation);
        VertexWithUV p3 = nodeTransform((VertexWithUV) rawP3, node_mesh_scale, scale, nodeMesh.getBoundingBox(), rotation);
        // uniform sampling:  http://math.stackexchange.com/questions/18686/uniform-random-point-in-triangle
        double sqrt_r1 = MathLib.sqrt(_randGen.random());
        double r2 = _randGen.random();
        double a = 1.0 - sqrt_r1;
        double b = sqrt_r1 * (1.0 - r2);
        double c = r2 * sqrt_r1;
        double dx = a * p1.x + b * p2.x + c * p3.x;
        double dy = a * p1.y + b * p2.y + c * p3.y;
        double dz = a * p1.z + b * p2.z + c * p3.z;
        sample.x = dx;
        sample.y = dy;
        sample.z = dz;
        sample.color = defaultColor;
        double u = a * p1.u + b * p2.u + c * p3.u;
        double v = a * p1.v + b * p2.v + c * p3.v;
        if (nodeColorMapHolder.isActive()) {
            double iu = GfxMathLib.clamp(u * (nodeColorMapHolder.getColorMapWidth() - 1.0), 0.0, nodeColorMapHolder.getColorMapWidth() - 1.0);
            double iv = GfxMathLib.clamp(nodeColorMapHolder.getColorMapHeight() - 1.0 - v * (nodeColorMapHolder.getColorMapHeight() - 1.0), 0, nodeColorMapHolder.getColorMapHeight() - 1.0);
            int ix = (int) MathLib.trunc(iu);
            int iy = (int) MathLib.trunc(iv);
            XYZPoint colorHolder = new XYZPoint();
            nodeColorMapHolder.applyImageColor(colorHolder, ix, iy, iu, iv);
            sample.color = nodeUVColorMapper.getUVColorIdx(Tools.FTOI(colorHolder.redColor), Tools.FTOI(colorHolder.greenColor), Tools.FTOI(colorHolder.blueColor));
        }
    } else {
        Vertex p1 = nodeTransform(rawP1, node_mesh_scale, scale, nodeMesh.getBoundingBox(), rotation);
        Vertex p2 = nodeTransform(rawP2, node_mesh_scale, scale, nodeMesh.getBoundingBox(), rotation);
        Vertex p3 = nodeTransform(rawP3, node_mesh_scale, scale, nodeMesh.getBoundingBox(), rotation);
        // uniform sampling:  http://math.stackexchange.com/questions/18686/uniform-random-point-in-triangle
        double sqrt_r1 = MathLib.sqrt(_randGen.random());
        double r2 = _randGen.random();
        double a = 1.0 - sqrt_r1;
        double b = sqrt_r1 * (1.0 - r2);
        double c = r2 * sqrt_r1;
        double dx = a * p1.x + b * p2.x + c * p3.x;
        double dy = a * p1.y + b * p2.y + c * p3.y;
        double dz = a * p1.z + b * p2.z + c * p3.z;
        sample.x = dx;
        sample.y = dy;
        sample.z = dz;
        sample.color = defaultColor;
    }
    return sample;
}
Also used : Vertex(org.jwildfire.create.tina.variation.mesh.Vertex) XYZPoint(org.jwildfire.create.tina.base.XYZPoint) Face(org.jwildfire.create.tina.variation.mesh.Face) XYZPoint(org.jwildfire.create.tina.base.XYZPoint) VertexWithUV(org.jwildfire.create.tina.variation.mesh.VertexWithUV)

Example 57 with XYZPoint

use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.

the class DCCubeFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    /* dc_cube by Xyrus02, http://xyrus02.deviantart.com/art/DC-Cube-plugin-update-170465423 */
    double p = 2 * pContext.random() - 1.0;
    double q = 2 * pContext.random() - 1;
    int i = pContext.random(Integer.MAX_VALUE) % 3;
    boolean j = (pContext.random(Integer.MAX_VALUE) & 1) == 1;
    double x = 0.0, y = 0.0, z = 0.0;
    switch(i) {
        case 0:
            x = pAmount * (j ? -1 : 1);
            y = pAmount * p;
            z = pAmount * q;
            if (j)
                pVarTP.color = c1;
            else
                pVarTP.color = c2;
            break;
        case 1:
            x = pAmount * p;
            y = pAmount * (j ? -1 : 1);
            z = pAmount * q;
            if (j)
                pVarTP.color = c3;
            else
                pVarTP.color = c4;
            break;
        case 2:
            x = pAmount * p;
            y = pAmount * q;
            z = pAmount * (j ? -1 : 1);
            if (j)
                pVarTP.color = c5;
            else
                pVarTP.color = c6;
            break;
        default:
            // nothing to do
            break;
    }
    pVarTP.x += x * this.x;
    pVarTP.y += y * this.y;
    pVarTP.z += z * this.z;
}
Also used : XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 58 with XYZPoint

use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.

the class DCPerlinFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    /* dc_perlin by slobo777, http://slobo777.deviantart.com/art/dc-perlin-Apophysis-Plugin-186190256 */
    double[] V = new double[3];
    double Vx = 0.0, Vy = 0.0, Col, r, theta, s, c, p, e;
    int t;
    t = 0;
    do {
        // Default edge value
        e = 0.0;
        // When pAmount is 0, use for coloring only, so no shape
        if (pAmount == 0) {
            Vx = pAffineTP.x;
            Vy = pAffineTP.y;
        } else {
            // Assign Vx, Vy according to shape
            switch(shape) {
                case SHAPE_SQUARE:
                    Vx = (1.0 + this.edge) * (pContext.random() - 0.5);
                    Vy = (1.0 + this.edge) * (pContext.random() - 0.5);
                    r = Vx * Vx > Vy * Vy ? Vx : Vy;
                    if (r > 1.0 - this.edge) {
                        e = 0.5 * (r - 1.0 + this.edge) / this.edge;
                    }
                    break;
                case SHAPE_DISC:
                    r = pContext.random() + pContext.random();
                    r = (r > 1.0) ? 2.0 - r : r;
                    r *= (1.0 + this.edge);
                    if (r > 1.0 - this.edge) {
                        e = 0.5 * (r - 1.0 + this.edge) / this.edge;
                    }
                    theta = pContext.random() * M_2PI;
                    s = sin(theta);
                    c = cos(theta);
                    Vx = 0.5 * r * s;
                    Vy = 0.5 * r * c;
                    break;
                case SHAPE_BLUR:
                    r = (1.0 + this.edge) * pContext.random();
                    if (r > 1.0 - this.edge) {
                        e = 0.5 * (r - 1.0 + this.edge) / this.edge;
                    }
                    theta = pContext.random() * M_2PI;
                    s = sin(theta);
                    c = cos(theta);
                    Vx = 0.5 * r * s;
                    Vy = 0.5 * r * c;
                    break;
                default:
                    // nothing to do
                    break;
            }
        }
        // Assign V for noise vector position according to map
        switch(this.map) {
            case MAP_FLAT:
                V[0] = this.scale * Vx;
                V[1] = this.scale * Vy;
                V[2] = this.scale * this.z;
                break;
            case MAP_SPHERICAL:
                r = 1.0 / (Vx * Vx + Vy * Vy + SMALL_EPSILON);
                V[0] = this.scale * Vx * r;
                V[1] = this.scale * Vy * r;
                V[2] = this.scale * this.z;
                break;
            case MAP_HSPHERE:
                r = 1.0 / (Vx * Vx + Vy * Vy + 0.5);
                V[0] = this.scale * Vx * r;
                V[1] = this.scale * Vy * r;
                V[2] = this.scale * this.z;
                break;
            case MAP_QSPHERE:
                r = 1.0 / (Vx * Vx + Vy * Vy + 0.25);
                V[0] = this.scale * Vx * r;
                V[1] = this.scale * Vy * r;
                V[2] = this.scale * this.z;
                break;
            case MAP_BUBBLE:
                r = 0.25 - (Vx * Vx + Vy * Vy);
                if (r < 0.0) {
                    r = sqrt(-r);
                } else {
                    r = sqrt(r);
                }
                V[0] = this.scale * Vx;
                V[1] = this.scale * Vy;
                V[2] = this.scale * (r + this.z);
                break;
            case MAP_BUBBLE2:
                r = 0.25 - (Vx * Vx + Vy * Vy);
                if (r < 0.0) {
                    r = sqrt(-r);
                } else {
                    r = sqrt(r);
                }
                V[0] = this.scale * Vx;
                V[1] = this.scale * Vy;
                V[2] = this.scale * (2 * r + this.z);
                break;
        }
        p = NoiseTools.perlinNoise3D(V, this.amps, this.freqs, this.octaves);
        // Add edge effects
        if (p > 0.0) {
            e = p * (1.0 + e * e * 20.0) + 2.0 * e;
        } else {
            e = p * (1.0 + e * e * 20.0) - 2.0 * e;
        }
    } while ((e < _notch_bottom || e > _notch_top) && t++ < this.select_bailout);
    // Add blur effect to transform
    pVarTP.x += pAmount * Vx;
    pVarTP.y += pAmount * Vy;
    if (pContext.isPreserveZCoordinate()) {
        pVarTP.z += pAmount * pAffineTP.z;
    }
    // Calculate and add direct colour
    Col = this.centre + this.range * p;
    pVarTP.color = Col - floor(Col);
}
Also used : XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 59 with XYZPoint

use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.

the class CPow2Func method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    /* cpow2 by Peter Sdobnov (Zueuk) */
    double a = pAffineTP.getPrecalcAtanYX();
    int n = pContext.random(range);
    if (a < 0)
        n++;
    a += 2 * M_PI * n;
    if (cos(a * inv_range) < pContext.random() * 2.0 - 1.0)
        a -= full_range;
    // logarithm * 2
    double lnr2 = log(pAffineTP.getPrecalcSumsq());
    double r = pAmount * exp(half_c * lnr2 - d * a);
    double th = c * a + half_d * lnr2 + ang * floor(divisor * pContext.random());
    pVarTP.x += r * cos(th);
    pVarTP.y += r * sin(th);
    if (pContext.isPreserveZCoordinate())
        pVarTP.z += pAmount * pAffineTP.z;
}
Also used : XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 60 with XYZPoint

use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.

the class CellFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    /* Cell in the Apophysis Plugin Pack */
    double inv_cell_size = 1.0 / size;
    /* calculate input cell */
    int x = (int) floor(pAffineTP.x * inv_cell_size);
    int y = (int) floor(pAffineTP.y * inv_cell_size);
    /* Offset from cell origin */
    double dx = pAffineTP.x - x * size;
    double dy = pAffineTP.y - y * size;
    /* interleave cells */
    if (y >= 0) {
        if (x >= 0) {
            y *= 2;
            x *= 2;
        } else {
            y *= 2;
            x = -(2 * x + 1);
        }
    } else {
        if (x >= 0) {
            y = -(2 * y + 1);
            x *= 2;
        } else {
            y = -(2 * y + 1);
            x = -(2 * x + 1);
        }
    }
    pVarTP.x += pAmount * (dx + x * size);
    pVarTP.y -= pAmount * (dy + y * size);
    if (pContext.isPreserveZCoordinate()) {
        pVarTP.z += pAmount * pAffineTP.z;
    }
}
Also used : XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Aggregations

XYZPoint (org.jwildfire.create.tina.base.XYZPoint)102 XForm (org.jwildfire.create.tina.base.XForm)16 Layer (org.jwildfire.create.tina.base.Layer)13 Test (org.junit.Test)4 VectorD (org.jwildfire.base.mathlib.VecMathLib.VectorD)4 Flame (org.jwildfire.create.tina.base.Flame)4 ZigguratRandomGenerator (org.jwildfire.create.tina.random.ZigguratRandomGenerator)4 FlameRenderer (org.jwildfire.create.tina.render.FlameRenderer)4 SimpleHDRImage (org.jwildfire.image.SimpleHDRImage)4 SimpleImage (org.jwildfire.image.SimpleImage)4 Complex (org.jwildfire.base.mathlib.Complex)2 XYZProjectedPoint (org.jwildfire.create.tina.base.XYZProjectedPoint)2 Face (org.jwildfire.create.tina.variation.mesh.Face)2 Vertex (org.jwildfire.create.tina.variation.mesh.Vertex)2 VertexWithUV (org.jwildfire.create.tina.variation.mesh.VertexWithUV)2 RenderColor (org.jwildfire.create.tina.palette.RenderColor)1 CannabisCurveWFFunc (org.jwildfire.create.tina.variation.CannabisCurveWFFunc)1 CloverLeafWFFunc (org.jwildfire.create.tina.variation.CloverLeafWFFunc)1 DCPerlinFunc (org.jwildfire.create.tina.variation.DCPerlinFunc)1 FlowerFunc (org.jwildfire.create.tina.variation.FlowerFunc)1