Skip to main content

No way to load a .obj

3 replies [Last post]
kurushetra
Offline
Joined: 2009-01-14

Hello i am new in java 3D and i use netbeans, my problem is that:

i get file not found errors when i try to load an obj, also i try with some sample code from some books and the same problem, i try to put the obj in the same pakage with the files .java and also in a folder like the images but not work.

Somebody can help me and explain me where is the problem...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
malborojones
Offline
Joined: 2010-09-20

I had a similar problem, I solved it by keeping the models in a folder in the first file of the project e.g. Netbeans Projects/J3D Test/Models.
I made a String called modelPath = System.getProperty("user.dir") + "/models/";
This gets the project directory and adds the models folder to the end.
Then when you load a model instead of the model name put modelPath + "model.obj"

Hope that's what you're after :)

Marcel nagm

you can put your code that you're using to do the import?

2010/7/23

> Hello i am new in java 3D and i use netbeans, my problem is that:
>
> i get file not found errors when i try to load an obj, also i try with
> some sample code from some books and the same problem, i try to put the obj
> in the same pakage with the files .java and also in a folder like the images
> but not work.
>
> Somebody can help me and explain me where is the problem...
> [Message sent by forum member 'kurushetra']
>
> http://forums.java.net/jive/thread.jspa?messageID=478430
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
> For additional commands, e-mail: interest-help@java3d.dev.java.net
>
>

--
Atc. Marcel Nagm
"Rico é o homem que tem fé em si e em Deus"
[att1.html]

robroche
Offline
Joined: 2010-05-19

Hey,

Here is a method I am using currently for my Java3D Immersive VR Class

This is actually found in a class: vr.utilities.Utility, but you could add this anywhere and/or remove static if need be

public static Shape3D LoadObjFromFile( String objectFileName )
{
// Load the Shape File to Retrieve the Shape3D Object Specified
Scene scene = null;
// Read in the Geometry Data From the File Given
ObjectFile objFileloader = new ObjectFile( ObjectFile.RESIZE );
// NOTE: THIS IS NOT A FULL IMPLEMENTATION OF THE OBJ FILE FORMAT
// IE: NO FREE-FORM GEOMETRY SUPPORT
try
{
if( !objectFileName.startsWith("file") || !objectFileName.startsWith("FILE") ) {
String temp = new String(objectFileName);
objectFileName = "File:" + temp;
}
URL fileLocation = new URL(objectFileName );
scene = objFileloader.load( fileLocation );
}
catch (FileNotFoundException fnfExp) {
System.err.println( "ERROR: Obj File Was Not Found!" );
fnfExp.printStackTrace();
Utility.Exit();
}
catch (ParsingErrorException peExp) {
System.err.println( "ERROR: Unable to Parse the Obj" +
" File Correctly" );
peExp.printStackTrace();
Utility.Exit();
}
catch (IncorrectFormatException ifExp) {
System.err.println( "ERROR: Incorrect Obj File Format" );
ifExp.printStackTrace();
Utility.Exit();
}
catch ( Exception e )
{
System.err.println( "ERROR: Object File Was Not Loaded" );
e.printStackTrace();
Utility.Exit();
}

//NOTE: I am sure there is a better way to do this last part. But if you don't remove the children, you will get a MultipleParentException if you try and add the Shape3D return value into a Universe.
// Get the BranchGroup Object Out of the Scene
BranchGroup objectGroup = scene.getSceneGroup();
Shape3D objectShape = (Shape3D)objectGroup.getChild(0);
// This line is important or an Exception: Multi-Parent Exception
// will be Thrown.
scene.getSceneGroup().removeAllChildren();

return objectShape;
}