# Custommaterial and importmesh

**URL:** <https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637>\
**Category:** Questions\
**Created:** [April 17, 2019, 4:07am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637 "2019-04-17T04:07:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [April 17, 2019, 4:07am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637/1 "2019-04-17T04:07:30Z")

</div>

so erm, weird thing I found. I think its my codes but any help would be appreciated. When the scene has native bjs meshes and imported mesh, assigning custom material on all meshes works only on the native meshes. If I comment those out, the imported meshes get the custom material too.

PG repro here: [https://www.babylonjs-playground.com/#UXCB15#59](https://www.babylonjs-playground.com/#UXCB15#59)  
comment out line 66 & 68 to see the difference. erm, what am I missing here ?

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [April 17, 2019, 5:41am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637/2 "2019-04-17T05:41:22Z")

</div>

ok, i figured out that the rabbit has a skeleton, setting rabbit.skeleton = null works. So I tried it with the candle babylon mesh instead. And now I can’t get it to work at all.

[https://www.babylonjs-playground.com/#UXCB15#60](https://www.babylonjs-playground.com/#UXCB15#60)

Any ideas?

---

<div class="post-metadata">

**Author:** ![nasimiasl](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nasimiasl/32/34_2.png) [@nasimiasl](https://forum.babylonjs.com/u/nasimiasl)\
**Post date:** [April 17, 2019, 5:58am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637/3 "2019-04-17T05:58:59Z")

</div>

[https://www.babylonjs-playground.com/#UXCB15#61](https://www.babylonjs-playground.com/#UXCB15#61)

hey we don’t catch the error yet that is alternative plan for yet

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [April 17, 2019, 5:59am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637/4 "2019-04-17T05:59:30Z")

</div>

well, it works on the babylon logo when vertex colors are switched off, so I dunno why it sometimes works, sometimes does not…_giveup_

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [April 17, 2019, 6:02am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637/5 "2019-04-17T06:02:45Z")

</div>

ok, I see what you did, is this gpu intensive ? I think its reloading textures per material assignment…

---

<div class="post-metadata">

**Author:** ![nasimiasl](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nasimiasl/32/34_2.png) [@nasimiasl](https://forum.babylonjs.com/u/nasimiasl)\
**Post date:** [April 17, 2019, 6:02am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637/6 "2019-04-17T06:02:58Z")

</div>

BABYLON.SceneLoader  
that not work for mesh created with BABYLON.SceneLoader if you set it before to other mesh

---

<div class="post-metadata">

**Author:** ![nasimiasl](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nasimiasl/32/34_2.png) [@nasimiasl](https://forum.babylonjs.com/u/nasimiasl)\
**Post date:** [April 17, 2019, 6:06am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637/7 "2019-04-17T06:06:18Z")

</div>

> [@phaselock](#):
>
> reloading textures per material

that is absolutely heavy form one instance but texture is load one time a in GPU too (i guess)

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [April 17, 2019, 6:09am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637/8 "2019-04-17T06:09:47Z")

</div>

ok, I don’t get it. What do you mean by ‘that not work for mesh created with BABYLON.SceneLoader if you set it before to other mesh’. I can’t assign custom materials to multiple meshes in sceneloader ?

like in this PG ? [https://www.babylonjs-playground.com/#UXCB15#64](https://www.babylonjs-playground.com/#UXCB15#64)

---

<div class="post-metadata">

**Author:** ![nasimiasl](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nasimiasl/32/34_2.png) [@nasimiasl](https://forum.babylonjs.com/u/nasimiasl)\
**Post date:** [April 17, 2019, 6:45am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637/9 "2019-04-17T06:45:58Z")

</div>

i see yes that is why i told we have problem with scene load  
that not happen in shadermaterial  
[https://www.babylonjs-playground.com/#UXCB15#67](https://www.babylonjs-playground.com/#UXCB15#67)

simple custommaterial is work well  
[https://www.babylonjs-playground.com/#UXCB15#68](https://www.babylonjs-playground.com/#UXCB15#68) (new Object don’t have Uv? )  
[https://www.babylonjs-playground.com/#UXCB15#69](https://www.babylonjs-playground.com/#UXCB15#69)

i find bug 🙂

when you use new Uniform that not set for all instance when you update that

[https://www.babylonjs-playground.com/#UXCB15#70](https://www.babylonjs-playground.com/#UXCB15#70) ( make pos.xz uv)

[https://www.babylonjs-playground.com/#UXCB15#71](https://www.babylonjs-playground.com/#UXCB15#71)

i don’t know where we can fix it need someone have time and check why when we define new Uniform that not update for all mesh

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [April 17, 2019, 7:00am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637/10 "2019-04-17T07:00:13Z")

</div>

Awesome, @nasimiasl !!  
So rabbit has skeleton, interferes with custommaterial  
babylon logo has vertex colors, interferes with custommaterial  
candle has no uvs, interferes with custommaterial (duh, lol)

And yh, the bug was what lead me to making pgs and testing them. tho i was using pbrcustommaterial. Now, I know why my textures weren’t loading for other meshes, hmm…

I need to go find a workaround, bleh…

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [April 17, 2019, 7:33am UTC](https://forum.babylonjs.com/t/custommaterial-and-importmesh/2637/11 "2019-04-17T07:33:00Z")

</div>

Sharing ss of the problem. This is an early prototype of the low poly terrain I’m working on. The small white house is its own mesh with its own material which works fine. The terrain is 1 single mesh with 1 pbrcustommaterial. My problem is that the grey trees are from a separate mesh instanced and sharing the same pbrcustommaterial and therefore the leaves and bark are showing my splatmap colors instead of the textures. Sceneloader loads terrain and assigns pbrcustommaterial fine but when it comes time to load the tree and assign the same pbrcustommaterial, only the diffusetexture is loaded, the rest of uniforms don’t load.

 ![bug_pbrcustommaterial](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/7/7ef0eb272bdbe289434586841aec1e9a2e67b2c6.jpeg)

It’s a pity but my current workaround is to let the trees/props avoid sharing the terrain’s pbrcustommaterial and use their own material instead. I don’t like it as it means more memory for textures for what is essentially static props. But I don’t have time to debug the source for now…tsk tsk.
