google / google/model-viewer

Bug in `scale` or `getDimensions`

Open
#4,167 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
8.2k
Forks
947
PR merge metrics
No merged PRs in 30d

Description

### Description

Unexpected behaviour when trying to scale a model using Puppeteer (but I believe it will be reproduced in any browser).
After scaling at 1.5 times a model size becomes incredibly large according to `getDimensions` and `getBoundingBoxCenter` (see the output below). However, it looks like the problem is in the output of incorrect values for sizes, because the model is rendered as if it had been enlarged correctly.

image

**Code snippet that I used to generate this output**

```
let evalError = await page.evaluate(async () => {
const scale = async (modelViewerTransform) => {
console.log(`dims: ${modelViewerTransform.getDimensions()}`);
console.log(`bbcenter: ${modelViewerTransform.getBoundingBoxCenter()}`);
modelViewerTransform.scale = "1.5 1.5 1.5";
modelViewerTransform.updateFraming();
await modelViewerTransform.updateComplete;
console.log(`dims: ${modelViewerTransform.getDimensions()}`);
console.log(`bbcenter: ${modelViewerTransform.getBoundingBoxCenter()}`);
};
const modelViewer = document.getElementById('snapshot-viewer');
await scale(modelViewer);
})
```

**Model (for additional info: I transformed it with gltf-transform since it has SpecGloss PBR format):**
[robot.glb.zip](https://github.com/google/model-viewer/files/10994178/robot.glb.zip)

**html template:**
```
const defaultAttributes = {
id: 'snapshot-viewer',
style: `background-color: ${backgroundColor};`,
'interaction-prompt': 'none',
src: inputPath,
'animation-crossfade-duration': 0,
'interpolation-decay': 1,
};

validateCustomAttributes(defaultAttributes, modelViewerArgs);

const defaultAttributesString = toHTMLAttributeString(defaultAttributes);
const modelViewerArgsString = toHTMLAttributeString(modelViewerArgs);

let htmlTemplate = `







body {
margin: 0;
}
model-viewer {
--progress-bar-color: transparent;
width: ${width}px;
height: ${height}px;
}






`;

```

### Version

- model-viewer: v3.0.1 (min.js)

### Browser Affected

- [x] Puppeteer, version: 13.7.0

### OS

- [x] Linux

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.