如何在Threejs中正确加载Json文件 [英] How to properly load a Json File in Threejs

查看:3843
本文介绍了如何在Threejs中正确加载Json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Blender上完成了几个项目,并决定使用threejs显示其中一个项目,但是该对象没有显示.用关键帧动画加载JSON文件的正确方法是什么?

I have done a couple of projects on Blender and decided to display one of them using threejs, however the object doesn't display. What would be the proper way to load a JSON file with keyframe animation?

这是我要加载的特定JSON文件

以及我正在使用的代码的摘录:

and the extract of the code that I'm using:

var mesh;
function initMesh() {
var loader = new THREE.JSONLoader();
loader.load('./ocean.json', function(geometry, materials) {
    mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));
    mesh.scale.x = 0.75;
    mesh.scale.y = 1;
    mesh.scale.z = 0.75;
    scene.add(mesh);
}, undefined, function (e) {console.log('ERROR: ',e )});

推荐答案

我建议先从其编辑器开始: https://threejs.org/editor/

I would recommend to start with their editor: https://threejs.org/editor/

这里有GUI,您可以在其中导入.json,.obj等. 这是查看您所做工作的快速方法,可以添加灯光,玩材料,添加自定义脚本等. 例如,您可以加载一些示例,删除默认对象,导入模型,按播放,如果您喜欢,请单击发布". 它将下载整个项目,您可以将其上载到服务器,并且可以作为将来工作的基础.

Here you have GUI where you can import .json, .obj, etc. It is a quick way to see what have you done, you can add lights, play with materials, add custom scripts, etc. For example you can load some example, delete default objects, import your model, press play and if you like what you see just hit publish. It will download entire project which you can upload to your server and that can be the base for future work.

快速入门是一个完美的选择,因为它可以正常工作,并且会激发您进行进一步研究和学习的机会.

For a quick start it is perfect because it works and will motivate you to investigate and learn further.

我知道这不是问题的直接答案,但我去过那里,看到所有这些加载程序都无法正常工作令人沮丧,因为从搅拌机或任何原因导出时,您没有选择所有正确的复选框(有可能很多).

I know that this is not direct answer to the question but I've been there and it's frustrating to see all those loaders not working because you didn't select all the right check boxes when exporting from blender or whatever reason (there could be a lot of them).

首先尝试编辑器,弄清楚它的工作原理并继续进行. 只是一个建议

Try editor first, figure out how it works and move on. Just an advice

这篇关于如何在Threejs中正确加载Json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆