Hi Cazoulat,
    I had the same problems with you, when I was
trying to animate the textures very fast. I thing that
the problem as you are also mentioning is in the thread
synchronization, where probably one thread is running
out of data.
    Anyway, with the current version of Java 3D, you
have to slow down. Forget the double texture technique
where you are preparing the one and you display the other.
I tried that also but it didn't work.
    What you have to do is try to control the texture update
with the rate of the updates of the canvas3d. What follows is
the response that I have from SUN for this problem, where
they were proposing another way to solve, temporarily this
problem. The future version of Java 3D will be better.

    Vasilios Darlagiannis
----------------------------------------
-----------------------------------------

Bad news and good news.  The bad news is that you found a bug in our code.
The good news is that there is a way to work around it.  I have attached your
modified program that shows the workaround.  It basically uses the Canvas3D
callbacks to set the texture reference.  This works around the problem and
also has the advantage of being synchronized with thw render thread.  This
ensures that you are doing texture setting at the same speed as the framerate.
I also tested your original program against our "coming sometime soon" 1.2
release, and the bug is fixed.

Doug.


> X-Accept-Language: en
> MIME-Version: 1.0
> To: Doug Twilleager <[EMAIL PROTECTED]>
> Subject: Re: [JAVA3D] Animated textures
>
> Hi Doug,
>     I attach a simple test where the problem of setting the
> texture of the Appearance object appears. I also attach
> a simple image file. If you take a look in the output
> window, a counter is printed. After some time it freezes.
> Also, if you see the CPU Utilization in the task manager
> you will see that it drops from 100% to 0%.
>     If you need any more info, please send me an e-mail.
>
>     Thank you very much for your help,
>
>     Vasilios Darlagiannis
>
>
> Doug Twilleager wrote:
>
> > If you have a small test case of the freezing problem, please
> > send it to [EMAIL PROTECTED] so we can look at it.
> >
> > Thanks,
> > Doug Twilleager
> > Java 3D Team
> >
> > > X-Accept-Language: en
> > > MIME-Version: 1.0
> > > Content-Transfer-Encoding: 7bit
> > > Subject: Re: [JAVA3D] Animated textures
> > > Comments: cc: Jeremy Smoler <[EMAIL PROTECTED]>
> > > To: [EMAIL PROTECTED]
> > >
> > > Hi Jeremy,
> > >     I am working on a similar application, where I want to
> > > display animated textures on Shape3D objects. In the
> > > beginning I was using new ImageComponent and Texture
> > > objects for every new texture.  But, since Java3d classes
> > > can not be cleaned-up, I was eventually running out of memory.
> > >     My new solution is to construct only on of those objects
> > > in the beginning and reuse them. For the ImageComponent
> > > object you can use the set(BufferedImage buf) and for the
> > > Texture the setImage(int level, ImageComponent image).
> > > Of cource, the Texture Object should not be part of the live
> > > scene. So, you have to set the texture of the appearance
> > > either to null or to another value, before you modify those objects.
> > >     The problem with this solution is that after some time
> > > of random duration, the application freezes. The problem is
> > > probably the Appearance object. I made some tests where I
> > > was simply setting the texture of the Appearance object and
> > > it was also freezing after a number of times (usually after 10000 to
> > > 20000 times). There is a posibility that this is a bug of Java3D.
> > >     Please let me know if you use this solution, if you face the
> > > same problems.
> > >
> > >     Best regards,
> > >
> > >     Vasilios Darlagiannis
> > >
> > >
> > > Jeremy Smoler wrote:
> > >
> > > > Sorry if this is repetitive, I posted it a couple of weeks ago and
> > > > didn't get an answer:
> > > >
> > > > Is there a faster / more efficient way to do animated textures than to
> > > > create new ImageComponent and Texture objects every time a texture image

> > > > changes? I can't find any documentation that says Java 3D does / doesn't

> > > > support animated textures.
> > > >
> > > > -Jeremy Smoler
> > > >
> > > >
===========================================================================
> > > > 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".
> > >
> > >
===========================================================================
> > > 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".






import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.TextureLoader;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.Box;
import java.awt.GraphicsConfiguration;

public class AppearanceTest2 extends Applet {
    static class MyCanvas3D extends Canvas3D {
        Appearance app = null;
        TextureLoader tex = null;
        int count = 0;
        public void postSwap() {
            if (tex == null) {
                tex = new TextureLoader("./apimage.jpg", this);
            }
            app.setTexture(tex.getTexture());
            System.out.println("i: " + count++);
        }

        public MyCanvas3D(GraphicsConfiguration gcfg) {
            super(gcfg);
        }
    }

    static public Appearance app;
    static public BranchGroup objRoot, intermediate;
    static SimpleUniverse u;
    static AppearanceTest2 at;

    private BranchGroup createSceneGraph() {
        // Create the root of the branch graph
        objRoot = new BranchGroup();
    objRoot.setCapability(BranchGroup.ALLOW_DETACH);
    objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    intermediate = new BranchGroup();
    intermediate.setCapability(BranchGroup.ALLOW_DETACH);

        // Create a bounds for the background and lights
        BoundingSphere bounds =
            new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);

        // Set up the background
        TextureLoader bgTexture = new TextureLoader("bg.jpg", this);
        Background bg = new Background(bgTexture.getImage());
        bg.setApplicationBounds(bounds);
        objRoot.addChild(bg);

        // Set up the global lights
        Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
        Vector3f lDir1  = new Vector3f(-1.0f, -1.0f, -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);

        // Create a bunch of objects with a behavior and add them
        // into the scene graph.

        int row, col;
        app = new Appearance();
    app.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
    app.setCapability(Appearance.ALLOW_TEXTURE_READ);
    intermediate.addChild(createObject(app, 0.12,  0, 0));


         objRoot.addChild(intermediate);
        // Let Java 3D perform optimizations on this scene graph.
        objRoot.compile();

        return objRoot;
    }


    static void addNode1(BranchGroup n){
        objRoot.addChild(n);
    }


    private Appearance createAppearance() {
        Appearance app = new Appearance();
    app.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
    app.setCapability(Appearance.ALLOW_TEXTURE_READ);


        return app;
    }


    private Group createObject(Appearance app, double scale,
                               double xpos, double ypos) {

        // Create a transform group node to scale and position the object.
        Transform3D t = new Transform3D();
        t.set(scale, new Vector3d(xpos, ypos, 0.0));
        TransformGroup objTrans = new TransformGroup(t);



        // Create a simple shape leaf node and set the appearance
        Box shape = new Box(1.6f, 1.2f, 0.0f, Box.GENERATE_NORMALS |
        Box.ENABLE_APPEARANCE_MODIFY | Box.GENERATE_TEXTURE_COORDS, app);
        shape.setAppearance(app);
        objTrans.addChild(shape);

        return objTrans;
    }


    public AppearanceTest2() {
        setLayout(new BorderLayout());
        MyCanvas3D c = new MyCanvas3D(null);
        add("Center", c);

        // Create a simple scene and attach it to the virtual universe
        BranchGroup scene = createSceneGraph();
        c.app = app;
        u = new SimpleUniverse(c);

        // This will move the ViewPlatform back a bit so the
        // objects in the scene can be viewed.
        u.getViewingPlatform().setNominalViewingTransform();

        u.addBranchGraph(scene);
    }


    //
    // The following allows AppearanceTest to be run as an application
    // as well as an applet
    //
    public static void main(String[] args) {
        AppearanceTest2 at = new AppearanceTest2();
        new MainFrame(at, 700, 700);
            //TextureLoader tex = new TextureLoader("./apimage.jpg", at);
            //        for (int i = 0; i < 1000000; i++){
            //            app.setTexture(tex.getTexture());
            //            System.out.println("i: " + i);
        //}
    }
}

-------------------------------------------
-------------------------------------------

CAZOULAT Renaud CNET/DIH/REN wrote:

> Hi Vasilio,
>
> >     The problem with this solution is that after some time
> > of random duration, the application freezes. The problem is
> > probably the Appearance object. I made some tests where I
> > was simply setting the texture of the Appearance object and
> > it was also freezing after a number of times (usually after 10000 to
> > 20000 times). There is a posibility that this is a bug of Java3D.
> >     Please let me know if you use this solution, if you face the
> > same problems.
>
> I am facing the same problem. I made a lot of tests and I made a dump
> of the threads (using the closing button of the window). Here is what I
> have:
> My thread call:
>         at javax.media.j3d.Canvas3D.addZombieTextureList(Compiled Code)
>         at javax.media.j3d.TextureRetained.clearLive(Compiled Code)
>         at javax.media.j3d.AppearanceRetained.setTexture(Compiled Code)
>         at javax.media.j3d.Appearance.setTexture(Compiled Code)
>         ....
>
> The "J3D-Renderer-1" thread
>         at javax.media.j3d.Canvas3D.processZombieTextureList(Compiled Code)
>         at javax.media.j3d.Renderer.run(Compiled Code)
>
> I reach the freeze much sooner than you, because I use two textures (one is
> rendered ans the other is updated, then I swap). If I use more spare
> textures, my application runs longer.
>
> I think (the java3D team did not answered me yet so it is only my
> considerations) that it's because when you set a texture, the previously set
> texture is put in a list for a later treatment. As I swap fast from one to
> the other, it may happen that the J3D-Renderer-1 wants to process a texture
> which is already in the appearance or at the exact time I want to set it to
> the appearance.
>
> Another point is when do you update your texture ? Do you set it
> asynchonously from the java3D thread ?
> (a possible way could be to do the change in the postswap method of the
> canvas 3D, because I saw that there a some interactions between a canvas3D
> and the processzombies..)
>
> any comments would be appreciated
> cheers
>
> renaud
>
> ===========================================================================
> 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".

===========================================================================
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".

Reply via email to