簡體   English   中英

為什么沒有顯示我的對象?

[英]Why isn't my object being displayed?

這是我使用幻想藝術制作的3D模型:

在此處輸入圖片說明

我按照本教程為所有感興趣的人制作了沙漏:

我將其導出到名為hourglass.obj的文件中。 現在,這是我用來嘗試顯示對象的代碼:

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);
    }
}

無論是編譯還是運行它,都沒有任何錯誤,加載時我只會得到一個空白的Universe。 我從這里得到了這段代碼:

為什么我的對象沒有顯示在宇宙中?

該對象正在顯示,但由於沒有光源而無法看到,這是我為使沙漏可見而必須添加的代碼:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM