我一直在跟踪视频以在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)
答案 0 :(得分:0)
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