【问题标题】:Threejs blender exporter exports in wrong formatThreejs 搅拌器导出器以错误的格式导出
【发布时间】:2015-03-20 15:24:03
【问题描述】:

我正在尝试借助提供的blender exporter 将搅拌机模型导出到threejs json。在解析 json 文件时出现错误:

Uncaught TypeError: Cannot read property 'length' of undefined

json 文件如下所示(省略顶点和面):

{
    "textures": [],
    "metadata": {
        "version": 4.3,
        "sourceFile": "UV-World.blend",
        "type": "Object",
        "generator": "io_three"
    },
    "images": [],
    "materials": [],
    "object": {
        "matrix": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
        "children": [{
            "type": "Mesh",
            "name": "Kugel",
            "uuid": "5051D840-9982-4F9A-8CFF-36303B38E091",
            "position": [0.0,0.0,0.0],
            "rotation": [-1.5707964897155762,0.0,0.0],
            "scale": [1.0,0.9999999403953552,0.9999999403953552],
            "visible": true,
            "castShadow": true,
            "receiveShadow": true,
            "geometry": "DEAE2CE2-9824-4F91-BE4C-1C80BEDC566A"
        }],
        "type": "Scene",
        "uuid": "8C543616-2AB0-4D1D-B76D-549E32A0E468"
    },
    "geometries": [{
        "type": "Geometry",
        "data": {
            "name": "KugelGeometry",
            "metadata": {
                "version": 3,
                "faces": 512,
                "vertices": 482,
                "generator": "io_three"
            },
            "vertices": [...],
            "faces": [...]
        },
        "uuid": "DEAE2CE2-9824-4F91-BE4C-1C80BEDC566A"
    }]
}

这似乎不在format that threejs expects 中。如果我手动将 json 更改为以下threejs 解析并按预期显示模型。

{
    "scale": 1,
    "vertices": [...],
    "faces": [...]
}

向/从 obj 导出和导入按预期工作。

因为我找不到任何人也有这个问题,我猜这是一个使用错误。我是搅拌机的新手,所以也许我在那里做错了什么?我正在使用刚从存储库克隆的 Blender 2.73a 和threejs。

【问题讨论】:

  • 向我们展示您的加载代码。

标签: javascript json three.js


【解决方案1】:

我怀疑您使用的是JSONLoader。尝试改用ObjectLoader

【讨论】:

  • JSONLoader 是否仅适用于 format version 3,而 ObjectLoader 是第 4 版?
  • @syntonym 是正确的!下一个版本应该会抛出一个控制台错误。
  • 这里是使用 ObjectLoader 加载的完整代码。 var loader = new THREE.ObjectLoader(); loader.load('models.json', function(obj){ console.log(obj); scene.add(obj); });
【解决方案2】:

如果您想使用 JSONLoader,请取消选中 scene 选项。然后,您将拥有一个单一的网格 JSON 文件,正如您所期望的那样。

【讨论】:

  • 它是 Blender Exporter 的旧版本。不是 Clara.io。如果您使用 Blender,只需使用最新的并取消选中所有场景项目。
猜你喜欢
  • 2015-06-23
  • 2012-02-07
  • 2017-09-03
  • 2017-07-08
  • 2012-02-02
  • 1970-01-01
  • 2017-06-15
  • 2016-02-28
  • 1970-01-01
相关资源
最近更新 更多