|
3630 | 3630 | if (!landState) { |
3631 | 3631 | let live = true; |
3632 | 3632 | landState = { |
| 3633 | + loaded: false, |
3633 | 3634 | disconnect() { |
3634 | 3635 | live = false; |
3635 | 3636 | }, |
|
4286 | 4287 |
|
4287 | 4288 | _rtcConnect('land', loginToken.name, 'land', async state => { |
4288 | 4289 | await p; |
4289 | | - const xrSite = state.childNodes.find(childNode => childNode.nodeName === 'xr-site'); |
4290 | | - const xrIframes = xrSite.childNodes.filter(childNode => childNode.nodeName === 'xr-iframe'); |
4291 | | - console.log('got land xr iframes', state, xrIframes); |
| 4290 | + |
| 4291 | + const landXrIframe = root.childNodes[0]; |
| 4292 | + const extentXrIframes = _getChildXrIframes(landXrIframe); |
| 4293 | + const assetXrIframes = extentXrIframes.map(extentXrIframe => _getChildXrIframes(extentXrIframe)).flat(); |
| 4294 | + |
| 4295 | + const stateXrSite = state.childNodes.find(node => node.tagName === 'xr-site'); |
| 4296 | + const stateXrIframes = stateXrSite ? stateXrSite.childNodes.filter(node => node.tagName === 'xr-iframe') : []; |
| 4297 | + for (let i = 0; i < stateXrIframes.length; i++) { |
| 4298 | + const stateXrIframe = stateXrIframes[i]; |
| 4299 | + if (stateXrIframe.attrs) { |
| 4300 | + const idAttr = stateXrIframe.attrs.find(attr => attr.name === 'id'); |
| 4301 | + if (idAttr) { |
| 4302 | + const id = idAttr.value; |
| 4303 | + const xrIframe = assetXrIframes.find(xrIframe => xrIframe.id === id); |
| 4304 | + console.log('set attrs', xrIframe, stateXrIframe.attrs); |
| 4305 | + if (xrIframe) { |
| 4306 | + for (let j = 0; j < stateXrIframe.attrs.length; j++) { |
| 4307 | + const attr = stateXrIframe.attrs[j]; |
| 4308 | + const {name, value} = attr; |
| 4309 | + xrIframe.setAttribute(name, value); |
| 4310 | + } |
| 4311 | + } |
| 4312 | + } |
| 4313 | + } |
| 4314 | + } |
| 4315 | + landState.loaded = true; |
4292 | 4316 | }); |
4293 | 4317 |
|
4294 | 4318 | const p = _connectLand(); |
|
5753 | 5777 | } |
5754 | 5778 | } |
5755 | 5779 | } |
| 5780 | + |
| 5781 | + if (rtcWs && landState && landState.loaded) { |
| 5782 | + for (let i = 0; i < assetMeshes.length; i++) { |
| 5783 | + const moveMesh = assetMeshes[i]; |
| 5784 | + const {xrIframe} = moveMesh; |
| 5785 | + rtcWs.send(JSON.stringify({ |
| 5786 | + method: 'editState', |
| 5787 | + spec: { |
| 5788 | + keyPath: [0, '#' + xrIframe.id], |
| 5789 | + method: 'setAttributes', |
| 5790 | + values: [ |
| 5791 | + { |
| 5792 | + key: 'position', |
| 5793 | + value: xrIframe.getAttribute('position'), |
| 5794 | + }, |
| 5795 | + { |
| 5796 | + key: 'orientation', |
| 5797 | + value: xrIframe.getAttribute('orientation'), |
| 5798 | + }, |
| 5799 | + { |
| 5800 | + key: 'data', |
| 5801 | + value: xrIframe.getAttribute('data'), |
| 5802 | + }, |
| 5803 | + ], |
| 5804 | + }, |
| 5805 | + })); |
| 5806 | + } |
| 5807 | + } |
5756 | 5808 | }; |
5757 | 5809 | _updateCurrentMoveMeshes(); |
5758 | 5810 |
|
|
0 commit comments