Ok, I've discovered the ImageComponent2D.Updater interface and well, it
saves me call to the Texture2D's setImage method... But that's it. As soon
as I call the renderOffscreenBuffer() method, everything grinds to a halt.

This isn't good when you want a real-time animated texture!!!

Here's my code, does anyone see anything blatantly wrong here?:

public class P3DNavigationMap extends BranchGroup {
private ImageComponent2D screenshotBuffer = null;
private Canvas3D offScreenCanvas = null;
private TexturedPlane mapPlane = null;
private P3DNavigationMapRefreshBehavior mrb = null;

public P3DNavigationMap(Canvas3D imageSource) {
this.offScreenCanvas = imageSource;
RenderedImage renderedImage = new BufferedImage(256, 512,
BufferedImage.TYPE_4BYTE_ABGR);
this.screenshotBuffer = new ImageComponent2D(ImageComponent2D.FORMAT_RGBA4,
renderedImage, true, true);
this.screenshotBuffer.setCapability(ImageComponent2D.ALLOW_IMAGE_WRITE);
this.offScreenCanvas.setOffScreenBuffer(this.screenshotBuffer);
this.mapPlane = new TexturedPlane(new Point3f(0.0f, 0.0f, 0.0f), new
Point3f(10.0f, 0.0f, 0.0f), new Point3f(10.0f, 20.0f, 0.0f), new
Point3f(0.0f, 20.0f, 0.0f), screenshotBuffer, 0.3f);
this.addChild(mapPlane);
this.mrb = new P3DNavigationMapRefreshBehavior(1000);
this.mrb.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
10000));
this.addChild(mrb);
offScreenCanvas.getScreen3D().setSize(256, 512);
offScreenCanvas.getScreen3D().setPhysicalScreenWidth(256 * 0.0254/90);
offScreenCanvas.getScreen3D().setPhysicalScreenHeight(512 * 0.0254/90);
/*mapPlane.setCapability(TexturedPlane.ALLOW_APPEARANCE_READ);
mapPlane.getAppearance().setCapability(Appearance.ALLOW_TEXTURE_READ);
mapPlane.getAppearance().getTexture().setCapability(Texture2D.ALLOW_IMAGE_WR
ITE);*/
}

class P3DNavigationMapRefreshBehavior extends Behavior implements
ImageComponent2D.Updater {
private long refreshRate = 500;
private WakeupCondition condition = null;
private ImageComponent2D m_imageComponent = null;

P3DNavigationMapRefreshBehavior(long refreshRate) {
if(refreshRate > 0)
this.refreshRate = refreshRate;

condition = new WakeupOnElapsedTime(refreshRate);
}

// Initialize the P3DPacmanKeyboardNavigationBehavior.
public void initialize(){
// Set the initial wakeup condition to a key pressed.
this.wakeupOn(condition);
}

public void updateData(ImageComponent2D imageComponent, int x, int y, int
width, int height)
{
if(m_imageComponent == null )
{
m_imageComponent = imageComponent;
}
System.out.println("Called");
//offScreenCanvas.renderOffScreenBuffer();
//mapPlane.getAppearance().getTexture().setImage(0, m_imageComponent);
}


public void processStimulus(Enumeration criteria) {
System.out.println("MAP");
WakeupCriterion wakeUp = null;
while (criteria.hasMoreElements()) {
wakeUp = (WakeupCriterion) criteria.nextElement();

// If a key was pressed, get the scan code and save it if it corresponds
// to an arrow (navigation) key.
if (wakeUp instanceof WakeupOnElapsedTime) {
//offScreenCanvas.renderOffScreenBuffer();
//mapPlane.getAppearance().getTexture().setImage(0, screenshotBuffer);
offScreenCanvas.renderOffScreenBuffer();
screenshotBuffer.updateData(this, 0, 0, 256, 512);
}
}
this.wakeupOn(condition);
}
}
}

CHRIS

----- Original Message -----
From: "Frederic Barachant" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, November 09, 2003 3:26 AM
Subject: Re: [JAVA3D] How to map an offscreen Canvas3D to a textured plane?


> >1) When calling the offScreenCanvas.renderOffScreenBuffer() method, the
> >texture isn't updated. I have to refresh the ImageComponent2D of the
> >Texture2D manually by calling
> >mapPlane.getAppearance().getTexture().setImage(0, screenshotBuffer) ->
even
> >though it's the same ImageComponent2D that's used as the OffScreenBuffer
of
> >the Canvas3D;
> you should have a look at ImageComponent2D.Updater for updating a texture
directly.
> I suspect that you duplicate data for nothing.
>
>
===========================================================================
> 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