|
3627 | 3627 | if (!live) return; |
3628 | 3628 | const xrIframes = _getChildXrIframes(xrIframe); |
3629 | 3629 |
|
3630 | | - const _loadAssetMoveMeshes = () => { |
3631 | | - xrIframes.forEach(async extentXrIframe => { |
3632 | | - await new Promise((accept, reject) => { |
3633 | | - if (extentXrIframe.loaded) { |
3634 | | - accept(); |
3635 | | - } else { |
3636 | | - extentXrIframe.addEventListener('load', accept); |
3637 | | - extentXrIframe.addEventListener('error', reject); |
3638 | | - } |
3639 | | - }); |
3640 | | - |
3641 | | - const assetXrIframes = _getChildXrIframes(extentXrIframe); |
3642 | | - for (let i = 0; i < assetXrIframes.length; i++) { |
3643 | | - const assetXrIframe = assetXrIframes[i]; |
3644 | | - const moveMesh = _makeMoveMesh('volume'); |
3645 | | - const {worldOffset} = assetXrIframe; |
3646 | | - moveMesh.position.fromArray(worldOffset.position); |
3647 | | - moveMesh.quaternion.fromArray(worldOffset.orientation); |
3648 | | - moveMesh.scale.fromArray(worldOffset.scale); |
3649 | | - moveMesh.visible = screenMesh.visible; |
3650 | | - moveMesh.xrIframe = assetXrIframe; |
3651 | | - scene.add(moveMesh); |
3652 | | - assetMeshes.push(moveMesh); |
3653 | | - assetXrIframe.moveMesh = moveMesh; |
3654 | | - |
3655 | | - const labelMesh = _makeLabelMesh(assetXrIframe.name || assetXrIframe.src, 'download'); |
3656 | | - labelMesh.visible = screenMesh.visible; |
3657 | | - labelMesh.moveMesh = moveMesh; |
3658 | | - labelMesh.xrIframe = assetXrIframe; |
3659 | | - scene.add(labelMesh); |
3660 | | - assetLabelMeshes.push(labelMesh); |
3661 | | - |
3662 | | - new assetXrIframe.ownerDocument.defaultView.MutationObserver(mutations => { |
3663 | | - for (let i = 0; i < mutations.length; i++) { |
3664 | | - const mutation = mutations[i]; |
3665 | | - const {attributeName} = mutation; |
3666 | | - if (attributeName === 'position') { |
3667 | | - moveMesh.position.fromArray(assetXrIframe.worldOffset.position); |
3668 | | - } else if (attributeName === 'orientation') { |
3669 | | - moveMesh.quaternion.fromArray(assetXrIframe.worldOffset.orientation); |
3670 | | - } else if (attributeName === 'scale') { |
3671 | | - moveMesh.scale.fromArray(assetXrIframe.worldOffset.scale); |
3672 | | - } |
3673 | | - } |
3674 | | - }).observe(assetXrIframe, { |
3675 | | - attributeFilter: ['position', 'orientation', 'scale'], |
3676 | | - attributes: true, |
3677 | | - }); |
3678 | | - } |
3679 | | - }); |
3680 | | - }; |
3681 | | - _loadAssetMoveMeshes(); |
3682 | | - |
3683 | 3630 | const _loadInventory = () => { |
3684 | 3631 | fetch(`${LAMBDA_URLS.inventory}?email=${encodeURIComponent(loginToken.email)}&token=${encodeURIComponent(loginToken.token)}`) |
3685 | 3632 | .then(res => res.json()) |
|
3787 | 3734 | } |
3788 | 3735 | }; |
3789 | 3736 | _loadGuardians(); |
| 3737 | + |
| 3738 | + const _loadAssetMoveMeshes = async () => { |
| 3739 | + let assetXrIframes = await Promise.all(xrIframes.map(async extentXrIframe => { |
| 3740 | + await new Promise((accept, reject) => { |
| 3741 | + if (extentXrIframe.loaded) { |
| 3742 | + accept(); |
| 3743 | + } else { |
| 3744 | + extentXrIframe.addEventListener('load', accept); |
| 3745 | + extentXrIframe.addEventListener('error', reject); |
| 3746 | + } |
| 3747 | + }); |
| 3748 | + |
| 3749 | + const assetXrIframes = _getChildXrIframes(extentXrIframe); |
| 3750 | + for (let i = 0; i < assetXrIframes.length; i++) { |
| 3751 | + const assetXrIframe = assetXrIframes[i]; |
| 3752 | + const moveMesh = _makeMoveMesh('volume'); |
| 3753 | + const {worldOffset} = assetXrIframe; |
| 3754 | + moveMesh.position.fromArray(worldOffset.position); |
| 3755 | + moveMesh.quaternion.fromArray(worldOffset.orientation); |
| 3756 | + moveMesh.scale.fromArray(worldOffset.scale); |
| 3757 | + moveMesh.visible = screenMesh.visible; |
| 3758 | + moveMesh.xrIframe = assetXrIframe; |
| 3759 | + scene.add(moveMesh); |
| 3760 | + assetMeshes.push(moveMesh); |
| 3761 | + assetXrIframe.moveMesh = moveMesh; |
| 3762 | + |
| 3763 | + const labelMesh = _makeLabelMesh(assetXrIframe.name || assetXrIframe.src, 'download'); |
| 3764 | + labelMesh.visible = screenMesh.visible; |
| 3765 | + labelMesh.moveMesh = moveMesh; |
| 3766 | + labelMesh.xrIframe = assetXrIframe; |
| 3767 | + scene.add(labelMesh); |
| 3768 | + assetLabelMeshes.push(labelMesh); |
| 3769 | + |
| 3770 | + new assetXrIframe.ownerDocument.defaultView.MutationObserver(mutations => { |
| 3771 | + for (let i = 0; i < mutations.length; i++) { |
| 3772 | + const mutation = mutations[i]; |
| 3773 | + const {attributeName} = mutation; |
| 3774 | + if (attributeName === 'position') { |
| 3775 | + moveMesh.position.fromArray(assetXrIframe.worldOffset.position); |
| 3776 | + } else if (attributeName === 'orientation') { |
| 3777 | + moveMesh.quaternion.fromArray(assetXrIframe.worldOffset.orientation); |
| 3778 | + } else if (attributeName === 'scale') { |
| 3779 | + moveMesh.scale.fromArray(assetXrIframe.worldOffset.scale); |
| 3780 | + } |
| 3781 | + } |
| 3782 | + }).observe(assetXrIframe, { |
| 3783 | + attributeFilter: ['position', 'orientation', 'scale'], |
| 3784 | + attributes: true, |
| 3785 | + }); |
| 3786 | + } |
| 3787 | + |
| 3788 | + return assetXrIframes; |
| 3789 | + })); |
| 3790 | + assetXrIframes = assetXrIframes.flat(); |
| 3791 | + |
| 3792 | + const htmlString = `<xr-site>\n${assetXrIframes.map(xrIframe => ' ' + xrIframe.outerHTML).join('\n')}\n</xr-site>\n`; |
| 3793 | + console.log('set html string', htmlString); |
| 3794 | + }; |
| 3795 | + await _loadAssetMoveMeshes(); |
3790 | 3796 | } |
3791 | 3797 | }; |
3792 | 3798 | const _disconnectLand = () => { |
|
0 commit comments