Babylon - fundamental Camera and Light problem from Blendr scene

Hi All,

I’m new to BabylonJS. MY code below is based off the babylon js tutorials.

I’ve created a scene in blender 2.8 and exported into .babylon format, using the blendr2babylon exporter 6.2.0

I’m trying to get babylon to make use of the camera and lights that i created in blendr.

I’ve managed to load my .babylon scene file using LoadAssetContainer.

U will notice i create an Arc camera first, because that was part of tutorial code. The only way i could find to make use of the Blendr camera was to explicitly set the active camera, but i realize it loses the “Arc” capabilty, and it results in a fixed camera which doesn’t move.

scene.activeCamera = container.cameras[0];

Questions:

  • Could someone show me how to make proper use of Blendr Camera thorugh code or settings? My camera type in Blendr is Universal which i thought would automatically be able to “move” around in babylon using the keys.

  • Could someone show me how to make use of Blendr lights? I have a “Sun” light in blendr which i understand is supposed to be converted to “directional” in babylon, but when rendering the babylon scene, its obvious my “sun” is not there, as its darkish and the trees don’t cast shadows?

Kevin

var canvas = document.getElementById(“renderCanvas”); // Get the canvas element
var engine = new BABYLON.Engine(canvas, true); // Generate the BABYLON 3D engine

var createScene = function () {

// Create the scene space
var scene = new BABYLON.Scene(engine);

 var camera = new BABYLON.ArcRotateCamera("BabylonCamera", 0,0,5, new BABYLON.Vector3(0,0,0), scene);
 camera.attachControl(canvas, true);

// Add lights to the scene
var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene);
var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 6, -1), scene);

BABYLON.SceneLoader.LoadAssetContainer(“assets/”, “NatureScene.babylon”, scene, function (container) {
var meshes = container.meshes;
var materials = container.materials;

  if(container.cameras[0]){
  	
        scene.removeCamera(camera)
        scene.activeCamera = container.cameras[0];

    }

    // Adds all elements to the scene
  container.addAllToScene();

});

return scene;

};
/******* End of the create scene function ******/

var scene = createScene(); //Call the createScene function

// Register a render loop to repeatedly render the scene
engine.runRenderLoop(function () {
scene.render();

});

Maybe @JCPalmer can help as he is the mastermind behind the blender exporter :slight_smile:

and by the way Welcome to the forum !!!

On the camera, ditch the one in code. Whether you do it in a callback, or like this, just attach it.

const canvas = document.getElementById("renderCanvas");
const engine = new BABYLON.Engine(canvas, true);

BABYLON.SceneLoader.Append(url, "armature.babylon", scene);
scene.executeWhenReady(function () {
   // Attach camera to canvas inputs
    scene.activeCamera.attachControl(canvas);

    // Once the scene is loaded, register a render loop
    engine.runRenderLoop(function() {
        scene.render();
    });
});

To use an exported ArcRotate camera, in addition to setting the type in the exporter properties, you need to add a track to constraint on the camera. This is done different in 2.80. Set the target to the mesh you want. It does not matter for export, but you probably want change the To to Z, so if you did test views in blender, the camera is not pointing to the ground.

Shadows are not automatically transferred. You need to check the Receives Shadows or Casts Shadows on the appropriate meshes, exporter properties. The light must also have a shadow generator set in the exporter propeties for lights. FYI, when you export in PBR, shadows can be very faint, depending on your environment texture & its intensity. Switching to a STD materials export can give you an sanity check.

1 Like

Thank you Sebavan! Glad to be part of the community!

Thank you JCPalmer, that seems to work for the camera and code is much simpler. I will start to troubleshoot the lights / shadows. Thank you!!!

Hi JCPalmer,

I’m reading the docs here
https://doc.babylonjs.com/resources/blender#cameras
https://doc.babylonjs.com/resources/blender_tips#arcrotate

One thing stated in the 2nd link is that Babylon and Blender do alot of things differently.

With that said:

  1. while in using your code i got the camera from Blender to ‘work’ in Babylon, I don’t get the other settings carried across such as Field of View

  2. My blender light settings (intensity, shadows), don’t seem to be carried across, screenshot in Blender vs Babylon below. Are basic settings like intensity not carrying across? is there something i need to do in code?

Screenshots showing light intensity and camera FOV not carrying across from Blender to Babylon

@JCPalmer or anyone would you be able to provide some guidance around this? :slight_smile:

maybe @Vinc3r

FOV is transferred. Never seen what you are showing for lights. They are not lights created in 2.80. Old lights from scenes prior to 2.80 have different properties.

Erf, first at all, Blender Exporter doc’ should be update about 2.8. It could be a nice idea to share very basic Blender example scenes by the way isn’t it ? (I have to say that since I’m using a lot gltf now, I haven’t yet test .babylon exporter on 2.8…)