I need to texture mapping some text such as "C A R" to a sphere. First I create a text2D object then I use TextCoordGeneration. The problem is the text is textured to the metaball properly, but there is also a reflection of the text is also textured. I use OBJECT_LINEAR. I can't figure it out. I attach all my program below. Thank you very very much if you can help me.
import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.media.j3d.*; import javax.vecmath.*; import java.awt.BorderLayout; import java.awt.Frame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior; import com.sun.j3d.utils.behaviors.keyboard.*; import com.sun.j3d.utils.universe.PlatformGeometry; import java.awt.event.KeyEvent; import com.sun.j3d.utils.geometry.Text2D; import java.awt.Font; import javax.vecmath.Vector3f; public class sphere { static Sphere createMetaball(){ String result = " C A R "; Text2D text2d = new Text2D(result, new Color3f(0.9f, 1.0f, 1.0f), "Courier", 12, Font.BOLD); text2d.setString(result); text2d.setCapability( Shape3D.ALLOW_GEOMETRY_READ); text2d.setCapability( Shape3D.ALLOW_GEOMETRY_WRITE); text2d.setRectangleScaleFactor(1.0f / 256.0f); text2d.setString(result); Appearance appearance = text2d.getAppearance(); TexCoordGeneration tcg = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,TexCoordGeneration.TEXTURE_COORDINATE_2); tcg.setEnable( true ); appearance.setTexCoordGeneration(tcg); appearance.getTexture().setBoundaryModeS(Texture.CLAMP_TO_BOUNDARY); appearance.getTexture().setBoundaryModeT(Texture.CLAMP_TO_BOUNDARY); PolygonAttributes pa1 = new PolygonAttributes(); pa1.setPolygonMode( PolygonAttributes.POLYGON_FILL); pa1.setCullFace(PolygonAttributes.CULL_BACK); //pa1.setBackFaceNormalFlip( true ); appearance.setPolygonAttributes( pa1 ); TextureAttributes texturemode = new TextureAttributes(); texturemode.setTextureMode(TextureAttributes.DECAL); texturemode.setPerspectiveCorrectionMode(TextureAttributes.NICEST); appearance.setTextureAttributes(texturemode); // set material Material material = new Material(); // lighting attributes material.setShininess(50.0f); // add by ldu material.setAmbientColor( new Color3f( 0.2f, 0.0f, 0.0f ) ); material.setDiffuseColor( new Color3f( 0.0f, 0.0f, 0.7f ) ); material.setLightingEnable( true ); appearance.setMaterial( material); TransparencyAttributes transparencyAttributes = new TransparencyAttributes(); transparencyAttributes.setTransparencyMode(TransparencyAttributes.NONE); transparencyAttributes.setTransparency(0.0f); appearance.setTransparencyAttributes(transparencyAttributes); Sphere sphere = new Sphere(3.0f); // ball.setGeometry(gi.getGeometryArray()); sphere.setAppearance(appearance); return sphere; } public static void main( String[] args ) { // Build the canvas GraphicsConfigTemplate3D tmpl = new GraphicsConfigTemplate3D( ); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = env.getDefaultScreenDevice(); GraphicsConfiguration config = device.getBestConfiguration(tmpl); Canvas3D canvas = new Canvas3D( config ); // Build the view PhysicalBody body = new PhysicalBody( ); PhysicalEnvironment environment = new PhysicalEnvironment(); View view = new View(); view.addCanvas3D( canvas ); view.setPhysicalBody( body ); view.setPhysicalEnvironment( environment ); // create the universe VirtualUniverse universe = new VirtualUniverse( ); Locale locale = new Locale( universe ); // Create the view branch BranchGroup viewRoot = new BranchGroup( ); TransformGroup viewTransform = new TransformGroup( ); viewTransform.setCapability( TransformGroup.ALLOW_TRANSFORM_READ ); viewTransform.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE ); Transform3D transform = new Transform3D( ); transform.set( new Vector3d( 0, 0, 15 ) ); viewTransform.setTransform( transform ); ViewPlatform vp = new ViewPlatform( ); vp.setCapability(ViewPlatform.ALLOW_POLICY_READ); vp.setCapability(ViewPlatform.ALLOW_POLICY_WRITE); vp.setViewAttachPolicy(View.NOMINAL_HEAD); view.attachViewPlatform( vp ); viewTransform.addChild( vp ); viewRoot.addChild( viewTransform ); viewRoot.compile( ); locale.addBranchGraph( viewRoot ); BranchGroup objectRoot = new BranchGroup( ); TransformGroup objectTransform = new TransformGroup( ); //TransformGroup objectTransform2 = new TransformGroup( ); transform.set( new Vector3d( 0, 0, 0 ) ); //transform.rotX(Math.PI/4.0d); objectTransform.setTransform( transform ); objectTransform.setCapability( TransformGroup.ALLOW_TRANSFORM_READ ); objectTransform.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE ); objectRoot.addChild(objectTransform); objectTransform.addChild(createMetaball()); Alpha rotationAlpha = new Alpha(-1, 50000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objectTransform); // a bounding sphere specifies a region a behavior is active // create a sphere centered at the origin with radius of 1 BoundingSphere bounds = new BoundingSphere(); rotator.setSchedulingBounds(bounds); objectTransform.addChild(rotator); // add KeyNavigatorBehavior KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(viewTransform); keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(),1000.0)); keyNavBeh.setEnable( true ); objectRoot.addChild(keyNavBeh); // Create the light AmbientLight ambLight = new AmbientLight(new Color3f(1.0f,1.0f,1.0f) ); ambLight.setInfluencingBounds(new BoundingSphere(new Point3d( 0.0, 0.0, 0.0),1000)); objectRoot.addChild(ambLight); DirectionalLight dirLight = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f ),new Vector3f( -1.0f, -1.0f, -1.0f ) ); dirLight.setInfluencingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0),1000.0)); objectRoot.addChild(dirLight); objectRoot.compile( ); locale.addBranchGraph(objectRoot); // Create the UI javax.swing.JFrame frame = new javax.swing.JFrame( "Metaball Universe"); frame.getContentPane( ).setLayout( new java.awt.BorderLayout( ) ); frame.getContentPane( ).add( canvas, "Center" ); //frame.addKeyListener(java.awt.event.KeyListener); frame.setSize( new java.awt.Dimension( 300, 300 ) ); frame.addWindowListener( new java.awt.event.WindowAdapter( ) { public void windowClosing( java.awt.event.WindowEvent e ) { System.exit( 0 ); } } ); frame.setVisible( true ); } } =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".