Hi!
I am not sure if this is already known, or if this is the bug at all, but it seems to me so, so I decide to report.
Here is description and test case as well, so you can check it fast. Would appreciate if somebody can confirm it.
The problem is, that if you have Shape3D with the Appearance applied (let’s say “myApp”), and if this Shape3D is currently invisible, just behind your field of view for instance, then changing any of the attributes of “myApp” not neccessary will have efect, well, most of the time it will, but eventualy - not.
The test case is simply bunch of quads, spread over square area with the camera located roughly at its center. The square is constantly rotating so that you see roughly half of it at a time. While in rotation the Appearance (same applied to all the quads!!!) is modified (coloring attr. for example) on regular intervals. Now have a look what you actually going to get from that…
Is it proper behaviour? BTW, I found experimentaly how to actually avoid the problem (see and try the comment at the end of code)…
It was tested with the latest Xith _0.7.1 on JSR-231, Windows, and few different PC’s (different video-cards).
import java.awt.Color;
import javax.swing.JFrame;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
import com.xith3d.render.CanvasPeer;
import com.xith3d.render.RenderPeer;
import com.xith3d.render.jsr231.RenderPeerImpl;
import com.xith3d.scenegraph.Appearance;
import com.xith3d.scenegraph.BranchGroup;
import com.xith3d.scenegraph.Canvas3D;
import com.xith3d.scenegraph.ColoringAttributes;
import com.xith3d.scenegraph.Geometry;
import com.xith3d.scenegraph.Locale;
import com.xith3d.scenegraph.Shape3D;
import com.xith3d.scenegraph.Transform3D;
import com.xith3d.scenegraph.TransformGroup;
import com.xith3d.scenegraph.View;
import com.xith3d.scenegraph.VirtualUniverse;
import com.xith3d.test.TestUtils;
public class AppearanceChangeTest {
public AppearanceChangeTest() {
JFrame frame = new JFrame("AppearanceChangeTest");
frame.setSize(500, 500);
//======= setting up Universe ===============
VirtualUniverse My_Universe = new VirtualUniverse();
Locale locale = new Locale();
My_Universe.addLocale(locale);
BranchGroup scRootBG = new BranchGroup();
locale.addBranchGraph(scRootBG);
//------------------------------
RenderPeer renderPeer = new RenderPeerImpl();
CanvasPeer canvasPeer = renderPeer.
makeCanvas(frame.getContentPane(), 0, 0, 32, false);
Canvas3D scrCanvas = new Canvas3D();
scrCanvas.set3DPeer(canvasPeer);
//------------------------------
View scView = new View();
scView.addCanvas3D(scrCanvas);
My_Universe.addView(scView);
//------ rotation group --------
TransformGroup rotTG = new TransformGroup();
scRootBG.addChild(rotTG);
//======== adding many shapes3d ===============
Appearance app = new Appearance();
ColoringAttributes colAtt1 = new ColoringAttributes(
new Color3f(Color.RED), 0);
ColoringAttributes colAtt2 = new ColoringAttributes(
new Color3f(Color.BLUE), 0);
app.setColoringAttributes(colAtt1);
float dL = 0.1f;
for (float i = -5; i < 5; i++) for (float j = -5; j < 5; j++) {
Point3f P1 = new Point3f( i+dL, j+dL, 0);
Point3f P2 = new Point3f( i+dL, j + 1-dL, 0);
Point3f P3 = new Point3f( i + 1-dL, j + 1-dL, 0);
Point3f P4 = new Point3f( i + 1-dL, j+dL, 0);
Geometry geom = TestUtils.createQuad(P1, P2, P3, P4, 1, 1);
rotTG.addChild(new Shape3D(geom, app));
}
//======= running =============================
frame.setVisible(true);
scView.getTransform().lookAt( new Point3f (0, 2, 2),
new Point3f (0, 0, 0),
new Vector3f(0, 0, 1));
float a = 0;
long currTime = System.currentTimeMillis();
long lastTime = currTime;
int count = 0; //
Transform3D rotTF = new Transform3D();
while (frame.isVisible()) {
scView.renderOnce();
//-----------------------------------
currTime = System.currentTimeMillis();
if (currTime - lastTime > 20) {
lastTime = currTime;
a += 0.03f; if (a > 2*Math.PI) a -= 2*(float)Math.PI;
rotTF.rotZ(a);
rotTG.setTransform(rotTF);
count++;
if (count > 50) {
count = 0;
if (app.getColoringAttributes() == colAtt1) {
app.setColoringAttributes(colAtt2);
} else {
app.setColoringAttributes(colAtt1);
}
//--- uncomment both lines to fix the problem ---
//rotTG.setLive(false);
//rotTG.setLive(true);
}
}
//------------------------------------
}
System.exit(0);
}
public static void main(String args[]) {
new AppearanceChangeTest();
}
}
Bohdan.