Total members 11890 |It is currently Fri Apr 19, 2024 11:21 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





This is an Java object loader applications to *.obj files.
it is a well know code to load teabot.obj or any other .obj file as a 3D- object

To run the file you must do the following :
1. You must have the Java3D package
if u don't have it you can download is from this link :
Code:
http://java.sun.com/products/java-media/3D/download.html


2.Compile the Following file :
java code
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import java.awt.GraphicsConfiguration;
import javax.media.j3d.*;
import javax.vecmath.*;

import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.objectfile.*;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;

public class ObjectLoader extends Applet{

public void init(){
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
canvas3D = new Canvas3D( config );
add("Center", canvas3D);
BranchGroup szene = macheSzene();
szene.compile();
universe = new SimpleUniverse( canvas3D );
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(szene);
}

public BranchGroup macheSzene(){
BranchGroup objWurzel = new BranchGroup();
Transform3D drehung = new Transform3D();
Transform3D drehung2 = new Transform3D();
drehung.rotX(Math.PI / 4.0d);
drehung2.rotY(Math.PI / 5.0d);
drehung.mul(drehung2);
TransformGroup objDreh =
new TransformGroup(drehung);
objDreh.setCapability(17);
objDreh.setCapability(18);
ObjectFile file = new ObjectFile (ObjectFile.RESIZE);
Scene scene = null;
//new URL("jar:"+getCodeBase()+"ObjectLoader.jar!/teapot.obj")
try {
if (getCodeBase()!=null){
try {
System.exit(1);
scene = file.load(ClassLoader.getSystemResource("teapot.obj"));
}
catch (Exception e) {
System.err.println(e);
}
}
else scene = file.load(ClassLoader.getSystemResource("teapot.obj"));

}
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);
}
objDreh.addChild(scene.getSceneGroup());

DirectionalLight d_Licht = new DirectionalLight(
new Color3f (0.7f, 1.5f, 0.3f), new Vector3f (1.0f, -10.0f, 1.0f));
d_Licht.setInfluencingBounds (new BoundingSphere (new Point3d(0.0d,0.0d,0.0d), 100.0d));
objDreh.addChild(d_Licht);

BoundingSphere bounds=new BoundingSphere();
MouseRotate spin=new MouseRotate();
spin.setTransformGroup(objDreh);
spin.setSchedulingBounds(bounds);

objWurzel.addChild(spin);
objWurzel.addChild(objDreh);
return objWurzel;
}

public void destroy(){
universe.removeAllLocales();
}

public static void main(String[] args) {
frame = new MainFrame(new ObjectLoader(),500,500);
frame.setTitle("ObjectLoader");
}

private SimpleUniverse universe;
private Canvas3D canvas3D;
private static Frame frame;
}





Attachments:
File comment: Object loader Project
LO.rar [16.75 KiB]
Downloaded 705 times

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

updated.

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : 3D-object loader
 BMP Loader     -  
 object detection     -  
 use out object in a method at jsp     -  
 Object Orientation in c++, how to a do object Orientation     -  
 Connection object in jsp     -  
 Object without new Operator     -  
 How to use connection object in jsp     -  
 need help about object detection using haarTraining     -  
 HOW TO KEEP OBJECT MOVING FOLLOW.     -  
 Change the shading of object     -  



Topic Tags

Java Graphics
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com