Java 3D in headless mode

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Java 3D in headless mode

Avi Kalcheim
I have a java3D application I am trying to execute in "batch" mode on a Linux machine without graphical environment.
It reads a macro file, do some work, then save graphics objects created with java3D.
I saw on gitHub you added recently a commit:
j3dcore: allow Java3D to operate in headless mode when using the noop… …
hharrison committed on Oct 29, 2016

// Java 3D cannot run in headless mode unless using the noop renderer
                        + if (java.awt.GraphicsEnvironment.isHeadless() && pipelineType != Pipeline.Type.NOOP) {
                        + throw new java.awt.HeadlessException();
                        + }
                        +


So, on the java line I wrote:
java  -Dj3d.rend=noop  -Djava.awt.headless=true ….


Then, in the program if wrote:

GraphicsConfiguration preferredConfiguration;
boolean   offScreenFlag;
Canvas3D canvas;


            String headless = System.getProperty("java.awt.headless");
            if (headless.equals("true"))
            {
                offScreenFlag = true;
                preferredConfiguration = null; /// This is obviously wrong…
             }
            else
            {            
// Retrieve preferred graphics configuration.

                preferredConfiguration = SimpleUniverse.getPreferredConfiguration();
                if (preferredConfiguration == null)
                {
                    // Write an error message to the logger and exit
                                ….
                }
                offScreenFlag = false;
            }
           
            // Create canvas.
            canvas = new Canvas3D(preferredConfiguration, offScreenFlag);
        }

I am getting
Exception in thread "main" java.lang.NullPointerException: Canvas3D: null GraphicsConfiguration
                at javax.media.j3d.Canvas3D.checkForValidGraphicsConfig(Canvas3D.java:943)

I presume I must supply a valid preferredConfiguration for the headless mode in some way, but I don’t know how.

Can you please help me ?
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in headless mode

philjord
Avi,
Unfortunately the Headless mode for Java3D doesn't allow you to actually do any Java3D work.

So the change you saw go in was based of a discussion here:
http://forum.jogamp.org/Using-Java-3D-scene-tree-in-a-headless-environment-td4026340.html

Where the users wanted to be able to create a full Java3D scenegraph, but not actually run any Java3D rendering work at all.
So there is no requirement for a Canvas3D in that configuration, and because Canvas3D extends java.awt.Canvas and does it's work on an addNotify call you won't be able to do anything with it at all, therefore there is no point in constructing it.

This is part of the reason why GraphicsConfiguration has protected constructors that can only be instantiated through factories, because unless you have a full bodied Graphics Environment you shouldn't try to use a onscreen element like Canvas3D.

If you supply some more thoughts about what you want to do in the "batch" mode with your Java3D scene we might be able to suggest some ideas. But note you won't be able do any 3d rendering with the graphics card, unless by headless you simply mean "no screen attached", which is not quite the same thing.

Thanks,
Phil.
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in headless mode

ThomasR
Hi Phil,

What are some options for "batch" processing in a "no screen attached" situation. We have Linux server with with a new Nvidia graphics card and want to do Java3D rendering to an offscreen Canvas from an automated script.

Tom