Example usage for javax.media.j3d Appearance ALLOW_TEXTURE_WRITE

List of usage examples for javax.media.j3d Appearance ALLOW_TEXTURE_WRITE

Introduction

In this page you can find the example usage for javax.media.j3d Appearance ALLOW_TEXTURE_WRITE.

Prototype

int ALLOW_TEXTURE_WRITE

To view the source code for javax.media.j3d Appearance ALLOW_TEXTURE_WRITE.

Click Source Link

Document

Specifies that this Appearance object allows writing its texture component information.

Usage

From source file:ImageComponentByReferenceTest.java

public BranchGroup createSceneGraph() {
    objRoot = new BranchGroup();

    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(Group.ALLOW_CHILDREN_WRITE);

    objRoot.addChild(objTrans);//from  ww  w  . j  a  v a2s  .co  m

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

    app.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    textureCube = new Box(0.4f, 0.4f, 0.4f, Box.GENERATE_TEXTURE_COORDS | Box.GENERATE_NORMALS, app);
    boxShape = textureCube.getShape(Box.FRONT);
    boxShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    objTrans.addChild(textureCube);

    checkBoard = new TiledImage();
    TextureLoader texLoader = new TextureLoader(texImage, this);
    ImageComponent2D oneImage = texLoader.getImage();
    bImage1 = oneImage.getImage();

    int index = 0;
    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, true);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, true);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, false);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, false);

    createRaster(objRoot);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, true);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, true);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, false);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, false);

    texOne = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[2].getWidth(), image[2].getHeight());

    texOne.setCapability(Texture.ALLOW_IMAGE_WRITE);
    texOne.setImage(0, image[2]);

    app.setTexture(texOne);

    texCheckBoard = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[4].getWidth(), image[4].getHeight());

    texCheckBoard.setCapability(Texture.ALLOW_IMAGE_WRITE);
    objRoot.compile();
    return objRoot;
}

From source file:TexBug.java

void setupAppearance() {
    appearance = new Appearance();

    // Texture2D/*from   w w  w .jav  a 2s .  c om*/

    // set the values to the defaults
    texEnable = false;
    texMipMapMode = Texture.BASE_LEVEL;
    texBoundaryModeS = Texture.WRAP;
    texBoundaryModeT = Texture.WRAP;
    texMinFilter = Texture.BASE_LEVEL_POINT;
    texMagFilter = Texture.BASE_LEVEL_POINT;
    texBoundaryColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f);

    // set up the appearance to allow the texture to be changed
    appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    // set the texture
    setTexture();
}

From source file:ExTexture.java

public Group buildScene() {
    // Get the current menu choices for appearance attributes
    int textureMode = ((Integer) modes[currentMode].value).intValue();
    Color3f color = (Color3f) colors[currentColor].value;
    Color3f blendColor = (Color3f) colors[currentBlendColor].value;

    // Turn on the example headlight
    setHeadlightEnable(true);//from   w  ww.  jav a2s  . c  om

    // Default to examine navigation
    setNavigationType(Examine);

    // Disable scene graph compilation for this example
    setCompilable(false);

    // Create the scene group
    Group scene = new Group();

    // BEGIN EXAMPLE TOPIC
    // Set up a basic material
    Material mat = new Material();
    mat.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    mat.setSpecularColor(0.0f, 0.0f, 0.0f);
    mat.setLightingEnable(true);

    // Set up the texturing attributes with an initial
    // texture mode, texture transform, and blend color
    texatt = new TextureAttributes();
    texatt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    texatt.setTextureMode(textureMode);
    texatt.setTextureTransform(new Transform3D()); // Identity
    texatt.setTextureBlendColor(blendColor.x, blendColor.y, blendColor.z, 0.5f);

    // Enable changing these while the node component is live
    texatt.setCapability(TextureAttributes.ALLOW_MODE_WRITE);
    texatt.setCapability(TextureAttributes.ALLOW_BLEND_COLOR_WRITE);
    texatt.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE);

    // Create an appearance using these attributes
    app = new Appearance();
    app.setMaterial(mat);
    app.setTextureAttributes(texatt);
    app.setTexture(tex);

    // And enable changing these while the node component is live
    app.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
    app.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_WRITE);

    // Build a shape and enable changing its appearance
    shape = new Shape3D(buildGeometry(), app);
    shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    // END EXAMPLE TOPIC

    // Create some dummy appearance and tex attribute node components
    // In response to menu choices, we quickly switch the shape to
    // use one of these, then diddle with the main appearance or
    // tex attribute, then switch the shape back. This effectively
    // makes the appearance or tex attributes we want to change
    // become un-live during a change. We have to do this approach
    // because some texture features have no capability bits to set
    // to allow changes while live.
    dummyApp = new Appearance();
    dummyAtt = new TextureAttributes();

    scene.addChild(shape);

    return scene;
}

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.  ja  v  a 2s.co 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:AppearanceExplorer.java

void setupAppearance() {
    appearance = new Appearance();

    // ColoringAttributes
    coloringColor = new Color3f(red);
    coloringAttr = new ColoringAttributes(coloringColor, coloringShadeModel);
    coloringAttr.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
    coloringAttr.setCapability(ColoringAttributes.ALLOW_SHADE_MODEL_WRITE);
    appearance.setColoringAttributes(coloringAttr);

    // set up the editor
    coloringAttrEditor = new ColoringAttributesEditor(coloringAttr);

    // PointAttributes
    pointAttr = new PointAttributes(pointSize, pointAAEnable);
    pointAttr.setCapability(PointAttributes.ALLOW_SIZE_WRITE);
    pointAttr.setCapability(PointAttributes.ALLOW_ANTIALIASING_WRITE);
    appearance.setPointAttributes(pointAttr);

    // set up the editor
    pointAttrEditor = new PointAttributesEditor(pointAttr);

    // LineAttributes
    lineAttr = new LineAttributes(lineWidth, linePattern, lineAAEnable);
    lineAttr.setCapability(LineAttributes.ALLOW_WIDTH_WRITE);
    lineAttr.setCapability(LineAttributes.ALLOW_PATTERN_WRITE);
    lineAttr.setCapability(LineAttributes.ALLOW_ANTIALIASING_WRITE);
    appearance.setLineAttributes(lineAttr);

    // set up the editor
    lineAttrEditor = new LineAttributesEditor(lineAttr);

    // PolygonAttributes
    polygonAttr = new PolygonAttributes(polygonMode, polygonCull, 0.0f);
    polygonAttr.setPolygonOffset(polygonOffsetBias);
    polygonAttr.setPolygonOffsetFactor(polygonOffsetFactor);
    polygonAttr.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
    polygonAttr.setCapability(PolygonAttributes.ALLOW_CULL_FACE_WRITE);
    polygonAttr.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE);
    appearance.setPolygonAttributes(polygonAttr);

    // set up the editor
    polygonAttrEditor = new PolygonAttributesEditor(polygonAttr);

    // Rendering attributes
    renderAttr = new RenderingAttributes(renderDepthBuffer, renderDepthBufferWrite, 0.0f,
            RenderingAttributes.ALWAYS, renderVisible, renderIgnoreVertexColor, renderRasterOpEnable,
            renderRasterOp);/* www .j  a  va  2  s . com*/
    renderAttr.setCapability(RenderingAttributes.ALLOW_IGNORE_VERTEX_COLORS_WRITE);
    renderAttr.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE);
    renderAttr.setCapability(RenderingAttributes.ALLOW_RASTER_OP_WRITE);
    renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_FUNCTION_WRITE);
    renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_VALUE_WRITE);
    appearance.setRenderingAttributes(renderAttr);
    appearance.setCapability(Appearance.ALLOW_RENDERING_ATTRIBUTES_WRITE);

    // set up the editor
    renderAttrEditor = new RenderingAttributesEditor(renderAttr);

    // TransparencyAttributes
    transpAttr = new TransparencyAttributes(transpMode, transpValue);
    transpAttr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transpAttr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
    transpAttr.setCapability(TransparencyAttributes.ALLOW_BLEND_FUNCTION_WRITE);
    appearance.setTransparencyAttributes(transpAttr);

    // set up the editor
    transpAttrEditor = new TransparencyAttributesEditor(transpAttr);

    // Material
    material = new Material(red, black, red, white, 20.f);
    material.setLightingEnable(false);
    material.setCapability(Material.ALLOW_COMPONENT_WRITE);
    appearance.setMaterial(material);

    // material presets
    String[] materialNames = { "Red", "White", "Red Ambient", "Red Diffuse", "Grey Emissive", "White Specular",
            "Aluminium", "Blue Plastic", "Copper", "Gold", "Red Alloy", "Black Onyx" };
    Material[] materialPresets = new Material[materialNames.length];
    materialPresets[0] = new Material(red, black, red, white, 20.0f);
    materialPresets[1] = new Material(white, black, white, white, 20.0f);
    materialPresets[2] = new Material(red, black, black, black, 20.0f);
    materialPresets[3] = new Material(black, black, red, black, 20.0f);
    materialPresets[4] = new Material(black, grey, black, black, 20.0f);
    materialPresets[5] = new Material(black, black, black, white, 20.0f);
    Color3f alum = new Color3f(0.37f, 0.37f, 0.37f);
    Color3f alumSpec = new Color3f(0.89f, 0.89f, 0.89f);
    materialPresets[6] = new Material(alum, black, alum, alumSpec, 17);
    Color3f bluePlastic = new Color3f(0.20f, 0.20f, 0.70f);
    Color3f bluePlasticSpec = new Color3f(0.85f, 0.85f, 0.85f);
    materialPresets[7] = new Material(bluePlastic, black, bluePlastic, bluePlasticSpec, 22);
    Color3f copper = new Color3f(0.30f, 0.10f, 0.00f);
    ;
    Color3f copperSpec = new Color3f(0.75f, 0.30f, 0.00f);
    materialPresets[8] = new Material(copper, black, copper, copperSpec, 10);
    Color3f gold = new Color3f(0.49f, 0.34f, 0.00f);
    Color3f goldSpec = new Color3f(0.89f, 0.79f, 0.00f);
    materialPresets[9] = new Material(gold, black, gold, goldSpec, 15);
    Color3f redAlloy = new Color3f(0.34f, 0.00f, 0.34f);
    Color3f redAlloySpec = new Color3f(0.84f, 0.00f, 0.00f);
    materialPresets[10] = new Material(redAlloy, black, redAlloy, redAlloySpec, 15);
    Color3f blackOnyxSpec = new Color3f(0.72f, 0.72f, 0.72f);
    materialPresets[11] = new Material(black, black, black, blackOnyxSpec, 23);

    // set up the editor
    materialEditor = new MaterialPresetEditor(material, materialNames, materialPresets);

    // Texture2D

    // set the values to the defaults
    texEnable = false;
    texMipMapMode = Texture.BASE_LEVEL;
    texBoundaryModeS = Texture.WRAP;
    texBoundaryModeT = Texture.WRAP;
    texMinFilter = Texture.BASE_LEVEL_POINT;
    texMagFilter = Texture.BASE_LEVEL_POINT;
    texBoundaryColor = new Color4f(0.0f, 0.0f, 0.0f, 0.0f);

    // set up the image choices
    String[] texImageNames = { "Earth", "Fish", };
    String[] texImageFileNames = { "earth.jpg", "fish1.gif", };
    int texImageFileIndex = 0;

    // set up the appearance to allow the texture to be changed
    appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    // set up the editor (this will create the initial Texture2D and
    // assign it to the appearance)
    texture2DEditor = new Texture2DEditor(appearance, codeBaseString, texImageNames, texImageFileNames,
            texImageFileIndex, texEnable, texBoundaryModeS, texBoundaryModeT, texMinFilter, texMagFilter,
            texMipMapMode, texBoundaryColor);

    // TextureAttributes
    texMode = TextureAttributes.REPLACE;
    texBlendColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f);
    texTransform = new Transform3D();
    texPerspCorrect = TextureAttributes.NICEST;
    textureAttr = new TextureAttributes(texMode, texTransform, texBlendColor, texPerspCorrect);

    // set the capabilities to allow run time changes
    textureAttr.setCapability(TextureAttributes.ALLOW_MODE_WRITE);
    textureAttr.setCapability(TextureAttributes.ALLOW_BLEND_COLOR_WRITE);
    textureAttr.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE);

    // connect it to the appearance
    appearance.setTextureAttributes(textureAttr);

    // setup the editor
    textureAttrEditor = new TextureAttributesEditor(textureAttr);

    // set up the tex coordinate generation
    texGenEnable = false;
    texGenMode = TexCoordGeneration.OBJECT_LINEAR;
    texGenPlaneS = new Vector4f(1.0f, 0.0f, 0.0f, 0.0f);
    texGenPlaneT = new Vector4f(0.0f, 1.0f, 0.0f, 0.0f);

    // set the appearance so that we can replace the tex gen when live
    appearance.setCapability(Appearance.ALLOW_TEXGEN_WRITE);

    // setup the editor
    texGenEditor = new TexCoordGenerationEditor(appearance, texGenEnable, texGenMode, texGenPlaneS,
            texGenPlaneT);

}

From source file:BehaviorTest.java

public WakeupCondition restart(Shape3D shape3D, int nElapsedTime, int nNumFrames, ExplosionListener listener) {
    System.out.println("Will explode after: " + nElapsedTime / 1000 + " secs.");

    m_Shape3D = shape3D;/*from   www.  j  av  a2 s. co  m*/
    m_nElapsedTime = nElapsedTime;
    m_nNumFrames = nNumFrames;
    m_nFrameNumber = 0;

    // create the WakeupCriterion for the behavior
    m_InitialWakeupCondition = new WakeupOnElapsedTime(m_nElapsedTime);

    m_Listener = listener;

    // save the GeometryArray that we are modifying
    m_GeometryArray = (GeometryArray) m_Shape3D.getGeometry();

    if (m_Shape3D.isLive() == false && m_Shape3D.isCompiled() == false) {
        // set the capability bits that the behavior requires
        m_Shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
        m_Shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_POINT_ATTRIBUTES_WRITE);
        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE);
        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_TEXTURE_WRITE);

        m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
        m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
        m_GeometryArray.setCapability(GeometryArray.ALLOW_COUNT_READ);
    }

    // make a copy of the object's original appearance
    m_Appearance = new Appearance();
    m_Appearance = (Appearance) m_Shape3D.getAppearance().cloneNodeComponent(true);

    // allocate an array for the model coordinates
    m_CoordinateArray = new float[3 * m_GeometryArray.getVertexCount()];

    // make a copy of the models original coordinates
    m_OriginalCoordinateArray = new float[3 * m_GeometryArray.getVertexCount()];
    m_GeometryArray.getCoordinates(0, m_OriginalCoordinateArray);

    // start (or restart) the behavior
    setEnable(true);

    return m_InitialWakeupCondition;
}

From source file:AppearanceTest.java

protected void setAppearanceCapability() {
    m_Appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
}