如何将场景转换为data3d的json

时间:2018-05-07 03:24:20

标签: aframe archilogic 3d.io

我有一个开发代码问题,使用开源来获取' 3dio-js'代码。

如何

<a-entity class="io3d-scene" position="" rotation="" io3d-uuid="ddd8f1a11-7f5fs-4fds4-ad3d-ec58cc2cssa817" scale="" visible="">all elements are children </a-entity>

转换为:

  {   "type": "plan",   "children": [
        {
          "type": "level",
          "children": [
             {
               "type": "interior"
             }
             // all elements are children of the level
          ]
        }
 ] }

您有代码示例吗?

非常感谢。

1 个答案:

答案 0 :(得分:0)

你可以用io3d.scene.getSceneStructureFromAframeElements()方法做到这一点 https://3d.io/docs/api/1/scene.html#get-scene-structure-from-a-frame-elements

<a-scene>
  <a-entity io3d-furniture="id:3aff54e2-fdff-44a3-9646-f2db1ea3bbfc" position="3.4 0 1.4"></a-entity>
</a-scene>

<script>
  const el = document.querySelector('[io3d-furniture]')
  const sceneStructure = io3d.scene.getSceneStructureFromAframeElements(el)

  console.log(sceneStructure)

  // result:
  // {
  //   "type": "interior",
  //   "x": 3.4,
  //   "y": 0,
  //   "z": 1.4,
  //   "src": "!3aff54e2-fdff-44a3-9646-f2db1ea3bbfc"
  // }
</script>