2012-07-12 239 views
0

這是一個3D模型我用幻想的藝術製作:爲什麼不顯示我的對象?

enter image description here

我跟着這個教程,使沙漏爲所有那些有興趣誰的:

我將它導出到名爲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); 
    } 
} 

沒有任何錯誤,當我編譯或運行它,我只是得到了一個空白的宇宙時,它加載。我從這裏驗證碼:

+1

有點偏離主題,但如果您對更強大(並且主動維護)的免費3D圖形程序感興趣,請嘗試[Blender](http://www.blender.org/)。 – Blender 2012-07-12 00:27:04

+0

@Blender我看了一下頁面,我真的很喜歡它,它有一個很好的教程去用它? – John 2012-07-12 00:35:25

+0

有*噸*:http://www.blender.org/education-help/tutorials/ – Blender 2012-07-12 00:39:55

回答

0

正在顯示的對象,但它不能被看到,因爲沒有光源,這裏是代碼我不得不添加,使沙漏可見:

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