scenerygraphics / scenery

Flexible VR Visualisation for Volumetric and Geometric Data on the Java VM, powered by Kotlin and Vulkan.
https://scenery.graphics
GNU Lesser General Public License v3.0
131 stars 32 forks source link

Attempting to try the Minimal Scenery Example with java creates a frozen window. #771

Open odinsbane opened 3 months ago

odinsbane commented 3 months ago

Porting the MinimalSceneryExample to java creates a window that is non-responding.

package org.livingtech.scbridge;

import graphics.scenery.*;
import graphics.scenery.backends.Renderer;
import org.joml.Vector3f;

public class CreateSceneryWindow {
    public static void main(String[] args){
        SceneryBase base = new SceneryBase("Scenery Window"){
            @Override
            public void init(){
                Hub hub = getHub();
                Scene scene = getScene();
                hub.add(
                        SceneryElement.Renderer,
                        Renderer.createRenderer(
                                hub,
                                getApplicationName(),
                                getScene(),
                                512, 512
                        )
                );
                Box box = new Box(new Vector3f(1.0f, 1.0f, 1.0f));
                box.material().setDiffuse(new Vector3f(1.0f) );
                scene.addChild(box);

                PointLight light = new PointLight( 15.0f );
                light.spatial().setPosition(new Vector3f(0.0f, 0.0f, 2.0f));
                light.setIntensity(5.0f);
                light.setEmissionColor(new Vector3f(1.0f, 1.0f, 1.0f) );
                scene.addChild(light);

                DetachedHeadCamera cam = new DetachedHeadCamera();
                cam.spatial().setPosition(new Vector3f(0.0f, 0.0f, 5.0f) );
                cam.perspectiveCamera(50.0f, 512, 512, 0f, 10f);
                scene.addChild(cam);

            }
        };

        new Thread(base::main).start();
    }
}

Expected behavior

The window should show with a rendered cube?

Desktop (please complete the following information):

Additional context

This isn't too important. If I create a sciview context I can get a scenery rendering window. I was curious if this would work/ should work.

odinsbane commented 3 months ago

I found a fix for this, I had to set the renderer in the SceneryBase not just add the renderer to the hub.

                Renderer renderer = Renderer.createRenderer(
                        hub,
                        getApplicationName(),
                        scene,
                        512, 512
                );
                setRenderer(renderer);
                hub.add( SceneryElement.Renderer, renderer );