4 Replies Latest reply on May 9, 2014 10:11 PM by MyKel D.

    JavaFX3D-Converting application to "object"

    MyKel D.

      Working with the MoleculeSampleApp - from this point I'd like to take it from the 'application' and make it a usable object. Noticed that the camera is  attached to the Scene element, and hoping that a SubScene is my answer, will continue to try to make it the way I'd like but a helping  hand would do me good- am just learning javafx but have some experience with other languages. Since I can't seem to find one them code wrapping things, I hope that putting this code here is ok.

       

      Snippet of my code:

       

      /**
      *
      * @progName: EvelynsGEMz
      * @fileName: EvelynsGemz.java
      * @author: MyKel D
      * @contributor: Wesley Owen
      * @date: July 8,2013
      *
      */
      public class EvelynsGemz extends Application {
        
          public Boolean isDISABLED = false;
      
      
          @Override
          public void start(final Stage primaryStage) {
      
      
              primaryStage.initStyle(StageStyle.TRANSPARENT);
              Rectangle Splash = new Rectangle(900, 600);
              Image SplashImage;
              SplashImage = new Image(EvelynsGemz.class.getResourceAsStream("Images/SplashFrame.gif"));
              Splash.setFill(new ImagePattern(SplashImage, 0, 0, 1, 1, true));
            
              Rectangle sideSplash = new Rectangle(481, 500);
              Image sideSplashImage;
              sideSplashImage = new Image(EvelynsGemz.class.getResourceAsStream("Images/Infinity.jpg"));
              sideSplash.setFill(new ImagePattern(sideSplashImage, 0, 0, 1, 1, true));
              sideSplash.setTranslateX(59);
              sideSplash.setTranslateY(50);
      
      
              WebView NewsView = NewsArea(540, 50, 300, 500);
              Button goGame = GameLaunch(primaryStage, 666, 515);
              goGame.setDefaultButton(true);
              Button CreateAccount = CreateAccnt(740,525,300,500);
            
              Group update = updater(70, 525, 570, 13);
            
              Group root = new Group();
              root.getChildren().addAll(Splash, sideSplash, NewsView, CreateAccount, goGame, update , doExit(864, 8, "X"));
      
      
              Scene scene = new Scene(root);
              primaryStage.setScene(scene);
              primaryStage.show();
          }
      ////////////////////////////////////////////////////////////////////////////////
      
      
          private Button CreateAccnt(double posX, double posY, final double sizeX, final double sizeY) {
              final Button CreateAccount = new Button("Create Account");
              CreateAccount.setStyle("-fx-base: blue;");
              CreateAccount.setTranslateX(posX);
              CreateAccount.setTranslateY(posY);
              EventHandler<ActionEvent> goNewAccount = new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                      Stage stage = new Stage();
                      stage.initStyle(StageStyle.UTILITY);
      
      
                      Group NAccnt = new Group();
      
      
                      final WebView CNA = new WebView();
                      CNA.setPrefSize(sizeX, sizeY);
                      final WebEngine eng = CNA.getEngine();
                      eng.load("http://myks3d.sytes.net/Game/NewUser.html");
      
      
                      NAccnt.getChildren().add(CNA);
                      Scene scene = new Scene(NAccnt);
                      stage.setScene(scene);
                      stage.show();
                  }
              };
              CreateAccount.setOnAction(goNewAccount);
              return CreateAccount;
          }
      
      
          private WebView NewsArea(double posX, double posY, double sizeX, double sizeY) {
              final WebView Splashview = new WebView();
              Splashview.setPrefSize(sizeX, sizeY);
              Splashview.setTranslateX(posX);
              Splashview.setTranslateY(posY);
              final WebEngine eng = Splashview.getEngine();
              eng.load("http://myks3d.sytes.net/Game/GameSplash.html");
              return Splashview;
          }
      
      
          private Group updater(double posX, double posY, double sizeX, double sizeY) {
      
      
              String s1 = "Checking for Updates...";
              String s2 = "Update Available...Updating...";
              String s3 = "Update Complete";
              String s4 = "No update available";
              Text txt;
      
      
              ProgressBar p = new ProgressBar();
              p.setStyle("-fx-accent: black;");
              p.setTranslateX(posX);
              p.setTranslateY(posY);
              p.setPrefSize(sizeX, sizeY);
      
      
              Timeline progressAnimation = new Timeline(
                      new KeyFrame(
                              Duration.ZERO,
                              new KeyValue(p.progressProperty(), 0)
                      ),
                      new KeyFrame(
                              Duration.seconds(4),
                              new KeyValue(p.progressProperty(), 1)
                      )
              );
      
      
              if (exists("http://myks3d.sytes.net/updateYes.txt") == true) {
                  txt = new Text(5, 515, s2);
                  txt.setFill(Color.GOLD);
                  progressAnimation.playFromStart();
                  isDISABLED = false;
              } else {
                  txt = new Text(posX, posY - 10, s4);
                  txt.setFill(Color.GOLD);
                  p.setProgress(100);
                  isDISABLED = false;
              }
      
      
              Group Progress = new Group();
              Progress.getChildren().addAll(p, txt);
              return Progress;
      
      
          }
      
      
          private Button GameLaunch(final Stage primaryStage, double posX, double posY) {
              final Button GameLaunch = new Button("GO");
              Font font1;
              font1 = new Font("Helvitica", 20);
              GameLaunch.setFont(font1);
              GameLaunch.setStyle("-fx-base: green;");
              GameLaunch.setTranslateX(posX);
              GameLaunch.setTranslateY(posY);
              EventHandler<ActionEvent> goGameLaunch = new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                      //PlayGame mp = new PlayGame(primaryStage); ///<--- can switch out these to run other pages
                      //ServerSelect mp = new ServerSelect(primaryStage);///<--- can switch out these to run other pages
                      MoleculeSample mp = new MoleculeSample(primaryStage);///<--- can switch out these to run other pages this is the one that fits. whe this is done then I can replace the bkground in PlayGame with the resulting 3D.
                      Scene s2 = new Scene(mp);
                      primaryStage.setScene(s2);
                  }
              };
              GameLaunch.setOnAction(goGameLaunch);
              return GameLaunch;
          }
      
      
          protected Button doExit(double X, double Y, String btnName) {
              final Button ExitButton = new Button(btnName);
      
      
              ExitButton.setStyle("-fx-base: red;");
              ExitButton.setTranslateX(X);
              ExitButton.setTranslateY(Y);
              EventHandler<ActionEvent> ExitAction = new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                      Platform.exit();
                      System.exit(0);
                  }
              };
              ExitButton.setOnAction(ExitAction);
              return ExitButton;
          }
      
      
          public boolean exists(String URLName) {
              try {
                  HttpURLConnection.setFollowRedirects(false);
                  // note : you may also need
                  //        HttpURLConnection.setInstanceFollowRedirects(false)
                  HttpURLConnection con
                          = (HttpURLConnection) new URL(URLName).openConnection();
                  con.setRequestMethod("HEAD");
                  return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
              } catch (IOException e) {
      
      
                  return false;
              }
          }
      
      
          public static void main(String[] args) {
              launch(args);
          }
      }
      
      

      and the relavant PART of the modified MoleculeSample:

       

      public final class MoleculeSample extends GEMz {
      
      
          final Group root = new Group();
          final Group axisGroup = new Group();
          final Xform world = new Xform();
          final PerspectiveCamera camera = new PerspectiveCamera(true);
          final Xform cameraXform = new Xform();
          final Xform cameraXform2 = new Xform();
          final Xform cameraXform3 = new Xform();
          final double cameraDistance = 450;
          final Xform moleculeGroup = new Xform();
          private Timeline timeline;
          boolean timelinePlaying = false;
          double ONE_FRAME = 1.0 / 24.0;
          double DELTA_MULTIPLIER = 200.0;
          double CONTROL_MULTIPLIER = 0.1;
          double SHIFT_MULTIPLIER = 0.1;
          double ALT_MULTIPLIER = 0.5;
          double mousePosX;
          double mousePosY;
          double mouseOldX;
          double mouseOldY;
          double mouseDeltaX;
          double mouseDeltaY;
      
      
          MoleculeSample(final Stage ThreeDStage) {
              super(ThreeDStage);
              /// this line must be  included untill the bug is fixed ///
                  System.setProperty("prism.dirtyopts", "false");
              /////////////////////////////////////////////////////////// 
              setFullscreen(ThreeDStage);
              Scene myPane = new Scene(root, 1024, 768);
              //Pane myPane = new Pane();
              //myPane.setTranslateX(centerX-200);
              //myPane.setTranslateY(centerY-200);
              getChildren().add(world);
            
              buildCamera();
              //buildAxes();
              buildMolecule();
      
      
            
              //scene.setFill(Color.GREY);
              //scene.setCamera(camera);
              handleKeyboard(myPane, world);
              handleMouse(myPane, world);
            
            
              //ThreeDStage.setScene(scene);
              //ThreeDStage.show();
           
          }
      
      

       

      Will place on my webserver the complete nbproject IDK if others have it  as I am just learning.

      Please help me if you can this is a new world  top tech and the beggining of a new era in 3D gaming on both Android and pc - i'd love to join. See where this can lead me. I'd really like to be abel to put my VRML code in this place but as the industry has gone away from  this, have lost that oppourtunity (MayHaps one day I can return to VRML/JavaFX(without Java3D and the AWT, and I can understand how to load an ocxwith JACOB). and succeed there as well. thank you for any and all help. looking forward to this discussion.

       

      Message was edited by: MyKel D. for Syntax Highlighting..

       

      Message was edited by: MyKel D. GOODBYE !!!! Thank you anyhow.

        • 1. Re: JavaFX3D-Converting application to "object"
          MyKel D.

          Time for an update then on to see the other posts:

           

          Got it to work where I want it:

          the CALL:

          public class PlayGame extends GEMz {
          
          
              PlayGame(final Stage PlayGameStage) {
                  super(PlayGameStage);
                  setFullscreen(PlayGameStage);
                  bkground = new ImageView(new Image(EvelynsGemz.class.getResourceAsStream("Images/GameLaunchImage.jpg")));
                  bkground.setFitHeight(maxY);
                  bkground.setFitWidth(maxX);
          
          
                  Pane chatbox = ChatBox(minX + 3, maxY - 265, 352, 234);
                  Group Manager = UImanagment(PlayGameStage, centerX-150, maxY - 28, 350, 25);
              
                  View3D Td = new View3D(PlayGameStage);// <---- the actual call to my "object"
              
                  Group root;
                  root = new Group();
                  root.getChildren().addAll(Td, chatbox, Manager, doExit(maxX - 25, minY + 3, "X"));
                  getChildren().add(root);
              }
          
          
          

           

          the object:

           

          package evelynsgemz;
          /*
          * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
          * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
          *
          * This code is free software; you can redistribute it and/or modify it
          * under the terms of the GNU General Public License version 2 only, as
          * published by the Free Software Foundation.  Oracle designates this
          * particular file as subject to the "Classpath" exception as provided
          * by Oracle in the LICENSE file that accompanied this code.
          *
          * This code is distributed in the hope that it will be useful, but WITHOUT
          * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
          * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
          * version 2 for more details (a copy is included in the LICENSE file that
          * accompanied this code).
          *
          * You should have received a copy of the GNU General Public License version
          * 2 along with this work; if not, write to the Free Software Foundation,
          * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
          *
          * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
          * or visit www.oracle.com if you need additional information or have any
          * questions.
          */
          
          
          import javafx.event.EventHandler;
          import javafx.scene.Group;
          import javafx.scene.PerspectiveCamera;
          import javafx.scene.PointLight;
          import javafx.scene.SceneAntialiasing;
          import javafx.scene.SubScene;
          import javafx.scene.image.Image;
          import javafx.scene.input.MouseEvent;
          import javafx.scene.paint.Color;
          import javafx.scene.paint.PhongMaterial;
          import javafx.scene.shape.Box;
          import javafx.scene.shape.Sphere;
          import javafx.scene.transform.Rotate;
          
          
          import javafx.stage.Stage;
          
          
          /**
          *
          * @author Mykel D
          */
          public class View3D extends GEMz {
          
          
              public View3D(Stage ThreeDStage) {
                  super(ThreeDStage);
                  System.setProperty("prism.dirtyopts", "false");
                  setFullscreen(ThreeDStage);
              
                  PerspectiveCamera perspectiveCamera = new PerspectiveCamera(false);
                  //s2.setCamera(perspectiveCamera);
              
                  final PhongMaterial redMaterial = new PhongMaterial();
                  //redMaterial.setSpecularColor(Color.ORANGE);
                  //redMaterial.setDiffuseColor(Color.RED);
          
          
                  Image boxImage;
                  boxImage = new Image(EvelynsGemz.class.getResourceAsStream("Images/GreenMarble.jpg"));//<--- why are these monochrome????
                  redMaterial.setBumpMap(boxImage);
          
          
                  final PhongMaterial blueMaterial = new PhongMaterial();
                  //blueMaterial.setDiffuseColor(Color.BLUE);
                  //blueMaterial.setSpecularColor(Color.LIGHTBLUE);
          
                  Image sphereImage;
                  sphereImage = new Image(View3D.class.getResourceAsStream("Images/Marble1.gif"));//<--- why are these monochrome????
          
          
                  blueMaterial.setBumpMap(sphereImage);
          
          
                  final Box red = new Box(400, 400, 400);
                  red.setMaterial(redMaterial);
          
          
                  final Sphere blue = new Sphere(200);
                  blue.setMaterial(blueMaterial);
          
          
                  blue.setTranslateX(centerX);
                  blue.setTranslateY(centerY);
                  blue.setTranslateZ(50);
          
          
                  red.setTranslateX(centerX);
                  red.setTranslateY(centerY);
                  red.setTranslateZ(650);
          
          
                  final Group parent = new Group(red, blue);
                  parent.setTranslateZ(500);
                  parent.setRotationAxis(Rotate.Y_AXIS);
          
          
                  final Group tings = new Group(parent);
                  tings.setOnMousePressed(new EventHandler<MouseEvent>() {
                      @Override
                      public void handle(MouseEvent event) {
                          anchorX = event.getScreenX();
                          anchorY = event.getScreenY();
                          anchorAngle = parent.getRotate();
                      }
                  });
          
          
                  tings.setOnMouseDragged(new EventHandler<MouseEvent>() {
                      @Override
                      public void handle(MouseEvent event) {
                          parent.setRotate(anchorAngle + anchorX - event.getScreenX());
                      }
                  });
          
          
                  PointLight pointLight = new PointLight(Color.BEIGE);
                  pointLight.setTranslateX(15);
                  pointLight.setTranslateY(-10);
                  pointLight.setTranslateZ(-100);
              
                  SubScene theScene = new SubScene(tings, maxX, maxY, true, SceneAntialiasing.BALANCED);
                  theScene.setFill(Color.GRAY);
                  theScene.setCamera(perspectiveCamera);
              
                  tings.getChildren().add(pointLight);
                  getChildren().add(theScene);
          
          
              }
          }
          
          
          

          now that it works  in the place where I want it to work,  the next bit of time will be to create a "Floor/Terrain" and work on the movements. i.e: Modes: EXAMINE, WALK, FLY, SLIDE, PAN, JUMP.

          then putt that off for a bit to make a 3DModler based on JavaFX3D. Hope that this will turn out well.

          Till next post

           

           

          Message was edited by: MyKel D. to include a Screen shot

           

          Message was edited by: MyKel D.

           

          Message was edited by: MyKel D.

          • 2. Re: JavaFX3D-Converting application to "object"
            MyKel D.

            My Rant sorry if I offend:

            VRML It should NOT be dead - but the foundation of todays 3d!!!!

             

            Two questions though ;

            1. Why is there no color in the images that i have tried to use as Materials ?  Am I doing something wrong??

            2. Sorry forgot  question 2 - might  edit later though if I remember.

            • 3. Re: JavaFX3D-Converting application to "object"
              MyKel D.

              Made 'some' changes: all changes to the original Java code has been done for personal clarification. All copyrights still in place.

              got the XFORM.java added in but only the mouse code works. Should I put the keyboard scanning code in the PlayGame pane? If so; how can the values be passed back to the View3D? because its based on the Group containing all 3d primatives? Or can it stay where it is? or...  do I need to make all my primatives/models XFORMS?

              Oh and any tips on the texture on the Floor?

              It only 'tabs' to 3 of the elements, if can set focus on the View3D; then maybe the keyboard checks can stay put.

              IDK <shrugs>

              • 4. Re: JavaFX3D-Converting application to "object"
                MyKel D.

                GOODBYE Thank you anyhow -  much appreciated - wont bother you again.!!!!!!!!!!!!!!!!