# GLTF Parser Hooks

**URL:** <https://forum.babylonjs.com/t/gltf-parser-hooks/950>\
**Category:** Questions\
**Created:** [January 25, 2019, 10:59am UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950 "2019-01-25T10:59:51Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 1, 2019, 1:26am UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/21 "2019-02-01T01:26:35Z")

</div>

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???

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 1, 2019, 1:33am UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/22 "2019-02-01T01:33:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 1, 2019, 1:42am UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/23 "2019-02-01T01:42:43Z")

</div>

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 ???

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 1, 2019, 2:00am UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/24 "2019-02-01T02:00:48Z")

</div>

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.

> [@MackeyK24](#):
>
> When should I set scene.useRightHandSystem in onLoaded in the gltf parser.

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

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 1, 2019, 2:08am UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/25 "2019-02-01T02:08:40Z")

</div>

If you are using one of the SceneLoader that creates a scene, then you need to set [forceRightHanded](https://doc.babylonjs.com/api/enums/babylon.gltfloadercoordinatesystemmode#force_right_handed) on the loader. See [Advanced Usage](https://doc.babylonjs.com/how_to/load_from_any_file_type#advanced-usage) for how to set loader options.

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 1, 2019, 8:15am UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/26 "2019-02-01T08:15:48Z")

</div>

Yo @Deltakosh and @bghgary

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

```auto
        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.

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

```

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

```auto
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 ???

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 1, 2019, 12:01pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/27 "2019-02-01T12:01:09Z")

</div>

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 ???

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [February 1, 2019, 4:40pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/28 "2019-02-01T16:40:35Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 2, 2019, 11:50pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/29 "2019-02-02T23:50:44Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 5, 2019, 5:53pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/30 "2019-02-05T17:53:27Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 5, 2019, 10:15pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/31 "2019-02-05T22:15:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 6, 2019, 1:30pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/32 "2019-02-06T13:30:02Z")

</div>

yup… I guess 🙂

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 6, 2019, 10:13pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/33 "2019-02-06T22:13:35Z")

</div>

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 ???

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 6, 2019, 10:31pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/34 "2019-02-06T22:31:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 6, 2019, 10:32pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/35 "2019-02-06T22:32:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 7, 2019, 2:11am UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/36 "2019-02-07T02:11:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 7, 2019, 8:57am UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/37 "2019-02-07T08:57:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 7, 2019, 2:28pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/38 "2019-02-07T14:28:46Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [February 7, 2019, 2:52pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/39 "2019-02-07T14:52:06Z")

</div>

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 ???

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 7, 2019, 3:04pm UTC](https://forum.babylonjs.com/t/gltf-parser-hooks/950/40 "2019-02-07T15:04:48Z")

</div>

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;

[Previous page](https://forum.babylonjs.com/t/gltf-parser-hooks/950.md?page=1)

[Next page](https://forum.babylonjs.com/t/gltf-parser-hooks/950.md?page=3)
