Search in sources :

Example 1 with FloatParameter

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

the class TriangleMesh method update.

@Override
public boolean update(ParameterList pl, SunflowAPI api) {
    boolean updatedTopology = false;
    {
        int[] trianglesu = pl.getIntArray("triangles");
        if (trianglesu != null) {
            this.triangles = trianglesu;
            updatedTopology = true;
        }
    }
    if (triangles == null) {
        UI.printError(Module.GEOM, "Unable to update mesh - triangle indices are missing");
        return false;
    }
    if (triangles.length % 3 != 0) {
        UI.printWarning(Module.GEOM, "Triangle index data is not a multiple of 3 - triangles may be missing");
    }
    pl.setFaceCount(triangles.length / 3);
    {
        FloatParameter pointsP = pl.getPointArray("points");
        if (pointsP != null) {
            if (pointsP.interp != InterpolationType.VERTEX) {
                UI.printError(Module.GEOM, "Point interpolation type must be set to \"vertex\" - was \"%s\"", pointsP.interp.name().toLowerCase(Locale.ENGLISH));
            } else {
                points = pointsP.data;
                updatedTopology = true;
            }
        }
    }
    if (points == null) {
        UI.printError(Module.GEOM, "Unable to update mesh - vertices are missing");
        return false;
    }
    pl.setVertexCount(points.length / 3);
    pl.setFaceVertexCount(3 * (triangles.length / 3));
    FloatParameter normalsu = pl.getVectorArray("normals");
    if (normalsu != null) {
        this.normals = normalsu;
    }
    FloatParameter uvsu = pl.getTexCoordArray("uvs");
    if (uvsu != null) {
        this.uvs = uvsu;
    }
    int[] faceShadersu = pl.getIntArray("faceshaders");
    if (faceShadersu != null && faceShadersu.length == triangles.length / 3) {
        this.faceShaders = new byte[faceShadersu.length];
        for (int i = 0; i < faceShadersu.length; i++) {
            int v = faceShadersu[i];
            if (v > 255) {
                UI.printWarning(Module.GEOM, "Shader index too large on triangle %d", i);
            }
            this.faceShaders[i] = (byte) (v & 0xFF);
        }
    }
    if (updatedTopology) {
        // create triangle acceleration structure
        init();
    }
    return true;
}
Also used : FloatParameter(org.sunflow.core.ParameterList.FloatParameter)

Example 2 with FloatParameter

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

the class Box method update.

@Override
public boolean update(ParameterList pl, SunflowAPI api) {
    FloatParameter pts = pl.getPointArray("points");
    if (pts != null) {
        BoundingBox bounds = new BoundingBox();
        for (int i = 0; i < pts.data.length; i += 3) {
            bounds.include(pts.data[i], pts.data[i + 1], pts.data[i + 2]);
        }
        // cube extents
        minX = bounds.getMinimum().x;
        minY = bounds.getMinimum().y;
        minZ = bounds.getMinimum().z;
        maxX = bounds.getMaximum().x;
        maxY = bounds.getMaximum().y;
        maxZ = bounds.getMaximum().z;
    }
    return true;
}
Also used : BoundingBox(org.sunflow.math.BoundingBox) FloatParameter(org.sunflow.core.ParameterList.FloatParameter)

Example 3 with FloatParameter

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

the class Hair method update.

@Override
public boolean update(ParameterList pl, SunflowAPI api) {
    numSegments = pl.getInt("segments", numSegments);
    if (numSegments < 1) {
        UI.printError(Module.HAIR, "Invalid number of segments: %d", numSegments);
        return false;
    }
    FloatParameter pointsP = pl.getPointArray("points");
    if (pointsP != null) {
        if (pointsP.interp != InterpolationType.VERTEX) {
            UI.printError(Module.HAIR, "Point interpolation type must be set to \"vertex\" - was \"%s\"", pointsP.interp.name().toLowerCase(Locale.ENGLISH));
        } else {
            points = pointsP.data;
        }
    }
    if (points == null) {
        UI.printError(Module.HAIR, "Unabled to update hair - vertices are missing");
        return false;
    }
    pl.setVertexCount(points.length / 3);
    FloatParameter widthsP = pl.getFloatArray("widths");
    if (widthsP != null) {
        if (widthsP.interp == InterpolationType.NONE || widthsP.interp == InterpolationType.VERTEX) {
            widths = widthsP;
        } else {
            UI.printWarning(Module.HAIR, "Width interpolation type %s is not supported -- ignoring", widthsP.interp.name().toLowerCase(Locale.ENGLISH));
        }
    }
    return true;
}
Also used : FloatParameter(org.sunflow.core.ParameterList.FloatParameter)

Example 4 with FloatParameter

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

the class ParticleSurface method update.

@Override
public boolean update(ParameterList pl, SunflowAPI api) {
    FloatParameter p = pl.getPointArray("particles");
    if (p != null) {
        particles = p.data;
    }
    r = pl.getFloat("radius", r);
    r2 = r * r;
    n = pl.getInt("num", n);
    return particles != null && n <= (particles.length / 3);
}
Also used : FloatParameter(org.sunflow.core.ParameterList.FloatParameter)

Example 5 with FloatParameter

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

the class QuadMesh method update.

@Override
public boolean update(ParameterList pl, SunflowAPI api) {
    {
        int[] quadsu = pl.getIntArray("quads");
        if (quadsu != null) {
            this.quads = quadsu;
        }
    }
    if (quads == null) {
        UI.printError(Module.GEOM, "Unable to update mesh - quad indices are missing");
        return false;
    }
    if (quads.length % 4 != 0) {
        UI.printWarning(Module.GEOM, "Quad index data is not a multiple of 4 - some quads may be missing");
    }
    pl.setFaceCount(quads.length / 4);
    {
        FloatParameter pointsP = pl.getPointArray("points");
        if (pointsP != null) {
            if (pointsP.interp != InterpolationType.VERTEX) {
                UI.printError(Module.GEOM, "Point interpolation type must be set to \"vertex\" - was \"%s\"", pointsP.interp.name().toLowerCase(Locale.ENGLISH));
            } else {
                points = pointsP.data;
            }
        }
    }
    if (points == null) {
        UI.printError(Module.GEOM, "Unabled to update mesh - vertices are missing");
        return false;
    }
    pl.setVertexCount(points.length / 3);
    pl.setFaceVertexCount(4 * (quads.length / 4));
    FloatParameter normalsp = pl.getVectorArray("normals");
    if (normalsp != null) {
        this.normals = normalsp;
    }
    FloatParameter uvsp = pl.getTexCoordArray("uvs");
    if (uvsp != null) {
        this.uvs = uvsp;
    }
    int[] faceShadersl = pl.getIntArray("faceshaders");
    if (faceShadersl != null && faceShadersl.length == quads.length / 4) {
        this.faceShaders = new byte[faceShadersl.length];
        for (int i = 0; i < faceShadersl.length; i++) {
            int v = faceShadersl[i];
            if (v > 255) {
                UI.printWarning(Module.GEOM, "Shader index too large on quad %d", i);
            }
            this.faceShaders[i] = (byte) (v & 0xFF);
        }
    }
    return true;
}
Also used : FloatParameter(org.sunflow.core.ParameterList.FloatParameter)

Aggregations

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