Java Code Examples for com.jme3.scene.Node#setName()

The following examples show how to use com.jme3.scene.Node#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCcd.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.1f);
    setupKeys();

    mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);

    mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.getAdditionalRenderState().setWireframe(true);
    mat2.setColor("Color", ColorRGBA.Red);

    // An obstacle mesh, does not move (mass=0)
    Node node2 = new Node();
    node2.setName("mesh");
    node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));
    node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(4, 4, 0.1f)), 0));
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);

    // The floor, does not move (mass=0)
    Node node3 = new Node();
    node3.setLocalTranslation(new Vector3f(0f, -6, 0f));
    node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);

}
 
Example 2
Source File: TestGhostObject.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);

    // Mesh to be shared across several boxes.
    Box boxGeom = new Box(1f, 1f, 1f);
    // CollisionShape to be shared across several boxes.
    CollisionShape shape = new BoxCollisionShape(new Vector3f(1, 1, 1));

    Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox.setName("box0");
    physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
    rootNode.attachChild(physicsBox);
    getPhysicsSpace().add(physicsBox);

    Node physicsBox1 = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox1.setName("box1");
    physicsBox1.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0, 40, 0));
    rootNode.attachChild(physicsBox1);
    getPhysicsSpace().add(physicsBox1);

    Node physicsBox2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
    physicsBox2.setName("box0");
    physicsBox2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.5f, 80, -.8f));
    rootNode.attachChild(physicsBox2);
    getPhysicsSpace().add(physicsBox2);

    // the floor, does not move (mass=0)
    Node node = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(100, 1, 100)), 0);
    node.setName("floor");
    node.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node);
    getPhysicsSpace().add(node);

    initGhostObject();
}
 
Example 3
Source File: TestSaveGame.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {

    //node that is used to store player data
    Node myPlayer = new Node();
    myPlayer.setName("PlayerNode");
    myPlayer.setUserData("name", "Mario");
    myPlayer.setUserData("health", 100.0f);
    myPlayer.setUserData("points", 0);

    //the actual model would be attached to this node
    Spatial model = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    myPlayer.attachChild(model);

    //before saving the game, the model should be detached so it's not saved along with the node
    myPlayer.detachAllChildren();
    SaveGame.saveGame("mycompany/mygame", "savegame_001", myPlayer);

    //later the game is loaded again
    Node player = (Node) SaveGame.loadGame("mycompany/mygame", "savegame_001");
    player.attachChild(model);
    rootNode.attachChild(player);

    //and the data is available
    System.out.println("Name: " + player.getUserData("name"));
    System.out.println("Health: " + player.getUserData("health"));
    System.out.println("Points: " + player.getUserData("points"));

    AmbientLight al = new AmbientLight();
    rootNode.addLight(al);
    
    //note you can also implement your own classes that implement the Savable interface.
}
 
Example 4
Source File: FbxLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Spatial constructSceneGraph() {
    // Acquire the implicit root object.
    FbxNode fbxRoot = (FbxNode) objectMap.get(FbxId.ROOT);

    // Convert it into a jME3 scene
    Node jmeRoot = (Node) FbxNode.createScene(fbxRoot);

    // Fix the name (will probably be set to something like "-node")
    jmeRoot.setName(sceneName + "-scene");

    return jmeRoot;
}
 
Example 5
Source File: TestCcd.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.1f);
    setupKeys();

    mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);

    mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.getAdditionalRenderState().setWireframe(true);
    mat2.setColor("Color", ColorRGBA.Red);

    // An obstacle mesh, does not move (mass=0)
    Node node2 = new Node();
    node2.setName("mesh");
    node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));
    node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(Vector3f.ZERO, 4, 4, 0.1f)), 0));
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);

    // The floor, does not move (mass=0)
    Node node3 = new Node();
    node3.setLocalTranslation(new Vector3f(0f, -6, 0f));
    node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);

}
 
Example 6
Source File: TestGhostObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);

    // Mesh to be shared across several boxes.
    Box boxGeom = new Box(Vector3f.ZERO, 1f, 1f, 1f);
    // CollisionShape to be shared across several boxes.
    CollisionShape shape = new BoxCollisionShape(new Vector3f(1, 1, 1));

    Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox.setName("box0");
    physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
    rootNode.attachChild(physicsBox);
    getPhysicsSpace().add(physicsBox);

    Node physicsBox1 = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox1.setName("box1");
    physicsBox1.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0, 40, 0));
    rootNode.attachChild(physicsBox1);
    getPhysicsSpace().add(physicsBox1);

    Node physicsBox2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
    physicsBox2.setName("box0");
    physicsBox2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.5f, 80, -.8f));
    rootNode.attachChild(physicsBox2);
    getPhysicsSpace().add(physicsBox2);

    // the floor, does not move (mass=0)
    Node node = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(100, 1, 100)), 0);
    node.setName("floor");
    node.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node);
    getPhysicsSpace().add(node);

    initGhostObject();
}
 
Example 7
Source File: TestSaveGame.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {

        //node that is used to store player data
        Node myPlayer = new Node();
        myPlayer.setName("PlayerNode");
        myPlayer.setUserData("name", "Mario");
        myPlayer.setUserData("health", 100.0f);
        myPlayer.setUserData("points", 0);

        //the actual model would be attached to this node
        Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
        myPlayer.attachChild(model);

        //before saving the game, the model should be detached so its not saved along with the node
        myPlayer.detachAllChildren();
        SaveGame.saveGame("mycompany/mygame", "savegame_001", myPlayer);

        //later the game is loaded again
        Node player = (Node) SaveGame.loadGame("mycompany/mygame", "savegame_001");
        player.attachChild(model);
        rootNode.attachChild(player);

        //and the data is available
        System.out.println("Name: " + player.getUserData("name"));
        System.out.println("Health: " + player.getUserData("health"));
        System.out.println("Points: " + player.getUserData("points"));

        AmbientLight al = new AmbientLight();
        rootNode.addLight(al);
        
        //note you can also implement your own classes that implement the Savable interface.
    }