JAVA 3D已启动小程序 但是一片空白怎么办?代码如下: 80
importjava.applet.Applet;publicclassvrmlloaderextendsApplet{privateBranchGroupcreateS...
import java.applet.Applet;
public class vrmlloader extends Applet {
private BranchGroup createSceneGraph(String filename){
SimpleUniverse su =new SimpleUniverse();
//建立一个组
BranchGroup group =new BranchGroup();
//设置光的 颜色
Color3f colorlight =new Color3f(0.1f,0.1f,0.1f);
//光照的范围
BoundingSphere sphere =new BoundingSphere(new Point3d(0.0,0.0,0.0),1000.0);
//光照的方向
Vector3f vec =new Vector3f(12.0f,3.0f,2.0f);
//创建环境的光
AmbientLight at=new AmbientLight(colorlight);
at.setInfluencingBounds(sphere);
group.addChild(at);
//把光照和方向放进去
DirectionalLight diretionlight =new DirectionalLight(colorlight,vec);
//把光照添加到组里面
group.addChild(diretionlight);
//背景颜色
Background bg =new Background(new Color3f(1.5f,-12.0f,0.5f));
bg.setApplicationBounds(sphere);
group.addChild(bg);
//设置变换组
TransformGroup tran =new TransformGroup();
//允许读
tran.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
//允许写
tran.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D T3D=new Transform3D();
tran.getTransform(T3D);
//放缩
T3D.setScale(0.5);
tran.setTransform(T3D);
//旋转
MouseRotate rate =new MouseRotate(tran);
rate.setSchedulingBounds(sphere);
group.addChild(rate);
//移动
MouseZoom zoom =new MouseZoom(tran);
zoom.setSchedulingBounds(sphere);
group.addChild(zoom);
//变换
MouseTranslate translate =new MouseTranslate(tran);
translate.setSchedulingBounds(sphere);
group.addChild(translate);
//加载VEML文件
VrmlLoader loader=new VrmlLoader();
Scene s=null;
try{
s=loader.load(filename);
}catch(Exception e){
//异常处理
System.exit(1);
}
group.addChild(s.getSceneGroup());
Transform3D t=new Transform3D();
t.setTranslation(new Vector3f(0.5f,1.0f,0.6f));
TransformGroup tg=new TransformGroup(t);
tg.addChild(new ColorCube(1.5f));
group.compile();
return group;
}
public void VrmlLoader(String filename) {
//文件路径
filename="F/:java 3D/java/b.wrl";
this.setLayout(new BorderLayout());
Canvas3D c=new Canvas3D(SimpleUniverse.getPreferredConfiguration());
this.add("Center",c);
//建立一个虚拟宇宙
SimpleUniverse su =new SimpleUniverse(c);
su.addBranchGraph((BranchGroup) createSceneGraph(filename));
su.getViewingPlatform().setNominalViewingTransform();
}
public static void main(String[] args){
new MainFrame(new vrmlloader(), 360,360);
}
} 展开
public class vrmlloader extends Applet {
private BranchGroup createSceneGraph(String filename){
SimpleUniverse su =new SimpleUniverse();
//建立一个组
BranchGroup group =new BranchGroup();
//设置光的 颜色
Color3f colorlight =new Color3f(0.1f,0.1f,0.1f);
//光照的范围
BoundingSphere sphere =new BoundingSphere(new Point3d(0.0,0.0,0.0),1000.0);
//光照的方向
Vector3f vec =new Vector3f(12.0f,3.0f,2.0f);
//创建环境的光
AmbientLight at=new AmbientLight(colorlight);
at.setInfluencingBounds(sphere);
group.addChild(at);
//把光照和方向放进去
DirectionalLight diretionlight =new DirectionalLight(colorlight,vec);
//把光照添加到组里面
group.addChild(diretionlight);
//背景颜色
Background bg =new Background(new Color3f(1.5f,-12.0f,0.5f));
bg.setApplicationBounds(sphere);
group.addChild(bg);
//设置变换组
TransformGroup tran =new TransformGroup();
//允许读
tran.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
//允许写
tran.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D T3D=new Transform3D();
tran.getTransform(T3D);
//放缩
T3D.setScale(0.5);
tran.setTransform(T3D);
//旋转
MouseRotate rate =new MouseRotate(tran);
rate.setSchedulingBounds(sphere);
group.addChild(rate);
//移动
MouseZoom zoom =new MouseZoom(tran);
zoom.setSchedulingBounds(sphere);
group.addChild(zoom);
//变换
MouseTranslate translate =new MouseTranslate(tran);
translate.setSchedulingBounds(sphere);
group.addChild(translate);
//加载VEML文件
VrmlLoader loader=new VrmlLoader();
Scene s=null;
try{
s=loader.load(filename);
}catch(Exception e){
//异常处理
System.exit(1);
}
group.addChild(s.getSceneGroup());
Transform3D t=new Transform3D();
t.setTranslation(new Vector3f(0.5f,1.0f,0.6f));
TransformGroup tg=new TransformGroup(t);
tg.addChild(new ColorCube(1.5f));
group.compile();
return group;
}
public void VrmlLoader(String filename) {
//文件路径
filename="F/:java 3D/java/b.wrl";
this.setLayout(new BorderLayout());
Canvas3D c=new Canvas3D(SimpleUniverse.getPreferredConfiguration());
this.add("Center",c);
//建立一个虚拟宇宙
SimpleUniverse su =new SimpleUniverse(c);
su.addBranchGraph((BranchGroup) createSceneGraph(filename));
su.getViewingPlatform().setNominalViewingTransform();
}
public static void main(String[] args){
new MainFrame(new vrmlloader(), 360,360);
}
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏80(财富值+成长值)
1个回答
2014-11-04
展开全部
看看后台有什么错误信息。。。。。没有附件,也测试不了。
异常处理的地方,不要不显示错误信息,什么信息都不显示,那样没法调试
异常处理的地方,不要不显示错误信息,什么信息都不显示,那样没法调试
追问
后台什么错误页没有显示,异常处理改为 System.out.println("3DS模型加载失败" + e.getMessage());依旧没有显示什么错误, 调试的文件在这里在这里http://pan.baidu.com/s/1sjLQo49
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询