Search in sources :

Example 26 with Shading

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

the class PolygonalMeshRenderer method drawFaces.

private void drawFaces(Renderer renderer, RenderProps props, boolean highlight, RenderObject robj, FeatureIndexArray features, boolean featureSelection) {
    boolean useTextures = robj.hasTextureCoords();
    Renderer.FaceStyle savedFaceStyle = renderer.getFaceStyle();
    Shading savedShadeModel = renderer.getShading();
    Shading shading = props.getShading();
    if (!robj.hasNormals() && shading != Shading.FLAT) {
        shading = Shading.NONE;
    }
    renderer.setShading(shading);
    renderer.setFaceColoring(props, highlight);
    // XXX always front and back when selecting?
    if (renderer.isSelecting()) {
        renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
    } else {
        renderer.setFaceStyle(props.getFaceStyle());
    }
    // int i = 0; // i is index of face
    ColorInterpolation savedColorInterp = null;
    if (usingHSV(getMesh())) {
        savedColorInterp = renderer.setColorInterpolation(ColorInterpolation.HSV);
    }
    if (props.getDrawEdges()) {
        renderer.setDepthOffset(-1);
    }
    ColorMapProps oldtprops = null;
    NormalMapProps oldnprops = null;
    BumpMapProps oldbprops = null;
    if (useTextures) {
        ColorMapProps dtprops = props.getColorMap();
        oldtprops = renderer.setColorMap(dtprops);
        NormalMapProps ntprops = props.getNormalMap();
        oldnprops = renderer.setNormalMap(ntprops);
        BumpMapProps btprops = props.getBumpMap();
        oldbprops = renderer.setBumpMap(btprops);
    }
    if (renderer.isSelecting() && featureSelection) {
        for (int i = 0; i < features.numFeatures(); ++i) {
            renderer.beginSelectionQuery(features.getFeature(i));
            renderer.drawVertices(robj, features.getVertices(), features.getFeatureOffset(i), features.getFeatureLength(i), DrawMode.TRIANGLES);
            renderer.endSelectionQuery();
        }
    } else {
        renderer.drawVertices(robj, features.getVertices(), DrawMode.TRIANGLES);
    }
    if (useTextures) {
        // restore diffuse texture properties
        renderer.setColorMap(oldtprops);
        renderer.setNormalMap(oldnprops);
        renderer.setBumpMap(oldbprops);
    }
    if (props.getDrawEdges()) {
        renderer.setDepthOffset(0);
    }
    if (savedColorInterp != null) {
        renderer.setColorInterpolation(savedColorInterp);
    }
    renderer.setFaceStyle(savedFaceStyle);
    renderer.setShading(savedShadeModel);
}
Also used : BumpMapProps(maspack.render.BumpMapProps) FaceStyle(maspack.render.Renderer.FaceStyle) ColorMapProps(maspack.render.ColorMapProps) Renderer(maspack.render.Renderer) Shading(maspack.render.Renderer.Shading) ColorInterpolation(maspack.render.Renderer.ColorInterpolation) NormalMapProps(maspack.render.NormalMapProps)

Example 27 with Shading

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

the class PolygonalMeshRenderer method drawEdges.

/**
 * Draws the edges associated with this mesh. Edge drawing is done using
 * edgeWidth and edgeColor (or LineColor if edgeColor is undefined), according
 * to the following rules:
 *
 * <p>If faces <i>are</i> also being drawn and there <i>is</i> vertex
 * coloring, then edges should render using the edge color, with whatever
 * shading is selected, and should respond to highlighting.
 *
 * <p>If faces <i>are</i> also being drawn and there <i>is no</i> vertex
 * coloring, then (a) edges should not respond to highlighting (the faces
 * will instead), and (b) edges should be rendered with whatever shading is
 * selected, <i>unless</i> the edge color is the same as the face color, in
 * which case shading is turned off so that the edges can be seen.
 *
 * <p>If faces <i>are not</i> also being drawn and there <i>is</i> vertex
 * coloring, then edges should render using the vertex coloring, with
 * whatever shading is selected, unless the mesh being highlighted, in which
 * case it should they should be rendered with the highlight color.
 *
 * <p>If faces <i>are not</i> also being drawn and there <i>is no</i> vertex
 * coloring, then edges should be rendered with whatever shading is
 * selected, and should respond to highlighting.
 */
private void drawEdges(Renderer renderer, RenderProps props, boolean highlight, boolean alsoDrawingFaces, RenderObject robj, FeatureIndexArray features, boolean featureSelection) {
    float savedLineWidth = renderer.getLineWidth();
    Shading savedShadeModel = renderer.getShading();
    boolean disableColors = false;
    renderer.setLineWidth(props.getEdgeWidth());
    Shading shading = props.getShading();
    if (!robj.hasNormals() && shading != Shading.FLAT) {
        shading = Shading.NONE;
    }
    float[] edgeColor = getEffectiveEdgeColor(props);
    if (alsoDrawingFaces) {
        highlight = false;
        if (robj.hasColors()) {
            disableColors = true;
        } else {
            if (colorsEqual(edgeColor, props.getFaceColorF())) {
                // turn off shading so we can see edges
                shading = Shading.NONE;
            }
        }
    } else {
        if (robj.hasColors()) {
            if (highlight) {
                disableColors = true;
            }
        }
    }
    renderer.setEdgeColoring(props, highlight);
    renderer.setShading(shading);
    ColorInterpolation savedColorInterp = null;
    if (usingHSV(getMesh())) {
        savedColorInterp = renderer.setColorInterpolation(ColorInterpolation.HSV);
    }
    ColorMixing savedColorMixing = null;
    if (disableColors) {
        savedColorMixing = renderer.getVertexColorMixing();
        renderer.setVertexColorMixing(ColorMixing.NONE);
    }
    if (renderer.isSelecting() && featureSelection) {
        for (int i = 0; i < features.numFeatures(); ++i) {
            renderer.beginSelectionQuery(features.getFeature(i));
            renderer.drawVertices(robj, features.getVertices(), features.getFeatureOffset(i), features.getFeatureLength(i), DrawMode.LINES);
            renderer.endSelectionQuery();
        }
    } else {
        renderer.drawVertices(robj, features.getVertices(), DrawMode.LINES);
    }
    if (savedColorInterp != null) {
        renderer.setColorInterpolation(savedColorInterp);
    }
    if (disableColors) {
        renderer.setVertexColorMixing(savedColorMixing);
    }
    renderer.setLineWidth(savedLineWidth);
    renderer.setShading(savedShadeModel);
}
Also used : ColorMixing(maspack.render.Renderer.ColorMixing) Shading(maspack.render.Renderer.Shading) ColorInterpolation(maspack.render.Renderer.ColorInterpolation)

Example 28 with Shading

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

the class PointMeshRenderer method render.

@Override
public void render(Renderer renderer, RenderProps props, int flags) {
    PointMesh mesh = getMesh();
    RenderObject rob = getRenderObject();
    if (mesh.numVertices() == 0) {
        return;
    }
    boolean highlight = ((flags & Renderer.HIGHLIGHT) != 0);
    renderer.pushModelMatrix();
    if (mesh.isRenderBuffered()) {
        renderer.mulModelMatrix(mesh.getXMeshToWorldRender());
    } else {
        renderer.mulModelMatrix(mesh.XMeshToWorld);
    }
    float savedLineWidth = renderer.getLineWidth();
    Shading savedShadeModel = renderer.getShading();
    // if (renderer.isSelecting()) {
    // shading = Shading.NONE;
    // }
    PointStyle pointStyle = props.getPointStyle();
    if (pointStyle == PointStyle.POINT && !mesh.hasNormals()) {
        renderer.setShading(Shading.NONE);
    } else {
        renderer.setShading(props.getShading());
    }
    ColorInterpolation savedColorInterp = null;
    if (usingHSV(mesh)) {
        savedColorInterp = renderer.setColorInterpolation(ColorInterpolation.HSV);
    }
    renderer.setPointColoring(props, highlight);
    switch(pointStyle) {
        case POINT:
            {
                int size = props.getPointSize();
                if (size > 0) {
                    renderer.drawPoints(rob, PointStyle.POINT, size);
                }
                break;
            }
        case CUBE:
        case SPHERE:
            {
                double rad = props.getPointRadius();
                if (rad > 0) {
                    renderer.drawPoints(rob, pointStyle, rad);
                }
                break;
            }
    }
    if (savedColorInterp != null) {
        renderer.setColorInterpolation(savedColorInterp);
    }
    if (mesh.getNormalRenderLen() > 0) {
        renderer.setLineWidth(props.getLineWidth());
        renderer.setLineColoring(props, highlight);
        renderer.drawLines(rob);
    }
    renderer.setLineWidth(savedLineWidth);
    renderer.setShading(savedShadeModel);
    renderer.popModelMatrix();
}
Also used : PointStyle(maspack.render.Renderer.PointStyle) Shading(maspack.render.Renderer.Shading) ColorInterpolation(maspack.render.Renderer.ColorInterpolation) RenderObject(maspack.render.RenderObject)

Example 29 with Shading

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

the class PolylineMeshRenderer method render.

@Override
public void render(Renderer renderer, RenderProps props, int flags) {
    PolylineMesh mesh = getMesh();
    RenderObject rob = getRenderObject();
    if (mesh.numVertices() == 0) {
        return;
    }
    boolean highlight = ((flags & Renderer.HIGHLIGHT) != 0);
    renderer.pushModelMatrix();
    if (mesh.isRenderBuffered()) {
        renderer.mulModelMatrix(mesh.getXMeshToWorldRender());
    } else {
        renderer.mulModelMatrix(mesh.XMeshToWorld);
    }
    float savedLineWidth = renderer.getLineWidth();
    Shading savedShadeModel = renderer.getShading();
    // Shading shading = props.getShading();
    // if (renderer.isSelecting()) {
    // shading = Shading.NONE;
    // }
    LineStyle lineStyle = props.getLineStyle();
    Shading savedShading = renderer.getShading();
    if (lineStyle == LineStyle.LINE && !mesh.hasNormals()) {
        renderer.setShading(Shading.NONE);
    } else {
        renderer.setShading(props.getShading());
    }
    ColorInterpolation savedColorInterp = null;
    if (usingHSV(mesh)) {
        savedColorInterp = renderer.setColorInterpolation(ColorInterpolation.HSV);
    }
    renderer.setLineColoring(props, highlight);
    switch(lineStyle) {
        case LINE:
            {
                int width = props.getLineWidth();
                if (width > 0) {
                    renderer.drawLines(rob, LineStyle.LINE, width);
                }
                break;
            }
        case SPINDLE:
        case SOLID_ARROW:
        case CYLINDER:
            {
                double rad = props.getLineRadius();
                if (rad > 0) {
                    renderer.drawLines(rob, props.getLineStyle(), rad);
                }
                break;
            }
    }
    if (savedColorInterp != null) {
        renderer.setColorInterpolation(savedColorInterp);
    }
    renderer.setShading(savedShading);
    renderer.setLineWidth(savedLineWidth);
    renderer.setShading(savedShadeModel);
    renderer.popModelMatrix();
}
Also used : LineStyle(maspack.render.Renderer.LineStyle) Shading(maspack.render.Renderer.Shading) ColorInterpolation(maspack.render.Renderer.ColorInterpolation) RenderObject(maspack.render.RenderObject)

Example 30 with Shading

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

the class VertexList 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)

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