My stuff just won't appear!

i run, if i put showPhysics i can see the wireframe of things, if i set this out i can't see a thing…



import com.jme.bounding.BoundingBox;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Spatial;
import com.jme.scene.state.LightState;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.PhysicsNode;
import com.jmex.physics.PhysicsSpace;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.contact.ContactCallback;
import com.jmex.physics.contact.MutableContactInfo;
import com.jmex.physics.contact.PendingContact;
import com.jmex.physics.geometry.PhysicsBox;
import com.jmex.physics.geometry.PhysicsSphere;
import com.jmex.physics.material.Material;
import com.jmex.physics.util.SimplePhysicsGame;
import java.util.Vector;

/**
 *
 * @author Rafael Guedes
 */
public class Main extends SimplePhysicsGame{

    private PhysicsSpace space;
    private Vector<PhysicsNode> PongBalls = new Vector<PhysicsNode>();
    private PhysicsNode Player;
    private Material PLAYERMAT;
    private Material BALLMAT;
   
    public static void main(String[] args) {
        new Main().start();
    }
   

    @Override
    protected void simpleInitGame() {
        space = getPhysicsSpace();
        //space.setDirectionalGravity(new Vector3f(0,-10,0));
        //InitContactCallbacks();
        InitMaterials();
        InitPlayer();
        StaticPhysicsNode n = staticNodeLoader();
        rootNode.attachChild(n);
        PhysicsBox box = staticBoxLoader("Player",n, 50, 5, 50);
        n.getLocalTranslation().set(0, -10, 15);
        //showPhysics = true;
        LightState ls=display.getRenderer().createLightState(); //LIGHT MANAGER GUY
        PointLight l=new PointLight(); //MAKE A LIGHT
        l.setLocation(new Vector3f(5,5,5)); //SET POSITION
        l.setDiffuse(ColorRGBA.blue); //SET TYPE AND COLLOR
        l.setEnabled(true); //MAKE VISIBLE
        ls.attach(l); //LINK TO THE MANAGER
        rootNode.setRenderState(ls);
       
      
    }

    /*@Override
    protected void simpleUpdate() {
        super.simpleUpdate();
    }*/

    private void InitContactCallbacks() {
        ContactCallback contactPlayerPongBall = new ContactCallback() {
            public boolean adjustContact( PendingContact c ) {
                boolean case1 = PongBalls.contains(c.getNode1());
                boolean case2 = PongBalls.contains(c.getNode2());
                if ((
                    case1 && c.getNode2() == Player  )|| (
                    case2 && c.getNode1() == Player  )){
                    if(case1){
                        doColisionPlayerPongBall((DynamicPhysicsNode)c.getNode1(), c.getNode2());
                    }
                    else{
                        doColisionPlayerPongBall((DynamicPhysicsNode)c.getNode2(), c.getNode1());
                    }
                    //return true;
                }
                return false;
            }
        };
        getPhysicsSpace().getContactCallbacks().add( contactPlayerPongBall  );

    }

    private void InitMaterials() {
        PLAYERMAT = new Material();
        PLAYERMAT.setDensity(1000);
        BALLMAT = new Material();
        BALLMAT.setDensity(0);
        MutableContactInfo info = new MutableContactInfo();
        info.setBounce(1.25f);
        info.setMu(0);
        BALLMAT.putContactHandlingDetails(PLAYERMAT, info);
        info = new MutableContactInfo();
        info.setBounce(1.25f);
        info.setMu(0);
        BALLMAT.putContactHandlingDetails(Material.DEFAULT, info);
       
       
    }

    private void InitPlayer() {
        Player = space.createDynamicNode();
        Spatial player = OBJImporter.importer(ResourcePath.Player);
        player.updateModelBound();
        player.updateRenderState();
        Player.attachChild(player);
        Player.generatePhysicsGeometry(true);
    }
    private void doColisionPlayerPongBall(DynamicPhysicsNode ball, PhysicsNode other) {
        Vector3f force = ball.getLocalTranslation();
        force = force.subtract(other.getLocalTranslation());
        force = force.mult(-50);
        //force.z *= -1;
        ball.addForce(force);
        System.out.println(force);
    }
   
   
   
   
   
   
   
   
   
    public PhysicsBox staticBoxLoader(String name, PhysicsNode parent, float height, float width, float length){
        PhysicsBox box = parent.createBox(name);
        box.setLocalScale(new Vector3f(height,width,length));
        box.setModelBound(new BoundingBox());
        box.updateModelBound();
        return box;
    }
   
    public PhysicsBox dynamicBoxLoader(String name, PhysicsNode parent,float height, float width, float length){
        PhysicsBox box = parent.createBox(name);
        box.setLocalScale(new Vector3f(height,width,length));
        box.updateModelBound();
        return box;
    }
   
    public PhysicsSphere dynamicSphereLoader(String name, PhysicsNode parent,float height, float width, float length){
        PhysicsSphere sphere = parent.createSphere(name);
        sphere.setLocalScale(new Vector3f(height,width,length));
        sphere.updateModelBound();
        return sphere;
    }
    public PhysicsSphere staticSphereLoader(String name, PhysicsNode parent,float height, float width, float length){
        PhysicsSphere sphere = parent.createSphere(name);
        sphere.setLocalScale(new Vector3f(height,width,length));
        sphere.updateModelBound();
        return sphere;
    }
   
    public StaticPhysicsNode staticNodeLoader(){
        StaticPhysicsNode node = space.createStaticNode();
        return node;
    }
   
    public DynamicPhysicsNode dynamicNodeLoader(){
        DynamicPhysicsNode node = space.createDynamicNode();
        return node;
    }

}



i realy don't get why this won't work, since they appear on showPhysics mode they should apear on normal mode, they won't show even if i add a light :/

Thanx for the test, makes it really easier to test :slight_smile:



Your physics nodes need to be attached to the scene in order to be rendered.

ex: rootNode.attachChild( Player );

would explain why the Player won't appear, but why

StaticPhysicsNode n = staticNodeLoader();
rootNode.attachChild(n);
PhysicsBox box = staticBoxLoader("Player",n, 50, 5, 50);

won't either?

public StaticPhysicsNode staticNodeLoader(){
        StaticPhysicsNode node = space.createStaticNode();
        return node;
    }



    public PhysicsBox staticBoxLoader(String name, PhysicsNode parent, float height, float width, float length){
        PhysicsBox box = parent.createBox(name);
        box.setLocalScale(new Vector3f(height,width,length));
        box.setModelBound(new BoundingBox());
        box.updateModelBound();
        parent.attachChild(box); // was added during this post, and just tested it, and it won't solve the puzzle
        return box;
    }



as i understand, "n" was attached to "rootNode", then it makes a box, that is attached to "n". so "box" is attached to "rootNode". and even so it won't appear unless showPhysics is set to true

and if i try to attach "box" to rootNode it throws that i can't attach a PhysicsObject to anything that is not a PhysicsNode or something like it

a PhysicsBox  has no visual appearance, its just physics.



You need to create a Box to dispay a box :slight_smile: