Hi, I'm getting 3 strange things with j3d 1.3fcs I wrote two test case for these.
- alt+tab problem In the first, HelloUniverse, there is a Sphere and a yellow overlay "TEST" in the upper left corner. If I "alt+tab" to another window the sphere disappear as soon as the new window gets the focus. If I comment out the overlay code ("OVERLAY BLOCK" in the source) this does not happen. I this the sphere is not removed from the scene, but that it just do not get lighted (from the test this is not clear, but if you look at the other problems I think this is the most probable thing). - textured blackout problem For this test to work you'll need NWNLoader 0.7 from sourceforge (http://sourceforge.net/projects/nwn-j3d/). This test first add a sphere. After 10 seconds it add a NWN model. As soon as the model is added the sphere gets not longer lighted. The sphere is still there but it's black, you can see only the head of the model and not the shoulders because these remain inside the sphere. In the bugs, I found 4518080 that is similar. I tryed not to compile the branchgroup but nothing changed. The same thing (the blackout) happens if I add a skybox to the scene. If I add other shapes that does not happens. The only difference I found between breaking and non breaking shapes is that non breaking shapes are not textured. If I remove the texture from the skybox the problem does not happens. Ehm...if you think it could be useful I can rewrite the test case not to use NWN model but just a simple textured cube (I suspect it would be enough..). Running the app where I first found the problem, sometimes, randomly moving around the camera, the light gets back and remains. Only if I do some strange camera movements again the light goes off. I didn't tryed to reproduce this, anyway I move tha camera using sun KeyNavBehavior. - silver band problem In both examples on the upper half of the sphere appears a silver/black band. The problem is that every time I run the program this band has a different aspect. Some times it' almost completely silver, other times it's black, other it's black with just an highlight on the right and few other cases. None of these things happens on win2k, same video card, j3d 1.3 fcs opengl version, jdk 1.4. Thanks for any hint. Bye Here are some info on the configuration Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode) java3d-sdk-1.3-fcs-linux-i386 XFree86 Version 4.1.0 / X Window System (protocol Version 11, revision 0, vendor release 6510) Release Date: 2 June 2001 If the server is older than 6-12 months, or if your card is newer than the above date, look for a newer version before reporting problems. (See http://www.XFree86.Org/FAQ) Build Operating System: Linux 2.4.4 i686 [ELF] Module Loader present Geforce2 MX with NVidia driver 29.60 (compiled locally) Linux sigil 2.4.18 #1 Wed Apr 17 19:57:31 UTC 2002 i686 unknown Debian GNU/Linux 2.2 This is the output from QueryProperties version = 1.3.0 vendor = Blackdown Java-Linux & Sun Microsystems, Inc. specification.version = 1.3 specification.vendor = Sun Microsystems, Inc. renderer = OpenGL Renderer version = 1.3.1 NVIDIA 29.60 doubleBufferAvailable = true stereoAvailable = false sceneAntialiasingAvailable = true sceneAntialiasingNumPasses = 8 textureColorTableSize = 0 textureEnvCombineAvailable = true textureCombineDot3Available = true textureCombineSubtractAvailable = true texture3DAvailable = true textureCubeMapAvailable = true textureSharpenAvailable = false textureDetailAvailable = false textureFilter4Available = false textureAnisotropicFilterDegreeMax = 2.0 textureBoundaryWidthMax = 1 textureWidthMax = 2048 textureHeightMax = 2048 textureLodOffsetAvailable = false textureLodRangeAvailable = true textureUnitStateMax = 2 compressedGeometry.majorVersionNumber = 1 compressedGeometry.minorVersionNumber = 0 compressedGeometry.minorMinorVersionNumber = 2
/* * ModelLoader.java * * Created on July 13, 2002, 5:49 PM */ import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.loaders.*; // NWN import net.sf.nwn.loader.*; import com.sun.j3d.demos.utils.scenegraph.traverser.*; import arpg.core.CoreException; import java.util.logging.*; import java.util.*; /** * * @author trz * @version */ public class ModelLoader { final static String MODEL_DIR = "data/model/"; private static ModelLoader instance = new ModelLoader(); HashMap loaders = new HashMap(); /** Creates new ModelLoader */ private ModelLoader() { NWNLoader loaderNWN = new NWNLoader(); loaderNWN.enableModelCache(true); loaders.put("MDL", loaderNWN); } public static ModelLoader getInstance() { return instance; } private Loader getLoader(String ext) { return (Loader)loaders.get(ext); } public Scene loadScene(String fileName) throws Exception { String ext = fileName.substring(fileName.lastIndexOf(".")+1).toUpperCase(); Loader loader = getLoader(ext); Scene scene = null; try { scene = loader.load(MODEL_DIR + fileName); //Scene s = nwn.load("data/model/Bugbear.mdl"); return scene; }catch(Exception e) { //throw new CoreException("Errore caricando il file " + fileName, e); //log.info("Errore caricando il file " + fileName + ": " + e); //return scene; throw e; } } /* NWNModel */ public static BranchGroup getModel(Scene scene) throws Exception { BranchGroup modelGroup = scene.getSceneGroup(); if (modelGroup == null) throw new CoreException("Errore caricando il modello"); setCapabilities(modelGroup); setTextureUnitState(modelGroup, false); modelGroup.compile(); return modelGroup; } //------------------- private static void setCapabilities(BranchGroup bg) { TreeScan.findNode(bg, new Class[] {Group.class, Shape3D.class, Behavior.class}, capabilityProcessor, false, false); } private static ProcessNodeInterface capabilityProcessor = new ProcessNodeInterface() { public void processNode(javax.media.j3d.Node node) { //test node.setCapability(Group.ENABLE_PICK_REPORTING); if (node instanceof Group) { if (node instanceof BranchGroup) { node.setCapability(javax.media.j3d.Node.ALLOW_LOCAL_TO_VWORLD_READ); } node.setCapability(Group.ALLOW_CHILDREN_READ); if (node instanceof TransformGroup) { node.setCapability(TransformGroup.ALLOW_LOCAL_TO_VWORLD_READ); } } else if (node instanceof Shape3D) { Shape3D s = (Shape3D) node; //test s.setCapability(Shape3D.ALLOW_GEOMETRY_READ); Geometry geom = s.getGeometry(); geom.setCapability(GeometryArray.ALLOW_COORDINATE_READ); geom.setCapability(GeometryArray.ALLOW_COUNT_READ); geom.setCapability(GeometryArray.ALLOW_FORMAT_READ); geom.setCapability(IndexedGeometryArray.ALLOW_COORDINATE_INDEX_READ); //??? s.setCapability(Shape3D.ALLOW_APPEARANCE_READ); s.getAppearance().setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_READ); s.getAppearance().clearCapabilityIsFrequent(Appearance.ALLOW_TEXTURE_UNIT_STATE_READ); s.getAppearance().setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE); s.getAppearance().clearCapabilityIsFrequent(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE); s.getAppearance().setCapability(Appearance.ALLOW_RENDERING_ATTRIBUTES_WRITE); s.getAppearance().clearCapabilityIsFrequent(Appearance.ALLOW_RENDERING_ATTRIBUTES_WRITE); Appearance app = s.getAppearance(); Material m = app.getMaterial(); //System.out.println("material " + m); m.setLightingEnable(true); for (int i = 0; i < s.getAppearance().getTextureUnitCount(); i++) { if (s.getAppearance().getTextureUnitState(i) != null) { s.getAppearance().getTextureUnitState(i).setCapability(TextureUnitState.ALLOW_STATE_READ); s.getAppearance().getTextureUnitState(i).getTexture().setCapability(Texture.ALLOW_ENABLE_WRITE); s.getAppearance().getTextureUnitState(i).getTextureAttributes().setCapability(TextureAttributes.ALLOW_MODE_WRITE); s.getAppearance().getTextureUnitState(i).getTexture().clearCapabilityIsFrequent(Texture.ALLOW_ENABLE_WRITE); s.getAppearance().getTextureUnitState(i).getTextureAttributes().clearCapabilityIsFrequent(TextureAttributes.ALLOW_MODE_WRITE); } } } else if (node instanceof Behavior) { //System.out.println("setto behavior"); Behavior b = (Behavior)node; b.setSchedulingBounds( new BoundingSphere(new Point3d(), 1000) ); } } }; static void setTextureUnitState(BranchGroup bg, final boolean enabled) { final int TEX_METAL = 1; final int unit = TEX_METAL; treeScan(new AppearanceChangeProcessor() { public void changeAppearance(javax.media.j3d.Shape3D shape, javax.media.j3d.Appearance app) { if (shape instanceof ParticleCollection || shape instanceof Walkmesh) return; if (unit == TEX_METAL && app.getTextureUnitCount() == 1) return; TextureUnitState tus = app.getTextureUnitState(unit); if (tus != null) { tus.getTexture().setEnable(enabled); } } }, bg); } public static void treeScan(ProcessNodeInterface pni, javax.media.j3d.Node root) { TreeScan.findNode(root, Shape3D.class, pni, false, false); } //fine metodi nwn loader }
import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.awt.GraphicsConfiguration; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import arpg.m3d.util.*; import org.j3d.geom.overlay.LabelOverlay; import java.awt.*; public class HelloUniverse extends Applet { private SimpleUniverse u = null; public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); Color3f color = new Color3f(0.95f, 0.15f, 0.15f); TransformGroup tgPos = new TransformGroup(); Transform3D trPos = new Transform3D(); Vector3d vPos = new Vector3d(3, 0.3f, 3); trPos.setTranslation(vPos); tgPos.setTransform(trPos); Vector3f lightDir = new Vector3f(-1.0f, 0, -1.0f); DirectionalLight light = new DirectionalLight(color, lightDir); light.setInfluencingBounds(bounds); tgPos.addChild(light); objRoot.addChild(tgPos); Sphere sphere = new Sphere(0.5f); Appearance app = new Appearance(); Material mat = new Material(); app.setMaterial(mat); sphere.setAppearance(app); objRoot.addChild(sphere); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; } public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); BranchGroup scene = createSceneGraph(); u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); // --- START OVERLAY BLOCK --- TransformGroup view = u.getViewingPlatform().getViewPlatformTransform(); Color ovColor = new Color(0, 0, 0, 0); LabelOverlay overlay = new LabelOverlay(u.getCanvas(), new Rectangle(20, 20, 100, 35), "TEST"); overlay.setColor(Color.yellow); overlay.setBackgroundColor(ovColor); overlay.setVisible(true); view.addChild(overlay.getRoot()); overlay.repaint(); overlay.initialize(); // --- END OVERLAY BLOCK --- u.addBranchGraph(scene); } public void destroy() { u.removeAllLocales(); } public static void main(String[] args) { new MainFrame(new HelloUniverse(), 512, 512); } }
import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.awt.GraphicsConfiguration; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.loaders.*; //import arpg.m3d.util.*; import org.j3d.geom.overlay.LabelOverlay; import java.awt.*; public class HelloNWN extends Applet { private SimpleUniverse u = null; private BranchGroup objRoot; public BranchGroup createSceneGraph() { objRoot = new BranchGroup(); objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); Color3f color = new Color3f(0.95f, 0.15f, 0.15f); TransformGroup tgPos = new TransformGroup(); Transform3D trPos = new Transform3D(); Vector3d vPos = new Vector3d(3, 0.3f, 3); trPos.setTranslation(vPos); tgPos.setTransform(trPos); Vector3f lightDir = new Vector3f(-1.0f, 0, -1.0f); DirectionalLight light = new DirectionalLight(color, lightDir); light.setInfluencingBounds(bounds); tgPos.addChild(light); objRoot.addChild(tgPos); Sphere sphere = new Sphere(1f); Appearance app = new Appearance(); Material mat = new Material(); app.setMaterial(mat); sphere.setAppearance(app); objRoot.addChild(sphere); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; } void addNWNModel() throws Exception { arpg.m3d.ModelLoader loader = arpg.m3d.ModelLoader.getInstance(); Scene scene = loader.loadScene("Bugbear.mdl"); BranchGroup bg = loader.getModel(scene); BranchGroup root = new BranchGroup(); Transform3D tr = new Transform3D(); tr.setScale(0.5); TransformGroup tg = new TransformGroup(); tg.setTransform(tr); tg.addChild(bg); root.addChild(tg); objRoot.addChild(root); } public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); BranchGroup scene = createSceneGraph(); u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); } public void destroy() { u.removeAllLocales(); } public static void main(String[] args) throws Exception { HelloNWN hello = new HelloNWN(); new MainFrame(hello, 512, 512); System.out.println("wait..."); Thread.sleep(10000); System.out.println("ok"); hello.addNWNModel(); } }