最近我在学习Java3d时,发现网上的配置教程是老版本的eclipse,现在不能用了。我在尝试了一个晚上后找出了方法,就在下边,自己看吧~
- 首先,你要有一个Eclipse(这不废话吗)
- 然后,你要有一个Java3d(64位的下64位的,32下32的,别弄反了)
- Windows->Preferences->Java->Build Path->UserLibraries
! - new,输上名字,就叫Java3d好了,下面那个复选框不用选。
- Add Extenral JARs,全选上。
- 你还可以在官网下载JavaDoc,不过你不配置也没关系。
三个JAR都配置上。 - 这个是必须要配置的
到他的bin文件夹
同理,三个也都要配置上。 - And Then,Apply and Close.
- 到这一步,你还会看到你的代码一片错,不过马上就要最后一步了!
右键你的项目,找到BuildPath->Add Libraries.
User Library,然后next。
选上,Finish.
-然后你会看到你的代码无比的顺滑,运行一下,成功! - 下面是从http://www.java3d.org摘抄下来的 java3d项目,文件名称为 Ball.java ,试一试应该会出现如下图的一个窗口,出现了就说明成功了!
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class Ball {
public Ball() {
// Create the universe
SimpleUniverse universe = new SimpleUniverse();
// Create a structure to contain objects
BranchGroup group = new BranchGroup();
// Create a ball and add it to the group of objects
Sphere sphere = new Sphere(0.5f);
group.addChild(sphere);
// Create a red light that shines for 100m from the origin
Color3f light1Color = new Color3f(1.8f, 0.1f, 0.1f);
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
DirectionalLight light1
= new DirectionalLight(light1Color, light1Direction);
light1.setInfluencingBounds(bounds);
group.addChild(light1);
// look towards the ball
universe.getViewingPlatform().setNominalViewingTransform();
// add the group of objects to the Universe
universe.addBranchGraph(group);
}
public static void main(String[] args) {
System.setProperty("sun.awt.noerasebackground", "true");
new Ball();
}
}
点个赞可以支持作者写更多的文章,谢谢!