Search in sources :

Example 16 with Shading

use of maspack.render.Renderer.Shading in project artisynth_core by artisynth.

the class PointList method drawPoints.

private void drawPoints(Renderer renderer, int gidx, RenderProps props, boolean selected) {
    Shading savedShading = renderer.setPointShading(props);
    renderer.setPointColoring(props, selected);
    PointStyle style = props.getPointStyle();
    switch(style) {
        case POINT:
            {
                int size = props.getPointSize();
                if (size > 0) {
                    // renderer.setLightingEnabled (false);
                    // renderer.setColor (props.getPointColorArray(), selected);
                    renderer.drawPoints(myRob, gidx, PointStyle.POINT, size);
                // renderer.setLightingEnabled (true);
                }
                break;
            }
        case CUBE:
        case SPHERE:
            {
                double rad = props.getPointRadius();
                if (rad > 0) {
                    // Shading savedShading = renderer.getShadeModel();
                    // renderer.setPointLighting (props, selected);
                    renderer.drawPoints(myRob, gidx, style, rad);
                // renderer.setShadeModel(savedShading);
                }
                break;
            }
    }
    renderer.setShading(savedShading);
}
Also used : PointStyle(maspack.render.Renderer.PointStyle) Shading(maspack.render.Renderer.Shading)

Example 17 with Shading

use of maspack.render.Renderer.Shading in project artisynth_core by artisynth.

the class TextLabeller3d method render.

// @Override
// public void renderx(GLRenderer renderer, int flags) {
// if (isSelectable() || !renderer.isSelecting()) {
// render(renderer, 0);
// }
// }
@Override
public void render(Renderer renderer, int flags) {
    if (!isSelectable() && renderer.isSelecting()) {
        return;
    }
    FaceRenderProps rprops = (FaceRenderProps) getRenderProps();
    rprops.getFaceColor(rgb);
    Point3d tmp = new Point3d();
    // for consistency, assume line top as 3/4 font size
    Rectangle2D box = renderer.getTextBounds(myFont, "X", myTextSize);
    double t = box.getY() + box.getHeight();
    double vc = box.getY() + box.getHeight() / 2;
    rEye.invert(renderer.getViewMatrix().R);
    rEye.getColumn(0, xdir);
    rEye.getColumn(1, ydir);
    myTransform.R.set(rEye);
    Shading oldShading = renderer.getShading();
    float[] loc = new float[3];
    for (LabelItem label : myItems) {
        renderPos.setZero();
        // text orientation computation
        box = renderer.getTextBounds(myFont, label.text, myTextSize);
        double w = box.getWidth();
        switch(hAlignment) {
            case LEFT:
                renderPos.add(xdir[0] * (myTextOffset.x), xdir[1] * (myTextOffset.x), xdir[2] * (myTextOffset.x));
                break;
            case CENTRE:
                renderPos.add(-xdir[0] * w / 2, -xdir[1] * w / 2, -xdir[2] * w / 2);
                break;
            case RIGHT:
                renderPos.add(-xdir[0] * (w + myTextOffset.x), -xdir[1] * (w + myTextOffset.x), -xdir[2] * (w + myTextOffset.x));
                break;
            default:
                break;
        }
        switch(vAlignment) {
            case BOTTOM:
                renderPos.add(ydir[0] * (myTextOffset.y), ydir[1] * (myTextOffset.y), ydir[2] * (myTextOffset.y));
                break;
            case CENTRE:
                renderPos.add(-ydir[0] * vc, -ydir[1] * vc, -ydir[2] * vc);
                break;
            case TOP:
                renderPos.add(-ydir[0] * (t + myTextOffset.y), -ydir[1] * (t + myTextOffset.y), -ydir[2] * (t + myTextOffset.y));
                break;
            default:
        }
        // renderPos.transform(rEye);
        tmp.set(label.pos);
        tmp.transform(label.trans);
        renderPos.add(tmp);
        myTransform.p.set(renderPos);
        renderer.pushModelMatrix();
        renderer.mulModelMatrix(myTransform);
        renderer.setShading(Shading.NONE);
        renderer.setColor(rgb[0], rgb[1], rgb[2], (float) rprops.getAlpha());
        renderer.drawText(myFont, label.text, loc, myTextSize);
        renderer.popModelMatrix();
        renderer.setShading(oldShading);
    }
}
Also used : FaceRenderProps(maspack.render.FaceRenderProps) Point3d(maspack.matrix.Point3d) Rectangle2D(java.awt.geom.Rectangle2D) Shading(maspack.render.Renderer.Shading)

Example 18 with Shading

use of maspack.render.Renderer.Shading in project artisynth_core by artisynth.

the class FaceComponent method render.

@Override
public void render(Renderer renderer, int flags) {
    RenderProps props = getRenderProps();
    if (props == null) {
        return;
    }
    if (props.getDrawEdges()) {
        float savedLineWidth = renderer.getLineWidth();
        Shading savedShadeModel = renderer.getShading();
        renderer.setLineWidth(props.getLineWidth());
        if (props.getLineColor() != null && !renderer.isSelecting()) {
            renderer.setShading(Shading.NONE);
            renderer.setLineColoring(props, isSelected());
        }
        if (useVertexColouring && !renderer.isSelecting()) {
            renderer.setShading(Shading.SMOOTH);
        } else {
            renderer.setShading(Shading.FLAT);
        }
        drawEdges(renderer, props);
        renderer.setLineWidth(savedLineWidth);
        renderer.setShading(savedShadeModel);
    }
    if (props.getFaceStyle() != Renderer.FaceStyle.NONE) {
        Shading savedShadeModel = renderer.getShading();
        Shading shading = props.getShading();
        if (shading != Shading.NONE) {
            renderer.setFaceColoring(props, isSelected());
        }
        if (shading == Shading.NONE) {
            renderer.setColor(props.getFaceColorF(), isSelected());
        }
        renderer.setShading(shading);
        if (props.getDrawEdges()) {
            renderer.setDepthOffset(1);
        }
        drawFaces(renderer, shading, props);
        if (props.getDrawEdges()) {
            renderer.setDepthOffset(0);
        }
        renderer.setShading(savedShadeModel);
    }
}
Also used : RenderProps(maspack.render.RenderProps) Shading(maspack.render.Renderer.Shading)

Example 19 with Shading

use of maspack.render.Renderer.Shading in project artisynth_core by artisynth.

the class TextComponent3d method render.

@Override
public void render(Renderer renderer, int flags) {
    if (!isSelectable() && renderer.isSelecting()) {
        return;
    }
    // text orientation computation
    Rectangle2D box = renderer.getTextBounds(myFont, myText, myTextSize);
    double w = box.getWidth();
    double t = box.getY() + box.getHeight();
    double vc = box.getY() + box.getHeight() / 2;
    rEye.invert(renderer.getViewMatrix().R);
    if (followEye) {
        rEye.getColumn(0, xdir);
    } else {
        xdir[0] = 1;
        xdir[1] = 0;
        xdir[2] = 0;
    }
    renderPos.setZero();
    switch(hAlignment) {
        case CENTRE:
            renderPos.add(-xdir[0] * w / 2, -xdir[1] * w / 2, -xdir[2] * w / 2);
            break;
        case RIGHT:
            renderPos.add(-xdir[0] * w, -xdir[1] * w, -xdir[2] * w);
            break;
        default:
            break;
    }
    if (followEye) {
        rEye.getColumn(1, xdir);
    } else {
        xdir[0] = 0;
        xdir[1] = 1;
        xdir[2] = 0;
    }
    switch(vAlignment) {
        case CENTRE:
            renderPos.add(-xdir[0] * vc, -xdir[1] * vc, -xdir[2] * vc);
            break;
        case TOP:
            renderPos.add(-xdir[0] * t, -xdir[1] * t, -xdir[2] * t);
            break;
        default:
    }
    // account for non-zero orientation
    myTransform.setRotation(myOrientation);
    if (followEye) {
        myTransform.R.mul(rEye, myTransform.R);
        renderPos.inverseTransform(rEye);
    }
    renderPos.transform(myTransform.R);
    renderPos.add(myPos);
    myTransform.p.set(renderPos);
    renderer.pushModelMatrix();
    renderer.mulModelMatrix(myTransform);
    RenderProps rprops = getRenderProps();
    // Shading savedShading = renderer.setShading (rprops.getShading ());
    Shading savedShading = renderer.setShading(Shading.NONE);
    renderer.setFaceColoring(rprops, isSelected());
    FaceStyle savedFaceStyle = renderer.setFaceStyle(rprops.getFaceStyle());
    final float[] ZERO = { 0, 0, 0 };
    renderer.drawText(myFont, myText, ZERO, myTextSize);
    renderer.setFaceStyle(savedFaceStyle);
    renderer.setShading(savedShading);
    renderer.popModelMatrix();
}
Also used : FaceStyle(maspack.render.Renderer.FaceStyle) Rectangle2D(java.awt.geom.Rectangle2D) RenderProps(maspack.render.RenderProps) Shading(maspack.render.Renderer.Shading)

Example 20 with Shading

use of maspack.render.Renderer.Shading in project artisynth_core by artisynth.

the class RenderProps method setWireFrame.

/**
 * Sets the render properties for a renderable to be consistent with either
 * wireframe or solid face rendering. For wireframe rendering, the
 * <code>faces</code>, <code>drawEdges</code> and <code>shading</code>
 * properties are set to <code>Faces.NONE</code>, <code>true</code>, and
 * <code>Shading.NONE</code>, respectively. For solid frame rendering, they
 * are set to <code>Faces.FRONT</code>, <code>false</code>, and
 * <code>Shading.FLAT</code>.
 *
 * @param r Renderable whose properties are to be set
 * @param enable if <code>true</code>, enable wireframe rendering.
 */
public static void setWireFrame(Renderable r, boolean enable) {
    Shading shading = enable ? Shading.NONE : Shading.FLAT;
    setWireFrame(r, enable, shading);
}
Also used : Shading(maspack.render.Renderer.Shading)

Aggregations

Shading (maspack.render.Renderer.Shading)38 RenderProps (maspack.render.RenderProps)10 RigidTransform3d (maspack.matrix.RigidTransform3d)7 Vector3d (maspack.matrix.Vector3d)7 FaceStyle (maspack.render.Renderer.FaceStyle)5 RenderObject (maspack.render.RenderObject)4 ColorInterpolation (maspack.render.Renderer.ColorInterpolation)4 PointStyle (maspack.render.Renderer.PointStyle)4 ModelComponent (artisynth.core.modelbase.ModelComponent)3 Point3d (maspack.matrix.Point3d)3 ColorMapProps (maspack.render.ColorMapProps)3 LineRenderProps (maspack.render.LineRenderProps)3 LineStyle (maspack.render.Renderer.LineStyle)3 FractionRenderType (artisynth.core.femmodels.AuxMaterialBundle.FractionRenderType)2 Rectangle2D (java.awt.geom.Rectangle2D)2 FaceRenderProps (maspack.render.FaceRenderProps)2 Renderer (maspack.render.Renderer)2 ColorMixing (maspack.render.Renderer.ColorMixing)2 DirectionRenderType (artisynth.core.femmodels.MuscleBundle.DirectionRenderType)1 LinkedList (java.util.LinkedList)1