Updating materials (and textures) from the API


I’d like to be able to make changes to some materials directly from the API. In particular, I’d like to update the textures (changing the bitmap and the transparency textures).

I have made some tests using this article as a reference:

In my example I tried to update a texture for an advanced material (version: “2.0”), but it didn’t work.

(By the way, the above link is also not working from what I can tell.)

I also tried to update that material with a simple material (version:“1.0”) without any texture, but again it didn’t seem to be working.

I’d have a couple of questions, before I spend too long testing:

  • Is this even supposed to work?
  • “IF” this works, will I be able to avoid getting back to the GH file, and just update the materials “in real time”? (right now I’m already updating the materials through the GH model, but this takes a bit of time)

Thank you!

1 Like

@Marco_Traverso the example model in the support article you referenced was not working due to a missing allowed domain (jsfiddle seems to have updated sth on their side), now it’s working again.

Yes of course!

That’s exactly what you can do.

In case you need help, please provide your example on JsFiddle or Codepen or equivalent.

Thank you @snabela for the confirm and for fixing the article, I got my example working.

One more question: would it be possible to change a mesh mapping defined in Grasshopper (in particular I’d like to change the texture size for the mesh box mapping) via the API? Maybe accessing some mesh attributes like for a regular Three.js geometry?

Alternatively, is it possible to create/add to the 3D viewport/scene assets (meshes) created on the fly with Three.js?

Is there any example or specific documentation about this? I searched for it but didn’t find much.

Thanks again

You can apply transformations to the texture coordinates by using the material specification format MaterialV3, which allows you to set the bitmaptexture property to a Texture object.

Thank you @snabela, this works perfectly!