chrome 的 <model-viewer> 因承诺拒绝而暂停

问题描述

我正在尝试将画布(fabric.js)中的纹理分配给模型查看器的 baseColorTexture。但没有运气。错误在承诺拒绝时暂停。我需要指导。谢谢

var img = new Image();
img.src = document.getElementById('canvas').toDataURL('image/jpeg',1.0);
const modelViewerTexture = document.querySelector('model-viewer');
modelViewerTexture.model.materials[0].pbrMetallicRoughness['baseColorTexture'].texture.source.setURI(img);

解决方法

我已经找到了解决方案

var can = document.getElementById('canvas').toDataURL('image/jpeg',1.0)
const modelViewerTexture = document.querySelector('model-viewer')

localStorage.setItem('imgData',can)
modelViewerTexture.model.materials[0].pbrMetallicRoughness['baseColorTexture'].texture.source.setURI(localStorage.getItem('imgData'))