Strange behaviour

Hi there,



I’m having this strange problem: I have a Node with many JME Boxes attached. You can see them:







and all works fine. I can move into the house without problems. But when I import an obj file and I attach it into rootNode it happens that if I move the mouse or the location of the camera (using W,A,S,D keys) the screen flicks, like here:







It flicks only in some zones of the scene.



So I tried to comment the line where I attach the Boxes, and it correctly load the obj and the screen doesn’t flick anymore. So The problem is only when I put both the Boxes and the obj.



Have you any idea about it?

it appears that the entire scene is being culled when the flickering occurs. This is typically due to bounding volume issues. How are you attaching your obj model the scene and how are you attaching the models to the scene?

the walls, floor and ceil are boxes generated in this way:



public void makeWall(String name, int type, int tex) {
      Vector3f wDim;
      float y = 0f;
      
      if(type == 2 || type == 4)
         wDim = new Vector3f(.5f, 2f, 1f);
      else
         wDim = new Vector3f(1f, 2f, .5f);
      if(type == 4)
         y = 1.7f;   
      Box b = new Box(name, wCenter, wDim);      
      
      b.setLocalTranslation(new Vector3f(x_walls, y, z_walls));
      b.setRenderState(ts[tex]);
      if(type == 3)
         makeWall(name + "_corner", 2, tex);         
      nWalls.attachChild(b);
   }



then:


nLights.attachChild(nWalls);



where nLights is a Node where a PointLight is attached.

From the main class:


Node lights = lev.getLights(); //it returns the node "nLights"
rootNode.attachChild(lights);
Node rifle = weapon.getRifle(); //this is the node containing the .obj
                                             //imported
rootNode.attachChild(rifle);



and finally here is the method where I load the obj, is merely a cut'n'paste from HelloLoader, or whatever is the name :D


URL model=
               Weapons.class.getClassLoader().getResource("models/" + objWeapons[0]);
   
           FormatConverter converter=new ObjToJme();
           converter.setProperty("mtllib", model);           
           ByteArrayOutputStream BO=new ByteArrayOutputStream();
           JmeBinaryReader jbr=new JmeBinaryReader();
           BinaryToXML btx=new BinaryToXML();
           converter.convert(model.openStream(), BO);
           btx.sendBinarytoXML(new ByteArrayInputStream(BO.toByteArray()),
                               new OutputStreamWriter(System.out));
           jbr.setProperty("bound","box");
           rifle = jbr.loadBinaryFormat(new ByteArrayInputStream(BO.toByteArray()));
           rifle.setLocalScale(1f);

Ok, what I believe is happening is the following:



The boxes do not have boundings when you make them. Which is fine when they are the only things in the scene (they will always be sent to the graphics card). Not very efficient, but works.



As soon as you add an object with boundings (the obj model), it causes the bounding to propogate to the parent (parent of both the obj model and the boxes). So the bounding of the model is controlling if the boxes can be seen or not. I.e. if you can’t see the model, the boxes are not drawn.



To fix this, add boundings to your boxes. (setModelBounds/updateModelBounds).



This should fix the problem for you. You should also notice dynamic culling of non-visible boxes.

thanks. To be honest I was thinking the same but I cannot figure how to use setModelBounds on Box object. This method is not present, as compiler says and as I saw in classes reference…

Box b = new Box(name, wCenter, wDim);

b.setModelBound(new BoundingSphere());

b.updateModelBound();

yep… I’m quite drunk tonight :x



Ok, now it doens’t flick anymore. But now I have the problem that the wall tiles vanish while they shouldn’t…



look them:







and as I move around I see the tiles being visible and invisible…

What exactly are the “wall tiles”? Are they models or boxes? What’s odd with the screen shot, is it appears they are in wireframe mode?

sorry, I wasn’t that clear.



The walls are boxes, used like tiles in 2D games. So, when some box vanishes I see an “hole” in the wall. Infact, on the left of the image, you shouldn’t see the white wall, because in front of the camera there is the bricks made one, but as this last vanishes moving the mouse, you see through it.



The screenshot shows the boundings.



Thanks for supporting me and sorry for my bad english

ok… I have forgotten updateModelBound();



now it’s perfect! thanks again.