Inervted normals?

ok so really basic here. I created a scene with a simple box. I then created a cull state and set it to cull CS_BACK but the wrong sides are being culled, do all of the normals in a box face in the inside by default? if so is there a simple way to flip all of the normals?

Oh, here is the code if it helps any… (well atleast the best to my memory)



...
camera.setLocation(new Vector3f(0,0,-10));
camera.LookAt( new Vector3f(0,0,0),  new Vector3f(0,1,0) );

Box b = new Box("box", new Vector3f(-5,-5,-5), new Vector3f(5,5,5));
b.setModelBounds(new BoundingBox());

Texture texture = TextureManager.loadTexture("monkey.tga", Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
ts.setTexture();

rootNode.attachChild(b);
rootNode.setRenderState(ts);
rootNode.updateWorldBounds();
rootNode.updateRenderState();
...



ok i think that's basically my code... any idea's whats going on?

Normals on all of our 3d primitves face outwards.  The only thing I can think of that would change thing would be if you changed windorder, or something in your camera setup.

Make sure you do a

Actually, doing it after you attach will pick up the renderstates of the root, which you probably want.  Also, this should not affect face culling done with a cullstate.



Another possibility is you are expecting the wrong face to be culled?  CS_BACK would cull the face away from the normal direction, so on our 3d shapes, nothing would look different unless you went inside the shape with your camera.  (Try adding a cullstate to TestBoxColor as a test.)

Ok, i'll try adding the cullstate later.



right now i can see in the insides of the box. The side that is facing me is getting culled and i can see the insides of the cube.



weird huh?



here is the actual code, copy and pasted


package com;

import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.scene.state.CullState;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;

public class BasicWorld extends SimpleGame {

   protected void simpleInitGame() {
      display.setTitle("Basic World");
      
      cam.setLocation(new Vector3f(0,0, 10));
      cam.lookAt(new Vector3f(0,0,0), new Vector3f(0,1,0));
      
      Box box = new Box("box", new Vector3f(-1, 1, -1), new Vector3f(1,-1,1));
      box.setModelBound(new BoundingBox());
      box.updateModelBound();
      
      
      Texture texture = TextureManager.loadTexture("Monkey.tga", Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);
      TextureState ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);
      ts.setTexture(texture);
      
      CullState cull = display.getRenderer().createCullState();
      cull.setEnabled(true);
      cull.setCullMode(CullState.CS_BACK);
      
      rootNode.attachChild(box);
      rootNode.setRenderState(ts);
      rootNode.setRenderState(cull);
   }
   
   public static void main(String[] args){
      BasicWorld app = new BasicWorld();
      app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
       app.start();
   }

}



edit: ok problem solved!!

It seems that it matters which vector is the min and which is the max for defining a box. Weird huh? When i switch my min and max everything works fine.  :roll:

Ah, you built an inside out box :slight_smile:

…reminds me of that movie where people get turned inside-out.  :stuck_out_tongue: