Esempio n. 1
0
  public void loadDoodads() {
    InputStream fis =
        game.getGameApplication()
            .getAssetManager()
            .locateAsset(new AssetKey("Scenes/" + map + "/doodads.jme"))
            .openStream();
    BinaryImporter importer = BinaryImporter.getInstance();
    importer.setAssetManager(assetManager);

    try {
      doodadNode = (Node) importer.load(new BufferedInputStream(fis));

      // this node is for buildings in fog (unsauber usw.....)
      doodadNode.attachChild(new Node());

      /*
      Node test =new Node();

      List list =doodadNode.getChildren();
        for(int i=0;i<list.size();i++)
        {
            BatchNode batch = new BatchNode();
            batch.attachChild((Node)list.get(i));
            batch.batch();
            test.attachChild(batch);
        }
      rootNode.attachChild(test);
       *
       */

      reflectNode.attachChild(doodadNode);
    } catch (IOException ex) {
      //  Logger.getLogger(Main.class.getName()).log(Level.SEVERE, "No saved node loaded.", ex);
    }
  }
Esempio n. 2
0
  @Override
  public void simpleInitApp() {
    // add a random cube
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.randomColor());
    geom.setMaterial(mat);
    geom.move(
        (FastMath.nextRandomFloat() * 10) - 5,
        (FastMath.nextRandomFloat() * 10) - 5,
        (FastMath.nextRandomFloat() * -10));
    rootNode.attachChild(geom);

    // add saved cubes
    String userHome = System.getProperty("user.home");
    BinaryImporter importer = BinaryImporter.getInstance();
    importer.setAssetManager(assetManager);
    try {
      File file = new File(userHome + "/mycoolgame/savedgame.j3o");
      Node sceneNode = (Node) importer.load(file);
      sceneNode.setName("My restored node");
      rootNode.attachChild(sceneNode);
      Logger.getLogger(SaveAndLoad.class.getName()).log(Level.INFO, "Success: Loaded saved node.");
    } catch (IOException ex) {
      Logger.getLogger(SaveAndLoad.class.getName())
          .log(Level.INFO, "Warning: Could not load saved node.", ex);
    }
  }
Esempio n. 3
0
  public void loadTerrain() {
    try {
      long start = System.currentTimeMillis();
      // remove the existing terrain and detach it from the root node.
      if (terrain != null) {
        Node existingTerrain = (Node) terrain;
        existingTerrain.removeFromParent();
        existingTerrain.removeControl(TerrainLodControl.class);
        existingTerrain.detachAllChildren();
        terrain = null;
      }

      InputStream fis =
          game.getGameApplication()
              .getAssetManager()
              .locateAsset(new AssetKey("Scenes/" + map + "/terrainsave.jme"))
              .openStream();
      BinaryImporter imp = BinaryImporter.getInstance();
      imp.setAssetManager(assetManager);

      terrain = (TerrainQuad) imp.load(new BufferedInputStream(fis));
      terrain.setShadowMode(ShadowMode.CastAndReceive);

      clickableNode.attachChild((Node) terrain);

      float duration = (System.currentTimeMillis() - start) / 1000.0f;
      System.out.println("Load took " + duration + " seconds");
    } catch (Exception e) {
    }
  }