4

Currently when I upload the code below into an HTML component on my site the content is constrained to a small box, however there is far more space in the html component to fit the content.

Can someone please let me know what and where to write the code that would be most appreciated!

<script type="module" 
        src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>

<model-viewer 
       alt="Neil Armstrong's Spacesuit from the Smithsonian Digitization Programs Office and National Air and Space Museum" 
       src="shared-assets/models/NeilArmstrong.glb" 
       ar ar-modes="webxr scene-viewer quick-look" 
       environment-image="shared-assets/environments/moon_1k.hdr" 
       poster="shared-assets/models/NeilArmstrong.webp" 
       seamless-poster shadow-intensity="1" camera-controls>
</model-viewer>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

3 Answers3

0

If you want to increase a model-viewer box width and height then you can easily apply a css on model-viewer tag.

    model-viewer{
         width:400px;
         height:400px;
    }
Iron Man
  • 35
  • 3
0

I had this exact same problem also

the content is constrained to a small box, however there is far more space in the html component to fit the content.

The solution for me was to do the following:

Wrap the model-viewer in an empty div and apply CSS to the DIV and the model-viewer that achieved the styling I desired.

Notes

When I tried using the following values for width on the model-viewer it would not style correctly.

width: auto;
width: 100%;

HTML below

<div class="model-view-css-fix">
      <model-viewer 
       alt="Neil Armstrong's Spacesuit from the Smithsonian Digitization Programs Office and National Air and Space Museum" 
       src="shared-assets/models/NeilArmstrong.glb" 
       ar ar-modes="webxr scene-viewer quick-look" 
       environment-image="shared-assets/environments/moon_1k.hdr" 
       poster="shared-assets/models/NeilArmstrong.webp" 
       seamless-poster shadow-intensity="1" camera-controls>
      </model-viewer>
</div>

CSS below

The width would fail to style correctly with 100% or auto therefore a 50% width to height ratio is maintained by vh.

.model-view-css-fix{
  object-fit: contain;
  height: 80vh;
  width:auto;  
}
model-viewer {
  width: 40vh;
  height: 80vh;
} 
Udesh
  • 1,919
  • 3
  • 20
  • 26
0

Just wrap model-viewer in a div and set the height and width attributes with the inherit value. Make sure divs have height and width set to an initial value of your choice.

div{
    height: 50vh;
    width: 50vw;
}
model-viewer{
    height: inherit;
    width: inherit;
}
CcmU
  • 780
  • 9
  • 22