# How to use Gltf Extension?

**URL:** https://discourse.threejs.org/t/how-to-use-gltf-extension/32754
**Category:** Questions
**Tags:** loaders, materials
**Created:** [December 17, 2021, 7:56am UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754 "2021-12-17T07:56:24Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![SeeOn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/seeon/32/50793_2.png) [@SeeOn](https://discourse.threejs.org/u/SeeOn)
#### Post date: [December 17, 2021, 7:56am UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754/1 "2021-12-17T07:56:24Z")

</div>

I wanted to use Gltf Extensions mentions in Documentation.

I wanted to load my model with meshPhysicalMaterial properties but I don’t want to keep replacing for every mesh when it loads. So the Other way is to extend MeshStandardMaterial.

These are the property/extension I want to use … But I don’t know how to add extension .  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/9/9/99c958360197baa85e42a8dee4d32d4e913e9860.png)

Any regarding this would be helpful.

Thank you.

---

<div class="post-metadata">

### Author: ![mrdoob](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mrdoob/32/22417_2.png) [@mrdoob](https://discourse.threejs.org/u/mrdoob)
#### Post date: [December 17, 2021, 12:37pm UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754/2 "2021-12-17T12:37:15Z")

</div>

The `GLTFLoader` already parses these extensions and returns a `MeshPhysicalMaterial` accordingly.

(Minus the `KHR_materials_pbrSpecularGlossiness` one which is deprecated)

---

<div class="post-metadata">

### Author: ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)
#### Post date: [December 17, 2021, 5:53pm UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754/3 "2021-12-17T17:53:46Z")

</div>

If the model doesn’t use any of these extensions yet but you want to ensure it loads with MeshPhysicalMaterial anyway, a quick way to add one would be to open the model on [https://gltf.report/](https://gltf.report/) and run this script:

```javascript
import { MaterialsSpecular } from '@gltf-transform/extensions';

const specularExtension = document.createExtension(MaterialsSpecular);
const specular = specularExtension.createSpecular();

for (const material of document.getRoot().listMaterials()) {
	material.setExtension('KHR_materials_specular', specular);
}

```

It won’t affect the appearance but does require MeshPhysicalMaterial. Note that MeshPhysicalMaterial is a more expensive material to render. You could do something similar by setting transmission or clearcoat in Blender.

---

<div class="post-metadata">

### Author: ![SeeOn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/seeon/32/50793_2.png) [@SeeOn](https://discourse.threejs.org/u/SeeOn)
#### Post date: [December 18, 2021, 6:29am UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754/4 "2021-12-18T06:29:07Z")

</div>

Thank you for replying,

@donmccurdy that gltf report is a Great Project. Absolutely loved it. 😍

and sorry, I don’t know how to make gltfLoader parse data or use those extensions, so it returns MeshPhysicalMaterial while loading model every time. Is there documentation or example I can refer to.

Here is a basic jsFiddle which load gltf model. If you wish please modify in this.  
[https://jsfiddle.net/seeon/ce58o43k/38/](https://jsfiddle.net/seeon/ce58o43k/38/)

Thankyou,  
Seeon

---

<div class="post-metadata">

### Author: ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)
#### Post date: [December 18, 2021, 7:37am UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754/5 "2021-12-18T07:37:14Z")

</div>

> [@SeeOn](#):
>
> and sorry, I don’t know how to make gltfLoader parse data or use those extensions, so it returns MeshPhysicalMaterial while loading model every time. Is there documentation or example I can refer to.

GLTFLoader does not have an option to force it to return MeshPhysicalMaterial, if that’s what you’re asking? The glTF file must be configured so that it _requires_ MeshPhysicalMaterial, otherwise it will return MeshStandardMaterial. The gltf.report script above is one way of doing that.

Replacing the material after the model loads is also fine. I think something like this would copy all the original properties:

```js
const nextMaterial = new MeshPhysicalMaterial();
MeshStandardMaterial.prototype.copy.call(mesh.material, nextMaterial);
mesh.material = nextMaterial;

```

---

<div class="post-metadata">

### Author: ![SeeOn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/seeon/32/50793_2.png) [@SeeOn](https://discourse.threejs.org/u/SeeOn)
#### Post date: [December 18, 2021, 8:02am UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754/6 "2021-12-18T08:02:28Z")

</div>

Yes, I was referring to loading MeshPhysicalMaterial by default.

At first, I thought to Extend MeshStandardMaterial and all those properties for each Mesh but later in GLTFLoader I found these extensions so wanted to know what they were and how can I use it.

But Certainly the one you mention for replacing is Easier and Better than doing it myself.

A small doubt : if we export a model from blender with those properties(like Clearcoat) in Principled BSDF shader, will it return MeshPhysicalMaterial in Threejs ?

---

<div class="post-metadata">

### Author: ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)
#### Post date: [December 18, 2021, 6:03pm UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754/7 "2021-12-18T18:03:31Z")

</div>

Blender only supports exporting some of those properties — clearcoat and transmission — today. But yes, if you set clearcoat\>0 or transmission\>0 in Blender Principled BSDF it should will load as MeshPhysicalMaterial in three.js, because that’s required to represent those materials.

---

<div class="post-metadata">

### Author: ![Lalit\_Kumar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lalit_kumar/32/41323_2.png) [@Lalit\_Kumar](https://discourse.threejs.org/u/Lalit_Kumar)
#### Post date: [October 26, 2023, 9:45am UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754/8 "2023-10-26T09:45:43Z")

</div>

Threejs v0.151.3 does not have extension support. can anyone let me know how to use this extension?  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/9/9/99c958360197baa85e42a8dee4d32d4e913e9860.png)

---

<div class="post-metadata">

### Author: ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)
#### Post date: [October 26, 2023, 1:05pm UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754/9 "2023-10-26T13:05:06Z")

</div>

I’m not sure what you’re asking exactly, but three.js r151 supports all of those extensions except `KHR_materials_pbrSpecularGlossiness`. You don’t need to do anything different to use them. `KHR_materials_pbrSpecularGlossiness` has been removed, but it’s possible to convert models offline to not use that extension while still looking the same, if that’s something you need.

---

<div class="post-metadata">

### Author: ![Lalit\_Kumar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lalit_kumar/32/41323_2.png) [@Lalit\_Kumar](https://discourse.threejs.org/u/Lalit_Kumar)
#### Post date: [November 2, 2023, 9:24am UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754/10 "2023-11-02T09:24:18Z")

</div>

I have tried to access as following  
import { GLTFLoader } from “three/examples/jsm/loaders/GLTFLoader”;  
const gltfLoader = new GLTFLoader();  
gltfLoader.setExtensions([list of extension…]);

threejs version 0.151.3

---

<div class="post-metadata">

### Author: ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)
#### Post date: [November 2, 2023, 12:23pm UTC](https://discourse.threejs.org/t/how-to-use-gltf-extension/32754/11 "2023-11-02T12:23:57Z")

</div>

I’m not sure what you’re trying to do. The extensions you’ve listed are already supported and you don’t need to do anything to use them, you just need a glTF model that requires them.

It might be best to start a new thread with full context on what you’re aiming to do, and what errors you are seeing along the way.
