|
604 | 604 | interfaceHtml, |
605 | 605 | labelHtml, |
606 | 606 | searchSitesJson, |
| 607 | + searchScenesJson, |
607 | 608 | keyboardHighlightCanvasCtx, |
608 | 609 | keyMap, |
609 | 610 | fontJson, |
|
661 | 662 | } |
662 | 663 | }; |
663 | 664 | }), |
| 665 | + fetch('scenes.json') |
| 666 | + .then(res => res.json()) |
| 667 | + .then(scenesJson => { |
| 668 | + return s => { |
| 669 | + console.log("scenes.json"); |
| 670 | + const maxResults = 12; |
| 671 | + if (s) { |
| 672 | + const regexps = s.split(/\s/).filter(s => !!s).map(s => new RegExp(escapeRegExp(s), 'i')); |
| 673 | + const results = []; |
| 674 | + for (let i = 0; i < scenesJson.length; i++) { |
| 675 | + const site = scenesJson[i]; |
| 676 | + if (regexps.some(regexp => regexp.test(site.label) || regexp.test(site.url))) { |
| 677 | + results.push(site); |
| 678 | + if (results.length >= maxResults) { |
| 679 | + break; |
| 680 | + } |
| 681 | + } |
| 682 | + } |
| 683 | + return results; |
| 684 | + } else { |
| 685 | + return scenesJson.slice(0, maxResults); |
| 686 | + } |
| 687 | + }; |
| 688 | + }), |
664 | 689 | new Promise((accept, reject) => { |
665 | 690 | const img = new Image(); |
666 | 691 | img.crossOrigin = 'Anonymous'; |
|
3257 | 3282 | } |
3258 | 3283 | }; |
3259 | 3284 |
|
3260 | | - const searchResults = searchSitesJson(searchString); |
| 3285 | + console.log(" ------ selectedTab = " + selectedTab); |
| 3286 | + if (selectedTab === 1) { |
| 3287 | + var searchResults = searchSitesJson(searchString); |
| 3288 | + } else if (selectedTab === 2) { |
| 3289 | + var searchResults = searchScenesJson(searchString); |
| 3290 | + } |
3261 | 3291 |
|
3262 | 3292 | uiIframe.contentWindow.postMessage({ |
3263 | 3293 | method: 'render', |
|
3350 | 3380 |
|
3351 | 3381 | let items = []; |
3352 | 3382 | let text = 'https://'; |
3353 | | - const measures = []; |
3354 | | - let cursor = text.length; |
| 3383 | + let sceneText = ''; |
| 3384 | + const urlMeasures = []; |
| 3385 | + const sceneMeasures = []; |
| 3386 | + let urlCursor = text.length; |
| 3387 | + let sceneCursor = sceneText.length; |
3355 | 3388 | const canvas = document.createElement('canvas'); |
3356 | 3389 | canvas.width = uiSize; |
3357 | 3390 | canvas.height = uiSize; |
3358 | 3391 | const ctx = canvas.getContext('2d'); |
3359 | 3392 | ctx.font = '300 80px Open Sans'; |
3360 | | - const _updateMeasures = () => { |
3361 | | - measures.length = 0; |
3362 | | - measures.push(0); |
| 3393 | + const _updateUrlMeasures = () => { |
| 3394 | + urlMeasures.length = 0; |
| 3395 | + urlMeasures.push(0); |
3363 | 3396 | const {width: barWidth} = ctx.measureText('['); |
3364 | 3397 | for (let i = 1; i <= text.length; i++) { |
3365 | 3398 | const {width} = ctx.measureText('[' + text.slice(0, i) + ']'); |
3366 | | - measures.push(width - barWidth*2); |
| 3399 | + urlMeasures.push(width - barWidth*2); |
| 3400 | + } |
| 3401 | + }; |
| 3402 | + _updateUrlMeasures(); |
| 3403 | + const _updateSceneMeasures = () => { |
| 3404 | + sceneMeasures.length = 0; |
| 3405 | + sceneMeasures.push(0); |
| 3406 | + const {width: barWidth} = ctx.measureText('['); |
| 3407 | + for (let i = 1; i <= sceneText.length; i++) { |
| 3408 | + const {width} = ctx.measureText('[' + sceneText.slice(0, i) + ']'); |
| 3409 | + sceneMeasures.push(width - barWidth*2); |
3367 | 3410 | } |
3368 | 3411 | }; |
3369 | | - _updateMeasures(); |
| 3412 | + _updateSceneMeasures(); |
3370 | 3413 |
|
3371 | 3414 | const urlInputPadding = [40, 53]; |
| 3415 | + const sceneInputPadding = [40, 53]; |
3372 | 3416 | const _updateTextureStatic = () => { |
3373 | | - const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input'); |
3374 | 3417 |
|
| 3418 | + const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input'); |
3375 | 3419 | if (urlInputAnchor) { |
3376 | 3420 | ctx.fillStyle = '#f2f3f5'; |
3377 | 3421 | ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, urlInputAnchor.width - urlInputPadding[0]*2 + 4, urlInputAnchor.height*0.6); |
|
3381 | 3425 | ctx.fillText(text, urlInputAnchor.x + urlInputPadding[0], urlInputAnchor.bottom - urlInputPadding[1]); |
3382 | 3426 |
|
3383 | 3427 | if (keyboardFocus) { |
3384 | | - ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] + measures[cursor] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, 6, urlInputAnchor.height*0.6); |
| 3428 | + ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] + urlMeasures[urlCursor] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, 6, urlInputAnchor.height*0.6); |
| 3429 | + } |
| 3430 | + } |
| 3431 | + |
| 3432 | + const sceneInputAnchor = anchors.find(anchor => anchor.id === 'scene-input'); |
| 3433 | + if (sceneInputAnchor) { |
| 3434 | + ctx.fillStyle = '#f2f3f5'; |
| 3435 | + ctx.fillRect(sceneInputAnchor.x + sceneInputPadding[0] - 4, sceneInputAnchor.y + sceneInputAnchor.height*0.2, sceneInputAnchor.width - sceneInputPadding[0]*2 + 4, sceneInputAnchor.height*0.6); |
| 3436 | + |
| 3437 | + ctx.fillStyle = 'black'; |
| 3438 | + ctx.textBaseline = 'bottom'; |
| 3439 | + ctx.fillText(sceneText, sceneInputAnchor.x + sceneInputPadding[0], sceneInputAnchor.bottom - sceneInputPadding[1]); |
| 3440 | + |
| 3441 | + if (keyboardFocus) { |
| 3442 | + ctx.fillRect(sceneInputAnchor.x + sceneInputPadding[0] + sceneMeasures[sceneCursor] - 4, sceneInputAnchor.y + sceneInputAnchor.height*0.2, 6, sceneInputAnchor.height*0.6); |
3385 | 3443 | } |
3386 | 3444 | } |
3387 | 3445 |
|
|
3585 | 3643 |
|
3586 | 3644 | const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input'); |
3587 | 3645 | const xOffset = x - urlInputAnchor.x - urlInputPadding[0]; |
3588 | | - cursor = measures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1]; |
| 3646 | + urlCursor = urlMeasures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1]; |
| 3647 | + } else if (id === 'scene-input') { |
| 3648 | + const {x, y} = intersectionSpec; |
| 3649 | + |
| 3650 | + keyboardFocus = { |
| 3651 | + textMesh: mesh, |
| 3652 | + caretMesh: mesh, |
| 3653 | + }; |
| 3654 | + |
| 3655 | + const sceneInputAnchor = anchors.find(anchor => anchor.id === 'scene-input'); |
| 3656 | + const xOffset = x - sceneInputAnchor.x - sceneInputPadding[0]; |
| 3657 | + sceneCursor = sceneMeasures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1]; |
3589 | 3658 | } else if (id === 'tab-1') { |
3590 | 3659 | _selectTab(1); |
3591 | 3660 | } else if (id === 'tab-2') { |
|
3662 | 3731 | } */ |
3663 | 3732 | }; |
3664 | 3733 |
|
3665 | | - mesh.getText = () => text; |
| 3734 | + mesh.getText = () => { |
| 3735 | + if (selectedTab === 1){ |
| 3736 | + return text; |
| 3737 | + } else if (selectedTab === 2) { |
| 3738 | + return sceneText; |
| 3739 | + } |
| 3740 | + } |
3666 | 3741 | mesh.setText = newText => { |
3667 | | - text = newText; |
3668 | | - _updateMeasures(); |
| 3742 | + if (selectedTab === 1){ |
| 3743 | + text = newText; |
| 3744 | + _updateUrlMeasures(); |
| 3745 | + } else if (selectedTab === 2) { |
| 3746 | + sceneText = newText; |
| 3747 | + _updateSceneMeasures(); |
| 3748 | + } |
3669 | 3749 | _updateTextureDynamic(); |
3670 | 3750 | }; |
3671 | | - mesh.getValue = () => cursor; |
| 3751 | + mesh.getValue = () => { |
| 3752 | + if (selectedTab === 1){ |
| 3753 | + console.log("getValue of urlCursor = " + urlCursor); |
| 3754 | + return urlCursor; |
| 3755 | + } else if (selectedTab === 2) { |
| 3756 | + console.log("getValue of sceneCursor = " + sceneCursor); |
| 3757 | + return sceneCursor; |
| 3758 | + } |
| 3759 | + }; |
3672 | 3760 | mesh.setValue = newValue => { |
3673 | | - cursor = newValue; |
| 3761 | + if (selectedTab === 1){ |
| 3762 | + urlCursor = newValue; |
| 3763 | + console.log("set urlCursor = " + newValue); |
| 3764 | + } else if (selectedTab === 2) { |
| 3765 | + sceneCursor = newValue; |
| 3766 | + console.log("set sceneCursor = " + newValue); |
| 3767 | + } |
3674 | 3768 | _updateTextureStatic(); |
3675 | 3769 | }; |
3676 | 3770 | mesh.refresh = _updateTextureStatic; |
|
3828 | 3922 |
|
3829 | 3923 | return object; |
3830 | 3924 | })(); |
3831 | | - mesh.add(keyboardMesh); |
| 3925 | + if (fakeXrDisplay) { |
| 3926 | + mesh.add(keyboardMesh); |
| 3927 | + } |
3832 | 3928 |
|
3833 | 3929 | const appIconMeshes = new THREE.Object3D(); |
3834 | 3930 | scene.add(appIconMeshes); |
|
0 commit comments