aframearchilogic3d.io

How to convert scene to json of data3d


I have a development code issues use open source for '3dio-js' code.

How to will

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

convert to:

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

Do you have a code example?

Thank you very much.


Solution

  • you can do that with the io3d.scene.getSceneStructureFromAframeElements() method 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>