Search in sources :

Example 1 with VertexWithUV

use of org.jwildfire.create.tina.variation.mesh.VertexWithUV in project JWildfire by thargor6.

the class DLA3DWFFunc method getRawSampleFromJunctMesh.

private Sample getRawSampleFromJunctMesh(double scale, double defaultColor, Matrix3D rotation) {
    Sample sample = new Sample();
    Face f = junctMesh.getFace(_randGen.random(junctMesh.getFaceCount()));
    Vertex rawP1 = junctMesh.getVertex(f.v1);
    Vertex rawP2 = junctMesh.getVertex(f.v2);
    Vertex rawP3 = junctMesh.getVertex(f.v3);
    if (junctColorMapHolder.isActive() && rawP1 instanceof VertexWithUV) {
        VertexWithUV p1 = nodeTransform((VertexWithUV) rawP1, junct_mesh_scale, scale, junctMesh.getBoundingBox(), rotation);
        VertexWithUV p2 = nodeTransform((VertexWithUV) rawP2, junct_mesh_scale, scale, junctMesh.getBoundingBox(), rotation);
        VertexWithUV p3 = nodeTransform((VertexWithUV) rawP3, junct_mesh_scale, scale, junctMesh.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 (junctColorMapHolder.isActive()) {
            double iu = GfxMathLib.clamp(u * (junctColorMapHolder.getColorMapWidth() - 1.0), 0.0, junctColorMapHolder.getColorMapWidth() - 1.0);
            double iv = GfxMathLib.clamp(junctColorMapHolder.getColorMapHeight() - 1.0 - v * (junctColorMapHolder.getColorMapHeight() - 1.0), 0, junctColorMapHolder.getColorMapHeight() - 1.0);
            int ix = (int) MathLib.trunc(iu);
            int iy = (int) MathLib.trunc(iv);
            XYZPoint colorHolder = new XYZPoint();
            junctColorMapHolder.applyImageColor(colorHolder, ix, iy, iu, iv);
            sample.color = junctUVColorMapper.getUVColorIdx(Tools.FTOI(colorHolder.redColor), Tools.FTOI(colorHolder.greenColor), Tools.FTOI(colorHolder.blueColor));
        }
    } else {
        Vertex p1 = nodeTransform(rawP1, junct_mesh_scale, scale, junctMesh.getBoundingBox(), rotation);
        Vertex p2 = nodeTransform(rawP2, junct_mesh_scale, scale, junctMesh.getBoundingBox(), rotation);
        Vertex p3 = nodeTransform(rawP3, junct_mesh_scale, scale, junctMesh.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 2 with VertexWithUV

use of org.jwildfire.create.tina.variation.mesh.VertexWithUV in project JWildfire by thargor6.

the class DLA3DWFFunc method nodeTransform.

private VertexWithUV nodeTransform(VertexWithUV p, double preScale, double relScale, BoundingBox boundingBox, Matrix3D rotation) {
    VertexWithUV res = new VertexWithUV();
    double px, py, pz;
    if (rotation != null) {
        VectorD d = new VectorD(p.x - boundingBox.getXcentre(), p.y - boundingBox.getYcentre(), p.z - boundingBox.getZcentre());
        VectorD r = Matrix3D.multiply(rotation, d);
        px = r.x;
        py = r.y;
        pz = r.z;
    } else {
        px = p.x;
        py = p.y;
        pz = p.z;
    }
    res.x = (float) (px * preScale * relScale);
    res.y = (float) (py * preScale * relScale);
    res.z = (float) (pz * preScale * relScale);
    res.u = p.u;
    res.v = p.v;
    return res;
}
Also used : VectorD(org.jwildfire.base.mathlib.VecMathLib.VectorD) VertexWithUV(org.jwildfire.create.tina.variation.mesh.VertexWithUV)

Example 3 with VertexWithUV

use of org.jwildfire.create.tina.variation.mesh.VertexWithUV 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)

Aggregations

VertexWithUV (org.jwildfire.create.tina.variation.mesh.VertexWithUV)3 XYZPoint (org.jwildfire.create.tina.base.XYZPoint)2 Face (org.jwildfire.create.tina.variation.mesh.Face)2 Vertex (org.jwildfire.create.tina.variation.mesh.Vertex)2 VectorD (org.jwildfire.base.mathlib.VecMathLib.VectorD)1