Search in sources :

Example 1 with ColorMapProps

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

the class GL2Viewer method init.

@Override
public void init(GLAutoDrawable drawable) {
    super.init(drawable);
    this.drawable = drawable;
    this.gl = drawable.getGL().getGL2();
    if (DEBUG) {
        Logger.getSystemLogger().debug("GL: " + gl);
        Logger.getSystemLogger().debug("Dev id : ");
        GLContext context = drawable.getContext();
        String contextHC = Integer.toHexString(System.identityHashCode(context));
        Logger.getSystemLogger().debug("Context: " + context.getClass().getName() + "@" + contextHC + " (shared=" + context.isShared() + ")");
    }
    gl.setSwapInterval(1);
    int[] buff = new int[1];
    gl.glGetIntegerv(GL2.GL_MAX_CLIP_PLANES, buff, 0);
    maxClipPlanes = buff[0];
    setFaceStyle(FaceStyle.FRONT);
    gl.glEnable(GL2.GL_DEPTH_TEST);
    gl.glClearDepth(1.0);
    gl.glLightModelfv(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local, 0);
    gl.glLightModelfv(GL2.GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside, 0);
    gl.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, lmodel_ambient, 0);
    gl.glLightModelf(GL2.GL_LIGHT_MODEL_TWO_SIDE, 1);
    gl.glEnable(GL2.GL_LIGHTING);
    // normalize normals
    gl.glEnable(GL2.GL_NORMALIZE);
    myTextRenderer = GLTextRenderer.generate(gl, GL2PipelineRenderer.generate(gl));
    myTextTextureProps = new ColorMapProps();
    myTextTextureProps.setColorMixing(ColorMixing.MODULATE);
    myTextTextureProps.setEnabled(true);
    setLightingEnabled(true);
    setDepthEnabled(true);
    setColorEnabled(true);
    setVertexColoringEnabled(true);
    setTextureMappingEnabled(true);
    setFaceStyle(FaceStyle.FRONT);
    setShading(Shading.SMOOTH);
    setGammaCorrectionEnabled(false);
    lightManager.setMaxLights(getMaxLights(gl));
    setupLights(gl);
    // gl.glFrontFace (GL2.GL_CW);
    if (!isSelecting()) {
        gl.glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], backgroundColor[3]);
    }
    // initialize viewport
    resetViewVolume(gl);
    invalidateModelMatrix();
    invalidateProjectionMatrix();
    invalidateViewMatrix();
    // trigger rebuild of renderables
    buildInternalRenderList();
    if (DEBUG) {
        Logger.getSystemLogger().debug("GL2 initialized");
    }
}
Also used : ColorMapProps(maspack.render.ColorMapProps) GLContext(com.jogamp.opengl.GLContext)

Example 2 with ColorMapProps

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

the class TextureEgyptianTest method addContent.

@Override
protected void addContent(MultiViewer mv) {
    JFrame frame = new JFrame();
    JPanel controls = new JPanel();
    frame.add(controls);
    PolygonalMesh plane = MeshFactory.createRectangle(4000, 400, 32, 8, /*texture=*/
    true);
    RenderProps rprops = plane.getRenderProps();
    if (rprops == null) {
        rprops = new RenderProps();
    }
    rprops.setShading(Shading.SMOOTH);
    rprops.setShininess(20);
    rprops.setFaceColor(new Color(155, 196, 30));
    rprops.setSpecular(new Color(255, 113, 0));
    rprops.setFaceStyle(FaceStyle.FRONT_AND_BACK);
    plane.transform(new RigidTransform3d(Vector3d.ZERO, AxisAngle.ROT_X_90));
    String srcDir = PathFinder.findSourceDir(this);
    ColorMapProps dprops = new ColorMapProps();
    dprops.setFileName(srcDir + "/data/specular_map.jpg");
    dprops.setColorMixing(ColorMixing.MODULATE);
    dprops.setEnabled(true);
    NormalMapProps normalProps = new NormalMapProps();
    normalProps.setFileName(srcDir + "/data/foil_normal_map2.png");
    normalProps.setScaling(0.3f);
    normalProps.setEnabled(true);
    BumpMapProps bumpProps = new BumpMapProps();
    bumpProps.setFileName(srcDir + "/data/egyptian_friz_2.png");
    bumpProps.setScaling(2.5f);
    bumpProps.setEnabled(true);
    rprops.setColorMap(dprops);
    rprops.setNormalMap(normalProps);
    rprops.setBumpMap(bumpProps);
    // FixedMeshBody fm = new FixedMeshBody(plane);
    // fm.setRenderProps(rprops);
    mv.addRenderable(plane);
    if (false) {
        mv.addRenderable(new IsRenderable() {

            @Override
            public void updateBounds(Vector3d pmin, Vector3d pmax) {
                Point3d.X_UNIT.updateBounds(pmin, pmax);
                Point3d.Y_UNIT.updateBounds(pmin, pmax);
                Point3d.Z_UNIT.updateBounds(pmin, pmax);
                Point3d.NEG_X_UNIT.updateBounds(pmin, pmax);
                Point3d.NEG_Y_UNIT.updateBounds(pmin, pmax);
                Point3d.NEG_Z_UNIT.updateBounds(pmin, pmax);
            }

            @Override
            public void render(Renderer renderer, int flags) {
                renderer.setColor(Color.CYAN);
                renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
                renderer.drawSphere(Point3d.ZERO, 1);
            }

            @Override
            public void prerender(RenderList list) {
            // TODO Auto-generated method stub
            }

            @Override
            public int getRenderHints() {
                // TODO Auto-generated method stub
                return 0;
            }
        });
    }
    mv.autoFitViewers();
    LabeledComponentBase base = PropertyWidget.create("Color texture", rprops.getColorMap(), "enabled");
    controls.add(base);
    base = PropertyWidget.create("Normal map", rprops.getNormalMap(), "enabled");
    controls.add(base);
    base = PropertyWidget.create("Bump map", rprops.getBumpMap(), "enabled");
    controls.add(base);
    base = PropertyWidget.create("Specular", rprops.getColorMap(), "specularColoring");
    controls.add(base);
    base = PropertyWidget.create("Bump map scale", rprops.getBumpMap(), "scaling");
    controls.add(base);
    base = PropertyWidget.create("Normal map scale", rprops.getNormalMap(), "scaling");
    controls.add(base);
    frame.pack();
    frame.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) RigidTransform3d(maspack.matrix.RigidTransform3d) Color(java.awt.Color) ColorMapProps(maspack.render.ColorMapProps) RenderProps(maspack.render.RenderProps) PolygonalMesh(maspack.geometry.PolygonalMesh) RenderList(maspack.render.RenderList) BumpMapProps(maspack.render.BumpMapProps) IsRenderable(maspack.render.IsRenderable) JFrame(javax.swing.JFrame) Vector3d(maspack.matrix.Vector3d) Renderer(maspack.render.Renderer) LabeledComponentBase(maspack.widgets.LabeledComponentBase) NormalMapProps(maspack.render.NormalMapProps)

Example 3 with ColorMapProps

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

the class ImagePlaneProbe method setImage.

public void setImage(double t) {
    if (imageBasename == null || imageDirectory == null)
        return;
    int frameNum = (int) (t * frameRate) + 1;
    String filename = String.format(fileNameFormat, imageBasename, frameNum, imageFileExt);
    ColorMapProps tprops = myRenderProps.getColorMap();
    tprops.setFileName(imageDirectory.getAbsolutePath() + "/" + filename);
    myRenderProps.setColorMap(tprops);
}
Also used : ColorMapProps(maspack.render.ColorMapProps)

Example 4 with ColorMapProps

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

the class GL3Viewer method drawText.

@Override
public double drawText(Font font, String str, float[] pos, double emSize) {
    GL3 gl = getGL().getGL3();
    if (font == null) {
        font = getDefaultFont();
    }
    boolean savedBlending = isBlendingEnabled();
    boolean savedTexture = isTextureMappingEnabled();
    boolean savedDepth = isDepthWriteEnabled();
    BlendFactor dfactor = getBlendDestFactor();
    BlendFactor sfactor = getBlendSourceFactor();
    setDepthWriteEnabled(false);
    setBlendingEnabled(true);
    setDepthWriteEnabled(false);
    setBlendingEnabled(true);
    setBlendSourceFactor(BlendFactor.GL_SRC_ALPHA);
    setBlendDestFactor(BlendFactor.GL_ONE_MINUS_SRC_ALPHA);
    setTextureMappingEnabled(true);
    ColorMapProps savedTextureProps = setColorMap(myTextTextureProps);
    maybeUpdateState(gl);
    updateProgram(gl, RenderingMode.DEFAULT, true, false, true);
    myProgManager.activateTexture(gl, "color_map");
    myTextRenderer.begin(gl);
    double d = myTextRenderer.drawText(font, str, pos, (float) emSize);
    myTextRenderer.end(gl);
    setDepthWriteEnabled(savedDepth);
    setBlendSourceFactor(sfactor);
    setBlendDestFactor(dfactor);
    setBlendingEnabled(savedBlending);
    setTextureMappingEnabled(savedTexture);
    setColorMap(savedTextureProps);
    return d;
}
Also used : ColorMapProps(maspack.render.ColorMapProps) GL3(com.jogamp.opengl.GL3) GL2GL3(com.jogamp.opengl.GL2GL3)

Example 5 with ColorMapProps

use of maspack.render.ColorMapProps 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)

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