Three.JS UTF8装载机

时间:2012-07-28 19:14:27

标签: three.js

我正在尝试使用Won的WebGL Loader(http://code.google.com/p/webgl-loader/)在Three.JS中显示已转换为UTF8格式的3D模型。我不知道如何将从WebGL Loader输出的元数据转换为Three.JS所期望的内容,而Google搜索和阅读源代码并未提供任何见解。 WebGLLoader的输出和下面列出的Three.JS的输入要求。

WebGL Loader输出:

MODELS['abc_normals.obj'] = {
  materials: {
  },
  decodeParams: {
    decodeOffsets: [-8192,-88,-2278,0,0,-511,-511,-511],
    decodeScales: [0.012115,0.012115,0.012115,0.000978,0.000978,0.001957,0.001957,0.001957],
  },
  urls: {
    'abc_normals.utf8': [
      { material: '',
        attribRange: [0, 8288],
        indexRange: [66304, 14914],
        bboxes: 111046,
        names: ['default', ],
        lengths: [44742, ],
      },
    ],
  }
};

Three.JS要求:

{ scale: 0.815141, offsetX: -0.371823, offsetY: -0.011920, offsetZ: -0.416061 }

2 个答案:

答案 0 :(得分:1)

您是否正在使用r50,就像webgl-loader推荐的首页一样?我不认为之后的输出与three.js加载器兼容。

答案 1 :(得分:0)

您列出的输出是javascript数据结构,但THREE.js期望JSON。要使这个有效的json,它需要像这样:

{
  "materials": {
  },
  "decodeParams": {
    "decodeOffsets": [-8192,-88,-2278,0,0,-511,-511,-511],
    "decodeScales": [0.012115,0.012115,0.012115,0.000978,0.000978,0.001957,0.001957,0.001957],
  },
  "urls": {
    "abc_normals.utf8": [
      { "material": "",
    "attribRange": [0, 8288],
    "indexRange": [66304, 14914],
    "bboxes": 111046,
    "names": ["default", ],
    "lengths": [44742, ],
      },
    ],
  }
};

自动转换可以通过加载JS然后将模型保存为JSON。您可以在Chrome或Firef中试用此功能

MODELS={}
(insert your .js here)
JSON.stringify(MODELS)