Texturing in Java3d

Hi All,
I am trying to build a java 3d model of a cricket field. For this I will need to texture the strip area (a brown colour) a different texture than the rest of the field.
At present I have tried to create a thin cylinders and a thin box. The cylinder for the overall area of the area of the field and thr box for the cricket strip. And place one inside the other, however this doesn't give the right effect.
How can I either texture a small area of the field a different texture to represent the pitch, or make one shape take priority over the other one in terms of what is viewed if they are at the same location.
Adam

No I don't have to do anything with the pitch texture, just needs to sit there and look pretty.
I am a real newbie to java 3d, so you said draw it onto the the texture. Do you mean create a massive texture that is mostly made of the grass and then a bit of it of the pitch??? I thought one was suppose to take small textures and let java3d copy them onto the much bigger surface?
As for the shape slightly above the surface, firstly I have tried that and it didn't work very well, and secondly the pitch must be the same level as the outfield!
An example link or a bit of example code would be much appreciated, as I know very little about all of this at the moment.
Adam

Similar Messages

  • Loading a jpg image into my java 3d scene

    public class Example3D extends JApplet {
        public BranchGroup createSceneGraph() {
         // creating the universe
         BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
         BranchGroup objRoot = new BranchGroup();
         TransformGroup mainTG = new TransformGroup();          
         mainTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
         mainTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
         // Now you can add new elements to the mainTG
         ColorCube c2 = new ColorCube(.1);
         mainTG.addChild(c2);
         objRoot.addChild(mainTG);
         // Create the rotate behavior node
         MouseRotate behavior = new MouseRotate();
         behavior.setTransformGroup(mainTG);
         objRoot.addChild(behavior);
         behavior.setSchedulingBounds(bounds);
         // Create the zoom behavior node
         MouseZoom behavior2 = new MouseZoom();
         behavior2.setTransformGroup(mainTG);
         objRoot.addChild(behavior2);
         behavior2.setSchedulingBounds(bounds);
         // Create the translate behavior node
          MouseTranslate behavior3 = new MouseTranslate();
         behavior3.setTransformGroup(mainTG);
         objRoot.addChild(behavior3);
         behavior3.setSchedulingBounds(bounds);
         objRoot.compile();
         return objRoot;
        public Example3D() {
         Container cp = getContentPane();
         cp.setLayout(new BorderLayout());
         Canvas3D c = new Canvas3D(SimpleUniverse.
                          getPreferredConfiguration() );
         cp.add("Center", c);
         BranchGroup scene = createSceneGraph();
         SimpleUniverse u = new SimpleUniverse(c);
         u.getViewingPlatform().setNominalViewingTransform();
         u.addBranchGraph(scene);
        public static void main(String[] args) {       
         new MainFrame(new Example3D(), 512, 512);
    }as a test, i added a cube into the scene and it works fine. but i also want to add a 2d jpg image into the scene too, its called flatTable.jpg
    i hope someone can help me, thanks guys.

    Check out this link:
    http://java3d.j3d.org/tutorials/raw_j3d/chapter1/textures.html
    It should give you enough information about loading textures with java3d.

  • Building a house... need help on design!

    Hi! I'm kind of new to Java3D, and I'm sure someone asked this in this forum alread,y but...what the heck.
    I have a project in school where we need to make a model of a house, and allow the user to navigate through it. I know that I'll be using KeyNavigator here; I got that part already. But I AM having trouble with the whole designing part altogether. The house I'm making is rather detailed (as in I have to include the chairs, tables, bookshelves, posters, etc.). Some of the items need to be clickable, as well.
    I already made walls, and I can navigate through the room, but now that I'm putting textures in (and textures in almost each wall need to be different), I'm having trouble! And don't know how to make irregularly-shaped things... Can anyone help me? Like, can someone show me code of even a small room, with (preferably clickable) objects lying around and each wall having posters and stuff on them? Or even programs that can help me? I'm using JCreator now, which, of course, everyone knows, is originally for plain ol' Java.
    Oh, and I have no idea how to keep the user from going through walls...
    I need to finish this by mid-February, and I'm about ready to tear my hair out. I've got tutorials here...but I'm stuck. Maybe I just didn't explore the API enough, but...ARGH. I'm still stuck.
    If you can help me (or even point me to a tutorial that can quickly help me) I will love you forever. Thanks!

    http://dmoz.org/Computers/Software/Graphics/3D/Models/
    might be a good resource
    http://escience.anu.edu.au/lecture/cg/TextureJ3D/printNotes.en.html
    is a tute on texturing
    http://java3d.j3d.org/implementation/collision.html
    are tutes on collisions
    here is code to make a textured plane, you pass the path to the texture in the constructor.
    *      @(#)TexturedPlane.java 1.0 99/08/02 16:06:00
    * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
    * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
    * modify and redistribute this software in source and binary code form,
    * provided that i) this copyright notice and license appear on all copies of
    * the software; and ii) Licensee does not utilize the software in a manner
    * which is disparaging to Sun.
    * This software is provided "AS IS," without a warranty of any kind. ALL
    * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
    * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
    * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
    * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
    * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
    * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
    * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
    * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
    * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
    * POSSIBILITY OF SUCH DAMAGES.
    * This software is not designed or intended for use in on-line control of
    * aircraft, air traffic, aircraft navigation or aircraft communications; or in
    * the design, construction, operation or maintenance of any nuclear
    * facility. Licensee represents and warrants that it will not use or
    * redistribute the Software for such purposes.
       A class to create a simple textured plane.
    import com.sun.j3d.utils.image.TextureLoader;
    import NewTextureLoader;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    * TexturedPlane creates a single plane with texture mapping.
      public class TexturedPlane extends Shape3D {
        TexturedPlane(String filename) {
            if (NewTextureLoader.getImageObserver() == null)
                System.out.println("call NewTextureLoader.setImageObserver()");
            this.setGeometry(createGeometry());
            if(filename != "")
                    this.setAppearance(createAppearance(filename));
        Geometry createGeometry(){
            QuadArray plane = new QuadArray(4, GeometryArray.COORDINATES
                                               | GeometryArray.TEXTURE_COORDINATE_2
            Point3f p = new Point3f(-1.0f,  1.0f,  0.0f);
            plane.setCoordinate(0, p);
            p.set(-1.0f, -1.0f,  0.0f);
            plane.setCoordinate(1, p);
            p.set(1.0f, -1.0f,  0.0f);
            plane.setCoordinate(2, p);
            p.set(1.0f,  1.0f,  0.0f);
            plane.setCoordinate(3, p);
            Point2f q = new Point2f( 0.0f,  1.0f);
            plane.setTextureCoordinate(0, q);
            q.set(0.0f, 0.0f);
            plane.setTextureCoordinate(1, q);
            q.set(1.0f, 0.0f);
            plane.setTextureCoordinate(2, q);
            q.set(1.0f, 1.0f);
            plane.setTextureCoordinate(3, q);
            return plane;
        Appearance createAppearance(String filename) {
            Appearance appear = new Appearance();
            System.out.println("TexturedPlane attempt to load file: "+filename);
            TextureLoader loader = new NewTextureLoader(filename);
            ImageComponent2D image = loader.getImage();
            if(image == null) {
                    System.out.println("load failed for texture: "+filename);
            System.out.println("Image width  = " + image.getWidth());
            System.out.println("Image height = " + image.getHeight());
            // can't use parameterless constuctor
            Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
                                              image.getWidth(), image.getHeight());
            texture.setImage(0, image);
            texture.setEnable(true);
            texture.setMagFilter(Texture.NICEST);
            appear.setTexture(texture);
            appear.setTransparencyAttributes(
               new TransparencyAttributes(TransparencyAttributes.FASTEST, 0.1f));
            return appear;
      } // end of TexturedPlane classregards

  • Java3d speed collapse caused by other java apps running at the same time

    Hi
    I am programming a flightsimulator for some months.
    The current state is online available (all free, no copyrights)
    at http://www.snowraver.org/efcn/efcnsim/index.htm
    especially the sample (source) which shows the
    behaviour which is the reason for my post is here
    http://www.snowraver.org/efcn/efcnsim/page2.htm
    My Problem:
    When I start the sim while two other java programs
    ( one is a server running localhost, one is a client )
    are running, the speed of the flightsim is very slow,
    one frame update takes 3 to 5 seconds.
    ( 3 java.exe's in task list plus 1 which is the IDE )
    When I start the flightsim ALONE, I have 30 to 40 frames per second.
    ( 2 java.exe's in the task list = the flightsim and the IDE -> no prob here )
    That means, the flightsim is about 100 times slower, when
    started while the other two apps are running.
    BUT the other two applications do almost ***NOTHING***, the
    CPU load is 1 or 2 percent.
    Of course they have threads running, but all are waiting
    for a signal - no thread really consumes CPU power.
    Interestingly, when I FIRST start the flightsim and AFTER THIS
    start the two other applications, the flightsim
    holds 30 frames per seconds without problems, even
    though the other applications consume some CPU power
    until they have completely started up.
    Configurations:
    JSDK 1.4.2_1 , 0_2..
    Java3D 1.3.1 OPENGL (The DirectX version crashes with D3D device lost)
    Win2000,XP CPU 800MHz upto 3 GHz
    In my point of view, the java3d thread scheduler makes
    some funny decisions when it starts up, which lead
    to the order dependent behaviour described above.
    My question is, if anyone has some ideas, how I could
    get away from this speed collapse.
    The problem is caused in native code I guess.
    I also could imagine, that it has to do something with
    the order in which one creates, attaches and starts
    the Canvas3D. (? could produce race conditions)
    The flightsim runs in full retained mode. Of course
    the CPU work in the behaviours is rather big, because
    the ROAM triangulation update (..) is done there
    and the triangles are recalculated and passed
    ( all BY_REFERENCE ).
    Or could it have to do something with the memory
    consumption ( when all runs, almost all of
    the 512MB RAM is taken by the three java.exe's ) ?
    Any hints or ideas ?

    :) No, Sun does handle it [lol]
    I just have tested it on my computer at work
    ( 3GHz HP compaq, 1GB Ram and a Intel 82865G Graphics
    Card with 64MB memory, Windows XP )
    and it has worked without problems any way I tried.
    ( Except for xclusive fullscreen mode, but I guess, the administrators
    have deactivated it somehow, so we don't play games at work :)
    I couldn't test it under Linux so far, but I think, this will be less
    problematic than Windows [usually].
    However my current assumption is:
    I totally have forgot the [limited] videocard memory.
    I suppose, Java3D tries to put all triangle data and all
    textures to the videocards memory, so most data processing
    then can be passed to it's graphiccard CPU using
    OpenGL commands.
    Now the flightsim produces a varying amount of (by_reference) triangle data ( a few thousands )
    and has some texture maps for the terrain, the sea and other things,
    plus indexed triangle data for the planes and ships.
    The notebook system, which slows down has an ATI Mobile Radeon card
    with only 32MB RAM onboard, whereas the others have 64MB Ram.
    An additional pointer to that theory is that I can trigger the slowdown by resizing
    the flightsim window, while it is running.
    On the notebook, it holds 30fps, until the window exceeds a size of 962*862 pixels.
    At this size the speed collapses and goes down to 1 frame update every 4 seconds.
    If I make the window a few pixels smaller, the speed of 30fps immediately
    is there again.
    Therefore I guess, some data passed to the graphic cards memory depends
    linearly from the canvas3d's window dimension, and at some limit,
    the graphiccard's memory is too small and Java3D changes it's strategy
    and performs most calculations on the computer's mainmemory,
    which of course is a lot slower.
    I'm not very sure about that, I'm just speculating.
    Next thing I will try is to disable directdraw for the other two applications,
    possibly swing also uses graphicscard memory, when directdraw is enabled.
    The solution seems to be clear anyway: The flightsim must examine the system
    and set some parameters depending on the machine's capabilities.
    Onboard videagraphic ram is one of them. If it's too slow, I start to decrease
    the window size and expect to see a sudden increase of speed, as soon as
    the rendering can be done by the graphicscard CPU. If this never happens,
    I assume no OpenGL accelerator is present on that system. This can be seen as a method
    for finding out the amount of videocard memory on a system by trial and error ..?:)
    Thanks for your tips, Alain.
    I especially have to check out the data sharing class in 1.5.

  • Texture in a box - problem(wrong colours)

    hello guys I want to create a box with a texture of chess board on top of it, but the problem is that it loads just a dark blue colour surface instead of blue and white squares surface,feel free to check what I mean, here is what the program shows
    http://img97.imageshack.us/i/checkes.png/
    and here the original texture I want to put in the box
    http://img266.imageshack.us/i/arizonae.jpg/
    here also is my code
    import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior;
    import javax.media.j3d.Transform3D;
    import javax.swing.JFrame;
    import java.awt.*;
    import javax.swing.*;
    import javax.media.j3d.Canvas3D;
    import com.sun.j3d.utils.universe.SimpleUniverse;
    import javax.media.j3d.BranchGroup;
    import com.sun.j3d.utils.geometry.Box;
    import com.sun.j3d.utils.image.TextureLoader;
    import javax.vecmath.*;
    import javax.media.j3d.DirectionalLight;
    import javax.media.j3d.BoundingSphere;
    import javax.media.j3d.Appearance;
    import javax.media.j3d.ImageComponent2D;
    import javax.media.j3d.Material;
    import javax.media.j3d.Texture;
    import javax.media.j3d.Texture2D;
    import javax.media.j3d.TransformGroup;
    import com.sun.j3d.utils.behaviors.mouse.*;
    public class vrlm extends JFrame {
    * The SimpleUniverse object
    protected SimpleUniverse simpleU;
    * The root BranchGroup Object.
    protected BranchGroup rootBranchGroup;
    * Constructor that consturcts the window with the given name.
    * @param name
    * The name of the window, in String format
    public vrlm(String name) {
    // The next line will construct the window and name it
    // with the given name
    super(name);
    // Perform the initial setup, just once
    initial_setup();
    * Perform the essential setups for the Java3D
    protected void initial_setup() {
    // A JFrame is a Container -- something that can hold
    // other things, e.g a button, a textfield, etc..
    // however, for a container to hold something, you need
    // to specify the layout of the storage. For our
    // example, we would like to use a BorderLayout.
    // The next line does just this:
    getContentPane().setLayout(new BorderLayout());
    // The next step is to setup graphics configuration
    // for Java3D. Since different machines/OS have differnt
    // configuration for displaying stuff, therefore, for
    // java3D to work, it is important to obtain the correct
    // graphics configuration first.
    GraphicsConfiguration config = SimpleUniverse
    .getPreferredConfiguration();
    // construct the canvas.
    Canvas3D canvas3D = new Canvas3D(config);
    // And we need to add the "canvas to the centre of our
    // window..
    getContentPane().add("Center", canvas3D);
    // Creates the universe
    simpleU = new SimpleUniverse(canvas3D);
    // First create the BranchGroup object
    rootBranchGroup = new BranchGroup();
    * Adds a light source to the universe
    * @param direction
    * The inverse direction of the light
    * @param color
    * The color of the light
    public void addDirectionalLight(Vector3f direction, Color3f color) {
    // Creates a bounding sphere for the lights
    BoundingSphere bounds = new BoundingSphere();
    bounds.setRadius(1000d);
    // Then create a directional light with the given
    // direction and color
    DirectionalLight lightD = new DirectionalLight(color, direction);
    lightD.setInfluencingBounds(bounds);
    // Then add it to the root BranchGroup
    rootBranchGroup.addChild(lightD);
    * Adds a box to the universe
    * @param x
    * x dimension of the box
    * @param y
    * y dimension of the box
    * @param z
    * z dimension of the box
    Appearance vasixrwma(){
         Appearance vasixrwmaa = new Appearance();
    //load the texture
         String filename = "C:/Documents and Settings/Andy/Desktop/Arizona.jpg";
         TextureLoader loader = new TextureLoader(filename, this);
    ImageComponent2D image = loader.getImage();
    if(image == null) {
    System.out.println("load failed for texture: "+filename);
    Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
    image.getWidth(), image.getHeight());
    texture.setEnable(true);
    texture.setImage(0, image);
    texture.setMagFilter(Texture.BASE_LEVEL_LINEAR);
    texture.setMinFilter(Texture.BASE_LEVEL_LINEAR);
    vasixrwmaa.setTexture(texture);
         return vasixrwmaa;
    public void addBox(float x, float y, float z, Color3f diffuse, Color3f spec, float a, float b, float c) {
    // Add a box with the given dimension
    // First setup an appearance for the box
    Appearance app = new Appearance();
    Material mat = new Material();
    mat.setDiffuseColor(diffuse);
    mat.setSpecularColor(spec);
    mat.setShininess(5.0f);
    app.setMaterial(mat);
    Box box = new Box(x, y, z, app);
    // Create a TransformGroup and make it the parent of the box
    Transform3D meros = new Transform3D();
    meros.setTranslation(new Vector3d(a, b, c));
    TransformGroup tg = new TransformGroup(meros);
    Appearance appear = vasixrwma();
    box.getShape(Box.TOP).setAppearance(appear);
    tg.addChild(box);
    // Then add it to the rootBranchGroup
    rootBranchGroup.addChild(tg);
    //code for mouse navigation
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    MouseRotate myMouseRotate = new MouseRotate();
    myMouseRotate.setTransformGroup(tg);
    myMouseRotate.setSchedulingBounds(new BoundingSphere());
    rootBranchGroup.addChild(myMouseRotate);
    MouseTranslate myMouseTranslate = new MouseTranslate();
    myMouseTranslate.setTransformGroup(tg);
    myMouseTranslate.setSchedulingBounds(new BoundingSphere());
    rootBranchGroup.addChild(myMouseTranslate);
    MouseZoom myMouseZoom = new MouseZoom();
    myMouseZoom.setTransformGroup(tg);
    myMouseZoom.setSchedulingBounds(new BoundingSphere());
    rootBranchGroup.addChild(myMouseZoom);
    // new code for key navigation
    KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(tg);
    keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(),1000.0));
    rootBranchGroup.addChild(keyNavBeh);
    * Finalise everything to get ready
    public void finalise() {
    // Then add the branch group into the Universe
    simpleU.addBranchGraph(rootBranchGroup);
    // And set up the camera position
    simpleU.getViewingPlatform().setNominalViewingTransform();
    public static void main(String[] argv) {
    vrlm bc = new vrlm("checkers");
    bc.setSize(250, 250);
    bc.addBox(10f, 10f, 10f, new Color3f(0.8f, 0.52f, 0.25f), new Color3f(0.8f, 0.52f, 0.25f), 0.7f, -0.0415f, 0.7f);
    bc.addDirectionalLight(new Vector3f(0f, 0f, -1),
    new Color3f(4f, 4f, 0f));
    bc.finalise();
    bc.show();
    return;
    please everyone's help is appreciated, because its urgent, thank you very much!!!!

    Dave,
    You won't need that hovering window next time!
    Jerry

  • Problem in loading  multiple textures

    hi guys
    i need some help form you in loading *.obj files into my scene. when i load a building into my scene only the white building is loading without any textures. when i tried to load a texture for eg: green...the whole building is in green color. i have some *.mtl files in the same folder but i dont know how to use them.
    here is code :
    ObjectFile file1 = new ObjectFile (ObjectFile.RESIZE);
              Scene scene1 = null;
              Scene scene2 = null;
              scene2 = file1.load("model/street lamps/Lamp_Post_Ornate.OBJ");
              tg_lamp.addChild(scene2.getSceneGroup());
              Appearance appear_lamp=new Appearance();
              TextureLoader loader_lamp = new TextureLoader("texture/building.png", this);
              appear_lamp.setTexture(loader_lamp.getTexture());
              BranchGroup branchGroup1 = scene2.getSceneGroup();
                 shape = (Shape3D) branchGroup1.getChild(0);
                  shape.setAppearance(appear_lamp);
              obj_bg.addChild(tg_lamp);

    hi venkat,
    any way there is some problem with the models download from the net, now i have milkshape3d. i changed some textures and lights. and i export them to obj and mtl file.
    i am developing a car game using javaRmi and java3d. almost my game is completed .(without graphical collisionw). i hva to submit on 21st to the collage.(its my final sem project).
    when i load buildings ,,i got __heap memory issues__
    so i want to add some gif files... will u please tell me where can i get them. and how to solve these heap memory problems
    regards
    satish

  • Loading raw images in java3d

    i am new to java3d, as u can very well know from my last question. i have loaded raw images in awt panels, but how can i do the same with java3d.
    please help me with one more question, if my image is very large, how can i pan through the image?
    also, if anyone can tell me what can i do with images that are not powers of 2?
    its my final semester project. please help me.

    i am new to java3d, as u can very well know from my
    last question. i have loaded raw images in awt panels,
    but how can i do the same with java3d.Use a simple plane in 3d space and put your image as texture on it.
    please help me with one more question, if my image is
    very large, how can i pan through the image?
    also, if anyone can tell me what can i do with images
    that are not powers of 2?
    Resize it. You could use the TexureLoader, which does a resizing afaik.
    its my final semester project. please help me.

  • Texture Difficulties: Maps as solid color

    Greetings,
    I've recently begun developing java3d applications, and have run into a snag with my latest endeavour. I am attempting to texturemap a cylinder, and have thus far been outwitted. The texture is pulled down from the URL and laid upon the cylinder, but it appears as a solid color. I originally thought this was a RGB vs RGBA issue, but after endless musings with the constructor I'm still at a loss.
    Below is a snip of my problem area. Thanks in advance for any insight. I will again remind you that I am a beginner at Java as well as 3D development so I apologize for possibly asking a silly question.
        URL url_bodyTexture = null;
        try
          url_bodyTexture = new URL("http://mrkasai.undergroup.com/agsense/images/body.png");
        catch (MalformedURLException e) {}
        // appearance of bin body
        Appearance a_binBody = new Appearance();
          ColoringAttributes c = new ColoringAttributes();
            c.setColor(gray);
            c.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
          TransparencyAttributes trans =
            new TransparencyAttributes(TransparencyAttributes.BLENDED,0.4f);
          Material m = new Material();
            m.setAmbientColor(darkgray);
            m.setDiffuseColor(lightgray);
            m.setSpecularColor(white);
            m.setShininess(90.0f);
         // my nemesis:  I have changed this line many many times with similar results
          Texture t_binBody = new TextureLoader(url_bodyTexture, "RGB", this).getTexture();
            t_binBody.setEnable(true);
          TextureAttributes ta_binBody = new TextureAttributes();
            ta_binBody.setTextureMode(TextureAttributes.MODULATE);
          a_binBody.setColoringAttributes(c);
          a_binBody.setTransparencyAttributes(trans);
          a_binBody.setMaterial(m);
          a_binBody.setTexture(t_binBody);
          a_binBody.setTextureAttributes(ta_binBody);Thanks,
    --Michael                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi,
    so maybe I should apply coordinates?--> you have to :) a texture can only successfully be put on an object, if there are coordinates, which describe the position, size, adjustment etc.. Texture coordinates can either be assigned to the object (for each vertex of the geometry), or to be generated automatically (in form of the class TexCoordGeneration and assigned
    to the Appearance).
    I would recommend you to read the manual at http://java.sun.com/developer/onlineTraining/java3d/index.html, Chapter 7 Textures. In addition I would like to suggest the use of AniFun3 to work trough the examples. In AniFun3 you can change all the parameters in dialog boxes and you will see changes on the fly - without the otherwise usual time-consuming change/compile/test procedure.
    Regards,
    Oliver

  • Issues implementing a simple waterfall in Java3D

    I am currently implementing a waterfall display using Java3D. I have some questions about design, and also one about performance difficulties.
    The overall design structure is as follows:
    * The display is made up of a 2 dimensional grid, with each cell representing a data point viewed as a different color. Specifically I am testing with 360 points per line, with 60 lines. That's a lot of snow. ;)
    * At each iteration the display must add a newline to the top, shift everything down by one line, and end by dropping the bottom line (in no particular order). This gives a nice animation affect.
    * I am representing each line by a BranchGroup containing a Shape3D constructed with a QuadArray. Each quad within the array represents a cell. So each line contains 4*360=1440 points.
    * At each iteration I generate a new object containing the above. The coordinates of each point are set to sit one line above the previous line. This BranchGroup (which contains the Shape3D of quads) is added to the scene. The last line in the display is told to detach itself from the scene.
    * I am then moving the viewer up by the distance of one line. I am doing this by setting the viewingplatform's viewplatformtransform.
    So, some questions:
    * Is this design hopelessly convoluted for Java3D?
    * Does the fact that I'm dealing with 4 * 360 * 60 = 86,400 points mean that my performance is going to be awful no matter what?
    * Does it make sense to use more individual Shape3D objects, or use other primatives (or even utility shapes like cubes)?
    * Should I move the points instead of the viewer?
    * Can anyone offer an alternative to drawing tens of thousands of little points into a 3D environment?
    As far as my performance question, I have the above working, but I'm experiencing bad screen flicker. Remember that I am adding a new Shape3D to the top, dropping one from the bottom, and moving the viewer. Is there a better way of doing this, something I should add, particular flags I should set, anything? Performance isn't completely awful, but it isn't really acceptable --the flickering is very hard on the eyes.
    Thanks for any help you can send my way!

    I am currently implementing a waterfall display using
    Java3D. I have some questions about design, and also
    one about performance difficulties.Hey there, I'm new to the Java 3D scene, but I'll see what I can do with my limited knowledge and good old plane sense. ;o)
    The overall design structure is as follows:
    * The display is made up of a 2 dimensional grid, with
    each cell representing a data point viewed as a
    different color. Specifically I am testing with 360
    points per line, with 60 lines. That's a lot of snow.
    * At each iteration the display must add a newline to
    the top, shift everything down by one line, and end by
    dropping the bottom line (in no particular order).
    This gives a nice animation affect.
    * I am representing each line by a BranchGroup
    containing a Shape3D constructed with a QuadArray.
    Each quad within the array represents a cell. So each
    line contains 4*360=1440 points.
    * At each iteration I generate a new object containing
    the above. The coordinates of each point are set to
    sit one line above the previous line. This BranchGroup
    (which contains the Shape3D of quads) is added to the
    scene. The last line in the display is told to detach
    itself from the scene.
    * I am then moving the viewer up by the distance of
    one line. I am doing this by setting the
    viewingplatform's viewplatformtransform.
    So, some questions:
    * Is this design hopelessly convoluted for Java3D?
    * Does the fact that I'm dealing with 4 * 360 * 60 =
    86,400 points mean that my performance is going to be
    awful no matter what?Well, graphically, it may not be that bad (where it in another language). But I think the real lagging is caused by the way Java 3D represents the scene, in a scene graph. So, you're asking the renderer to travel through a an object tree (branchgroup) containing 86 400 idiviudal objects to be treated seperatly... We all know that Java is a RAM and CPU monster and I think doing this may be the drop that overflows the glass (your system anyway)...
    * Does it make sense to use more individual Shape3D
    objects, or use other primatives (or even utility
    shapes like cubes)?
    * Should I move the points instead of the viewer?You're already moving the points down each time (as mentionned before). So, I dunno, maybe just moving the viewer and deleting the last line and adding the top line (the rest staying put) would be faster... I still find there's lots of objects to treat there...
    * Can anyone offer an alternative to drawing tens of
    thousands of little points into a 3D environment? Sounds like you want a 2D looking foutain. Why not just create a big board and add an animated texture to it? I can see the performance increasing by 50 gazillion just by doing this. ;o)
    As far as my performance question, I have the above
    working, but I'm experiencing bad screen flicker.
    Remember that I am adding a new Shape3D to the top,
    dropping one from the bottom, and moving the viewer.
    Is there a better way of doing this, something I
    should add, particular flags I should set, anything?
    Performance isn't completely awful, but it isn't
    really acceptable --the flickering is very hard on the
    eyes.
    Thanks for any help you can send my way!I hope this helps! Happy coding!

  • Mapping texture on polygon

    Hello,
    I'm trying to map an image texture on a convex polygon. I know that it is easy to do with java3d but I'm restricted to standard jdk.
    Does anyone has an algorithm? Sample code ?
    Thanks for your help
    Tanguy

    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class Textured extends JPanel {
        private Shape shape;
        private Paint paint;
        public Textured(Shape shape, Paint paint) {
            this.shape = shape;
            this.paint = paint;
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setPaint(paint);
            g2.fill(shape);
        public static void main(String[] args) throws IOException {
            GeneralPath gp = new GeneralPath();
            gp.moveTo(300, 0);
            gp.lineTo(0,300);
            gp.quadTo(300,300,300,600);
            gp.lineTo(600,300);
            gp.quadTo(300,300,300,0);
            gp.closePath();
            URL url = new URL("http://today.java.net/jag/bio/JagHeadshot-small.jpg");
            BufferedImage image = ImageIO.read(url);
            int w = image.getWidth(), h = image.getHeight();
            Paint paint = new TexturePaint(image, new Rectangle(0,0,w/4,h/4));
            JComponent comp = new Textured(gp, paint);
            comp.setPreferredSize(new Dimension(600,600));
            JFrame f = new JFrame("Textured");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(comp);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • Invoking paint method in Java3D

    I have some example programs in using Java3D but none of them paints 'directly' on the canvas3D.
    if i have a class that extends a Canvas3D how would i call the paint method, can i use this method to draw a 2D polygon on my canvas? (because i wanted to have 3D and 2D objects mixed).
    how would i do this? are the points in terms of x, y, z?
    can anyone help me with this?
    thanks in advance

    I've been trying to do this myself, snd it's a right pain in the arse.
    To actually paint on the Canvas3D, when you override postRender(), you do all your stuff but it doesn't work until you call flush(). However, when I tied it (just drawing a simple rectange), my app slowed from 20fps to 2, which is a bit too much of a performance hit for my liking.
    The J3D Repository overlay is fairly easy to set up, but for some reason the polygon it draws on is about 1 unit away from where you add it, so for a 1st person thing like I'm doing, it dissapears when you get too near a wall. In the end, i have just created my own by putting a texture on a cube just in front of the viewport.

  • How to modify the text in java3d??

    I want to modify the text in java3d.What should I do ??
    first , I add the text to the java3d;
    then , I pick it by using behaior;
    third, I setString("My dog") to change text!!
    but there have some capability error!
    how can I do that??
    thanks in advance!!

    Hi,
    I've a similar problem - I'm using Text2D to create labels for a node-link graph. I've set all the capabilities, etc., and am finally able to change the labels using setString in Text2D. With one slight problem - now I'm getting an error:
    java.lang.IllegalArgumentException: Texture:illegal image size
            at javax.media.j3d.TextureRetained.checkImageSize(TextureRetained.java:389)
            at javax.media.j3d.TextureRetained.setImage(TextureRetained.java:423)
            at javax.media.j3d.Texture.setImage(Texture.java:869)
            at com.sun.j3d.utils.geometry.Text2D.setString(Text2D.java:118)
            at Label3D.setLabelText(Label3D.java:59)The only time I don't get the error is when I change the label from component ID to (which is a string containing an integer, e.g., 1234) to start/stop stage (which is another string containing an integer, e.g., 04, 11). If I attempt to change from component name (a string containing a string, e.g., "mesoderm"), say, to component ID, I get the error. So it's not about the length of the string, since component name is invariably longer than the ID, and the ID could be longer than the start/stop stage.
    oh, this is the code I have for the capabilities bit - no more complaints there
    private void setCapabilities()
      text.setCapability(text.ALLOW_APPEARANCE_READ);          
      text.setCapability(text.ALLOW_APPEARANCE_WRITE);
      Appearance appearance = text.getAppearance();
      appearance.setCapability(appearance.ALLOW_TEXTURE_READ);
      appearance.setCapability(appearance.ALLOW_TEXTURE_WRITE);
      Texture texture = appearance.getTexture();
      texture.setCapability(texture.ALLOW_IMAGE_READ);
      texture.setCapability(texture.ALLOW_IMAGE_WRITE);
    }Any ideas, anyone?
    aba.

  • Adding Textures to Objects loaded via an Object Loader

    Does anybody know how to add a texture to an object which has been loaded from a file.
    e.g. a model in .obj format

    I would go look for the Java3D Tutorial.
    It has some examples using the .obj format for reading in 3D Objects.

  • New With a Textures Problem

    I've just started teaching myself Java after many years of dabbling with other languages. I've jumped right into Java3D. Needless to say, I've got problems.
    I'm trying to apply a texture to a sphere, and move that texture across the sphere. Clouds across a planet surface. I used setTextureTransform to rotate the texture relative to the surface. My problem is that the result looks like the texture is fixed at one edge and stretching itself in the direction I tell it to rotate, until it reverses itself, looking normal but applied the wrong way around, and then stretches back the other way until it returns to its original position. It does that no matter which axis I rotate, always stretching around the relevant axis.
    What simple little thing that I would have learned immediately in a formal educational environment am I missing?
    I hope it's not uncouth to post code here, and I apologize for how messy my style is. The TextureTransform is last paragraph from the bottom. objTrans, ap, basically everything that doesn't have a "2" on the end is the relevant stuff.
    I hope this is the right forum.
    package learntextures;
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    //import java.awt.image.*;
    //import java.awt.event.WindowAdapter;
    //import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.image.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import com.sun.j3d.utils.geometry.*;
    import javax.swing.Timer;
    import com.sun.j3d.utils.applet.MainFrame;
    * @author David
    public class Main {
    * @param args the command line arguments
    public static void main(String[] args) {
    // TODO code application logic here
    System.out.println("Program Started");
    Planet bb = new Planet();
    bb.addKeyListener(bb);
    MainFrame mf = new MainFrame(bb, 512, 512);
    public class Planet extends Applet implements ActionListener, KeyListener {
    private Button go = new Button("Go");
    private TransformGroup objTrans;
    private Transform3D trans = new Transform3D();
    private TransformGroup objTrans2;
    private Transform3D trans2 = new Transform3D();
    private Transform3D texRot = new Transform3D();
    private TextureAttributes ap3Attr = new TextureAttributes();
    private float height=0.0f;
    private float sign = 1.0f; // going up or down
    private Timer timer;
    private float xloc=0.0f;
    private double yrot=0.0;
    private double yrot2=0.0;
    Sphere sphere;
    Appearance ap3;
    public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);
    objTrans2 = new TransformGroup();
    objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans2);
    TextureLoader loader = new TextureLoader("cldmap256alpha.png", "AGBR", new Container());
    Texture texture = loader.getTexture();
    texture.setBoundaryModeS(Texture.WRAP);
    texture.setBoundaryModeT(Texture.WRAP);
    texture.setBoundaryColor( new Color4f( 0.0f, 1.0f, 0.0f, 0.0f ) );
    // Set up the texture attributes
    //could be REPLACE, BLEND or DECAL instead of MODULATE
    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);//COMBINE_SRC_ALPHA
    TransparencyAttributes transAttr = new TransparencyAttributes();
    transAttr.setTransparencyMode(TransparencyAttributes.NICEST);
    Appearance ap = new Appearance();
    ap.setTexture(texture);
    ap.setTextureAttributes(texAttr);
    ap.setTransparencyAttributes(transAttr);
    ap.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
    ap.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_WRITE);
    texAttr.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE);
    transAttr.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE);
    ap3Attr.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE);
    Material material = new Material();
    material.setAmbientColor(new Color3f(0.0f,0.0f,0.0f));
    ap.setMaterial(material);
    // Create a simple shape leaf node, add it to the scene graph.
    int primflags = Primitive.GENERATE_NORMALS +
    Primitive.GENERATE_TEXTURE_COORDS + Primitive.ENABLE_APPEARANCE_MODIFY;
    // sphere = new Box(1,1,1,primflags,ap);
    sphere = new Sphere(0.5f, primflags, ap);
    TextureLoader loader2 = new TextureLoader("EarthNoClouds.jpg", "GBR", new Container());
    Texture texture2 = loader2.getTexture();
    texture2.setBoundaryModeS(Texture.WRAP);
    texture2.setBoundaryModeT(Texture.WRAP);
    texture2.setBoundaryColor( new Color4f( 0.0f, 1.0f, 0.0f, 0.0f ) );
    // Set up the texture attributes
    //could be REPLACE, BLEND or DECAL instead of MODULATE
    TextureAttributes texAttr2 = new TextureAttributes();
    texAttr2.setTextureMode(TextureAttributes.MODULATE);
    // TransparencyAttributes transAttr2 = new TransparencyAttributes();
    // transAttr2.setTransparencyMode(TransparencyAttributes.BLENDED);
    Appearance ap2 = new Appearance();
    ap2.setTexture(texture2);
    ap2.setTextureAttributes(texAttr2);
    // ap2.setTransparencyAttributes(transAttr2);
    ap2.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
    Material material2 = new Material();
    material.setAmbientColor(new Color3f(0.0f,0.0f,0.0f));
    ap2.setMaterial(material2);
    // Create a simple shape leaf node, add it to the scene graph.
    int primflags2 = Primitive.GENERATE_NORMALS +
    Primitive.GENERATE_TEXTURE_COORDS + Primitive.ENABLE_APPEARANCE_MODIFY;
    // Box sphere2 = new Box(1,1,1,primflags,ap);
    Sphere sphere2 = new Sphere(0.49f,primflags2,ap2);
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D pos1 = new Transform3D();
    pos1.setTranslation(new Vector3f(0.0f,0.0f,0.0f));
    objTrans.setTransform(pos1);
    objTrans.addChild(sphere);
    objRoot.addChild(objTrans);
    objTrans2 = new TransformGroup();
    objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D pos2 = new Transform3D();
    pos2.setTranslation(new Vector3f(0.0f,0.0f,0.0f));
    objTrans2.setTransform(pos2);
    objTrans2.addChild(sphere2);
    objRoot.addChild(objTrans2);
    BoundingSphere bounds =
    new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
    Color3f light1Color = new Color3f(20.0f, 20.0f, 20.0f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, 0.0f);
    // Vector3f light1Direction = new Vector3f(4.0f, -7.0f, 0.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);
    // Set up the ambient light
    Color3f ambientColor = new Color3f(1.0f, 1.0f, 1.0f);
    // Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);
    return objRoot;
    public Planet() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config =
    SimpleUniverse.getPreferredConfiguration();
    Canvas3D c = new Canvas3D(config);
    add("Center", c);
    c.addKeyListener(this);
    timer = new Timer(100,this);
    //timer.start();
    Panel p =new Panel();
    p.add(go);
    add("North",p);
    go.addActionListener(this);
    go.addKeyListener(this);
    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();
    SimpleUniverse u = new SimpleUniverse(c);
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(scene);
    public void keyPressed(KeyEvent e) {
    //Invoked when a key has been pressed.
    if (e.getKeyChar()=='s') {xloc = xloc + .1f;}
    if (e.getKeyChar()=='a') {xloc = xloc - .1f;}
    public void keyReleased(KeyEvent e){
    // Invoked when a key has been released.
    public void keyTyped(KeyEvent e){
    //Invoked when a key has been typed.
    public void actionPerformed(ActionEvent e ) {
    // start timer when button is pressed
    if (e.getSource()==go){
    if (!timer.isRunning()) {
    timer.start();
    else {
    // height += .1 * sign;
    // if (Math.abs(height *2) >= 1 ) sign = -1.0f * sign;
    if (height<-0.4f) {
    trans.setScale(new Vector3d(1.0, .8, 1.0));
    else {
    trans.setScale(new Vector3d(1.0, 1.0, 1.0));
    trans.setTranslation(new Vector3f(xloc,height,0.0f));
    yrot=yrot+0.02;
    if(yrot>6.283) yrot-=6.283;
    Matrix3d temp=new Matrix3d();
    temp.rotY(yrot);
    ap3=sphere.getAppearance();
    ap3Attr=ap3.getTextureAttributes();
    // ap3Attr.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE);
    texRot.setRotation(temp);
    // ap3Attr.setTextureTransform(texRot);
    // sphere.setAppearance(ap3);
    // objTrans.getChild(0).setAppearance();
    // trans.setRotation(temp);
    // objTrans.setTransform(trans);
    trans2.setTranslation(new Vector3f(xloc,height,0.0f));
    yrot2=yrot2+0.02;
    if(yrot2>6.283) yrot2-=6.283;
    Matrix3d temp2=new Matrix3d();
    temp2.rotY(yrot2);
    trans.setRotation(temp2);
    objTrans.setTransform(trans);
    trans2.setRotation(temp2);
    objTrans2.setTransform(trans2);
    }

    Yeah, I was afraid I was making etiquette mistakes. Sorry about that.
    Let me see if I can simplify this. Imagine a rectangle (face of a Box) with a texture mapped onto it. I want to shift that texture along the X axis. I use the method setTextureTransform, feeding it the translation vector I want, which increases a fixed amount per frame. What I would expect to happen is that the texture slides to the right until it disappears completely. What actually happens is that the texture remains fixed at the left edge and stretches out in the positive X direction.
    The above description is for clarity's sake. My actual problem involves a 3D sphere and the expectation that the texture would wrap around fill in the part of the surface left blank by the moving left edge of the texture.
    I've obviously not set something that I should have, but since I'm learning the language by reading the SDK, I don't know enough yet to know where to look for the mistake. Probably somewhere in the texture coordinate assignment or the relationship of texture to object.
    That's as clear as I can make it without showing you the program running, and I don't know how to do that yet.

  • Texture missing in 3d application through JWS

    I created two applications using Java 3D, one did not include texture mapping, another did include texture mapping.
    After deploying two applications with Java Web Start, the one without texture works well, but the one with texture appears transparent.
    When two applications work on the local, both work normally.
    Did someone know this problem?
    THanks in advance!

    I havent heard of this, but there are a couple of common problem that can cause packages to run native , and fail in Java Web Start:
    1.) Security.
    Is you application signed and requesting all-permissions ? if not, there may be a security exception burried within Java3D that isn't being shown. To check this, sign the app, or use java.polcy to grant all-permissions to everything.
    2.) ClassLoader.
    There may be an SystemClassLoader assumption within Java 3D, using Class.forName() or getResource() w/o getContextClassLoader(). If this is the case, the console or log file should show you an exception.
    3.) Finally what versions are you running (javaws, java, and Java3D) ?
    The latest versions of each may fix bugs that address such problems.
    /Dietz

Maybe you are looking for

  • How to update session state from form field values without submitting page?

    Hi, I am new to Oracle APEX. I am using Oracle Apex 4.2 on Oracle 11g release 2. The problem is that when I am entering data on a form, when I enter a value in one field and move to the next field, how can I use the value of first field in the valida

  • How do i fix my photoshop cs2 for windows 7?

    I got a new comp thats is running windows 7 and installed my photoshop cs2 software and at first everything seemed fine until i noticed some differences in the performance. When i try to draw witht he brush tool it is way to slow, for example i draw

  • Opening calendar attachments on iPad 2

    I have an iPad 2 running iOS 5.0.1.I have a question though, I have a PC which is running Outlook 2003, with an Exchange 2003 server. When I set up and calendar entry and attach some documents for a meeting, I can see the attachments and open them on

  • Can apple replace a broke ipod touch?

    can apple replace a broken ipod touch?

  • I want to open URL in new tab in SSRS report.

    I want to open URL in new tab. Actually I am passing URL expression in Action options of Textbox properties in SSRS report.The user is getting directed to desired URL but using same tab in which report is generated. I want to open URL in new tab. How