GLTF Parser Hooks

That’s sounds good. Just to clarify. When should I set scene.useRightHandSystem in onLoaded in the gltf parser. And once I set that can I manually enter camera position 0,1,-10 and get the results I am expecting???

Also if I set scene to use right handed system, should I NOT switch handedness in the unity gltf exporter ???

From what I can tell … unity uses left handed system. So I should still switch handedness to right hand in C# gltf export. And simply set unity scene.useRigttHandSystem so I don’t have to manually invert position.z vectors and rotate y to Math.PI when adding camera, lights or meshes outside of the gltf export process

Is that correct, or am I way off ???

Unity is left-handed. glTF is right-handed. Babylon can be either.

Unity to glTF requires conversion. Loading glTF into Babylon does not if you set Babylon to right handed.

I don’t know your code, but normally you should set it to right handed right after the scene is created.

If you are using one of the SceneLoader that creates a scene, then you need to set forceRightHanded on the loader. See Advanced Usage for how to set loader options.

Yo @Deltakosh and @bghgary

I tried to use On Plugin Active to force right hand:

        BABYLON.SceneLoader.OnPluginActivatedObservable.add(function (loader) {
            if (loader.name === "gltf") {
                console.log("ACTIVATE GLTF LOADER");
                loader.coordinateSystemMode = 1;
                console.log(loader);
                loader.dispose();
            }
        });        

But it does not seem to do anything to the scene. I still have to add my camera in code with inverted values. When looking at the seen. I wanna create a camera and back it up 10 units. so its looking at the cube in the center of the scene at position zero.

var camera = new BABYLON.UniversalCamera("Default Camera", new BABYLON.Vector3(0, 1, -10), scene);

But its backwards… I have to make camera like this:

var camera = new BABYLON.UniversalCamera("Default Camera", new BABYLON.Vector3(0, 1, 10), scene);
camera.rotation = new BABYLON.Vector3(0, Math.PI, 0);

So i have to think INVERTED when write game mechanic code that has to do with position and rotation of a transform node.

I know Unity GLTF converts to right hand… If i make my unity exporter stay left handed. Can i disable the conversion that babylon uses… So both my exported GLTF and babylon are left handed and i can
still use camera positions like Vector3(0,1,-10) that is supposed to be 10 units BEHIND.

Just thinking out-load here. because im gonna HATE having to flip all my vector3 positions and quaternion rotations.

OR AM NOT USING scene.useRightHandedSystem correctly in the code snippet above ???

I guess its all relative to the camera position. But moving objects around… especially ZED … Negative values would go AWAY from camera and POSITIVE would come back CLOSER…

I dunno … the inverted Z is confusing me and dont know what would be the impact of -Z when writing game code… especially when determining what is FORWARD.

But i also thing the coord system should stay left handed… I am used to POSITIVE X values to move to the right and NEGATIVE vales moves to the left… Which is left handed system… i believe.

What are other Babylon Developers doing when using GLTF… Just deal with having inverted Z from what setup in the editor ???

Most of the gltf user stays on left handed as this is the default mode of Babylonjs and jsut let the gltf loader do its magic (it is adding a rootnode with a negative scaling z to compensate)

Yo @Deltakosh or @bghgary or @sebavan

In unity, a spot light seems to only have a variable for “Spot Angle” in degrees … It does not specify a separate Inner And Outer angles.

So i was doing babylonLight.angle = Deg2Rad(unity.spotangle)

But how should i compute the innerAgnle from the Spot Angle. Is there some default value i can use for computing the innerAngle for babylon ?

Unity only has an outer angle and no inner angle. Inner angle for Babylon defaults to 0 which is what you want in this case. Also, I think Unity’s angle is the same as glTF’s angle (from light direction to outer edge) which is half of Babylon’s angle (from edge to edge).

So should I double the angle the value I assign to Babylon light.angle ?

yup… I guess :slight_smile:

Hey @bghgary… I am now trying to match up Shadows. In unity there is ONLY options for HARD and SOFT shadows. In babylon we have several different shadow map generation options like usePoissonSampling and useExponentialShadowMap.

From my understanding all these options are considered SOFT shadows… Is that correct.
If so are there any options for HARD shadows ???

And what would be the BEST DEFAULT option for when unity is set to SOFT shadows… I was thinking blur close exponential would be a good default for soft shadows… What do you think about UNITY to BABYLON shadow options ???

@MackeyK24 Unfortunately, I don’t know much about shadows. Maybe @sebavan can help?

Thanks @bghgary for the quick response… Sebastian (@sebavan)… What do you think ???

I would say start with the FILTER_PCF the setup for the bias and normal bias should be close now Unity relies on cascaded shadow maps not supported in bjs so you might still have artifacts they do not.

The trick is too well position the max and min depth from the light to the scene.

So @sebavan and @Deltakosh … Can you please clarify a few things so i can setup the best defaults for the exporter and shadow generator.

UPDATED

1… Are ALL FILTERS considered SOFT shadows. Or are there any filters that would be considered HARD shadows ?

2… When you say the important thing is to properly set min and max… do you mean light.shadowMinZ and light.shadowMaxZ. And if so what is the proper calculations from unity data to set min and max

  1. Nope PCF, PCSS, Blur and PoissonSample are considered soft, Default mode is hard as well as exponential none blurred.

  2. Nope you can enable only one at a time, when you call use… it disables the other types.

  3. Yes, it should be set to ensure all the shadows and casters are enclosed in min max and as close as it can be from them. Except for inverseExponential where min should be the same and max can be further due to the inverse Nature.

  4. Unfortunately shadows do not multiply against ambient today and as it is considered as an indirect source of light we maybe should. @Deltakosh could weigh on this one ?

Yo @sebavan

So Exponential and Close Exponential are considered HARD shadows… Right?

What about contact Hardening… is that PCSS ???

I am just trying to make a drop down of filters you can apply when you have unity light set to SOFT shadows vs HARD shadows.

So if you have Unity set to HARD Shadows the HARD shadow list of filters you can choose from:
useExponentialShadowMap;
useCloseExponentialShadowMap;

and Soft Shadow Options:

usePoissonSampling;
usePercentageCloserFiltering;
useBlurExponentialShadowMap;
useBlurCloseExponentialShadowMap;
useContactHardeningShadow;

Is that right ???

So if you have Unity set to HARD Shadows the HARD shadow list of filters you can choose from:
None -> Default hard
useExponentialShadowMap;
useCloseExponentialShadowMap;

and Soft Shadow Options:

usePoissonSampling;
usePercentageCloserFiltering;
useBlurExponentialShadowMap;
useBlurCloseExponentialShadowMap;
useContactHardeningShadow;