加载 Maya 场景的 Java 3D 应用程序会产生空黑屏

发布于 2024-11-14 11:42:52 字数 2418 浏览 7 评论 0原文

我使用 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

我将不胜感激任何帮助。

I have made a 3D model using Maya 2011, and I used a loader to access in a Java 3D application. I have exported the file as an OBJ file, and used an OBJ file loader in my class. However when I run the application, all I get is an empty black screen.

Here is my code:

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

I would appreciate any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2024-11-21 11:42:52

您的场景包含任何灯光吗?尝试将环境光设置为中度灰色。

Does your scene contain any lighting? Try setting the ambient light to a mid level grey.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文