Google模型查看器没有显示输出
因此,我使用Google的模型查看器显示GLB文件。但这似乎正在抛出这些错误:
>Access to fetch at 'file:///C:/Users/User/Desktop/Untitled.glb' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
>Failed to load resource: net::ERR_FAILED
>model-viewer.js:50001 TypeError: Failed to fetch
at co.load (model-viewer.js:36818:3)
at Mh.load (model-viewer.js:44762:10)
at model-viewer.js:49881:16
at new Promise (<anonymous>)
at model-viewer.js:49880:12
at Jc.preload (model-viewer.js:49988:34)
at Jc.load (model-viewer.js:50018:20)
at n (model-viewer.js:51575:73)
at new Promise (<anonymous>)
at Bu.setSource (model-viewer.js:51572:26)
(anonymous) @ model-viewer.js:50001
我的代码&gt;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
</head>
<body>
<!-- Use it like any other HTML element -->
<model-viewer style = "width:1050px;height:1050px;" src="Untitled.glb" camera-controls ></model-viewer>
</body>
</html>
我从此网站获得了代码模型查看器
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不允许从
file://
直接加载cdn [reference] 。您可以使用 glitch 他们的文件系统与您通常使用的文件系统相似,而且它提供了免费的在线托管和自动保存选项。这是 model-viewer示例在glitch上。Use a CDN instead direct loading from
file://
is not allowed [reference]. You can use glitch their file system is similar to what you would normally use plus it provides free online hosting and auto-saving options. Here is a model-viewer example on glitch.解决该问题的简单方法是将GLB文件转换为dataUri,然后像这样加载:
Simple way to solve it is by converting the glb file to a DataURI and then loading it like this: