API findMaterial

Hi everyone,

I want to modify the textures of some materials in a project, I have read the documentation and also based on questions posted here, but viewer.findMaterial() returns null.

Here is part of the code I am using.

var viewer = WALK.getViewer();
viewer.setMaterialEditable(‘SOME MATERIAL’);

var textureElementIds = [‘TEXTURE0’, ‘TEXTURE1’, ‘TEXTURE2’];
var texture = textureElementIds[2];

var material = viewer.findMaterial(‘SOME MATERIAL’);
console.log(‘Find Material:’, material);
material.baseColorTexture = texture;
viewer.requestFrame();

I have tried to search for different materials but in any case it returns nothing but null.

If anyone is going through the same thing or knows what I could do I would appreciate your help, maybe I need to configure the material in my project or I am missing something to do.

1 Like

Hi,

Materials are available and can be found only after the scene is ready to display, you can use Viewer.onSceneReadyToDisplay function to get a notification when this happens. See a documentation here:

Hi @jan

Thanks for your quick response, working now.