Get model URL

I’m unable to get 3D models URL for my .glb file. I’m using this:

{% assign first_3d_model = product.media | where: “media_type”, “model” | last %}

{%- if first_3d_model -%}
{% for source in first_3d_model.sources %} {%- assign model3D_url = source.format -%} {%endfor%}

and the return is always .usdz, i’ve tried first and last filter either get only the url for usdz not for glb

I have had the same problem, I need to get the URL of USDZ and GLB files generated by Shopify.

I found this code and it works perfectly:

{% assign models = product.media | where: 'media_type', 'model' %}

{% if models.size > 0 %}
  {% assign model = models | first %}

  {% for model_source in model.sources %}
    {% if model_source.format == 'glb' %}
      {% assign model_url = model_source.url %}
    {% elsif model_source.format == 'usdz' %}
      {% assign model_url_usdz = model_source.url %}
    {% endif %}
  {% endif %}
{% endif %}

url glb = {{ model_url }}
url usdz = {{ model_url_usdz }}

Code taken from craigbaldwin blog: https://craigbaldwin.com/blog/3d-models-ar-shopify/

Can i ask where you put this code in? Is this code return url of 3d model in response when i fetch api with shopify-buy package in my custom develop app?

In this case, I use this code to list the 3D models in structured data format for Google to index.

You can use it in any liquid file of your theme. For the use of the API or development of applications I do not have that knowledge.

1 Like