// file: TexturedTiLogo.java //package j3dvisual.examples.tilogo; // generated automatically by j3dvisual // adapted by Jan Köhnlein // import statements import javax.media.j3d.GraphicsConfigTemplate3D; import java.awt.GraphicsEnvironment; import java.awt.GraphicsDevice; import java.awt.GraphicsConfiguration; import javax.vecmath.Color3f; import javax.media.j3d.AmbientLight; import javax.vecmath.Vector3f; import javax.media.j3d.DirectionalLight; import javax.media.j3d.Alpha; import javax.media.j3d.RotationInterpolator; import javax.media.j3d.Transform3D; import javax.media.j3d.TransformGroup; import com.sun.j3d.utils.behaviors.mouse.MouseRotate; import javax.media.j3d.Material; import java.net.URL; import com.sun.j3d.utils.image.TextureLoader; import javax.media.j3d.Texture; import javax.media.j3d.TextureAttributes; import javax.media.j3d.Appearance; import com.sun.j3d.utils.geometry.Cylinder; import com.sun.j3d.utils.geometry.Sphere; import javax.vecmath.Point3d; import javax.media.j3d.BoundingSphere; import com.sun.j3d.utils.geometry.Cone; import javax.media.j3d.BranchGroup; import javax.media.j3d.Locale; import com.sun.j3d.utils.universe.ViewingPlatform; import com.sun.j3d.utils.universe.SimpleUniverse; import javax.media.j3d.Canvas3D; import java.awt.Container; import javax.swing.JFrame; import com.sun.j3d.utils.applet.MainFrame; import java.applet.Applet; import java.awt.BorderLayout; public class TexturedTiLogo extends Applet { public TexturedTiLogo() { try { GraphicsConfigTemplate3D defaultGraphicsConfigTemplate3D = new GraphicsConfigTemplate3D(); GraphicsEnvironment defaultGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultGraphicsDevice = defaultGraphicsEnvironment.getDefaultScreenDevice(); GraphicsConfiguration defaultGraphicsConfiguration = defaultGraphicsDevice.getBestConfiguration( defaultGraphicsConfigTemplate3D ); Color3f aLightColour = new Color3f( 0.9f, 0.9f, 0.9f ); AmbientLight aLight = new AmbientLight( aLightColour ); Color3f dLightColour = new Color3f( 1f, 1f, 1f ); Vector3f dLightDirection = new Vector3f( 0f, 1f, -2f ); DirectionalLight dLight = new DirectionalLight( dLightColour, dLightDirection ); Alpha lightRotatorAlpha = new Alpha( -1, 2000 ); Vector3f dLight2Direction = new Vector3f( -1f, -1f, 1f ); DirectionalLight dLight2 = new DirectionalLight(); dLight2.setDirection( dLight2Direction ); Transform3D lightTrafo2Matrix = new Transform3D(); lightTrafo2Matrix.rotZ( 1.54 ); TransformGroup lightTrafo2 = new TransformGroup( lightTrafo2Matrix ); lightTrafo2.addChild( dLight2 ); TransformGroup lightTrafo = new TransformGroup(); lightTrafo.addChild( dLight ); lightTrafo.setCapability( 18 ); lightTrafo.addChild( lightTrafo2 ); RotationInterpolator lightRotator = new RotationInterpolator( lightRotatorAlpha, lightTrafo ); lightTrafo.addChild( lightRotator ); Transform3D rootTrafoMatrix = new Transform3D(); rootTrafoMatrix.setScale( 0.5 ); Material iCylinderMaterial = new Material(); iCylinderMaterial.setAmbientColor( 0.2f, 0.2f, 0f ); iCylinderMaterial.setSpecularColor( 0.8f, 0.8f, 0f ); URL iCylinderTextureURL = new URL( "http://www.tu-harburg.de/parallel/koehnlein/java/images/eroding_sandstone.jpg" ); TextureAttributes textureAttributes = new TextureAttributes(); textureAttributes.setTextureMode( TextureAttributes.MODULATE ); Appearance iCylinderAppearance = new Appearance(); iCylinderAppearance.setCapability( 3 ); iCylinderAppearance.setMaterial( iCylinderMaterial ); iCylinderAppearance.setTextureAttributes( textureAttributes ); Cylinder iCylinder = new Cylinder( 0.3f, 1.2f, 3, iCylinderAppearance ); Vector3f iCylinderTrafoTranslation = new Vector3f( 0f, -0.15f, 0f ); Transform3D iCylinderTrafoMatrix = new Transform3D(); iCylinderTrafoMatrix.setTranslation( iCylinderTrafoTranslation ); TransformGroup iCylinderTrafo = new TransformGroup(); iCylinderTrafo.setTransform( iCylinderTrafoMatrix ); iCylinderTrafo.addChild( iCylinder ); Material iSphereMaterial = new Material(); iSphereMaterial.setSpecularColor( 0f, 0.8f, 0f ); iSphereMaterial.setAmbientColor( 0f, 0.2f, 0f ); URL iSphereTextureURL = new URL( "http://www.tu-harburg.de/parallel/koehnlein/java/images/gremlin_buds.jpg" ); Appearance iSphereAppearance = new Appearance(); iSphereAppearance.setCapability( 3 ); iSphereAppearance.setMaterial( iSphereMaterial ); iSphereAppearance.setTextureAttributes( textureAttributes ); Sphere iSphere = new Sphere( 0.3f, 3, iSphereAppearance ); Vector3f iSphereTrafoTranslation = new Vector3f( 0f, 1f, 0f ); Transform3D iSphereTrafoMatrix = new Transform3D(); iSphereTrafoMatrix.setTranslation( iSphereTrafoTranslation ); TransformGroup iSphereTrafo = new TransformGroup( iSphereTrafoMatrix ); iSphereTrafo.addChild( iSphere ); Vector3f iTrafoTranslation = new Vector3f( 0.9f, 0f, 0f ); Transform3D iTrafoMatrix = new Transform3D(); iTrafoMatrix.setTranslation( iTrafoTranslation ); TransformGroup iTrafo = new TransformGroup(); iTrafo.setTransform( iTrafoMatrix ); iTrafo.addChild( iCylinderTrafo ); iTrafo.addChild( iSphereTrafo ); Point3d boundsCenter = new Point3d(); BoundingSphere bounds = new BoundingSphere( boundsCenter, 100 ); aLight.setInfluencingBounds( bounds ); dLight2.setInfluencingBounds( bounds ); dLight.setInfluencingBounds( bounds ); lightRotator.setSchedulingBounds( bounds ); Alpha rotatorAlpha = new Alpha( -1, 8000 ); Material tConeMaterial = new Material(); tConeMaterial.setAmbientColor( 0.2f, 0f, 0f ); tConeMaterial.setSpecularColor( 0.8f, 0f, 0f ); URL tConeTextureURL = new URL( "http://www.tu-harburg.de/parallel/koehnlein/java/images/abstract_clay.jpg" ); Appearance tConeAppearance = new Appearance(); tConeAppearance.setCapability( 3 ); tConeAppearance.setMaterial( tConeMaterial ); tConeAppearance.setTextureAttributes( textureAttributes ); Cone tCone = new Cone( 0.6f, 2f, 3, tConeAppearance ); tCone.setAppearance( tConeAppearance ); Vector3f tConeTrafoTranslation = new Vector3f( 0f, 0.25f, 0f ); Transform3D tConeTrafoMatrix = new Transform3D(); tConeTrafoMatrix.setTranslation( tConeTrafoTranslation ); TransformGroup tConeTrafo = new TransformGroup(); tConeTrafo.addChild( tCone ); tConeTrafo.setTransform( tConeTrafoMatrix ); Material tTorusMaterial = new Material(); tTorusMaterial.setAmbientColor( 0f, 0f, 0.2f ); tTorusMaterial.setSpecularColor( 0f, 0f, 0.8f ); URL tTorusTextureURL = new URL( "http://www.tu-harburg.de/parallel/koehnlein/java/images/freon_mist.jpg" ); Appearance tTorusAppearance = new Appearance(); tTorusAppearance.setCapability( 3 ); tTorusAppearance.setMaterial( tTorusMaterial ); tTorusAppearance.setTextureAttributes( textureAttributes ); Torus tTorus = new Torus(); tTorus.setAppearance( tTorusAppearance ); Vector3f tTorusTrafoTranslation = new Vector3f( 0f, 1f, 0f ); Transform3D tTorusTrafoMatrix = new Transform3D(); tTorusTrafoMatrix.rotX( 1.54 ); tTorusTrafoMatrix.setTranslation( tTorusTrafoTranslation ); TransformGroup tTorusTrafo = new TransformGroup( tTorusTrafoMatrix ); tTorusTrafo.addChild( tTorus ); Vector3f tTrafoTranslation = new Vector3f( -0.9f, 0f, 0f ); Transform3D tTrafoMatrix = new Transform3D(); tTrafoMatrix.setTranslation( tTrafoTranslation ); TransformGroup tTrafo = new TransformGroup( tTrafoMatrix ); tTrafo.setCapability( 18 ); tTrafo.addChild( tConeTrafo ); tTrafo.addChild( tTorusTrafo ); TransformGroup rotatorTrafo = new TransformGroup(); rotatorTrafo.addChild( iTrafo ); rotatorTrafo.addChild( tTrafo ); rotatorTrafo.setCapability( 18 ); RotationInterpolator rotator = new RotationInterpolator( rotatorAlpha, rotatorTrafo ); rotatorTrafo.addChild( rotator ); rotator.setSchedulingBounds( bounds ); TransformGroup rootTrafo = new TransformGroup( rootTrafoMatrix ); rootTrafo.setCapability( 17 ); rootTrafo.setCapability( 18 ); rootTrafo.addChild( rotatorTrafo ); rootTrafo.addChild( lightTrafo ); MouseRotate mouseRotator = new MouseRotate( rootTrafo ); rootTrafo.addChild( mouseRotator ); mouseRotator.setSchedulingBounds( bounds ); BranchGroup defaultBranchGroup = new BranchGroup(); defaultBranchGroup.addChild( rootTrafo ); defaultBranchGroup.addChild( aLight ); Canvas3D defaultCanvas3d = new Canvas3D( SimpleUniverse.getPreferredConfiguration() ); SimpleUniverse defaultSimpleUniverse = new SimpleUniverse( defaultCanvas3d ); ViewingPlatform defaultViewingPlatform = defaultSimpleUniverse.getViewingPlatform(); defaultViewingPlatform.setNominalViewingTransform(); defaultSimpleUniverse.addBranchGraph( defaultBranchGroup ); TextureLoader iCylinderTextureLoader = new TextureLoader( iCylinderTextureURL, "RGB", this ); TextureLoader iSphereTextureLoader = new TextureLoader( iSphereTextureURL, "RGB", this ); Texture iCylinderTexture = iCylinderTextureLoader.getTexture(); Texture iSphereTexture = iSphereTextureLoader.getTexture(); iSphereAppearance.setTexture( iSphereTexture ); // Container defaultContentPane = this.getContentPane(); setLayout(new BorderLayout()); add( defaultCanvas3d ); TextureLoader tTorusTextureLoader = new TextureLoader( tTorusTextureURL, "RGB", this ); TextureLoader tConeTextureLoader = new TextureLoader( tConeTextureURL, "RGB", this ); iCylinderAppearance.setTexture( iCylinderTexture ); Texture tTorusTexture = tTorusTextureLoader.getTexture(); tTorusAppearance.setTexture( tTorusTexture ); Texture tConeTexture = tConeTextureLoader.getTexture(); tConeAppearance.setTexture( tConeTexture ); } catch ( Throwable exception ) { exception.printStackTrace(); } } public static void main( String[] args ) { new MainFrame(new TexturedTiLogo(), 400,400); } } /* end class TexturedTiLogo */