#How do I access a Materials Textures via typescript
1 messages · Page 1 of 1 (latest)
Hey 👋 i think you can access any prop in the Material with mat["property name"].
While if you want to use a typed solution and you can retype the material to the one that is being used. You can see the type by just printing out the object.
console.log(material) which will most probably reveal it is a MeshStandardMaterial, but it's better to double check.
So then you can do mat as MeshStandardMaterial and use it acordingly.
This standard material has normal properties to set color, colorMap, normalMap etc.
Loading textures from a file is described here:
https://threejs.org/docs/#api/en/loaders/TextureLoader
.
.
Both the **Material **and **MeshStandardMaterial ** classes are from Three.js
So a good way how to figure out this on your own is to double check from where the type is and potentially search for how is it done in pure three.js 👍
Also to note, i had to invert the Y axis and set encoding before it worked for me. I have a bit different setup, so perhaps the encoding is the only thing you are interested in.
const tex = this.textures[index];
tex.encoding = sRGBEncoding;
tex.repeat = new Vector2(1, -1);
material[this.propertyName] = tex;