【发布时间】:2022-07-26 15:15:05
【问题描述】:
所以,我使用 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
我的代码>
<!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>
我从这个网站得到了代码Model Viewer
【问题讨论】:
-
检查一次文件的路径。因为你的代码完全没问题
-
我的文件很完美。我的意思是我的 HTML 文件和 GLB 文件在同一个目录中
-
你在使用 VS Code 的实时服务器扩展吗?
-
没有,我直接打开了。
标签: javascript html 3d model-viewer