List of usage examples for javax.media.j3d TexCoordGeneration OBJECT_LINEAR
int OBJECT_LINEAR
To view the source code for javax.media.j3d TexCoordGeneration OBJECT_LINEAR.
Click Source Link
From source file:SimpleTextureGen.java
/** * This defines the appearance for the shape using a texture. It uses a * TextureLoader to load the texture image from an external file and a * TexCoordGeneration to define the texture coordinates. * /*ww w.j av a2 s.c om*/ * @return Appearance that uses a texture. */ protected Appearance DefineAppearance() { //This is used to automatically define the texture coordinates. //The coordinates are generated in object coordinates, but by //commented out the line with 'OBJECT_LINEAR' and uncommenting //the line 'EYE_LINEAR' the program will use eye coordinates. TexCoordGeneration textCoorder = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, //TexCoordGeneration.EYE_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_2); //Load the texture from the external image file TextureLoader textLoad = new TextureLoader("housebrick.jpg", this); //Access the image from the loaded texture ImageComponent2D textImage = textLoad.getImage(); //Create a two dimensional texture Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture.RGB, textImage.getWidth(), textImage.getHeight()); //Set the texture from the image loaded texture.setImage(0, textImage); //Create the appearance that will use the texture Appearance app = new Appearance(); app.setTexture(texture); //Pass the coordinate generator to the appearance app.setTexCoordGeneration(textCoorder); //Define how the texture will be mapped onto the surface //by creating the appropriate texture attributes TextureAttributes textAttr = new TextureAttributes(); textAttr.setTextureMode(TextureAttributes.REPLACE); app.setTextureAttributes(textAttr); app.setMaterial(new Material()); return app; }
From source file:TexCoordTest.java
public void actionPerformed(ActionEvent event) { if (event.getActionCommand().equals("EYE_LINEAR") != false) m_TexGen.setGenMode(TexCoordGeneration.EYE_LINEAR); else if (event.getActionCommand().equals("OBJECT_LINEAR") != false) m_TexGen.setGenMode(TexCoordGeneration.OBJECT_LINEAR); else if (event.getActionCommand().equals("SPHERE_MAP") != false) m_TexGen.setGenMode(TexCoordGeneration.SPHERE_MAP); else if (event.getActionCommand().equals("Rotate") != false) m_RotationInterpolator.setEnable(!m_RotationInterpolator.getEnable()); else if (event.getActionCommand().equals("Translate") != false) m_PositionInterpolator.setEnable(!m_PositionInterpolator.getEnable()); // apply any changes to the TexCoordGeneration and copy into the // appearance TexCoordGeneration texCoordGeneration = new TexCoordGeneration(); texCoordGeneration = (TexCoordGeneration) m_TexGen.cloneNodeComponent(true); m_Appearance.setTexCoordGeneration(texCoordGeneration); }
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);// w w w .j a v a 2s. co m // 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: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);//from w w w .java 2 s . c om 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:AppearanceTest.java
protected NodeComponent createComponent() { return (NodeComponent) new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_3); }
From source file:AppearanceTest.java
public void onOBJECT_LINEAR() { getTexCoordGeneration().setGenMode(TexCoordGeneration.OBJECT_LINEAR); assignToAppearance(); }
From source file:AppearanceExplorer.java
TexCoordGenerationEditor(Appearance initApp, boolean initEnable, int initMode, Vector4f initPlaneS, Vector4f initPlaneT) {//from w ww .java 2 s.c o m super(BoxLayout.Y_AXIS); app = initApp; enable = initEnable; mode = initMode; planeS.set(initPlaneS); planeT.set(initPlaneT); setTexGen(); // set up the initial texGen JCheckBox enableCheckBox = new JCheckBox("Enable Tex Coord Gen"); enableCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { enable = ((JCheckBox) e.getSource()).isSelected(); texGen.setEnable(enable); } }); add(new LeftAlignComponent(enableCheckBox)); // texture boundaries String[] modeNames = { "OBJECT_LINEAR", "EYE_LINEAR", "SPHERE_MAP", }; int[] modeValues = { TexCoordGeneration.OBJECT_LINEAR, TexCoordGeneration.EYE_LINEAR, TexCoordGeneration.SPHERE_MAP, }; // tex gen modes IntChooser modeChooser = new IntChooser("Generation Mode:", modeNames, modeValues); modeChooser.setValue(mode); modeChooser.addIntListener(new IntListener() { public void intChanged(IntEvent event) { int value = event.getValue(); mode = value; setTexGen(); } }); add(modeChooser); // make a panel for both sets of sliders and then two sub-panels, // one for each group of sliders Box sliderPanel = new Box(BoxLayout.Y_AXIS); add(sliderPanel); Box planeSPanel = new Box(BoxLayout.Y_AXIS); Box planeTPanel = new Box(BoxLayout.Y_AXIS); sliderPanel.add(planeSPanel); sliderPanel.add(planeTPanel); planeSPanel.add(new LeftAlignComponent(new JLabel("Plane S:"))); FloatLabelJSlider planeSxSlider = new FloatLabelJSlider("X:", 0.1f, -10.0f, 10.0f, planeS.x); planeSxSlider.setMajorTickSpacing(0.1f); planeSxSlider.setPaintTicks(true); planeSxSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { planeS.x = e.getValue(); setTexGen(); } }); planeSPanel.add(planeSxSlider); FloatLabelJSlider planeSySlider = new FloatLabelJSlider("Y:", 0.1f, -10.0f, 10.0f, planeS.y); planeSySlider.setMajorTickSpacing(0.1f); planeSySlider.setPaintTicks(true); planeSySlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { planeS.y = e.getValue(); setTexGen(); } }); planeSPanel.add(planeSySlider); FloatLabelJSlider planeSzSlider = new FloatLabelJSlider("Z:", 0.1f, -10.0f, 10.0f, planeS.z); planeSzSlider.setMajorTickSpacing(0.1f); planeSzSlider.setPaintTicks(true); planeSzSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { planeS.z = e.getValue(); setTexGen(); } }); planeSPanel.add(planeSzSlider); FloatLabelJSlider planeSwSlider = new FloatLabelJSlider("W:", 0.1f, -10.0f, 10.0f, planeS.w); planeSwSlider.setMajorTickSpacing(0.1f); planeSwSlider.setPaintTicks(true); planeSwSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { planeS.w = e.getValue(); setTexGen(); } }); planeSPanel.add(planeSwSlider); planeSPanel.add(new LeftAlignComponent(new JLabel("Plane T:"))); FloatLabelJSlider planeTxSlider = new FloatLabelJSlider("X:", 0.1f, -10.0f, 10.0f, planeT.x); planeTxSlider.setMajorTickSpacing(0.1f); planeTxSlider.setPaintTicks(true); planeTxSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { planeT.x = e.getValue(); setTexGen(); } }); planeTPanel.add(planeTxSlider); FloatLabelJSlider planeTySlider = new FloatLabelJSlider("Y:", 0.1f, -10.0f, 10.0f, planeT.y); planeTySlider.setMajorTickSpacing(0.1f); planeTySlider.setPaintTicks(true); planeTySlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { planeT.y = e.getValue(); setTexGen(); } }); planeTPanel.add(planeTySlider); FloatLabelJSlider planeTzSlider = new FloatLabelJSlider("Z:", 0.1f, -10.0f, 10.0f, planeT.z); planeTzSlider.setMajorTickSpacing(0.1f); planeTzSlider.setPaintTicks(true); planeTzSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { planeT.z = e.getValue(); setTexGen(); } }); planeTPanel.add(planeTzSlider); FloatLabelJSlider planeTwSlider = new FloatLabelJSlider("W:", 0.1f, -10.0f, 10.0f, planeT.w); planeTwSlider.setMajorTickSpacing(0.1f); planeTwSlider.setPaintTicks(true); planeTwSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { planeT.w = e.getValue(); setTexGen(); } }); planeTPanel.add(planeTwSlider); }