# Change all material types of object from Standard to Basic

**URL:** <https://discourse.threejs.org/t/change-all-material-types-of-object-from-standard-to-basic/44255>\
**Category:** Questions\
**Tags:** materials\
**Created:** [November 2, 2022, 9:51am UTC](https://discourse.threejs.org/t/change-all-material-types-of-object-from-standard-to-basic/44255 "2022-11-02T09:51:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stoex](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@stoex](https://discourse.threejs.org/u/stoex)\
**Post date:** [November 2, 2022, 9:51am UTC](https://discourse.threejs.org/t/change-all-material-types-of-object-from-standard-to-basic/44255/1 "2022-11-02T09:51:49Z")

</div>

Hey, I want to know how to change all materials of a model from MeshStandardMaterial to MeshBasicMaterial.

After loading the object I call the following function:

```javascript
function changeMaterial( object ) {

    object.traverse(

        ( element ) => {

            if( element?.material?.type != undefined ) {

                let targetMaterial = new THREE.MeshBasicMaterial();
                targetMaterial = element.material.clone();
                element.material = targetMaterial;

            }

        }

    );

}

```

The problem is that this function doesn’t change the type of the material.

---

<div class="post-metadata">

**Author:** ![Oxyn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/oxyn/32/12902_2.png) [@Oxyn](https://discourse.threejs.org/u/Oxyn)\
**Post date:** [November 2, 2022, 12:05pm UTC](https://discourse.threejs.org/t/change-all-material-types-of-object-from-standard-to-basic/44255/2 "2022-11-02T12:05:51Z")

</div>

you can use these lines after the condition  
the goal here is to create a new material using the map (texture) of your loader’s Standard material.  
I don’t think cloning is working in this case. But I’m interested if a more straightforward answer exist. 🤔

```javascript
	const targetMaterial = new THREE.MeshBasicMaterial({ map: object.material.map });
	targetMaterial.map.needsUpdate = true;
	object.material = targetMaterial;

	//optional but useful
	object.material.map.anisotropy = renderer.capabilities.getMaxAnisotropy();

```

---

<div class="post-metadata">

**Author:** ![stoex](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@stoex](https://discourse.threejs.org/u/stoex)\
**Post date:** [November 2, 2022, 1:20pm UTC](https://discourse.threejs.org/t/change-all-material-types-of-object-from-standard-to-basic/44255/3 "2022-11-02T13:20:30Z")

</div>

Thank you for your answer. If I do it like you wrote, I get the following error code:

> Uncaught (in promise) TypeError: Cannot set properties of null (setting ‘needsUpdate’)

The code I’ve used is:

```javascript
function changeMaterial( object ) {

    object.traverse(

        ( element ) => {

            if( element?.material?.type != undefined ) {
                let targetMaterial = new THREE.MeshBasicMaterial( {map: element.material.map} );
                targetMaterial.map.needsUpdate = true;
                element.material = targetMaterial;
                targetMaterial.map.needsUpdate = false;
            }
        }
    );
}

```

To avoid this error I deleted the needsUpdate. The problem about this is that the material gets white color. So you can’t see the model anymore.

---

<div class="post-metadata">

**Author:** ![Oxyn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/oxyn/32/12902_2.png) [@Oxyn](https://discourse.threejs.org/u/Oxyn)\
**Post date:** [November 2, 2022, 2:06pm UTC](https://discourse.threejs.org/t/change-all-material-types-of-object-from-standard-to-basic/44255/4 "2022-11-02T14:06:16Z")

</div>

Does your loaded object return/contain any `material.map`?  
maybe you have to retrieve different properties from your Standard material.

---

<div class="post-metadata">

**Author:** ![stoex](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@stoex](https://discourse.threejs.org/u/stoex)\
**Post date:** [November 2, 2022, 2:10pm UTC](https://discourse.threejs.org/t/change-all-material-types-of-object-from-standard-to-basic/44255/5 "2022-11-02T14:10:46Z")

</div>

No. The map properties are null.
