|
20 | 20 | <script src="file-type.js"></script> |
21 | 21 | </head> |
22 | 22 | <body> |
| 23 | + <xr-site id=root></xr-site> |
23 | 24 | <script type=module> |
24 | 25 | (async () => { |
25 | 26 |
|
|
1204 | 1205 | const moveMesh = currentMoveMeshes[i]; |
1205 | 1206 | if (moveMesh) { |
1206 | 1207 | const {xrIframe} = moveMesh; |
1207 | | - layers.splice(layers.indexOf(xrIframe), 1); |
1208 | | - xrIframe.destroy(); |
1209 | | - scene.remove(moveMesh); |
1210 | | - scene.remove(moveMesh.labelMesh); |
1211 | | - moveMeshes.splice(moveMeshes.indexOf(moveMesh), 1); |
| 1208 | + xrIframe.parentNode.removeChild(xrIframe); |
1212 | 1209 | currentMoveMeshes[i] = null; |
1213 | 1210 | } |
1214 | 1211 | } |
|
3119 | 3116 | // const trayMesh = _makeTrayMesh(); |
3120 | 3117 | // scene.add(trayMesh); |
3121 | 3118 |
|
| 3119 | +class XRSite extends HTMLElement { |
| 3120 | + constructor() { |
| 3121 | + super(); |
| 3122 | + |
| 3123 | + this.observer = new MutationObserver(mutations => { |
| 3124 | + this.handleMutations(mutations); |
| 3125 | + }); |
| 3126 | + this.observer.observe(this, { |
| 3127 | + childList: true, |
| 3128 | + }); |
| 3129 | + } |
| 3130 | + update() { |
| 3131 | + this.handleMutations(this.observer.takeRecords()); |
| 3132 | + } |
| 3133 | + handleMutations(mutations) { |
| 3134 | + for (let i = 0; i < mutations.length; i++) { |
| 3135 | + const {addedNodes, removedNodes} = mutations[i]; |
| 3136 | + |
| 3137 | + for (let j = 0; j < removedNodes.length; j++) { |
| 3138 | + const removedNode = removedNodes[j]; |
| 3139 | + |
| 3140 | + if (removedNode instanceof XRIFrame) { |
| 3141 | + const xrIframe = removedNode; |
| 3142 | + |
| 3143 | + layers.splice(layers.indexOf(xrIframe), 1); |
| 3144 | + xrIframe.destroy(); |
| 3145 | + |
| 3146 | + const {moveMesh} = xrIframe; |
| 3147 | + scene.remove(moveMesh); |
| 3148 | + scene.remove(moveMesh.labelMesh); |
| 3149 | + moveMeshes.splice(moveMeshes.indexOf(moveMesh), 1); |
| 3150 | + } |
| 3151 | + } |
| 3152 | + for (let j = 0; j < addedNodes.length; j++) { |
| 3153 | + const addedNode = addedNodes[j]; |
| 3154 | + |
| 3155 | + if (addedNode instanceof XRIFrame) { |
| 3156 | + const xrIframe = addedNode; |
| 3157 | + |
| 3158 | + layers.push(xrIframe); |
| 3159 | + |
| 3160 | + const moveMesh = _makeMoveMesh('volume'); |
| 3161 | + moveMesh.xrIframe = xrIframe; |
| 3162 | + moveMesh.startTime = Date.now(); |
| 3163 | + scene.add(moveMesh); |
| 3164 | + moveMeshes.push(moveMesh); |
| 3165 | + xrIframe.moveMesh = moveMesh; |
| 3166 | + |
| 3167 | + const labelMesh = _makeLabelMesh(xrIframe.name || xrIframe.src); |
| 3168 | + scene.add(labelMesh); |
| 3169 | + moveMesh.labelMesh = labelMesh; |
| 3170 | + } |
| 3171 | + } |
| 3172 | + } |
| 3173 | + } |
| 3174 | +} |
| 3175 | +customElements.define('xr-site', XRSite); |
| 3176 | +const root = document.getElementById('root'); |
| 3177 | + |
3122 | 3178 | const uiSize = 2048; |
3123 | 3179 | let renderIds = 0; |
3124 | 3180 | const _renderUi = (searchString, selectedTab) => new Promise((accept, reject) => { |
|
3485 | 3541 | } else if (href) { |
3486 | 3542 | const xrIframe = document.createElement('xr-iframe'); |
3487 | 3543 | xrIframe.src = href; |
3488 | | - layers.push(xrIframe); |
3489 | | - |
3490 | | - const moveMesh = _makeMoveMesh('volume'); |
3491 | | - moveMesh.xrIframe = xrIframe; |
3492 | | - moveMesh.startTime = Date.now(); |
3493 | | - scene.add(moveMesh); |
3494 | | - moveMeshes.push(moveMesh); |
3495 | | - currentMoveMeshes[controllerIndex] = moveMesh; |
| 3544 | + xrIframe.name = name; |
| 3545 | + root.appendChild(xrIframe); |
| 3546 | + root.update(); // force mutation observer to run |
3496 | 3547 |
|
3497 | | - const labelMesh = _makeLabelMesh(name || href); |
3498 | | - scene.add(labelMesh); |
3499 | | - moveMesh.labelMesh = labelMesh; |
| 3548 | + currentMoveMeshes[controllerIndex] = xrIframe.moveMesh; |
3500 | 3549 | } /* else { |
3501 | 3550 | console.log('no match', intersectionSpec, new Error().stack); |
3502 | 3551 | } */ |
|
0 commit comments