Esempio n. 1
0
  @SuppressWarnings("unchecked")
  public void saveAsFile() {
    TransformGroup themodel = lobj.getModel3D();
    File file = showSaveImageDialog();
    if (file != null) {
      BranchGroup scene = new BranchGroup();
      render.removeObj3D(lobj);
      Enumeration<Group> enume = themodel.getAllChildren();

      while (enume.hasMoreElements()) {
        Group next = enume.nextElement();
        themodel.removeChild(next);
        scene.addChild(next);
      }

      // String file=this.getModel3DHref();
      // file.replace(".3ds", ".j3d");

      // OutputStream outS;
      try {
        SceneGraphFileWriter filew =
            new SceneGraphFileWriter(file, null, false, "genereted by Neptus", null);
        filew.writeBranchGraph(scene);
        System.err.println("vehicle w:" + file.getPath() + "\n");
        filew.close();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (UnsupportedUniverseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      TransformGroup themodel2 = new TransformGroup();
      enume = scene.getAllChildren();
      while (enume.hasMoreElements()) {
        Group next = enume.nextElement();
        scene.removeChild(next);
        themodel2.addChild(next);
      }

      lobj = new Obj3D();
      lobj.setModel3D(themodel2);
      render.addObj3D(lobj);
    }
  }
Esempio n. 2
0
  public Viewer3D(TransformGroup obj) {
    super();
    init();

    Obj3D obj3d = new Obj3D();
    obj3d.setModel3D(obj);
    /*
     * for(;t.isAlive();) try { Thread.sleep(500); } catch
     * (InterruptedException e) {
     *
     * //e.printStackTrace(); }
     */
    render.addObj3D(obj3d);
    doLayout();
    repaint();
    setVisible(true);
  }
Esempio n. 3
0
  public void createRender() {
    Camera3D cam = new Camera3D(Camera3D.USER);
    cam.setRho(60.0);
    Camera3D[] cams = new Camera3D[1];
    cams[0] = cam;
    render = new Renderer3D(cams, (short) 1, (short) 1);
    render.setMode(Renderer3D.VIEWER_MODE);
    render.grid(true, true);
    render.infoAxis(true);
    render.infoCam(true);
    render.setViewMode(Renderer3D.ROTATION);
    render.showAxis(true);
    // Obj3D obj = new Obj3D(Util3D.makeAxis(true, 10.));
    // obj.setModel3D(Util3D.makeAxis(true, 10.));
    // render.addObj3D(obj);

  }
Esempio n. 4
0
  @SuppressWarnings("unchecked")
  public void openFile(File fx) {
    saveFile = null;
    File file;
    if (fx == null) file = showOpenImageDialog();
    else file = fx;
    if (file != null) {
      if ("3ds".equalsIgnoreCase(FileUtil.getFileExtension(file))) {
        if (lobj != null) render.removeObj3D(lobj);
        Inspector3DS loader = new Inspector3DS(file.getAbsolutePath()); // constructor
        loader.parseIt(); // process the file
        TransformGroup theModel1 = loader.getModel(); // get the
        // resulting 3D
        NeptusLog.waste().info("Point to view window " + Util3D.getModelDim(theModel1));
        lobj = new Obj3D();
        lobj.setModel3D(theModel1);
        // lobj.setRoll(Math.PI/2);
        render.addObj3D(lobj);

        update3dFilesOpened(file);
      } else if ("wrl".equalsIgnoreCase(FileUtil.getFileExtension(file))) {

        /*
         * try {
         *
         * if (lobj != null) render.removeObj3D(lobj);
         *
         * String filename = file.getAbsolutePath(); VrmlLoader loader =
         * new VrmlLoader();
         *
         * BufferedReader in = null; in = new BufferedReader(new
         * InputStreamReader(new FileInputStream(filename), "UTF8"));
         *
         * URL url = FileUtil.pathToURL(file.getParent()+"/");
         * loader.setBaseUrl(url);
         *
         * Scene scene = loader.load(in); BranchGroup branch =
         * scene.getSceneGroup();
         *
         * TransformGroup ret = new TransformGroup(); Enumeration<Group>
         * enume = branch.getAllChildren(); while
         * (enume.hasMoreElements()) { Group next = enume.nextElement();
         * branch.removeChild(next); ret.addChild(next); }
         * lobj.setModel3D(ret); //lobj.setRoll(Math.PI / 2);
         * render.addObj3D(lobj);
         *
         *
         * } catch (Throwable e) { e.printStackTrace();
         * GuiUtils.errorMessage(this, "Load",
         * "Error Loading WRL File");
         *
         * }
         */

        // --------------------------------------------------------
        if (lobj != null) render.removeObj3D(lobj);

        Loader myFileLoader = null; // holds the file loader
        Scene myVRMLScene = null; // holds the loaded scene
        BranchGroup myVRMLModel = null; // BG of the VRML scene
        try {
          // create an instance of the Loader
          myFileLoader = new org.web3d.j3d.loaders.VRML97Loader();

          myFileLoader.setBasePath(file.getParent());
          myFileLoader.setFlags(
              myFileLoader.getFlags() | org.web3d.j3d.loaders.VRML97Loader.LOAD_BEHAVIOR_NODES);
          // Load the scene from your VRML97 file
          myVRMLScene = myFileLoader.load(file.getAbsolutePath());

          // Obtain the root BranchGroup for the Scene
          myVRMLModel = myVRMLScene.getSceneGroup();
          lobj = new Obj3D();
          TransformGroup scene = new TransformGroup();
          Enumeration<Node> enume = myVRMLModel.getAllChildren();
          while (enume.hasMoreElements()) {
            Node next = enume.nextElement();
            myVRMLModel.removeChild(next);
            scene.addChild(next);
          }
          lobj.setModel3D(scene);
          // lobj.setRoll(Math.PI / 2);
          render.addObj3D(lobj);

          /*
           * VrmlLoader f = new VrmlLoader(); Scene s = null;
           * BranchGroup myVRMLModel = null; //BG of the VRML scene
           * try { //f.setFlags(VrmlLoader.LOAD_ALL); s =
           * f.load(file.getAbsolutePath()); // Obtain the root
           * BranchGroup for the Scene myVRMLModel =
           * s.getSceneGroup(); lobj = new Obj3D(); TransformGroup
           * scene = new TransformGroup(); Enumeration<Group> enume =
           * myVRMLModel.getAllChildren(); while
           * (enume.hasMoreElements()) { Group next =
           * enume.nextElement(); myVRMLModel.removeChild(next);
           * scene.addChild(next); } lobj.setModel3D(scene);
           * //lobj.setRoll(Math.PI / 2); render.addObj3D(lobj); }
           * catch (FileNotFoundException e) { e.printStackTrace();
           * GuiUtils.errorMessage(this, "Load",
           * "Error Loading WRL File"); }
           */

          update3dFilesOpened(file);

          System.err.println("fez o load----------");
        } catch (Exception e) {
          // in case there was a problem, print the stack out
          e.printStackTrace();
          // we still need a model, even if we can't load the right
          // one, I use a color cube just in case
          GuiUtils.errorMessage(this, "Load", "Error Loading WRL File");
        }

      } else if ("x3d".equalsIgnoreCase(FileUtil.getFileExtension(file))
          || "x3dv".equalsIgnoreCase(FileUtil.getFileExtension(file))) {

        if (lobj != null) render.removeObj3D(lobj);

        Loader myFileLoader = null; // holds the file loader
        Scene myVRMLScene = null; // holds the loaded scene
        BranchGroup myVRMLModel = null; // BG of the VRML scene
        try {
          // create an instance of the Loader
          myFileLoader = new org.web3d.j3d.loaders.X3DLoader();
          myFileLoader.setBasePath(file.getParent());

          // myFileLoader.setFlags(org.web3d.j3d.loaders.X3DLoader.LOAD_ALL);
          // Load the scene from your VRML97 file
          myVRMLScene = myFileLoader.load(file.getAbsolutePath());

          // Obtain the root BranchGroup for the Scene
          myVRMLModel = myVRMLScene.getSceneGroup();
          lobj = new Obj3D();
          TransformGroup scene = new TransformGroup();
          Enumeration<Group> enume = myVRMLModel.getAllChildren();
          while (enume.hasMoreElements()) {
            Group next = enume.nextElement();
            myVRMLModel.removeChild(next);
            scene.addChild(next);
          }
          lobj.setModel3D(scene);
          // lobj.setRoll(Math.PI / 2);
          render.addObj3D(lobj);

          update3dFilesOpened(file);

          System.err.println("fez o load----------");
        } catch (Exception e) {
          // in case there was a problem, print the stack out
          e.printStackTrace();
          // we still need a model, even if we can't load the right
          // one, I use a color cube just in case
          GuiUtils.errorMessage(this, "Load", "Error Loading x3D File");
        }

      } else if ("j3d".equalsIgnoreCase(FileUtil.getFileExtension(file))) {

        if (lobj != null) render.removeObj3D(lobj);

        BranchGroup bg = null;

        try {
          SceneGraphFileReader filer = new SceneGraphFileReader(file);
          bg = (filer.readAllBranchGraphs())[0];
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        if (bg == null) {
          NeptusLog.pub().error("Error loading vehicle model\n" + this);
        }
        TransformGroup scene = new TransformGroup();

        Enumeration<Group> enume = bg.getAllChildren();
        while (enume.hasMoreElements()) {
          Group next = enume.nextElement();
          bg.removeChild(next);
          scene.addChild(next);
        }
        lobj = new Obj3D();
        lobj.setModel3D(scene);
        // lobj.setRoll(Math.PI / 2);
        render.addObj3D(lobj);

        update3dFilesOpened(file);
      } else GuiUtils.errorMessage(this, "Load", "Invalid file type.");
    }
  }