带有加载的Maya场景的Java 3D应用程序生成空黑屏

问题描述 投票:0回答:1

我使用Maya 2011创建了一个3D模型,并使用加载器访问Java 3D应用程序。我已将文件导出为OBJ文件,并在我的类中使用了OBJ文件加载器。但是当我运行应用程序时,我得到的只是一个空黑屏。

这是我的代码:

import com.sun.j3d.loaders.objectfile.ObjectFile;
com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.Scene;
import java.applet.Applet;
import java.awt.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.io.*;

public class ObjLoad extends Applet {

    public ObjLoad() {

        setLayout(new BorderLayout());
        GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
        Canvas3D canvas3D = new Canvas3D(config);
        add("Center", canvas3D);

        BranchGroup scene = createSceneGraph();
        scene.compile();    

        // SimpleUniverse is a Convenience Utility class
        SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

        // This moves the ViewPlatform back a bit so the
        // objects in the scene can be viewed.
        simpleU.getViewingPlatform().setNominalViewingTransform();
        simpleU.addBranchGraph(scene);
    } // end of ObjLoad (constructor)

    public BranchGroup createSceneGraph() {

        // Create the root of the branch graph
        BranchGroup objRoot = new BranchGroup();

        String filename = "C:/Users/myName/Documents/maya/projects/GettingStarted/scenes/temple.obj";

        ObjectFile f = new ObjectFile();
        Scene s = null;
        try {
            s = f.load(filename);
        }
        catch (FileNotFoundException e) {
            System.err.println(e);
            System.exit(1);
        }
        catch (ParsingErrorException e) {
                System.err.println(e);
            System.exit(1);
        }
        catch (IncorrectFormatException e) {
            System.err.println(e);
            System.exit(1);
        }

        objRoot.addChild(s.getSceneGroup());
        return objRoot;
    } // end of createSceneGraph method

    // The following allows this to be run as an application
    // as well as an applet

    public static void main(String[] args) {

        Frame frame = new MainFrame(new ObjLoad(), 500, 500);
    } // end of main (method of ObjLoad)
} // end of class ObjLoad

我将不胜感激任何帮助。

java 3d loader java-3d maya
1个回答
1
投票

你的场景是否包含任何照明?尝试将环境光设置为中等灰度。

© www.soinside.com 2019 - 2024. All rights reserved.