menu

Vectary

Vectary is an easy-to-use collaborative online 3D tool where you can make awesome 3D designs. Collaborate with your friends in real time!

Channels
# All channels
view-forward
# General
view-forward
# Announcements
view-forward
# AR/USDZ - Viewer
view-forward
# Archive
view-forward
# Feature Requests
view-forward
# Feedback
view-forward
# Figma
view-forward
# Help
view-forward
# Show and Tell
view-forward
# Sketch
view-forward
# Tips and Tricks
view-forward
# Tutorials
view-forward
Team

Setting materials via API call

February 10, 2021 at 10:00pm

Setting materials via API call

February 10, 2021 at 10:00pm
In my canvas, I have a single object, for which I would like to change the material via an API call (when a Customer clicks some buttons). When I try to do so via the setMaterial method, this breaks (I was assuming that, because it does not find the material used within my canvas). When querying for the available materials, I get as response only the materials used on the visible objects in my canvas (one only). Therefore, I do not know how to set a new material on my object, via an API call - am I doing something wrong or is this the way it should behave? Can my use case be implemented? Thanks in advance :)

February 11, 2021 at 8:45am
Any object hidden at the time of embedding will not be part of the final scene and neither its materials (if they are unique to those objects). You said you want to change the material of the current object via the API, the question is what is exactly that you plan on changing? Your use case of I have a single object, for which I would like to change the material via an API call (when a Customer clicks some buttons) can totally be implemented: https://www.vectary.com/webar/vectary-lamp-3d-configurator/
  • reply
  • like

February 11, 2021 at 9:55pm
Hello Jaume, thanks a lot for your reply! My use case is indeed similar to the one in your link. However, if I understood correctly the implementation from the sample you have given me, I got the following: the lamp does not actually modify its material on button click, but rather the entire lamp model is changed, by querying for another model from vectary, as below: var url = 'https://www.vectary.com/viewer-ar/v1/?model=' + uuid; document.querySelector(".arLink").setAttribute("href", url); - is this what you meant? I was looking at achieving the same, but calling the "setMaterial" API method so that I can use a single model, which I modify. Is there any other way I can retrieve a list of all materials, available in my vectary project (linked to the UID for which I render the model?). Thanks in advance, again :)
Edited
  • reply
  • like

February 12, 2021 at 8:34am
The change of modelid is only for the link of the AR button, nothing else. You can't change the glb/usdz file required for AR throught the API, only the 3D model that loaded into your website's canvas. Therefore you need to have the different variants as alt-projects of your original. But the demo I sent you is indeed changingthe material of the lamp, not loading another model on top (see the transition of color?)
  • reply
  • like

February 17, 2021 at 9:12pm
Make sense, Jaume! Thank you! :)
  • reply
  • like