我一直在关注一个在 threejs 中加载 json 图像的视频。但是,当我完全按照视频中的代码进行操作时,当我尝试使用自己的图像时,它不会在浏览器中显示任何内容。该图像是我从网站 clara.io 下载的 json 文件。
提供的是我使用过的js文件中的相关代码。
<script src="js/ObjectLoader.js"></script>
<script>
var loader = new THREE.ObjectLoader();
loader.load
(
'models/standard-male-figure.json',
function(object)
{
scene.add(object);
}
);
camera.position.z = 3;
</script>
这是来自控制台的错误。我认为该视频可能已过时,但我不知道如何解决。
Uncaught SyntaxError: Unexpected token {
three.js:22676 THREE.WebGLRenderer 104
three.js:38584 THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".
three.js:38598 Uncaught TypeError: Cannot set property 'uuid' of undefined
at ObjectLoader.parseGeometries (three.js:38598)
at ObjectLoader.parse (three.js:38274)
at Object.onLoad (three.js:38244)
at XMLHttpRequest.<anonymous> (three.js:34554)
最佳答案
JSONLoader
已于去年年底从 three.js
核心中移除,重命名为 LegacyJSONLoader
。该文件现在位于 examples directory 中.
请下载该文件并将其包含到您的项目中,这有望解决您的问题。但是,您应该考虑避免使用可能使用同样已弃用的 Blender JSON 导出器创建的遗留 JSON 文件。阅读官方 three.js
文档中的以下指南,了解有关更好的替代方案(如 glTF
)的更多信息。
https://threejs.org/docs/index.html#manual/en/introduction/Loading-3D-models
three.js R103
关于javascript - 无法在 threejs 中加载 json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55895900/