aframe - 如何将 JSON 数据加载到 A-Frame 组件中?

标签 aframe

将自定义 JSON 文件作为数据加载到 A-frame 组件中的最佳方法是什么?例如,JSON 文件可能包含点的坐标。我想将文件作为 Assets 加载并在组件中使用解析的 json 对象。

{"coordinates": [{"x": 0, "y": 1, "z": 2}, // ...]}

最佳答案

您可以 define your own property type in the schema that parses data how you wish .

要从组件解析 JSON,请创建 parse执行 JSON.parse 的函数:

AFRAME.registerComponent('foo', {
  schema: {
    jsonData: {
      parse: JSON.parse,
      stringify: JSON.stringify
    }
  }
});

然后使用组件:
el.setAttribute('foo', 'jsonData', yourJsonData);

或者:
<a-entity foo='jsonData: {"coordinates": [{"x": 0, "y": 1, "z": 2}]}'></a-entity>

关于aframe - 如何将 JSON 数据加载到 A-Frame 组件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41545518/

相关文章:

javascript - Substance Painter PBR金属 Material 在A Frame中显示黑色

javascript - 在未连接 VR 耳机的情况下使用桌面时如何在 A-Frame 中显示分割 VR 模式

aframe - 缩放 Aframe 模型

javascript - 带有javascript split id的Aframe动画

augmented-reality - 如何将 a-frame 对象定位到标记的左下角,并使其宽度等于标记的宽度?

augmented-reality - A-Frame & ar.js : Multiple markers & boxes

javascript - 触摸 Ar.js 中的 ar 对象

javascript - 尝试通过 A-Frame 内的 Three.js 编辑 Material 的侧面属性会导致渲染不正确

javascript - 为A-Frame中的所有对象加载html和js后调用函数

javascript - 始终通过计算 A-Frame 中对象的边界框来获得 Infinity