Example usage for javax.media.j3d Texture CLAMP

List of usage examples for javax.media.j3d Texture CLAMP

Introduction

In this page you can find the example usage for javax.media.j3d Texture CLAMP.

Prototype

int CLAMP

To view the source code for javax.media.j3d Texture CLAMP.

Click Source Link

Document

Clamps texture coordinates to be in the range [0, 1].

Usage

From source file:TexBug.java

public void actionPerformed(ActionEvent e) {
    String action = e.getActionCommand();
    Object source = e.getSource();
    if (action == texEnableString) {
        texEnable = texEnableCheckBox.isSelected();
        System.out.println("texture.setEnable(" + texEnable + ")");
        texture.setEnable(texEnable);//from  w  ww .j  a v a  2s.c om
    } else if (action == texBoundarySWrapString) {
        texBoundaryModeS = Texture.WRAP;
        setTexture();
    } else if (action == texBoundarySClampString) {
        texBoundaryModeS = Texture.CLAMP;
        setTexture();
    } else if (action == texBoundaryTWrapString) {
        texBoundaryModeT = Texture.WRAP;
        setTexture();
    } else if (action == texBoundaryTClampString) {
        texBoundaryModeT = Texture.CLAMP;
        setTexture();
    } else if (action == texMinFilterBasePointString) {
        texMinFilter = Texture.BASE_LEVEL_POINT;
        setTexture();
    } else if (action == texMinFilterBaseLinearString) {
        texMinFilter = Texture.BASE_LEVEL_LINEAR;
        setTexture();
    } else if (action == texMinFilterMultiPointString) {
        texMinFilter = Texture.MULTI_LEVEL_POINT;
        setTexture();
    } else if (action == texMinFilterMultiLinearString) {
        texMinFilter = Texture.MULTI_LEVEL_LINEAR;
        setTexture();
    } else if (action == texMinFilterFastestString) {
        texMinFilter = Texture.FASTEST;
        setTexture();
    } else if (action == texMinFilterNicestString) {
        texMinFilter = Texture.NICEST;
        setTexture();
    } else if (action == texMagFilterBasePointString) {
        texMagFilter = Texture.BASE_LEVEL_POINT;
        setTexture();
    } else if (action == texMagFilterBaseLinearString) {
        texMagFilter = Texture.BASE_LEVEL_LINEAR;
        setTexture();
    } else if (action == texMagFilterNicestString) {
        texMagFilter = Texture.NICEST;
        setTexture();
    } else if (action == texMagFilterFastestString) {
        texMagFilter = Texture.FASTEST;
        setTexture();
    } else if (action == texMipMapBaseString) {
        texMipMapMode = Texture.BASE_LEVEL;
        setTexture();
    } else if (action == texMipMapMultiString) {
        texMipMapMode = Texture.MULTI_LEVEL_MIPMAP;
        setTexture();
    }
}

From source file:TexCoordTest.java

void createAppearance(double yMaxHeight) {
    // create an Appearance and assign a Material
    m_Appearance = new Appearance();
    m_Appearance.setCapability(Appearance.ALLOW_TEXGEN_WRITE);

    Color3f black = new Color3f(0, 0.2f, 0);
    Color3f objColor = new Color3f(0.1f, 0.7f, 0.2f);
    m_Appearance.setMaterial(new Material(objColor, black, objColor, black, 0.8f));

    // load the texture image
    TextureLoader texLoader = new TextureLoader("stripes.gif", Texture.RGB, this);

    // clamp the coordinates in the S dimension, that way they
    // will not wrap when the calculated texture coordinate falls outside
    // the range 0 to 1. When the texture coordinate is outside this range
    // no texture coordinate will be used
    Texture tex = texLoader.getTexture();
    tex.setBoundaryModeS(Texture.CLAMP);

    // assign the texute image to the appearance
    m_Appearance.setTexture(tex);/*from   w  ww . ja  v a2s  . c om*/

    // create the TexCoordGeneration object.
    // we are only using 1D texture coordinates (S) - texture coordinates
    // are calculated from a vertex's distance from the Y = 0 plane
    // the 4th parameter to the Vector4f is the distance in *texture
    // coordinates*
    // that we shift the texture coordinates by (i.e. Y = 0 corresponds to S
    // = 0.5)
    TexCoordGeneration texGen = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,
            TexCoordGeneration.TEXTURE_COORDINATE_2, new Vector4f(0, (float) (1.0 / (2 * yMaxHeight)), 0, 0.5f),
            new Vector4f(0, 0, 0, 0), new Vector4f(0, 0, 0, 0));

    // create our "non-live" TexCoordGeneration object so we
    // can update the "genMode" parameter after we go live.
    m_TexGen = (TexCoordGeneration) texGen.cloneNodeComponent(true);

    // assign the TexCoordGeneration to the Appearance
    m_Appearance.setTexCoordGeneration(texGen);

    // we just glue the texture image to the surface, we are not
    // blending or modulating the texture image based on material
    // attributes. You can experiment with MODULATE or BLEND.
    TextureAttributes texAttribs = new TextureAttributes();
    texAttribs.setTextureMode(TextureAttributes.DECAL);
    m_Appearance.setTextureAttributes(texAttribs);
}

From source file:TextureByReference.java

public BranchGroup createSceneGraph() {

    // create the root of the branch group
    BranchGroup objRoot = new BranchGroup();

    // create the transform group node and initialize it
    // enable the TRANSFORM_WRITE capability so that it can be modified
    // at runtime. Add it to the root of the subgraph
    Transform3D rotate = new Transform3D();
    TransformGroup objTrans = new TransformGroup(rotate);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);/*from   w w  w  .  j av  a 2  s.  c o m*/

    // bounds
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // set up some light
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -0.5f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    Appearance appearance = new Appearance();

    // enable the TEXTURE_WRITE so we can modify it at runtime
    appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    // load the first texture
    TextureLoader loader = new TextureLoader(urls[0], TextureLoader.BY_REFERENCE | TextureLoader.Y_UP, this);
    // get the texture from the loader
    Texture2D tex = (Texture2D) loader.getTexture();

    // get the BufferedImage to convert to TYPE_4BYTE_ABGR and flip
    // get the ImageComponent because we need it anyway
    ImageComponent2D imageComp = (ImageComponent2D) tex.getImage(0);
    BufferedImage bImage = imageComp.getImage();
    // convert the image
    bImage = ImageOps.convertImage(bImage, BufferedImage.TYPE_4BYTE_ABGR);
    // flip the image
    ImageOps.flipImage(bImage);
    imageComp.set(bImage);

    tex.setCapability(Texture.ALLOW_IMAGE_WRITE);
    tex.setBoundaryModeS(Texture.CLAMP);
    tex.setBoundaryModeT(Texture.CLAMP);
    tex.setBoundaryColor(1.0f, 1.0f, 1.0f, 1.0f);

    // set the image of the texture
    tex.setImage(0, imageComp);

    // set the texture on the appearance
    appearance.setTexture(tex);

    // set texture attributes
    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    appearance.setTextureAttributes(texAttr);

    // set material properties
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    appearance.setMaterial(new Material(white, black, white, black, 1.0f));

    // create a scale transform
    Transform3D scale = new Transform3D();
    scale.set(.6);
    TransformGroup objScale = new TransformGroup(scale);
    objTrans.addChild(objScale);

    tetra = new Tetrahedron(true);
    tetra.setAppearance(appearance);
    objScale.addChild(tetra);

    // create the behavior
    animate = new AnimateTexturesBehavior(tex, urls, appearance, this);
    animate.setSchedulingBounds(bounds);

    objTrans.addChild(animate);

    // add a rotation behavior so we can see all sides of the tetrahedron
    Transform3D yAxis = new Transform3D();
    Alpha rotorAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);
    RotationInterpolator rotator = new RotationInterpolator(rotorAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);

    // have java3d perform optimizations on this scene graph
    objRoot.compile();

    return objRoot;
}

From source file:AppearanceTest.java

public void onS_CLAMP() {
    getTexture().setBoundaryModeS(Texture.CLAMP);
    assignToAppearance();
}

From source file:AppearanceTest.java

public void onT_CLAMP() {
    getTexture().setBoundaryModeT(Texture.CLAMP);
    assignToAppearance();
}

From source file:AppearanceExplorer.java

public Texture2DEditor(Appearance app, String codeBaseString, String[] texImageNames,
        String[] texImageFileNames, int texImageIndex, boolean texEnable, int texBoundaryModeS,
        int texBoundaryModeT, int texMinFilter, int texMagFilter, int texMipMapMode, Color4f texBoundaryColor) {

    super(BoxLayout.Y_AXIS);

    this.appearance = app;
    // TODO: make deep copies?
    this.imageNames = texImageNames;
    this.imageFileNames = texImageFileNames;
    this.imageIndex = texImageIndex;
    this.imageFile = texImageFileNames[texImageIndex];
    this.codeBaseString = codeBaseString;
    this.enable = texEnable;
    this.mipMapMode = texMipMapMode;
    this.boundaryModeS = texBoundaryModeS;
    this.boundaryModeT = texBoundaryModeT;
    this.minFilter = texMinFilter;
    this.magFilter = texMagFilter;
    this.boundaryColor.set(texBoundaryColor);

    // set up the initial texture
    setTexture();//from   w ww. j ava 2  s  . c  o m

    JCheckBox texEnableCheckBox = new JCheckBox("Enable Texture");
    texEnableCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            enable = ((JCheckBox) e.getSource()).isSelected();
            // workaround for bug
            // should just be able to
            // texture.setEnable(texEnable);
            // instead we have to:
            setTexture();
        }
    });

    // add the checkbox to the panel
    add(new LeftAlignComponent(texEnableCheckBox));

    IntChooser imgChooser = new IntChooser("Image:", imageNames);
    imgChooser.setValue(imageIndex);
    imgChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            imageIndex = event.getValue();
            imageFile = imageFileNames[imageIndex];
            setTexture();
        }
    });
    add(imgChooser);

    // texture boundaries
    String[] boundaryNames = { "WRAP", "CLAMP", };
    int[] boundaryValues = { Texture.WRAP, Texture.CLAMP, };

    // texture boundary S
    IntChooser bndSChooser = new IntChooser("Boundary S Mode:", boundaryNames, boundaryValues);
    bndSChooser.setValue(texBoundaryModeS);
    bndSChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            int value = event.getValue();
            boundaryModeS = value;
            setTexture();
        }
    });
    add(bndSChooser);

    // texture boundary T
    IntChooser bndTChooser = new IntChooser("Boundary T Mode:", boundaryNames, boundaryValues);
    bndTChooser.setValue(texBoundaryModeT);
    bndTChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            int value = event.getValue();
            boundaryModeT = value;
            setTexture();
        }
    });
    add(bndTChooser);

    // texture min filter
    String[] minFiltNames = { "FASTEST", "NICEST", "BASE_LEVEL_POINT", "BASE_LEVEL_LINEAR", "MULTI_LEVEL_POINT",
            "MULTI_LEVEL_LINEAR", };
    int[] minFiltValues = { Texture.FASTEST, Texture.NICEST, Texture.BASE_LEVEL_POINT,
            Texture.BASE_LEVEL_LINEAR, Texture.MULTI_LEVEL_POINT, Texture.MULTI_LEVEL_LINEAR, };

    // min filter
    IntChooser minFiltChooser = new IntChooser("Min Filter:", minFiltNames, minFiltValues);
    minFiltChooser.setValue(minFilter);
    minFiltChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            int value = event.getValue();
            minFilter = value;
            setTexture();
        }
    });
    add(minFiltChooser);

    // texture mag filter
    String[] magFiltNames = { "FASTEST", "NICEST", "BASE_LEVEL_POINT", "BASE_LEVEL_LINEAR", };
    int[] magFiltValues = { Texture.FASTEST, Texture.NICEST, Texture.BASE_LEVEL_POINT,
            Texture.BASE_LEVEL_LINEAR, };

    // mag filter
    IntChooser magFiltChooser = new IntChooser("Mag Filter:", magFiltNames, magFiltValues);
    magFiltChooser.setValue(magFilter);
    magFiltChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            int value = event.getValue();
            magFilter = value;
            setTexture();
        }
    });
    add(magFiltChooser);

    // texture mipmap mode
    String[] mipMapNames = { "BASE_LEVEL", "MULTI_LEVEL_MIPMAP", };
    int[] mipMapValues = { Texture.BASE_LEVEL, Texture.MULTI_LEVEL_MIPMAP, };

    // mipMap mode
    IntChooser mipMapChooser = new IntChooser("MipMap Mode:", mipMapNames, mipMapValues);
    mipMapChooser.setValue(mipMapMode);
    mipMapChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            int value = event.getValue();
            mipMapMode = value;
            setTexture();
        }
    });
    add(mipMapChooser);

    Color4fEditor boundaryColorEditor = new Color4fEditor("Boundary Color", boundaryColor);
    boundaryColorEditor.addColor4fListener(new Color4fListener() {
        public void colorChanged(Color4fEvent event) {
            event.getValue(boundaryColor);
            setTexture();
        }
    });
    add(boundaryColorEditor);
}