Search in sources :

Example 11 with ColorMapProps

use of maspack.render.ColorMapProps in project artisynth_core by artisynth.

the class WavefrontReader method processMaterialLine.

protected boolean processMaterialLine(ReaderTokenizer rtok, RenderProps props) throws IOException {
    // int lineno = rtok.lineno();
    if (rtok.sval.equals("Ka")) {
        // ambient colour
        double r = rtok.scanNumber();
        double g = rtok.scanNumber();
        double b = rtok.scanNumber();
        if (props != null) {
            props.setFaceColor(new Color((float) r, (float) g, (float) b));
        // System.out.println( props.getFaceColor().toString() );
        }
    } else if (rtok.sval.equals("Kd")) {
        // diffuse colour
        double r = rtok.scanNumber();
        double g = rtok.scanNumber();
        double b = rtok.scanNumber();
        if (props != null) {
            props.setFaceColor(new Color((float) r, (float) g, (float) b));
        // System.out.println( props.getFaceColor().toString() );
        }
    } else if (rtok.sval.equals("Ks")) {
        // specular colour
        double r = rtok.scanNumber();
        double g = rtok.scanNumber();
        double b = rtok.scanNumber();
        props.setSpecular(new Color((float) r, (float) g, (float) b));
    } else if (rtok.sval.equals("d") || rtok.sval.equals("Tr")) {
        String a = rtok.sval;
        double alpha = rtok.scanNumber();
        if (props != null) {
            if (a.equals("d")) {
                props.setAlpha(alpha);
            } else {
                props.setAlpha(1 - alpha);
            }
        }
    } else if (rtok.sval.equals("Ns")) {
        double shininess = rtok.scanNumber();
        if (props != null) {
            props.setShininess((float) shininess);
        }
    } else // eg map_Kd lenna.tga # the diffuse texture map
    if (rtok.sval.equals("map_Kd") || rtok.sval.equals("map_Ka")) {
        // we need period
        int savePeriod = rtok.getCharSetting('.');
        rtok.wordChar('.');
        int saveDash = rtok.getCharSetting('-');
        rtok.wordChar('-');
        String map = rtok.scanWord();
        if (map != null) {
            // set texture properties
            props.setFaceStyle(Renderer.FaceStyle.FRONT_AND_BACK);
            props.setShading(Shading.SMOOTH);
            ColorMapProps tprops = props.getColorMap();
            if (tprops == null) {
                tprops = new ColorMapProps();
            }
            tprops.setFileName(currPath + "/" + map);
            tprops.setEnabled(true);
            tprops.setColorMixing(ColorMixing.MODULATE);
            props.setColorMap(tprops);
        }
        // restore period state
        rtok.setCharSetting('.', savePeriod);
        rtok.setCharSetting('-', saveDash);
    } else // eg map_Kd lenna.tga # the diffuse texture map
    if (rtok.sval.equals("bump") || rtok.sval.equalsIgnoreCase("map_bump")) {
        // we need period
        int savePeriod = rtok.getCharSetting('.');
        rtok.wordChar('.');
        int saveDash = rtok.getCharSetting('-');
        rtok.wordChar('-');
        String map = rtok.scanWord();
        if (map != null) {
            // set texture properties
            props.setFaceStyle(Renderer.FaceStyle.FRONT_AND_BACK);
            props.setShading(Shading.SMOOTH);
            BumpMapProps tprops = props.getBumpMap();
            if (tprops == null) {
                tprops = new BumpMapProps();
            }
            tprops.setFileName(currPath + "/" + map);
            tprops.setEnabled(true);
            props.setBumpMap(tprops);
        }
        // restore period state
        rtok.setCharSetting('.', savePeriod);
        rtok.setCharSetting('-', saveDash);
    } else if (rtok.sval.equals("norm") || rtok.sval.equalsIgnoreCase("map_norm")) {
        // we need period
        int savePeriod = rtok.getCharSetting('.');
        rtok.wordChar('.');
        int saveDash = rtok.getCharSetting('-');
        rtok.wordChar('-');
        String map = rtok.scanWord();
        if (map != null) {
            // set texture properties
            props.setFaceStyle(Renderer.FaceStyle.FRONT_AND_BACK);
            props.setShading(Shading.SMOOTH);
            NormalMapProps tprops = props.getNormalMap();
            if (tprops == null) {
                tprops = new NormalMapProps();
            }
            tprops.setFileName(currPath + "/" + map);
            tprops.setEnabled(true);
            props.setNormalMap(tprops);
        }
        // restore period state
        rtok.setCharSetting('.', savePeriod);
        rtok.setCharSetting('-', saveDash);
    } else {
        return false;
    }
    return true;
}
Also used : BumpMapProps(maspack.render.BumpMapProps) Color(java.awt.Color) ColorMapProps(maspack.render.ColorMapProps) NormalMapProps(maspack.render.NormalMapProps)

Example 12 with ColorMapProps

use of maspack.render.ColorMapProps in project artisynth_core by artisynth.

the class GL2Viewer method drawText.

public double drawText(Font font, String str, float[] pos, double emSize) {
    if (font == null) {
        font = getDefaultFont();
    }
    boolean savedBlending = isBlendingEnabled();
    boolean savedTexture = isTextureMappingEnabled();
    boolean savedDepth = isDepthWriteEnabled();
    BlendFactor dfactor = getBlendDestFactor();
    BlendFactor sfactor = getBlendSourceFactor();
    setDepthWriteEnabled(false);
    setBlendingEnabled(true);
    setBlendSourceFactor(BlendFactor.GL_SRC_ALPHA);
    setBlendDestFactor(BlendFactor.GL_ONE_MINUS_SRC_ALPHA);
    setTextureMappingEnabled(true);
    ColorMapProps savedTextureProps = setColorMap(myTextTextureProps);
    maybeUpdateState(gl);
    activateTexture(gl, myTextRenderer.getTexture());
    myTextRenderer.begin(gl);
    double d = myTextRenderer.drawText(font, str, pos, (float) emSize);
    myTextRenderer.end(gl);
    deactivateTexture(gl);
    setDepthWriteEnabled(savedDepth);
    setBlendSourceFactor(sfactor);
    setBlendDestFactor(dfactor);
    setBlendingEnabled(savedBlending);
    setTextureMappingEnabled(savedTexture);
    setColorMap(savedTextureProps);
    return d;
}
Also used : ColorMapProps(maspack.render.ColorMapProps)

Aggregations

ColorMapProps (maspack.render.ColorMapProps)12 RenderProps (maspack.render.RenderProps)5 LineRenderProps (maspack.render.LineRenderProps)4 BumpMapProps (maspack.render.BumpMapProps)3 NormalMapProps (maspack.render.NormalMapProps)3 FaceStyle (maspack.render.Renderer.FaceStyle)3 Shading (maspack.render.Renderer.Shading)3 Color (java.awt.Color)2 Renderer (maspack.render.Renderer)2 GL2GL3 (com.jogamp.opengl.GL2GL3)1 GL3 (com.jogamp.opengl.GL3)1 GLContext (com.jogamp.opengl.GLContext)1 JFrame (javax.swing.JFrame)1 JPanel (javax.swing.JPanel)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 AffineTransform3d (maspack.matrix.AffineTransform3d)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 Vector3d (maspack.matrix.Vector3d)1 IsRenderable (maspack.render.IsRenderable)1 RenderList (maspack.render.RenderList)1