[英]Why isn't my object being displayed?
Here is a 3D model I made using Art of Illusion: 这是我使用幻想艺术制作的3D模型:
I followed this tutorial to make the hourglass for all of those who are interested: 我按照本教程为所有感兴趣的人制作了沙漏:
I exported it to a file called hourglass.obj. 我将其导出到名为hourglass.obj的文件中。 Now, here is the code I am using to try to display the object:
现在,这是我用来尝试显示对象的代码:
public class LoadAnObject extends Applet
{
public LoadAnObject()
{
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas = new Canvas3D(config);
add("Center", canvas);
BranchGroup content = getScene();
content.compile();
SimpleUniverse universe = new SimpleUniverse(canvas);
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(content);
}
public BranchGroup getScene()
{
BranchGroup group = new BranchGroup();
ObjectFile object = new ObjectFile();
Scene scene = null;
try
{
scene = object.load("/Users/John/ArtOfIllusion/Hourglass.obj");
}catch(Exception e){e.printStackTrace();}
group.addChild(scene.getSceneGroup());
return group;
}
public static void main(String args[])
{
Frame frame = new MainFrame(new LoadAnObject(), 256, 256);
}
}
No errors whatsoever when I compile it or run it, I just get a blank universe when it loads. 无论是编译还是运行它,都没有任何错误,加载时我只会得到一个空白的Universe。 I got this code from here:
我从这里得到了这段代码:
Why isn't my object being displayed in the universe? 为什么我的对象没有显示在宇宙中?
The object was being displayed, but it couldn't be seen because there was no light source, here is the code I had to add to make the hourglass visible: 该对象正在显示,但由于没有光源而无法看到,这是我为使沙漏可见而必须添加的代码:
public BranchGroup getScene()
{
BranchGroup group = new BranchGroup();
ObjectFile object = new ObjectFile();
Scene scene = null;
try
{
scene = object.load("/Users/John/ArtOfIllusion/Hourglass.obj");
}catch(Exception e){e.printStackTrace();}
group.addChild(scene.getSceneGroup());
Color3f light1Color = new Color3f(1.0f, 1.0f, 1.0f);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
Vector3f light1Direction = new Vector3f(.3f, 0, 0);
DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
light1.setInfluencingBounds(bounds);
group.addChild(light1);
return group;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.