Why no scene.getTextureByName() method?

Just curious why there’s no scene.getTextureByName() when we have getMaterialByName(), getSoundByName(), getMeshByName() etc?

I figure there’s a good reason for this. I just can’t think what it is :slight_smile:

2 Likes

Is Texture a construct anywhere in babylon? I can only recall ever working with materials I think.
I think i might use textureName for the file location. Not sure.

Okay I just looked it up, yeah it is a thing. So my best guess is that it isn’t something maybe that is relevant somehow to realtime manipulation. Like so by the time it matters in realtime it is already part of a material ready to be plastered on some geometry or something?

It just seems like something you would hold closer to your heart than having exposed to a realtime rendering environment perhaps.

Well mostly because we did not do it :slight_smile: All good if you want to send a PR to add it

4 Likes

Was this ever added? I did not see it in docs. If not +1 for need.

1 Like

I’m game, he’s a little PR for it modeled after getTextureByUniqueId. :slight_smile: :beers:

6 Likes

Is there a way to pass a reference to the original texture instead of making a copy (passing by value)? This would save resources and simplify the scene tree.

let texture = scene.getTextureByName(textureName); 
xxx.material.diffuseTexture = texture ;

To me expected behavior would be grabbing a reference to the original, but both your method and what I tossed in always return value, and the texture tree always shows a second texture. So, I assume it is passing value. Maybe this is just how Babylon works.

image

2 Likes

Can you make a little playground showing a duplicate texture in the inspector? Ideally by just creating one texture? I’ve never noticed a texturing being duplicated before, so a PG would def help to understand the issue better. :slight_smile:

Strange, it must be in my code somewhere.

It indeed does work fine
https://playground.babylonjs.com/#ZMCFYA#175

Looks like I have some debugging to do.

Nothing else to see here. You did great. Thanks.

1 Like

Merged, coming to the nightly build in a few hours.

4 Likes