Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How can I use loader  (Read 1979 times)
0 Members and 1 Guest are viewing this topic.
Offline Rahoobah

Junior Newbie





« Posted 2007-09-30 20:46:10 »

Hi,
I drew the box in 3d max and I want to display it using java 3d
my question are in what format can I export the box and how can I use loader
I tried before and this my tries:
I export the file in .OBJ format

code:
Quote
import com.sun.j3d.loaders.objectfile.ObjectFile;
 import com.sun.j3d.loaders.ParsingErrorException;
 import com.sun.j3d.loaders.IncorrectFormatException;
 import com.sun.j3d.loaders.Scene;
 import java.applet.Applet;
 import javax.media.j3d.*;
 import javax.vecmath.*;
 import java.io.*;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

 public class ObjLoad extends Applet {

 private String filename = "test";

 public BranchGroup createSceneGraph() {
 // Create the root of the branch graph
 BranchGroup objRoot = new BranchGroup();

 ObjectFile f = new ObjectFile();
Scene s = null;
 try {
 s = f.load(filename);
 }
 catch (FileNotFoundException e) {
 System.err.println(e);
 System.exit(1);
 }
 catch (ParsingErrorException e) {
 System.err.println(e);
 System.exit(1);
 }
 catch (IncorrectFormatException e) {
 System.err.println(e);
 System.exit(1);
 }

 objRoot.addChild(s.getSceneGroup());
 return objRoot;
 }
 
 public ObjLoad() {
        setLayout(new BorderLayout());
        GraphicsConfiguration config =
           SimpleUniverse.getPreferredConfiguration();

        Canvas3D canvas3D = new Canvas3D(config);
        add("Center", canvas3D);

        BranchGroup scene = createSceneGraph();

        // SimpleUniverse is a Convenience Utility class
        SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

   // This will move the ViewPlatform back a bit so the
   // objects in the scene can be viewed.
        simpleU.getViewingPlatform().setNominalViewingTransform();

        simpleU.addBranchGraph(scene);
    } // end of HelloJava3Db (constructor)
    //  The following allows this to be run as an application
    //  as well as an applet

    public static void main(String[] args) {
   Frame frame = new MainFrame(new ObjLoad(), 256, 256);
    } // end of main (method of HelloJava3Db)

} // end of class HelloJava3D
and I have this error in the run time:

java.io.FileNotFoundException: test (The system cannot find the file specified)

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.
Offline darkpegasus

Senior Newbie





« Reply #1 - Posted 2007-09-30 21:28:30 »

It looks like you are trying to load your file as "test".

To test it I would give the full filepath ("C:\images\test..3ds") and specify the file type to start with.

You may need to download a loader specific to your file type since Java only supports a few of the major ones. Here is an example of how I used a 3DS Loader I found on the web somewhere (start a googlin' for one).

Loader3DS myOBJ = new Loader3DS();
Scene myOBJScene = null;
   
//Attempt to load in the OBJ content using ObjectFile.
try {
   myOBJScene = myOBJ.load("C:\\workspace\\Java3D\\troll.3ds");
} catch (FileNotFoundException e) {
       System.out.println("Could not open OBJ file...exiting");
       System.exit(1);
}
Offline Rahoobah

Junior Newbie





« Reply #2 - Posted 2007-09-30 22:05:23 »

Thank you darkpegasus ,
I put the full file bath and there was no error , but the box did'nt appear. Embarrassed
I want to use 3DS loader but , I don't know how . Roll Eyes
 Must I download 3DS loader?! and where I can find it ?
and if you have any complete example please give me.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline darkpegasus

Senior Newbie





« Reply #3 - Posted 2007-09-30 22:34:47 »

You'll have to download a JAR file and put it in your classpath. I don't remember exactly where I got mine from but if you do a search for "java 3ds loader" you should find plenty of resources to get that particular format (I don't think you specified exactly which format you were using). If you're using a standard OBJ class you can use the built in loaders.

Here is all of the code I needed to just load an object and add it to the scene. The commented code can be uncommented to load an OBJ file with the standard Java calls.
// Deleted some imports for brevity
import com.microcrowd.loader.java3d.max3ds.Loader3DS;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class LoaderExample {

public LoaderExample()

{
   SimpleUniverse universe = new SimpleUniverse();
   BranchGroup group = constructContentBranch();
   universe.getViewingPlatform().setNominalViewingTransform();
   universe.addBranchGraph(group);
}

public static void main( String[] args ) {
   new LoaderExample();
}

   private BranchGroup constructContentBranch() {
        //ObjectFile myOBJ = new ObjectFile();
        Loader3DS myOBJ = new Loader3DS();
        Scene myOBJScene = null;
   
        //Attempt to load in the OBJ content using ObjectFile.
        try {
           myOBJScene = myOBJ.load("C:\\workspace\\Java3D\\troll.3ds");
           //myOBJScene = myOBJ.load("C:\\workspace\\Java3D\\troll.obj");
        } catch (FileNotFoundException e) {
          System.out.println("Could not open OBJ file...exiting");
          System.exit(1);
        }
        
        //Construct and return branch group containing our OBJ scene.
        BranchGroup contentBranchGroup = new BranchGroup();
        contentBranchGroup.addChild(transform(myOBJScene.getSceneGroup()));
        return(contentBranchGroup);
      }
}


                     

 


Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (54 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!