|
548 | 548 | keyboardImg, |
549 | 549 | uiIframe, |
550 | 550 | interfaceHtml, |
| 551 | + labelHtml, |
551 | 552 | searchSitesJson, |
552 | 553 | keyboardHighlightCanvasCtx, |
553 | 554 | keyMap, |
|
582 | 583 | document.body.appendChild(iframe); |
583 | 584 | }), |
584 | 585 | fetch('interface.html').then(res => res.text()), |
| 586 | + fetch('label.html').then(res => res.text()), |
585 | 587 | fetch('sites.json') |
586 | 588 | .then(res => res.json()) |
587 | 589 | .then(sitesJson => { |
|
1770 | 1772 | return object; |
1771 | 1773 | }; |
1772 | 1774 |
|
1773 | | -const _makeLabelMesh = () => { |
1774 | | - const geometry = new THREE.PlaneBufferGeometry(1, 0.1); |
| 1775 | +const _makeLabelMesh = label => { |
| 1776 | + const geometry = new THREE.PlaneBufferGeometry(2, 2/8); |
| 1777 | + |
| 1778 | + _renderLabel(label) |
| 1779 | + .then(async result => { |
| 1780 | + if (result.data) { |
| 1781 | + // result.data = await createImageBitmap(new ImageData(new Uint8ClampedArray(result.data.buffer, result.data.byteOffset, result.data.byteLength), uiSize, uiSize/8)); |
| 1782 | + // texture.image = result.data; |
| 1783 | + texture.image = new ImageData(new Uint8ClampedArray(result.data.buffer, result.data.byteOffset, result.data.byteLength), uiSize, uiSize/8); |
| 1784 | + texture.needsUpdate = true; |
| 1785 | + } |
| 1786 | + }); |
| 1787 | + const texture = new THREE.Texture( |
| 1788 | + null, |
| 1789 | + THREE.UVMapping, |
| 1790 | + THREE.ClampToEdgeWrapping, |
| 1791 | + THREE.ClampToEdgeWrapping, |
| 1792 | + THREE.LinearFilter, |
| 1793 | + THREE.LinearFilter, |
| 1794 | + THREE.RGBAFormat, |
| 1795 | + THREE.UnsignedByteType, |
| 1796 | + 16 |
| 1797 | + ); |
1775 | 1798 | const material = new THREE.MeshBasicMaterial({ |
1776 | | - color: 0x000080, |
| 1799 | + map: texture, |
| 1800 | + // color: 0x000080, |
| 1801 | + // transparent: true, |
1777 | 1802 | }); |
| 1803 | + |
1778 | 1804 | const mesh = new THREE.Mesh(geometry, material); |
1779 | 1805 | mesh.frustumCulled = false; |
1780 | 1806 | return mesh; |
|
3127 | 3153 | port: mc.port2, |
3128 | 3154 | }, '*', [mc.port2]); |
3129 | 3155 | }); |
| 3156 | +const _renderLabel = label => new Promise((accept, reject) => { |
| 3157 | + if (renderIds > 0) { |
| 3158 | + uiIframe.contentWindow.postMessage({ |
| 3159 | + method: 'cancel', |
| 3160 | + id: renderIds, |
| 3161 | + }); |
| 3162 | + } |
| 3163 | + |
| 3164 | + const start = Date.now(); |
| 3165 | + |
| 3166 | + const mc = new MessageChannel(); |
| 3167 | + mc.port1.onmessage = e => { |
| 3168 | + const {data} = e; |
| 3169 | + const {error, result} = data; |
| 3170 | + |
| 3171 | + console.log('render label', result); |
| 3172 | + |
| 3173 | + if (result) { |
| 3174 | + console.log('time taken', Date.now() - start); |
| 3175 | + |
| 3176 | + accept(result); |
| 3177 | + } else { |
| 3178 | + reject(error); |
| 3179 | + } |
| 3180 | + }; |
| 3181 | + |
| 3182 | + uiIframe.contentWindow.postMessage({ |
| 3183 | + method: 'render', |
| 3184 | + id: ++renderIds, |
| 3185 | + htmlString: labelHtml, |
| 3186 | + templateData: { |
| 3187 | + label, |
| 3188 | + }, |
| 3189 | + width: uiSize, |
| 3190 | + height: uiSize/8, |
| 3191 | + port: mc.port2, |
| 3192 | + }, '*', [mc.port2]); |
| 3193 | +}); |
3130 | 3194 |
|
3131 | 3195 | const _makeScreenMesh = () => { |
3132 | 3196 | const s = 2; |
|
3372 | 3436 | type: 'screen', |
3373 | 3437 | id: anchor && anchor.id, |
3374 | 3438 | href: anchor && anchor.href, |
| 3439 | + name: anchor && anchor.name, |
3375 | 3440 | x: uv.x, |
3376 | 3441 | y: uv.y, |
3377 | 3442 | distance, |
|
3384 | 3449 | mesh.click = (intersectionSpec, controllerIndex) => { |
3385 | 3450 | keyboardFocus = null; |
3386 | 3451 |
|
3387 | | - const {id, href} = intersectionSpec; |
| 3452 | + const {id, href, name} = intersectionSpec; |
3388 | 3453 | if (id === 'url-input') { |
3389 | 3454 | const {x, y} = intersectionSpec; |
3390 | 3455 |
|
|
3408 | 3473 | moveMeshes.push(moveMesh); |
3409 | 3474 | currentMoveMeshes[controllerIndex] = moveMesh; |
3410 | 3475 |
|
3411 | | - const labelMesh = _makeLabelMesh(); |
| 3476 | + const labelMesh = _makeLabelMesh(name || href); |
3412 | 3477 | scene.add(labelMesh); |
3413 | 3478 | moveMesh.labelMesh = labelMesh; |
3414 | 3479 | } /* else { |
|
0 commit comments