Search in sources :

Example 6 with FloatParameter

use of org.sunflow.core.ParameterList.FloatParameter in project joons-renderer by joonhyublee.

the class BezierMesh method update.

public boolean update(ParameterList pl, SunflowAPI api) {
    subdivs = pl.getInt("subdivs", subdivs);
    smooth = pl.getBoolean("smooth", smooth);
    quads = pl.getBoolean("quads", quads);
    int nu = pl.getInt("nu", 0);
    int nv = pl.getInt("nv", 0);
    pl.setVertexCount(nu * nv);
    boolean uwrap = pl.getBoolean("uwrap", false);
    boolean vwrap = pl.getBoolean("vwrap", false);
    FloatParameter points = pl.getPointArray("points");
    if (points != null && points.interp == InterpolationType.VERTEX) {
        int numUPatches = uwrap ? nu / 3 : (nu - 4) / 3 + 1;
        int numVPatches = vwrap ? nv / 3 : (nv - 4) / 3 + 1;
        if (numUPatches < 1 || numVPatches < 1) {
            UI.printError(Module.GEOM, "Invalid number of patches for bezier mesh - ignoring");
            return false;
        }
        // generate patches
        patches = new float[numUPatches * numVPatches][];
        for (int v = 0, p = 0; v < numVPatches; v++) {
            for (int u = 0; u < numUPatches; u++, p++) {
                float[] patch = patches[p] = new float[16 * 3];
                int up = u * 3;
                int vp = v * 3;
                for (int pv = 0; pv < 4; pv++) {
                    for (int pu = 0; pu < 4; pu++) {
                        int meshU = (up + pu) % nu;
                        int meshV = (vp + pv) % nv;
                        // copy point
                        patch[3 * (pv * 4 + pu) + 0] = points.data[3 * (meshU + nu * meshV) + 0];
                        patch[3 * (pv * 4 + pu) + 1] = points.data[3 * (meshU + nu * meshV) + 1];
                        patch[3 * (pv * 4 + pu) + 2] = points.data[3 * (meshU + nu * meshV) + 2];
                    }
                }
            }
        }
    }
    if (subdivs < 1) {
        UI.printError(Module.GEOM, "Invalid subdivisions for bezier mesh - ignoring");
        return false;
    }
    if (patches == null) {
        UI.printError(Module.GEOM, "No patch data present in bezier mesh - ignoring");
        return false;
    }
    return true;
}
Also used : FloatParameter(org.sunflow.core.ParameterList.FloatParameter)

Aggregations

FloatParameter (org.sunflow.core.ParameterList.FloatParameter)6 BoundingBox (org.sunflow.math.BoundingBox)1